wakame-adapters-tengine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'right_aws'
5
+
6
+ module Tama
7
+ module Controllers
8
+ A = Tama::Apis
9
+
10
+ # A Controller just passes any method calls it gets to its api
11
+ # The api can be whatever class you want it to be.
12
+ #
13
+ # A Controller can contain one api or an array of apis. In case of an array
14
+ # TamaController checks each of its apis in turn and executes the method
15
+ # on the first API that supports it
16
+ class Controller
17
+ attr_accessor :api
18
+
19
+ def initialize(api)
20
+ self.api = api
21
+ end
22
+
23
+ def method_missing(method_name,*args)
24
+ if self.api.is_a? Array
25
+ index = 0
26
+ begin
27
+ self.api[index].send(method_name,*args)
28
+ rescue NoMethodError => e
29
+ index += 1
30
+ raise if index == self.api.length || (not method_name == e.name)
31
+ retry
32
+ end
33
+ else
34
+ api.send(method_name)
35
+ end
36
+ end
37
+ end
38
+
39
+ # The TamaController is a controller that has two apis
40
+ # A RightAws::Ec2 object for handling Amazon Ec2 requests and
41
+ # a WakameApi for handling requests to Wakame-vdc
42
+ class TamaController < Controller
43
+ def initialize(access_key,ec2_host,ec2_port,ec2_protocol,wakame_host,wakame_port,wakame_protocol)
44
+ super([
45
+ A::WakameApi.new(access_key,wakame_host,wakame_port,wakame_protocol),
46
+ RightAws::Ec2.new(access_key,"dummy",{:server => ec2_host,:port => ec2_port,:protocol => ec2_protocol})
47
+ ])
48
+ end
49
+ end
50
+
51
+ # TamaTestController does the same as TamaController but
52
+ # reads output from a file on disk. It doesn't actually make
53
+ # any requests to Wakame or Ec2
54
+ class TamaTestController < TamaController
55
+ def initialize
56
+ self.api = [A::WakameApiTest.new,A::Ec2ApiTest.new]
57
+ end
58
+ end
59
+
60
+ class ControllerFactory
61
+ def self.create_controller(*args)
62
+ case
63
+ when args.first == :test || args.first == "test" then
64
+ TamaTestController.new
65
+ else TamaController.new(*args)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+
5
+ load_path = "#{File.expand_path(File.dirname(__FILE__))}/lib"
6
+ $LOAD_PATH.unshift(load_path) unless $LOAD_PATH.include?(load_path)
7
+
8
+ require 'apis/ec2'
9
+ require 'apis/wakame'
10
+ require 'controllers/controller'
11
+
12
+ module Tama
13
+ # Just a wrapper class for our controller to make the syntax a bit more beautiful ^_~
14
+ class Tama
15
+ def initialize(*args)
16
+ @controller = Controllers::ControllerFactory.create_controller(*args)
17
+ end
18
+
19
+ def method_missing(m,*args)
20
+ @controller.send(m,*args)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ load_path = "#{File.expand_path(File.dirname(__FILE__))}/../lib"
5
+ $LOAD_PATH.unshift(load_path) unless $LOAD_PATH.include?(load_path)
6
+
7
+ require 'tama'
8
+
9
+ def usage
10
+ bin_name = "calltama"
11
+ "Usage:
12
+ ruby #{bin_name} [test] [command] [options]
13
+
14
+ Test:
15
+ Using the word test as the first paremeter causes all output to be read from a file.
16
+
17
+ Commands:
18
+ run_instances # Start a new instance using the data defined in #{bin_name}.yml.
19
+ describe_instances [instance_ids] # Show the alive instances.
20
+ terminate_instances instance_ids # Terminate alive instances.
21
+ describe_images [image_ids] # Describes images in the database.
22
+ describe_host_nodes [host_ids] # Describes host nodes in the database
23
+ describe_instance_specs [spec_ids] # Describes instance specs in the database
24
+
25
+ Examples:
26
+ #{bin_name} test describe_instances
27
+ #{bin_name} run_instances
28
+ #{bin_name} terminate instances i-dlobuy33 i-8390cvle
29
+ #{bin_name} test describe_images wmi-lucid0 wmi-lucid5"
30
+ end
31
+
32
+ if ARGV[0] == "help" || ARGV[0] == "--help" || ARGV[0] == "-h"
33
+ puts usage
34
+ exit 0
35
+ end
36
+
37
+ begin
38
+ require 'yaml'
39
+ config = YAML.load_file File.expand_path('../calltama.yml', __FILE__)
40
+ rescue
41
+ puts "Warning: Config file (calltama.yml) not found."
42
+ config = {}
43
+ end
44
+
45
+ #Arguments for Tama
46
+ Account = config["Account"]
47
+
48
+ Ec2_host = config["Ec2_host"]
49
+ Ec2_port = config["Ec2_port"]
50
+ Ec2_protocol = config["Ec2_protocol"]
51
+
52
+ Wakame_host = config["Wakame_host"]
53
+ Wakame_port = config["Wakame_port"]
54
+ Wakame_protocol = config["Wakame_protocol"]
55
+
56
+ #Put the instances you want to terminate in this array
57
+ Instances_to_terminate = config["Instances_to_terminate"]
58
+
59
+ #Arguments for run_instances
60
+ Image_id = config["Image_id"]
61
+ Min = config["Min"]
62
+ Max = config["Max"]
63
+ Security_Groups = config["Security_Groups"]
64
+ SSH_Key = config["SSH_Key"]
65
+ User_Data = config["User_Data"]
66
+ Addressing_Type = config["Addressing_Type"]
67
+ Instance_Type = config["Instance_Type"]
68
+ HOST = config["HOST"]
69
+
70
+ if ARGV[0] == "test"
71
+ c = Tama::Tama.new(:test)
72
+ args = ARGV.slice(1..ARGV.length) || []
73
+ else
74
+ c = Tama::Tama.new(Account,Ec2_host,Ec2_port,Ec2_protocol,Wakame_host,Wakame_port,Wakame_protocol)
75
+ args = ARGV
76
+ end
77
+
78
+ if args.empty?
79
+ [:run_instances,:terminate_instances,:describe_instances,:describe_images,:describe_host_nodes,:describe_instance_specs].each { |method|
80
+ puts "Testing method: #{method}\n"
81
+ puts "Testing method: #{method}\n".gsub(/./) {|s| "-"}
82
+ p case method
83
+ when :run_instances then c.send(method,Image_id,Min,Max,Security_Groups,SSH_Key, User_Data, Addressing_Type, Instance_Type, nil, nil, HOST)
84
+ when :terminate_instances then c.send(method,Instances_to_terminate)
85
+ else c.send(method)
86
+ end
87
+ puts "\n"
88
+ }
89
+ elsif args[0] == "run_instances"
90
+ p c.run_instances(Image_id,Min,Max,Security_Groups,SSH_Key, User_Data, Addressing_Type, Instance_Type, nil, nil, HOST)
91
+ else
92
+ p c.send(args[0],args.slice(1..ARGV.length) || [])
93
+ end
@@ -0,0 +1,25 @@
1
+ # Arguments for Tama
2
+ Account: "a-shpoolxx"
3
+
4
+ Ec2_host: "192.168.2.22"
5
+ Ec2_port: "9005"
6
+ Ec2_protocol: "http"
7
+
8
+ Wakame_host: "192.168.2.22"
9
+ Wakame_port: "9001"
10
+ Wakame_protocol: "http"
11
+
12
+ #Put the instances you want to terminate in this array
13
+ Instances_to_terminate: []
14
+
15
+ #Arguments for run_instances
16
+ Image_id: 'wmi-lucid5'
17
+ Min: 1
18
+ Max: 1
19
+ Security_Groups: ['sg-demofgr']#['default', 'joske', 'jefke']
20
+ #Security_Groups: ['jefke']
21
+ SSH_Key: 'ssh-demo'
22
+ User_Data: 'joske'
23
+ Addressing_Type: 'public'
24
+ Instance_Type: 'is-demospec'
25
+ HOST: 'hn-demo1'
@@ -0,0 +1,13 @@
1
+ load_path = "#{File.expand_path(File.dirname(__FILE__))}/.."
2
+ $LOAD_PATH.unshift(load_path) unless $LOAD_PATH.include?(load_path)
3
+
4
+ require 'tama'
5
+
6
+ c = Tama::Tama.new(:test)
7
+
8
+ [:run_instances,:terminate_instances,:describe_instances,:describe_images,:describe_host_nodes,:describe_instance_specs].each { |method|
9
+ puts "Testing method: #{method}\n"
10
+ puts "Testing method: #{method}\n".gsub(/./) {|s| "-"}
11
+ p c.send(method)
12
+ puts "\n"
13
+ }
@@ -0,0 +1,31 @@
1
+ # Api parameters
2
+ Account: "a-shpoolxx"
3
+
4
+ Ec2_host: "192.168.2.22"
5
+ Ec2_port: "9005"
6
+ Ec2_protocol: "http"
7
+
8
+ Wakame_host: "192.168.2.22"
9
+ Wakame_port: "9001"
10
+ Wakame_protocol: "http"
11
+
12
+ # Run_instance parameters
13
+ Image_id: 'wmi-lucid0'
14
+ Min: 2
15
+ Max: 3
16
+ Security_Groups:
17
+ sg-demofgr: 'default'
18
+ #ng-5ltkiagj: 'joske'
19
+ #ng-cxiouozg: 'jefke'
20
+ SSH_Key: 'ssh-demo'
21
+ User_Data: 'joske'
22
+ Addressing_Type: 'public'
23
+ Instance_Type: 'is-demospec'
24
+ HOST: 'hn-demo1'
25
+
26
+ describe_host_nodes:
27
+ [hn-demo1]
28
+ describe_instance_specs:
29
+ [is-demo2, is-demospec]
30
+ describe_images:
31
+ [wmi-lucid0, wmi-lucid1, wmi-lucid5, wmi-lucid6]
@@ -0,0 +1,39 @@
1
+ load_path = "#{File.expand_path(File.dirname(__FILE__))}/../../lib"
2
+ $LOAD_PATH.unshift(load_path) unless $LOAD_PATH.include?(load_path)
3
+
4
+ require 'spec_helper'
5
+ require 'tama'
6
+
7
+ require 'yaml'
8
+ config = YAML.load_file File.expand_path('../config.yml', __FILE__)
9
+
10
+ describe "TamaController" do
11
+ tama = Tama::Tama.new(config["Account"],config["Ec2_host"],config["Ec2_port"],config["Ec2_protocol"],config["Wakame_host"],config["Wakame_port"],config["Wakame_protocol"])
12
+ res = tama.run_instances(config["Image_id"],config["Min"],config["Max"],config["Security_Groups"].keys,config["SSH_Key"], config["User_Data"], config["Addressing_Type"], config["Instance_Type"], nil, nil, config["HOST"])
13
+
14
+ describe "run_instances" do
15
+ it_should_behave_like "run_instances", res, config
16
+ it_should_behave_like "run_instances return values", res, config
17
+ end
18
+
19
+ describe "describe_instances" do
20
+ @desc_res = tama.describe_instances(res.map{|i| i[:aws_instance_id]})
21
+ it_should_behave_like "run_instances return values", @desc_res, config
22
+ it_should_behave_like "describe_instances return values", @desc_res, config
23
+ end
24
+
25
+ describe "terminate_instances" do
26
+ @uuids = res.map{|i| i[:aws_instance_id]}
27
+ it_should_behave_like "terminate_instances", tama, @uuids
28
+ end
29
+
30
+ describe "describe_images" do
31
+ it_should_behave_like "describe_images", tama, config["describe_images"]
32
+ end
33
+
34
+ [:describe_host_nodes,:describe_instance_specs].each { |method|
35
+ describe "#{method}" do
36
+ it_should_behave_like "wakame describe method", tama, method, config[method.to_s]
37
+ end
38
+ }
39
+ end
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'time'
4
+
5
+
6
+ shared_examples_for "run_instances" do |result,args|
7
+ it "Should have started a number of instances between #{args["Min"]} and #{args["Max"]}" do
8
+ result.length.should >= args["Min"]
9
+ result.length.should <= args["Max"]
10
+ end
11
+ end
12
+
13
+ shared_examples_for "run_instances return values" do |result,args|
14
+ result.each { |inst_map|
15
+ it "#{inst_map[:aws_instance_id]} should have a proper time value set for :aws_launch_time" do
16
+ Time.parse(inst_map[:aws_launch_time]).utc.xmlschema == inst_map[:aws_launch_time]
17
+ end
18
+
19
+ it "#{inst_map[:aws_instance_id]} should have #{args["Account"]} set as :aws_owner" do
20
+ inst_map[:aws_owner].should == args["Account"]
21
+ end
22
+
23
+ it "#{inst_map[:aws_instance_id]} should have #{args["Security_Groups"].keys.inspect} set as :aws_groups" do
24
+ inst_map[:aws_groups].sort.should == args["Security_Groups"].keys.sort
25
+ end
26
+
27
+ it "#{inst_map[:aws_instance_id]} should have 0 set as :aws_state_code" do
28
+ inst_map[:aws_state_code].should == 0
29
+ end
30
+
31
+ it "#{inst_map[:aws_instance_id]} should have #{args["Image_id"]} set as :aws_image_id" do
32
+ inst_map[:aws_image_id].should == args["Image_id"]
33
+ end
34
+
35
+ it "#{inst_map[:aws_instance_id]} should have #{args["Instance_Type"]} set as :aws_instance_type" do
36
+ inst_map[:aws_instance_type].should == args["Instance_Type"]
37
+ end
38
+
39
+ #it "#{inst_map[:aws_instance_id]} should have one of #{possible_states.join(",")} set as :aws_state" do
40
+
41
+ #end
42
+ }
43
+ end
44
+
45
+ shared_examples_for "describe_instances return values" do |result,args|
46
+ before(:all) do
47
+ @uuids = result.map {|i| i[:aws_instance_id]}
48
+ end
49
+
50
+ result.each { |inst_map|
51
+ #it "#{inst_map[:aws_instance_id]} should have #{args["HOST"]} set as :aws_availability_zone" do
52
+ #inst_map[:aws_availablity_zone].should == args["HOST"]
53
+ #end
54
+
55
+ it "#{inst_map[:aws_instance_id]} should have #{args["SSH_Key"]} set as :ssh_key_name" do
56
+ inst_map[:ssh_key_name].should == args["SSH_Key"]
57
+ end
58
+
59
+ #it "#{inst_map[:aws_instance_id]} should have #{args[:arch]} set as :architecture" do
60
+ #inst_map[:architecture].should == args[:arch]
61
+ #end
62
+ }
63
+ end
64
+
65
+ shared_examples_for "terminate_instances" do |tama,uuids|
66
+ it "should terminate instances #{uuids.join(",")}" do
67
+ res = tama.terminate_instances(uuids)
68
+
69
+ res.length.should == uuids.length
70
+ res.map {|i| i[:aws_instance_id]}.sort.should == uuids.sort
71
+ end
72
+ end
73
+
74
+ shared_examples_for "describe_images" do |tama,ids|
75
+ it "should describe all images" do
76
+ res = tama.describe_images
77
+ res.class.should == Array
78
+ end
79
+
80
+ it "should describe #{ids.join(",")}" do
81
+ res = tama.describe_images(ids)
82
+ res.length.should == ids.length
83
+ res.map {|img| img[:aws_id]}.sort.should == ids.sort
84
+ end
85
+ end
86
+
87
+ shared_examples_for "wakame describe method" do |tama,method_name,ids|
88
+ it "should describe all" do
89
+ res = tama.send(method_name)
90
+ res.nil?.should be_false
91
+ res.class.should == Array
92
+ #res.empty?.should be_false
93
+ #res.first["results"].class.should == Array
94
+ end
95
+
96
+ it "should describe #{ids.join(",")}" do
97
+ res = tama.send(method_name,ids)
98
+ res.length.should == ids.length
99
+ res.map {|node| node["uuid"]}.sort.should == ids.sort
100
+ end
101
+ end
@@ -0,0 +1,65 @@
1
+ [
2
+ {
3
+ "owner_total": 4,
4
+ "start": 0,
5
+ "results": [
6
+ {
7
+ "updated_at": "2011-10-18T03:53:37Z",
8
+ "account_id": "a-shpoolxx",
9
+ "boot_dev_type": 1,
10
+ "description": "ubuntu-10.04_with-metadata_kvm_i386.raw volume",
11
+ "source": "--- \n:snapshot_id: snap-lucid6\n",
12
+ "state": "init",
13
+ "arch": "x86",
14
+ "is_public": false,
15
+ "created_at": "2011-10-18T03:53:37Z",
16
+ "uuid": "wmi-lucid6",
17
+ "id": "wmi-lucid6",
18
+ "md5sum": "8e0d8d37d704751a076fdf704a311350"
19
+ },
20
+ {
21
+ "updated_at": "2011-10-18T03:53:36Z",
22
+ "account_id": "a-shpoolxx",
23
+ "boot_dev_type": 2,
24
+ "description": "ubuntu-10.04_with-metadata_kvm_i386.raw local",
25
+ "source": "--- \n:uri: file:///home/wakame/work/wakame-vdc/tmp/images/ubuntu-10.04_with-metadata_kvm_i386.raw\n",
26
+ "state": "init",
27
+ "arch": "x86",
28
+ "is_public": false,
29
+ "created_at": "2011-10-18T03:53:36Z",
30
+ "uuid": "wmi-lucid5",
31
+ "id": "wmi-lucid5",
32
+ "md5sum": "8e0d8d37d704751a076fdf704a311350"
33
+ },
34
+ {
35
+ "updated_at": "2011-10-18T03:53:35Z",
36
+ "account_id": "a-shpoolxx",
37
+ "boot_dev_type": 1,
38
+ "description": "ubuntu-10.04_without-metadata_kvm_i386.raw volume",
39
+ "source": "--- \n:snapshot_id: snap-lucid1\n",
40
+ "state": "init",
41
+ "arch": "x86",
42
+ "is_public": false,
43
+ "created_at": "2011-10-18T03:53:35Z",
44
+ "uuid": "wmi-lucid1",
45
+ "id": "wmi-lucid1",
46
+ "md5sum": "8b2a8fb606f5b6ceeca11d9f71e034a8"
47
+ },
48
+ {
49
+ "updated_at": "2011-10-18T03:53:35Z",
50
+ "account_id": "a-shpoolxx",
51
+ "boot_dev_type": 2,
52
+ "description": "ubuntu-10.04_without-metadata_kvm_i386.raw local",
53
+ "source": "--- \n:uri: file:///home/wakame/work/wakame-vdc/tmp/images/ubuntu-10.04_without-metadata_kvm_i386.raw\n",
54
+ "state": "init",
55
+ "arch": "x86",
56
+ "is_public": false,
57
+ "created_at": "2011-10-18T03:53:35Z",
58
+ "uuid": "wmi-lucid0",
59
+ "id": "wmi-lucid0",
60
+ "md5sum": "8b2a8fb606f5b6ceeca11d9f71e034a8"
61
+ }
62
+ ],
63
+ "limit": null
64
+ }
65
+ ]