tengine_resource 0.5.15 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/Gemfile +1 -27
  2. data/Gemfile.lock +60 -73
  3. data/README.rdoc +2 -2
  4. data/bin/create_indexes_for_tengine_resource +18 -0
  5. data/lib/tengine/resource/config/resource.rb +0 -3
  6. data/lib/tengine/resource/credential.rb +16 -17
  7. data/lib/tengine/resource/net_ssh.rb +22 -10
  8. data/lib/tengine/resource/physical_server.rb +8 -0
  9. data/lib/tengine/resource/provider.rb +206 -35
  10. data/lib/tengine/resource/server.rb +3 -3
  11. data/lib/tengine/resource/virtual_server.rb +1 -1
  12. data/lib/tengine/resource/virtual_server_image.rb +8 -8
  13. data/lib/tengine/resource/virtual_server_type.rb +2 -2
  14. data/lib/tengine/resource/watcher.rb +39 -9
  15. data/tmp/.gitkeep +0 -0
  16. metadata +92 -141
  17. data/.document +0 -5
  18. data/.rspec +0 -1
  19. data/Rakefile +0 -42
  20. data/VERSION +0 -1
  21. data/config/.gitignore +0 -2
  22. data/lib/tengine/resource/credential/ec2.rb +0 -5
  23. data/lib/tengine/resource/credential/ec2/dummy.rb +0 -148
  24. data/lib/tengine/resource/credential/ec2/launch_options.rb +0 -179
  25. data/lib/tengine/resource/provider/ec2.rb +0 -187
  26. data/lib/tengine/resource/provider/wakame.rb +0 -638
  27. data/spec/fixtures/goku_at_ec2_ap_northeast.rb +0 -177
  28. data/spec/mongoid.yml +0 -35
  29. data/spec/mongoid_en.yml +0 -48
  30. data/spec/spec_helper.rb +0 -43
  31. data/spec/support/ec2.rb +0 -129
  32. data/spec/support/mongo_index_key_log.rb +0 -91
  33. data/spec/tengine/resource/bugfix/watcher_for_wakame_spec.rb +0 -232
  34. data/spec/tengine/resource/credential_spec.rb +0 -205
  35. data/spec/tengine/resource/drivers/resource_control_driver_spec.rb +0 -84
  36. data/spec/tengine/resource/net_ssh_spec.rb +0 -148
  37. data/spec/tengine/resource/physical_server_spec.rb +0 -47
  38. data/spec/tengine/resource/provider/ec2_spec.rb +0 -473
  39. data/spec/tengine/resource/provider/test_files/describe_host_nodes.json +0 -22
  40. data/spec/tengine/resource/provider/test_files/describe_images.json +0 -23
  41. data/spec/tengine/resource/provider/test_files/describe_instance_specs.json +0 -23
  42. data/spec/tengine/resource/provider/test_files/describe_instances.json +0 -56
  43. data/spec/tengine/resource/provider/test_files/run_instances.json +0 -30
  44. data/spec/tengine/resource/provider/test_files/terminate_instances.json +0 -3
  45. data/spec/tengine/resource/provider/wakame/00_describe_host_nodes_0_physical_servers.json +0 -8
  46. data/spec/tengine/resource/provider/wakame/01_describe_host_nodes_10_physical_servers.json +0 -139
  47. data/spec/tengine/resource/provider/wakame/02_describe_host_nodes_60_physical_servers.json +0 -795
  48. data/spec/tengine/resource/provider/wakame/10_describe_instances_0_virtual_servers.json +0 -8
  49. data/spec/tengine/resource/provider/wakame/11_describe_instances_10_virtual_servers.json +0 -469
  50. data/spec/tengine/resource/provider/wakame/12_describe_instances_after_run_instances.json +0 -280
  51. data/spec/tengine/resource/provider/wakame/13_describe_instances_after_terminate_instances.json +0 -279
  52. data/spec/tengine/resource/provider/wakame/20_describe_images_0_virtual_server_images.json +0 -8
  53. data/spec/tengine/resource/provider/wakame/21_describe_images_5_virtual_server_images.json +0 -84
  54. data/spec/tengine/resource/provider/wakame/22_describe_images_60_virtual_server_images.json +0 -856
  55. data/spec/tengine/resource/provider/wakame/30_describe_instance_specs_0_virtual_server_specs.json +0 -8
  56. data/spec/tengine/resource/provider/wakame/31_describe_instance_specs_4_virtual_server_specs.json +0 -66
  57. data/spec/tengine/resource/provider/wakame/40_run_instances_0_virtual_servers.json +0 -1
  58. data/spec/tengine/resource/provider/wakame/41_run_instances_1_virtual_servers.json +0 -22
  59. data/spec/tengine/resource/provider/wakame/42_run_instances_5_virtual_servers.json +0 -106
  60. data/spec/tengine/resource/provider/wakame/50_terminate_instances_0_virtual_servers.json +0 -1
  61. data/spec/tengine/resource/provider/wakame/51_terminate_instances_3_virtual_servers.json +0 -5
  62. data/spec/tengine/resource/provider/wakame/sync_physical_servers_spec.rb +0 -114
  63. data/spec/tengine/resource/provider/wakame/sync_virtual_server_images_spec.rb +0 -116
  64. data/spec/tengine/resource/provider/wakame/sync_virtual_server_types_spec.rb +0 -116
  65. data/spec/tengine/resource/provider/wakame/sync_virtual_servers_spec.rb +0 -216
  66. data/spec/tengine/resource/provider/wakame_api_spec.rb +0 -319
  67. data/spec/tengine/resource/provider/wakame_spec.rb +0 -339
  68. data/spec/tengine/resource/provider_spec.rb +0 -252
  69. data/spec/tengine/resource/server_spec.rb +0 -195
  70. data/spec/tengine/resource/test_files/.gitignore +0 -6
  71. data/spec/tengine/resource/test_files/00_describe_host_nodes_0_physical_servers.json +0 -8
  72. data/spec/tengine/resource/test_files/01_describe_host_nodes_10_physical_servers.json +0 -139
  73. data/spec/tengine/resource/test_files/02_describe_host_nodes_60_physical_servers.json +0 -795
  74. data/spec/tengine/resource/test_files/10_describe_instances_0_virtual_servers.json +0 -8
  75. data/spec/tengine/resource/test_files/11_describe_instances_10_virtual_servers.json +0 -469
  76. data/spec/tengine/resource/test_files/12_describe_instances_after_run_instances.json +0 -280
  77. data/spec/tengine/resource/test_files/13_describe_instances_after_terminate_instances.json +0 -279
  78. data/spec/tengine/resource/test_files/14_describe_instances_after_run_1_instance.json +0 -55
  79. data/spec/tengine/resource/test_files/20_describe_images_0_virtual_server_images.json +0 -8
  80. data/spec/tengine/resource/test_files/21_describe_images_5_virtual_server_images.json +0 -84
  81. data/spec/tengine/resource/test_files/22_describe_images_60_virtual_server_images.json +0 -856
  82. data/spec/tengine/resource/test_files/30_describe_instance_specs_0_virtual_server_specs.json +0 -8
  83. data/spec/tengine/resource/test_files/31_describe_instance_specs_4_virtual_server_specs.json +0 -66
  84. data/spec/tengine/resource/test_files/40_run_instances_0_virtual_servers.json +0 -1
  85. data/spec/tengine/resource/test_files/41_run_instances_1_virtual_servers.json +0 -22
  86. data/spec/tengine/resource/test_files/42_run_instances_5_virtual_servers.json +0 -106
  87. data/spec/tengine/resource/test_files/43_run_instances_1_virtual_servers_without_aws_availability_zone.json +0 -22
  88. data/spec/tengine/resource/test_files/50_terminate_instances_0_virtual_servers.json +0 -1
  89. data/spec/tengine/resource/test_files/51_terminate_instances_3_virtual_servers.json +0 -5
  90. data/spec/tengine/resource/virtual_server_image_spec.rb +0 -94
  91. data/spec/tengine/resource/virtual_server_spec.rb +0 -116
  92. data/spec/tengine/resource/virtual_server_type_spec.rb +0 -4
  93. data/spec/tengine/resource/watcher_spec.rb +0 -1027
  94. data/spec/tengine_resource_spec.rb +0 -5
  95. data/tengine_resource.gemspec +0 -172
  96. data/tmp/log/.gitignore +0 -1
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/Rakefile DELETED
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "tengine_resource"
18
- gem.homepage = "http://github.com/tengine/tengine_resource"
19
- gem.license = "MPL2.0/LGPLv3"
20
- gem.summary = %Q{tengine_resource provides physical/virtual server management}
21
- gem.description = %Q{tengine_resource provides physical/virtual server management}
22
- gem.email = "tengine-info@groovenauts.jp"
23
- gem.authors = %w[taigou totty g-morita shyouhei akm hiroshinakao]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rspec/core'
29
- require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
38
-
39
- task :default => :spec
40
-
41
- require 'yard'
42
- YARD::Rake::YardocTask.new
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.15
data/config/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- /watchd.yml
2
- /watchd.yml.erb
@@ -1,5 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module Tengine::Resource::Credential::Ec2
3
- autoload :Dummy, 'tengine/resource/credential/ec2/dummy'
4
- autoload :LaunchOptions, 'tengine/resource/credential/ec2/launch_options'
5
- end
@@ -1,148 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # EC2に実際には接続しないであたかも接続しているかのように見せるためのダミーです。
3
- #
4
- # 環境変数EC2_DUMMYがtrueの場合に、RightAws::Ec2の代わりにこのクラスからインスタンスが生成されます。
5
- # 起動してから環境変数EC2_DUMMY_INTERVALで指定された秒数が経過したインスタンス(のダミー)はちゃんとrunningになるようになっています。
6
- #
7
- # [10/08/19 13:06:41] akimatter: モックはtestでしか使えません。
8
- # [10/08/19 13:08:47] akimatter: developmentでは、RightAws::Ec2のインスタンスの代わりのダミー(一般的にはモックって言うけど、specのモックと区別して敢えてダミーします)を使うようにするべきかも。
9
- # [10/08/19 13:09:19] akimatter: ただし、developmentでもダミーではなくEC2にちゃんと繋ぎたい場合もあるので、
10
- # [10/08/19 13:09:41] akimatter: 環境変数か何かの設定でこれらの動作が変わる方が良いかと思います。
11
- class Tengine::Resource::Credential::Ec2::Dummy
12
- cattr_accessor :last_instance_index
13
- @@last_instance_index = 0
14
-
15
- # クラス変数で生成しているインスタンスを保持したいところですが、
16
- # それだとdevelopmentモードでクラスがロードされる度に保持している内容がクリア
17
- # されてしまうのでNGでした。
18
- # 他に影響を与えないように実装する手段が他に思いつかなかったので、グローバル変数を使います。
19
- # cattr_accessor :instances
20
- # @@instances = {}
21
- def self.instances
22
- $ec2_dummy_instances ||= {}
23
- end
24
- def self.instances=(value)
25
- $ec2_dummy_instances = value
26
- end
27
-
28
- def instances
29
- self.class.instances
30
- end
31
-
32
- def initialize(access_key, secret_access_key, options = {})
33
- @access_key, @secret_access_key = access_key, secret_access_key
34
- @options = options || {}
35
- end
36
-
37
- STATIC_ATTRS = {
38
- :aws_reservation_id=>"r-71a46435",
39
- :aws_owner=>"000000000888",
40
- :aws_ramdisk_id=>"ari-c12e7f84",
41
- :aws_product_codes=>[],
42
- :monitoring_state=>"disabled",
43
- :aws_instance_type=>"m1.small",
44
- :root_device_type=>"instance-store",
45
- :aws_reason=>"",
46
- :aws_kernel_id=>"aki-773c6d32",
47
- :aws_availability_zone=>"us-west-1a"
48
- }
49
-
50
- def launch_instances(image_id, options)
51
- launch_time = Time.zone.now
52
- count = options.delete(:min_count) || 1
53
- options.delete(:max_count) # :max_countは無視
54
- idx = 0
55
- result = []
56
- count.times do
57
- instance_index = (self.class.last_instance_index += 1)
58
- instanceid = "i-DMY%05d" % instance_index
59
- instance_hash = {
60
- :aws_instance_id => instanceid,
61
- :aws_image_id => image_id,
62
- :state_reason_code=>"pending",
63
- :ssh_key_name => options[:key_name],
64
- :aws_groups => options[:group_ids],
65
- :state_reason_message=>"pending",
66
- :aws_state_code=>0,
67
- :dns_name=>"",
68
- :private_dns_name => "",
69
- :aws_launch_time => launch_time.iso8601,
70
- :aws_state => "pending",
71
- :ami_launch_index => idx.to_s,
72
- }.update(STATIC_ATTRS.dup)
73
- idx += 1
74
- result << instance_hash
75
- instances[instanceid] = instance_hash
76
- end
77
- result
78
- end
79
-
80
- def describe_instances(instance_ids = [])
81
- update_instances
82
- if instance_ids.empty?
83
- instances.values.sort_by{|hash| hash[:aws_instance_id]}
84
- else
85
- instance_ids.map{|id| instances[id]}
86
- end
87
- end
88
-
89
- def terminate_instances(instance_ids)
90
- update_instances
91
- instance_ids.each do |instance_id|
92
- update_status_running(instance_id) # 停止する前に一度はrunningにしておく
93
- hash = instances[instance_id]
94
- hash.update(
95
- :state_reason_code=>"Client.UserInitiatedShutdown",
96
- :state_reason_message=>"Client.UserInitiatedShutdown: User initiated shutdown",
97
- :aws_state_code=>48,
98
- :dns_name=>"",
99
- :private_dns_name=>"",
100
- :aws_state=>"terminated"
101
- )
102
- hash.delete(:ip_address)
103
- hash.delete(:private_ip_address)
104
- end
105
- instance_ids.map do |instance_id|
106
- {
107
- :aws_prev_state_name => "running",
108
- :aws_instance_id => instance_id,
109
- :aws_current_state_code => 32,
110
- :aws_current_state_name => "shutting-down",
111
- :aws_prev_state_code => 16
112
- }
113
- end
114
- end
115
-
116
- private
117
- UPDATE_INTERVAL = (ENV['EC2_DUMMY_INTERVAL'] || 30).to_i.seconds
118
-
119
- def update_instances
120
- t = Time.zone.now
121
- instances.each do |instanceid, hash|
122
- next unless hash[:aws_state] == "pending"
123
- launch_time = Time.zone.parse(hash[:aws_launch_time])
124
- next if (t - launch_time) < UPDATE_INTERVAL
125
- update_status_running(instanceid)
126
- end
127
- end
128
-
129
- def update_status_running(instance_id)
130
- hash = instances[instance_id]
131
- unless hash
132
- raise ArgumentError, "No instance found for #{instance_id.inspect}. " << instances.keys.map(&:to_s).join("\n") << " exist."
133
- end
134
- instance_index = hash[:aws_instance_id].sub(/^i\-DMY/, '').to_i
135
- hash.update(
136
- :aws_state_code=>16,
137
- :dns_name=>"ec2-184-72-20-#{instance_index}.us-west-1.compute.amazonaws.com",
138
- :ip_address=>"184.72.20.#{instance_index}",
139
- :private_dns_name=>"ip-10-162-153-#{instance_index}.us-west-1.compute.internal",
140
- :private_ip_address=>"10.162.153.#{instance_index}",
141
- :aws_state=>"running",
142
- :architecture=>"i386"
143
- )
144
- hash.delete(:state_reason_message)
145
- hash.delete(:state_reason_code)
146
- end
147
-
148
- end
@@ -1,179 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class Tengine::Resource::Credential::Ec2::LaunchOptions
3
-
4
- def initialize(credential)
5
- @credential = credential
6
- end
7
-
8
- LAUNCH_OPTIONS_KEYS = %w(current_region regions availability_zones key_pairs
9
- security_groups images instance_types kernel_ids ramdisk_ids)
10
-
11
- def launch_options(connection, current_region)
12
- @connection, @current_region = connection, current_region
13
- LAUNCH_OPTIONS_KEYS.inject({}){|dest, m| dest[m] = send(m); dest}
14
- ensure
15
- @connection, @current_region = nil, nil
16
- end
17
-
18
- attr_reader :current_region
19
-
20
- DEFAULT_REGION_CAPTIONS = {
21
- "us-east-1" => "US East" ,
22
- "us-west-1" => "US West" ,
23
- "eu-west-1" => "EU West" ,
24
- "ap-southeast-1" => "Asia Pacific"
25
- }.freeze
26
-
27
- def regions
28
- # ["eu-west-1", "us-east-1", "us-west-1", "ap-southeast-1"]
29
- raw = @connection.describe_regions
30
- raw.inject([]) do |dest, region|
31
- dest << {"name" => region, "caption" => DEFAULT_REGION_CAPTIONS[region]}
32
- end
33
- end
34
-
35
- def availability_zones
36
- # [
37
- # {:region_name=>"us-east-1", :zone_name=>"us-east-1a", :zone_state=>"available"},
38
- # {:region_name=>"us-east-1", :zone_name=>"us-east-1b", :zone_state=>"available"},
39
- # {:region_name=>"us-east-1", :zone_name=>"us-east-1c", :zone_state=>"available"},
40
- # {:region_name=>"us-east-1", :zone_name=>"us-east-1d", :zone_state=>"available"}
41
- # ]
42
- raw = @connection.describe_availability_zones
43
- raw.map{|h| h[:zone_name]}.sort
44
- end
45
-
46
- def key_pairs
47
- # [{:aws_key_name=>"west-dev01", :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:99"}]
48
- raw = @connection.describe_key_pairs
49
- raw.map{|h| h[:aws_key_name]}
50
- end
51
-
52
- def security_groups
53
- # [
54
- # { :aws_owner=>"892601002221", :aws_group_name=>"default", :aws_description=>"default group",
55
- # :aws_perms=>[{:owner=>"892601002221", :group=>"default"}, {:from_port=>"22", :to_port=>"22", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
56
- # { :aws_owner=>"892601002221", :aws_group_name=>"ruby-dev", :aws_description=>"for developmewnt with ruby",
57
- # :aws_perms=>[{:from_port=>"80", :to_port=>"80", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]}
58
- # ]
59
- raw = @connection.describe_security_groups
60
- raw.map{|h| h[:aws_group_name]}
61
- end
62
-
63
- def images
64
- # [
65
- # {
66
- # :aws_id=>"ami-5189d814",
67
- # :aws_architecture=>"i386", :root_device_type=>"instance-store",
68
- # :root_device_name=>"/dev/sda1",
69
- # :aws_location=>"akm2000-us-west-2/dev-20100521-01.manifest.xml",
70
- # :aws_image_type=>"machine", :aws_state=>"available",
71
- # :aws_owner=>"892601002221", :aws_is_public=>false,
72
- # :aws_kernel_id=>"aki-773c6d32", :aws_ramdisk_id=>"ari-c12e7f84",
73
- # },
74
- # ]
75
- saved_images = Tengine::Resource::VirtualServerImage.all
76
- # raw_images = @connection.describe_images_by_owner('self')
77
- raw_images = @connection.describe_images(saved_images.map(&:provided_id).uniq.compact) #クラスタに登録されているAMI
78
- # raw_images += @connection.describe_images_by_executable_by("self") # 実行可能なAMI
79
- amiid_to_hash = raw_images.inject({}){|d, hash| d[hash[:aws_id]] = hash; d}
80
- result = saved_images.map do |saved_image|
81
- if ami = amiid_to_hash[saved_image.provided_id]
82
- {
83
- 'id' => saved_image.id,
84
- 'name' => ami[:aws_id],
85
- 'caption' => saved_image.description,
86
- 'aws_architecture' => ami[:aws_architecture],
87
- 'aws_arch_root_dev' => to_aws_arch_root_dev(ami),
88
- }
89
- else
90
- nil
91
- end
92
- end
93
- result.compact.uniq
94
- end
95
-
96
- def instance_types
97
- # rawなし
98
- INSTANCE_TYPES
99
- end
100
-
101
- def kernel_ids
102
- # [
103
- # {
104
- # :aws_id=>"aki-233c6d66",
105
- # :aws_architecture=>"i386", :root_device_type=>"instance-store",
106
- # :aws_location=>"ec2-paid-ibm-images-us-west-1/vmlinuz-2.6.16.60-0.29-xenpae.i386.manifest.xml",
107
- # :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"470254534024",
108
- # :aws_is_public=>true, :image_owner_alias=>"amazon",
109
- # },
110
- # ]
111
- raw = amazon_images.select{|img| img[:aws_image_type] == 'kernel'}
112
- raw.inject({}) do |dest, hash|
113
- key = hash[:aws_architecture]
114
- dest[key] ||= []
115
- dest[key] << hash[:aws_id]
116
- dest
117
- end
118
- end
119
-
120
- def ramdisk_ids
121
- # [
122
- # {
123
- # :aws_id=>"ari-2d3c6d68",
124
- # :aws_architecture=>"i386", :root_device_type=>"instance-store",
125
- # :aws_location=>"ec2-paid-ibm-images-us-west-1/initrd-2.6.16.60-0.29-xenpae.i386.manifest.xml",
126
- # :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"470254534024",
127
- # :aws_is_public=>true, :image_owner_alias=>"amazon"
128
- # },
129
- # ]
130
- raw = amazon_images.select{|img| img[:aws_image_type] == 'ramdisk'}
131
- raw.inject({}) do |dest, hash|
132
- key = hash[:aws_architecture]
133
- dest[key] ||= []
134
- dest[key] << hash[:aws_id]
135
- dest
136
- end
137
- end
138
-
139
- private
140
-
141
- def amazon_images
142
- @amazon_images ||= @connection.describe_images_by_owner('amazon')
143
- end
144
-
145
-
146
- def to_aws_arch_root_dev(hash)
147
- "#{hash[:aws_architecture]}_#{hash[:root_device_type]}"
148
- end
149
-
150
- INSTANCE_TYPES = {
151
- 'i386_instance-store' => [
152
- { "value" => "m1.small" , "caption" => "Small" },
153
- { "value" => "c1.medium" , "caption" => "High-CPU Medium" },
154
- ].freeze,
155
- 'i386_ebs' => [
156
- { "value" => "t1.micro" , "caption" => "Micro" },
157
- { "value" => "m1.small" , "caption" => "Small" },
158
- { "value" => "c1.medium" , "caption" => "High-CPU Medium" },
159
- ].freeze,
160
- 'x86_64_instance-store' => [
161
- { "value" => "m1.large" , "caption" => "Large" },
162
- { "value" => "m1.xlarge" , "caption" => "Extra Large" },
163
- { "value" => "m2.xlarge" , "caption" => "High-Memory Extra Large" },
164
- { "value" => "m2.2xlarge", "caption" => "High-Memory Double Extra Large" },
165
- { "value" => "m2.4xlarge", "caption" => "High-Memory Quadruple Extra Large" },
166
- { "value" => "c1.xlarge" , "caption" => "High-CPU Extra Large" },
167
- ].freeze,
168
- 'x86_64_ebs' => [
169
- { "value" => "t1.micro" , "caption" => "Micro" },
170
- { "value" => "m1.large" , "caption" => "Large" },
171
- { "value" => "m1.xlarge" , "caption" => "Extra Large" },
172
- { "value" => "m2.xlarge" , "caption" => "High-Memory Extra Large" },
173
- { "value" => "m2.2xlarge", "caption" => "High-Memory Double Extra Large" },
174
- { "value" => "m2.4xlarge", "caption" => "High-Memory Quadruple Extra Large" },
175
- { "value" => "c1.xlarge" , "caption" => "High-CPU Extra Large" },
176
- ].freeze,
177
- }.freeze
178
-
179
- end
@@ -1,187 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class Tengine::Resource::Provider::Ec2 < Tengine::Resource::Provider
3
-
4
- field :connection_settings, :type => Hash
5
-
6
- def update_physical_servers
7
- connect do |conn|
8
- # ec2.describe_availability_zones #=> [{:region_name=>"us-east-1",
9
- # :zone_name=>"us-east-1a",
10
- # :zone_state=>"available"}, ... ]
11
- # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeAvailabilityZones.html
12
- hashs = conn.describe_availability_zones.map do |hash|
13
- {
14
- :provided_id => hash[:zone_name],
15
- :name => hash[:zone_name],
16
- :status => hash[:zone_state],
17
- }
18
- end
19
- update_physical_servers_by(hashs)
20
- end
21
- end
22
-
23
- def update_virtual_servers
24
- connect do |conn|
25
- # http://rightscale.rubyforge.org/right_aws_gem_doc/
26
- # ec2.describe_instances #=>
27
- # [{:aws_image_id => "ami-e444444d",
28
- # :aws_reason => "",
29
- # :aws_state_code => "16",
30
- # :aws_owner => "000000000888",
31
- # :aws_instance_id => "i-123f1234",
32
- # :aws_reservation_id => "r-aabbccdd",
33
- # :aws_state => "running",
34
- # :dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
35
- # :ssh_key_name => "staging",
36
- # :aws_groups => ["default"],
37
- # :private_dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
38
- # :aws_instance_type => "m1.small",
39
- # :aws_launch_time => "2008-1-1T00:00:00.000Z"},
40
- # :aws_availability_zone => "us-east-1b",
41
- # :aws_kernel_id => "aki-ba3adfd3",
42
- # :aws_ramdisk_id => "ari-badbad00",
43
- # ..., {...}]
44
- # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeInstances.html
45
- hashs = conn.describe_instances.map do |hash|
46
- result = {
47
- :provided_id => hash.delete(:aws_instance_id),
48
- :provided_image_id => hash.delete(:aws_image_id),
49
- :status => hash.delete(:aws_state),
50
- }
51
- hash.delete(:aws_state_code)
52
- result[:properties] = hash
53
- result[:addresses] = {
54
- :dns_name => hash.delete(:dns_name),
55
- :ip_address => hash.delete(:ip_address),
56
- :private_dns_name => hash.delete(:private_dns_name),
57
- :private_ip_address => hash.delete(:private_ip_address),
58
- }
59
- result
60
- end
61
- update_virtual_servers_by(hashs)
62
- end
63
- end
64
-
65
- def update_virtual_server_images
66
- connect do |conn|
67
- hashs = conn.describe_images.map do |hash|
68
- { :provided_id => hash.delete(:aws_id), }
69
- end
70
- update_virtual_server_images_by(hashs)
71
- end
72
- end
73
-
74
- # @param [String] name Name template for created virtual servers
75
- # @param [Tengine::Resource::VirtualServerImage] image Virtual server image object
76
- # @param [Tengine::Resource::VirtualServerType] type Virtual server type object
77
- # @param [String] physical Data center name to put virtual machines (availability zone)
78
- # @param [String] description What this virtual server is
79
- # @param [Numeric] min_count Minimum number of vortial servers to boot
80
- # @param [Numeric] max_count Maximum number of vortial servers to boot
81
- # @param [Array<Strng>] group_ids Array of names of security group IDs
82
- # @param [Strng] key_name Name of root key to sue
83
- # @param [Strng] user_data User-specified
84
- # @param [Strng] kernel_id Kernel image ID
85
- # @param [Strng] ramdisk_id Ramdisk image ID
86
- # @return [Array<Tengine::Resource::VirtualServer>]
87
- def create_virtual_servers name, image, type, physical, description, min_count, max_count, group_ids, key_name, user_data = "", kernel_id, ramdisk_id
88
- connect {|conn|
89
- results = conn.run_instances(
90
- image.provided_id,
91
- min_count,
92
- max_count,
93
- group_ids,
94
- key_name,
95
- user_data,
96
- nil, # <- addressing_type
97
- type.provided_id,
98
- kernel_id,
99
- ramdisk_id,
100
- physical,
101
- nil # <- block_device_mappings
102
- )
103
- yield if block_given? # テスト用のブロックの呼び出し
104
- results.map.with_index {|hash, idx|
105
- provided_id = hash.delete(:aws_instance_id)
106
- if server = self.virtual_servers.find(:first, :conditions => {:provided_id => provided_id})
107
- server
108
- else
109
- host_server_provided_id = hash[:aws_availability_zone]
110
- host_server_provided_id = physical if host_server_provided_id.nil? || host_server_provided_id.blank?
111
- # findではなくfirstで検索しているので、もしhost_server_provided_idで指定されるサーバが見つからなくても
112
- # host_serverがnilとして扱われるが、仮想サーバ自身の登録は行われます
113
- host_server = (host_server_provided_id && !host_server_provided_id.blank?) ?
114
- Tengine::Resource::PhysicalServer.first(:conditions => {:provided_id => host_server_provided_id}) : nil
115
- begin
116
- self.virtual_servers.create!(
117
- :name => sprintf("%s%03d", name, idx + 1), # 1 origin
118
- :address_order => address_order,
119
- :description => description,
120
- :provided_id => provided_id,
121
- :provided_image_id => hash.delete(:aws_image_id),
122
- :provided_type_id => hash.delete(:aws_instance_type),
123
- :host_server_id => host_server ? host_server.id : nil,
124
- :status => hash.delete(:aws_state),
125
- :properties => hash,
126
- :addresses => {
127
- # :dns_name => hash.delete(:dns_name),
128
- # :ip_address => hash.delete(:ip_address),
129
- # :private_dns_name => hash.delete(:private_dns_name),
130
- # :private_ip_address => hash.delete(:private_ip_address),
131
- })
132
- rescue Mongo::OperationFailure => e
133
- raise e unless e.message =~ /E11000 duplicate key error/
134
- self.virtual_servers.find(:first, :conditions => {:provided_id => provided_id}) or
135
- raise "VirtualServer not found for #{provided_id}"
136
- rescue Mongoid::Errors::Validations => e
137
- raise e unless e.document.errors[:provided_id].any?{|s| s =~ /taken/}
138
- self.virtual_servers.find(:first, :conditions => {:provided_id => provided_id}) or
139
- raise "VirtualServer not found for #{provided_id}"
140
- end
141
- end
142
- }
143
- }
144
- end
145
-
146
- def terminate_virtual_servers servers
147
- connect do |conn|
148
- # http://rightscale.rubyforge.org/right_aws_gem_doc/classes/RightAws/Ec2.html#M000287
149
- # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-TerminateInstances.html
150
- conn.terminate_instances(servers.map {|i| i.provided_id }).map do |hash|
151
- serv = self.virtual_servers.where(:provided_id => hash[:aws_instance_id]).first
152
- serv.update_attributes(:status => hash[:aws_current_state_name]) if serv
153
- serv
154
- end
155
- end
156
- end
157
-
158
- # 仮想サーバタイプの監視
159
- def virtual_server_type_watch
160
- # ec2から取得する情報はありません
161
- end
162
-
163
- # 物理サーバの監視
164
- def physical_server_watch ; raise NotImplementedError end
165
- # 仮想サーバの監視
166
- def virtual_server_watch ; raise NotImplementedError end
167
- # 仮想サーバイメージの監視
168
- def virtual_server_image_watch ; raise NotImplementedError end
169
-
170
- private
171
- def address_order
172
- @@address_order ||= %w"private_ip_address private_dns_name ip_address dns_name".each(&:freeze).freeze
173
- end
174
-
175
- def connect
176
- klass = (ENV['EC2_DUMMY'] == "true") ? Tengine::Resource::Credential::Ec2::Dummy : RightAws::Ec2
177
- connection = klass.new(
178
- self.connection_settings[:access_key],
179
- self.connection_settings[:secret_access_key],
180
- {
181
- :logger => Tengine.logger,
182
- :region => self.connection_settings[:region]
183
- }
184
- )
185
- yield connection
186
- end
187
- end