fairchild-poolparty 1.3.5 → 1.3.17
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/bin/cloud +1 -0
- data/bin/cloud-compile +1 -0
- data/bin/cloud-misc +34 -0
- data/bin/cloud-show +13 -1
- data/bin/cloud-ssh +4 -1
- data/bin/cloud-thrift +32 -18
- data/config/jeweler.rb +5 -3
- data/examples/monitored_cloud.rb +1 -1
- data/examples/thrift/thrift_example.rb +8 -4
- data/examples/vmware.rb +10 -0
- data/lib/cloud_providers/cloud_provider.rb +9 -0
- data/lib/cloud_providers/cloud_provider_instance.rb +9 -4
- data/lib/cloud_providers/connections.rb +9 -5
- data/lib/cloud_providers/ec2/ec2.rb +42 -12
- data/lib/cloud_providers/ec2/ec2_helpers.rb +62 -5
- data/lib/cloud_providers/ec2/ec2_instance.rb +14 -1
- data/lib/cloud_providers/vmware/vmware.rb +3 -0
- data/lib/core/file.rb +12 -0
- data/lib/core/object.rb +1 -1
- data/lib/dependency_resolvers/base.rb +2 -9
- data/lib/dependency_resolvers/chef.rb +3 -3
- data/lib/keypair.rb +5 -3
- data/lib/poolparty.rb +3 -1
- data/lib/poolparty/base.rb +45 -22
- data/lib/poolparty/cloud.rb +70 -15
- data/lib/poolparty/default.rb +1 -0
- data/lib/poolparty/installer.rb +1 -1
- data/lib/poolparty/installers/ec2.rb +30 -16
- data/lib/poolparty/monitor.rb +25 -3
- data/lib/poolparty/plugin.rb +1 -5
- data/lib/poolparty/plugins/apache.rb +37 -11
- data/lib/poolparty/plugins/apache2/passenger_site.rb +1 -1
- data/lib/poolparty/plugins/apache2/virtual_host.rb +1 -0
- data/lib/poolparty/plugins/collectd.rb +29 -0
- data/lib/poolparty/plugins/collectd/templates/collectd.conf.erb +369 -0
- data/lib/poolparty/plugins/hermes.rb +101 -0
- data/lib/poolparty/pool.rb +14 -6
- data/lib/poolparty/resource.rb +20 -17
- data/lib/poolparty/resources/file.rb +2 -2
- data/lib/poolparty/resources/line.rb +1 -1
- data/lib/poolparty/resources/link.rb +2 -1
- data/lib/proto/command_interface_handler.rb +42 -7
- data/lib/proto/command_query_handler.rb +19 -0
- data/lib/proto/gen-py/cloudthrift/CommandInterface.pyc +0 -0
- data/lib/proto/gen-py/cloudthrift/__init__.pyc +0 -0
- data/lib/proto/gen-py/cloudthrift/constants.pyc +0 -0
- data/lib/proto/gen-py/cloudthrift/ttypes.pyc +0 -0
- data/lib/proto/gen-py/thrift/Thrift.pyc +0 -0
- data/lib/proto/gen-py/thrift/__init__.pyc +0 -0
- data/lib/proto/gen-py/thrift/protocol/TBinaryProtocol.pyc +0 -0
- data/lib/proto/gen-py/thrift/protocol/TProtocol.pyc +0 -0
- data/lib/proto/gen-py/thrift/protocol/__init__.pyc +0 -0
- data/lib/proto/gen-py/thrift/transport/TSocket.pyc +0 -0
- data/lib/proto/gen-py/thrift/transport/TTransport.pyc +0 -0
- data/lib/proto/gen-py/thrift/transport/__init__.pyc +0 -0
- data/lib/proto/poolparty.thrift +1 -0
- data/tasks/poolparty.rake +24 -0
- data/test/fixtures/clouds/fake_clouds.rb +2 -2
- data/test/fixtures/clouds/simple_cloud.rb +2 -2
- data/test/fixtures/resources/fake_plugin.rb +5 -0
- data/test/fixtures/resources/fake_subclassed_plugin.rb +19 -0
- data/test/lib/cloud_providers/ec2/ec2_instance_test.rb +17 -8
- data/test/lib/cloud_providers/ec2/ec2_test.rb +15 -11
- data/test/lib/core/array_test.rb +4 -0
- data/test/lib/dependency_resolvers/base_test.rb +1 -1
- data/test/lib/dependency_resolvers/chef/resources/remote_directory_test.rb +2 -2
- data/test/lib/dependency_resolvers/chef/resources/remote_file_test.rb +1 -1
- data/test/lib/dependency_resolvers/chef_test.rb +3 -3
- data/test/lib/poolparty/base_test.rb +1 -1
- data/test/lib/poolparty/cloud_test.rb +140 -33
- data/test/lib/poolparty/monitor_test.rb +29 -2
- data/test/lib/poolparty/plugins/apache_test.rb +5 -0
- data/test/lib/poolparty/pool_test.rb +3 -3
- data/test/lib/poolparty/resource_test.rb +14 -2
- data/test/lib/poolparty/resources/conditional_test.rb +1 -0
- data/test/lib/poolparty/resources/directory_test.rb +1 -1
- data/test/lib/poolparty/resources/file_test.rb +1 -1
- data/test/lib/poolparty/resources/user_test.rb +1 -1
- data/test/lib/proto/command_query_handler_test.rb +11 -0
- data/test/lib/provision/bootstrapper_test.rb +0 -25
- data/test/test_helper.rb +0 -1
- metadata +15 -4
data/VERSION.yml
CHANGED
data/bin/cloud
CHANGED
@@ -33,6 +33,7 @@ EOS
|
|
33
33
|
$DEBUGGING = true if command[:debug]
|
34
34
|
$VERY_DEBUGGING = true if command[:very_debug]
|
35
35
|
|
36
|
+
PoolParty::Pool.command = command
|
36
37
|
@loaded_pool = PoolParty::Pool.find_and_load_default_clouds_dot_rb(command[:clouds_dot_rb])
|
37
38
|
@loaded_clouds = command[:name] ? [clouds[command[:name]]] : @loaded_pool.clouds.map {|name,cld|cld}
|
38
39
|
@loaded_clouds.map do |cld|
|
data/bin/cloud-compile
CHANGED
data/bin/cloud-misc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib")
|
3
|
+
require "poolparty"
|
4
|
+
|
5
|
+
require 'git-style-binary/command'
|
6
|
+
|
7
|
+
GitStyleBinary.command do
|
8
|
+
banner <<-EOS
|
9
|
+
Usage: #{$0} #{all_options_string}
|
10
|
+
|
11
|
+
read the code
|
12
|
+
EOS
|
13
|
+
|
14
|
+
short_desc "various cloud development tasks"
|
15
|
+
|
16
|
+
opt :inst_num, "The number of the instance to run bootstrap on", :type => :int
|
17
|
+
opt :force, "Force rebootstrapping (useful for upgrading)", :default => false
|
18
|
+
|
19
|
+
run do |command|
|
20
|
+
@loaded_clouds.each do |cld|
|
21
|
+
cld.nodes.each do |node|
|
22
|
+
|
23
|
+
case command.argv.shift
|
24
|
+
when "deploy_hermes"
|
25
|
+
hermesdir = File.dirname(__FILE__) + "/../vendor/erlang/hermes"
|
26
|
+
release = `#{hermesdir}/scripts/most_recent_release tar.gz`.strip
|
27
|
+
node.scp(:source => release, :destination => "/var/poolparty/tmp")
|
28
|
+
node.scp(:source => "#{hermesdir}/scripts/target_system", :destination => "/var/poolparty/tmp")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/bin/cloud-show
CHANGED
@@ -16,6 +16,7 @@ shows output about the clouds.rb
|
|
16
16
|
EOS
|
17
17
|
|
18
18
|
short_desc "shows output about the clouds.rb"
|
19
|
+
opt :generate_graph, "Generate the dependency tree graph", :type => :string, :default => nil
|
19
20
|
|
20
21
|
run do |command|
|
21
22
|
|
@@ -30,7 +31,18 @@ EOS
|
|
30
31
|
"Running on: #{cld.cloud_provider_name}"
|
31
32
|
]
|
32
33
|
|
33
|
-
|
34
|
+
if verbose?
|
35
|
+
msg << [
|
36
|
+
"Keypair: #{cld.keypair.basename}"
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
if command[:generate_graph]
|
41
|
+
vputs "Generating dependency graph at: #{command[:generate_graph]}"
|
42
|
+
cld.output_resources_graph('png', command[:generate_graph], {"fontsize" => 30})
|
43
|
+
end
|
44
|
+
|
45
|
+
print_msg(msg.flatten)
|
34
46
|
|
35
47
|
end
|
36
48
|
|
data/bin/cloud-ssh
CHANGED
@@ -13,11 +13,14 @@ EOS
|
|
13
13
|
|
14
14
|
short_desc "ssh into an instance of the cloud"
|
15
15
|
|
16
|
+
opt :instance_number, "Ssh into the instance number", :type => :integer, :default => 0
|
17
|
+
|
16
18
|
run do |command|
|
17
19
|
cloud = @loaded_clouds.first
|
18
20
|
|
19
21
|
if !cloud.nodes.empty?
|
20
|
-
cloud.nodes
|
22
|
+
inst = cloud.nodes[command[:instance_number]]
|
23
|
+
inst ? inst.ssh : puts("Error: The instance number (#{command[:instance_number]}) is too high for the current number of instances")
|
21
24
|
else
|
22
25
|
puts "No running instances can be found"
|
23
26
|
end
|
data/bin/cloud-thrift
CHANGED
@@ -22,9 +22,11 @@ Usage: #{$0} #{all_options_string}
|
|
22
22
|
EOS
|
23
23
|
|
24
24
|
short_desc "Start the cloud thrift interface"
|
25
|
-
opt :port, "Start
|
25
|
+
opt :port, "Start on port", :type => :integer, :default => 11223
|
26
26
|
opt :dir, "Pid directory", :type => :string, :default => "/tmp"
|
27
27
|
opt :daemon, "Daemonize", :type => :bool, :default => true
|
28
|
+
# Query params
|
29
|
+
opt :host, "Query on host", :type => :string, :default => "localhost"
|
28
30
|
|
29
31
|
run do |command|
|
30
32
|
|
@@ -33,12 +35,12 @@ EOS
|
|
33
35
|
cmd = ARGV.shift
|
34
36
|
cmd = ARGV.shift if cmd == "thrift"
|
35
37
|
|
36
|
-
if %w(run start restart stop).include?(cmd)
|
38
|
+
if %w(run start restart stop query).include?(cmd)
|
37
39
|
args = [cmd]
|
38
40
|
args << ["--", command.argv] unless command.argv.empty?
|
39
41
|
args.flatten!
|
40
42
|
else
|
41
|
-
puts "You must pass one of the following: #{%w(run start restart stop).join(", ")}"
|
43
|
+
puts "You must pass one of the following: #{%w(run start restart stop query).join(", ")}"
|
42
44
|
args = ["--help"]
|
43
45
|
end
|
44
46
|
|
@@ -55,22 +57,34 @@ EOS
|
|
55
57
|
:monitor => true
|
56
58
|
}.merge(command.opts)
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
processor = CloudThrift::CommandInterface::Processor.new(handler)
|
61
|
-
transport = Thrift::ServerSocket.new( options[:port] )
|
62
|
-
transportFactory = Thrift::BufferedTransportFactory.new()
|
63
|
-
server = Thrift::SimpleServer.new(processor, transport, transportFactory)
|
60
|
+
if cmd == "query"
|
61
|
+
require "command_query_handler"
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
@loaded_clouds.each do |cld|
|
64
|
+
puts CommandQueryHandler.run_query(cld, ARGV.shift, ARGV, options)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
block = Proc.new do
|
68
|
+
handler = CommandInterfaceHandler.new
|
69
|
+
processor = CloudThrift::CommandInterface::Processor.new(handler)
|
70
|
+
transport = Thrift::ServerSocket.new( options[:port] )
|
71
|
+
transportFactory = Thrift::BufferedTransportFactory.new()
|
72
|
+
server = Thrift::SimpleServer.new(processor, transport, transportFactory)
|
73
|
+
|
74
|
+
puts "Starting the cloud server..."
|
75
|
+
begin
|
76
|
+
server.serve()
|
77
|
+
rescue
|
78
|
+
exit 10
|
79
|
+
end
|
80
|
+
puts "done."
|
81
|
+
end
|
82
|
+
|
83
|
+
if command[:daemon]
|
84
|
+
Daemons.run_proc("cloud-thrift", options, &block)
|
85
|
+
else
|
86
|
+
block.call
|
87
|
+
end
|
74
88
|
end
|
75
89
|
|
76
90
|
end
|
data/config/jeweler.rb
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
s.description = "PoolParty: The easy, open-source, cross-cloud management solution"
|
16
16
|
s.summary = <<-EOM
|
17
17
|
Self-healing, auto-scaling system administration, provisioning
|
18
|
-
and maintaining tool that makes cloud computing
|
18
|
+
and maintaining tool that makes cloud computing easier.
|
19
19
|
EOM
|
20
20
|
|
21
21
|
s.homepage = "http://poolpartyrb.com"
|
@@ -25,9 +25,11 @@ end
|
|
25
25
|
s.test_files = Dir["test/**/test_*.rb"]
|
26
26
|
|
27
27
|
s.files = (%w(Rakefile README.rdoc License.txt VERSION.yml) + Dir["{config,examples,lib,test,tasks,script,generators,bin,vendor}/**/*"])
|
28
|
+
s.files += ["vendor/erlang/hermes/ebin/*.tar.gz"]
|
28
29
|
|
29
|
-
s.files.exclude '
|
30
|
-
s.files.exclude
|
30
|
+
s.files.exclude 'vendor/erlang/hermes'
|
31
|
+
s.files.exclude 'examples/thrift/**/*.beam'
|
32
|
+
# s.files.exclude "**/*/erl_crash.dump"
|
31
33
|
|
32
34
|
s.has_rdoc = true
|
33
35
|
s.extra_rdoc_files = ["README.rdoc", "License.txt", 'History.txt']
|
data/examples/monitored_cloud.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
$:.unshift(File.dirname(__FILE__) + "/../../lib")
|
4
4
|
$:.unshift(File.dirname(__FILE__) + "/../../examples")
|
5
5
|
require "poolparty"
|
6
|
-
require "simple"
|
6
|
+
# require "simple"
|
7
7
|
|
8
8
|
$:.unshift("#{File.dirname(__FILE__)}/../../lib/proto/gen-rb")
|
9
9
|
|
@@ -15,13 +15,17 @@ require "poolparty_types"
|
|
15
15
|
port = ARGV.pop || 11223
|
16
16
|
|
17
17
|
transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', port))
|
18
|
+
# transport = Thrift::BufferedTransport.new(Thrift::Socket.new('192.168.2.31', port))
|
19
|
+
# transport = Thrift::BufferedTransport.new(Thrift::Socket.new('vm', port))
|
18
20
|
protocol = Thrift::BinaryProtocol.new(transport)
|
19
21
|
|
20
22
|
client = CloudThrift::CommandInterface::Client.new(protocol)
|
21
23
|
transport.open()
|
22
24
|
|
23
25
|
cld = CloudThrift::CloudQuery.new
|
24
|
-
cld.name = '
|
26
|
+
cld.name = 'pp2'
|
27
|
+
# cld.name = 'monitored_app'
|
28
|
+
# cld.name = 'vmware'
|
25
29
|
|
26
30
|
resp = client.run_command(cld, "name", [])
|
27
31
|
puts resp.response
|
@@ -29,8 +33,8 @@ puts resp.response
|
|
29
33
|
resp = client.run_command(cld, "maximum_instances", [])
|
30
34
|
puts resp.response
|
31
35
|
|
32
|
-
resp = client.run_command(cld, "run_monitor", ["cpu", "0.91"])
|
36
|
+
resp = client.run_command(cld, "run_monitor", ["cpu-idle", "0.91"])
|
33
37
|
p resp.response
|
34
38
|
|
35
|
-
resp = client.run_command(cld, "run_monitor", ["cpu", "0.01"])
|
39
|
+
resp = client.run_command(cld, "run_monitor", ["cpu-idle", "0.01"])
|
36
40
|
p resp.response
|
data/examples/vmware.rb
CHANGED
@@ -10,9 +10,19 @@ pool "poolparty" do
|
|
10
10
|
image_id "/Users/nmurray/Documents/VMware/Ubuntu-jaunty.vmwarevm/Ubuntu-jaunty.vmx"
|
11
11
|
public_ip "192.168.133.128"
|
12
12
|
end
|
13
|
+
has_hermes
|
13
14
|
has_file "/etc/motd", :content => "welcome to your instance"
|
14
15
|
|
15
16
|
has_convenience_helpers
|
16
17
|
end
|
17
18
|
|
18
19
|
end
|
20
|
+
|
21
|
+
# hermes
|
22
|
+
# want to be able to run cloud configure to update it
|
23
|
+
# but want to be able to pull from locally to configure it
|
24
|
+
# submodules?
|
25
|
+
# node name
|
26
|
+
# install path
|
27
|
+
# how to upload the escript target system
|
28
|
+
# how to upload the tar.gz of the release
|
@@ -68,10 +68,15 @@ module CloudProviders
|
|
68
68
|
raise StandardError.new("You must pass in a cloud to configure an instance") unless cloud
|
69
69
|
cloud.compile(self)
|
70
70
|
|
71
|
-
scp(:source => keypair.full_filepath,
|
72
|
-
|
71
|
+
# scp(:source => keypair.full_filepath,
|
72
|
+
# :destination => "/etc/poolparty/keys/#{keypair.basename}")
|
73
73
|
|
74
74
|
FileUtils.mkdir_p cloud.tmp_path/"etc"/"poolparty" unless File.directory?(cloud.tmp_path/"etc"/"poolparty")
|
75
|
+
FileUtils.mkdir_p cloud.tmp_path/"etc"/"poolparty"/"keys" unless File.directory?(cloud.tmp_path/"etc"/"poolparty"/"keys")
|
76
|
+
|
77
|
+
FileUtils.cp keypair.full_filepath, cloud.tmp_path/"etc"/"poolparty"/"keys"/keypair.basename
|
78
|
+
File.open(cloud.tmp_path/"etc"/"poolparty"/"cloud_name", "w") {|f| f << cloud.name }
|
79
|
+
|
75
80
|
pack_clouds_dot_rb_and_expected_directories
|
76
81
|
|
77
82
|
dputs("Rsyncing #{cloud.tmp_path/"*"}")
|
@@ -99,10 +104,10 @@ module CloudProviders
|
|
99
104
|
%w(lib plugins).each do |dir|
|
100
105
|
if File.directory?(d = cloud.clouds_dot_rb_dir/dir)
|
101
106
|
dputs("Adding local path: #{d}")
|
102
|
-
FileUtils.cp_r d, cloud.tmp_path/cloud.base_config_directory
|
107
|
+
FileUtils.cp_r d, cloud.tmp_path/cloud.base_config_directory, :verbose => true, :remove_destination => true # req'd for symlinks
|
103
108
|
end
|
104
109
|
end
|
105
|
-
FileUtils.cp cloud.clouds_dot_rb_file, cloud.tmp_path/"/etc/poolparty/"
|
110
|
+
FileUtils.cp cloud.clouds_dot_rb_file, cloud.tmp_path/"/etc/poolparty/clouds.rb"
|
106
111
|
end
|
107
112
|
# Determine the os
|
108
113
|
# Default to ubuntu
|
@@ -41,10 +41,11 @@ module CloudProviders
|
|
41
41
|
# {'-i'=>'keyfile, '-l' => 'fred' } would become
|
42
42
|
# "-i keyfile -o StrictHostKeyChecking=no -i keypair.to_s -l fred"
|
43
43
|
def ssh_options(opts={})
|
44
|
-
|
44
|
+
return @ssh_options if @ssh_options && opts.empty?
|
45
|
+
ssh_opts = {"-i" => keypair.full_filepath,
|
45
46
|
"-o" =>"StrictHostKeyChecking=no"
|
46
47
|
}.merge(opts)
|
47
|
-
|
48
|
+
@ssh_options = ssh_opts.collect{ |k,v| "#{k} #{v}"}.join(' ')
|
48
49
|
end
|
49
50
|
|
50
51
|
def rsync( opts={} )
|
@@ -81,15 +82,18 @@ module CloudProviders
|
|
81
82
|
while (chunk = stdin.readpartial(opts[:sysread]))
|
82
83
|
buf << chunk
|
83
84
|
unless chunk.nil? || chunk.empty?
|
84
|
-
$stdout.write(chunk) if debugging? || verbose?
|
85
|
+
$stdout.write(chunk) #if debugging? || verbose?
|
85
86
|
end
|
86
87
|
end
|
87
88
|
err = stderr.readlines
|
88
89
|
$stderr.write_nonblock(err)
|
89
90
|
rescue SystemCallError => error
|
90
|
-
|
91
|
+
err = stderr.readlines
|
92
|
+
$stderr.write_nonblock(err)
|
91
93
|
rescue EOFError => error
|
92
|
-
|
94
|
+
err = stderr.readlines
|
95
|
+
$stderr.write_nonblock(err)
|
96
|
+
# used to do nothing
|
93
97
|
end
|
94
98
|
end
|
95
99
|
buf
|
@@ -19,19 +19,22 @@ using :provider_name
|
|
19
19
|
EOM
|
20
20
|
end
|
21
21
|
|
22
|
+
require "#{File.dirname(__FILE__)}/ec2_helpers"
|
22
23
|
require "#{File.dirname(__FILE__)}/ec2_response"
|
23
24
|
require "#{File.dirname(__FILE__)}/ec2_instance"
|
24
25
|
|
25
26
|
module CloudProviders
|
26
27
|
class Ec2 < CloudProvider
|
27
28
|
|
28
|
-
|
29
|
+
include CloudProviders::Ec2Helpers
|
30
|
+
|
31
|
+
# Set the aws keys from the environment, or load from /etc/poolparty/env.yml if the environment variable is not set
|
29
32
|
def self.default_access_key
|
30
33
|
ENV['EC2_ACCESS_KEY'] || load_keys_from_file[:access_key]
|
31
34
|
end
|
32
35
|
|
33
36
|
def self.default_secret_access_key
|
34
|
-
ENV['EC2_SECRET_KEY'] || load_keys_from_file[:
|
37
|
+
ENV['EC2_SECRET_KEY'] || load_keys_from_file[:secret_access_key]
|
35
38
|
end
|
36
39
|
|
37
40
|
def self.default_private_key
|
@@ -59,10 +62,11 @@ module CloudProviders
|
|
59
62
|
end
|
60
63
|
|
61
64
|
# Load the yaml file containing keys. If the file does not exist, return an empty hash
|
62
|
-
def self.load_keys_from_file(filename='/etc/poolparty/
|
65
|
+
def self.load_keys_from_file(filename='/etc/poolparty/env.yml', caching=true)
|
63
66
|
return @aws_yml if @aws_yml && caching==true
|
64
67
|
return {} unless File.exists?(filename)
|
65
|
-
|
68
|
+
ddputs("Reading keys from file: #{filename}")
|
69
|
+
@aws_yml = YAML::load( open(filename).read ) || {}
|
66
70
|
end
|
67
71
|
|
68
72
|
default_options({
|
@@ -87,22 +91,29 @@ module CloudProviders
|
|
87
91
|
:ramdisk_id => nil,
|
88
92
|
:availability_zone => nil,
|
89
93
|
:block_device_mappings => nil,
|
90
|
-
:elastic_ips =>
|
91
|
-
:
|
94
|
+
:elastic_ips => [], # An array of the elastic ips
|
95
|
+
:ebs_volumes => [] # The volume id of an ebs volume # TODO: ensure this is consistent with :block_device_mappings
|
92
96
|
})
|
93
97
|
|
94
98
|
|
95
99
|
def ec2(o={})
|
96
|
-
@ec2 ||= Rightscale::Ec2.new(access_key, secret_access_key, o.merge(:logger => PoolParty::PoolPartyLog))
|
100
|
+
@ec2 ||= Rightscale::Ec2.new(access_key, secret_access_key, o.merge(:logger => PoolParty::PoolPartyLog, :endpoint_url => ec2_url))
|
97
101
|
end
|
98
102
|
|
99
103
|
# Start a new instance with the given options
|
100
104
|
def run_instance(o={})
|
105
|
+
number_of_instances = o[:number_of_instances] || 1
|
101
106
|
set_vars_from_options o
|
102
107
|
raise StandardError.new("You must pass a keypair to launch an instance, or else you will not be able to login. options = #{o.inspect}") if !keypair_name
|
108
|
+
vputs("--- Launching ec2 instances")
|
109
|
+
vputs({
|
110
|
+
"image_id" => image_id,
|
111
|
+
"security_group" => security_group,
|
112
|
+
"keypair" => keypair.basename
|
113
|
+
})
|
103
114
|
response_array = ec2(o).run_instances(image_id,
|
104
115
|
min_count,
|
105
|
-
|
116
|
+
number_of_instances,
|
106
117
|
security_group,
|
107
118
|
keypair.basename,
|
108
119
|
user_data,
|
@@ -113,10 +124,12 @@ module CloudProviders
|
|
113
124
|
availability_zone,
|
114
125
|
block_device_mappings
|
115
126
|
)
|
116
|
-
instances = response_array
|
127
|
+
instances = response_array.collect do |aws_response_hash|
|
117
128
|
Ec2Instance.new( Ec2Response.pp_format(aws_response_hash).merge(o) )
|
118
129
|
end
|
119
|
-
|
130
|
+
|
131
|
+
after_run_instance(instances)
|
132
|
+
|
120
133
|
instances.first
|
121
134
|
end
|
122
135
|
|
@@ -153,6 +166,22 @@ module CloudProviders
|
|
153
166
|
].include?(ec2_url)
|
154
167
|
end
|
155
168
|
|
169
|
+
# Callbacks
|
170
|
+
def before_compile(cld)
|
171
|
+
end
|
172
|
+
|
173
|
+
def after_compile(cld)
|
174
|
+
save_aws_env_to_yml(cld.tmp_path/"etc"/"poolparty"/"env.yml") rescue nil
|
175
|
+
end
|
176
|
+
|
177
|
+
# Run after all the instances are run
|
178
|
+
def after_run_instance(instances_list)
|
179
|
+
instances_list.each do |inst|
|
180
|
+
associate_address(inst.instance_id) if next_unused_elastic_ip
|
181
|
+
attach_volume(inst.instance_id) if next_unused_volume
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
156
185
|
# Read yaml file and use it to set environment variables and local variables.
|
157
186
|
def set_aws_env_from_yml_file(filename='/etc/poolparty/env.yml')
|
158
187
|
aws = self.class.load_keys_from_file(filename)
|
@@ -161,8 +190,9 @@ module CloudProviders
|
|
161
190
|
end
|
162
191
|
|
163
192
|
# Save aws keys and env variables to a yaml file
|
164
|
-
def save_aws_env_to_yml(filename='/etc/poolparty/
|
165
|
-
|
193
|
+
def save_aws_env_to_yml(filename='/etc/poolparty/env.yml')
|
194
|
+
hsh = aws_hash(default_options, "/etc/poolparty/ec2")
|
195
|
+
File.open(filename, 'w') {|f| f<<YAML::dump(hsh) }
|
166
196
|
end
|
167
197
|
|
168
198
|
# Return a hash of the aws keys and environment variables
|