auser-poolparty 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/VERSION.yml +1 -1
  2. data/bin/cloud +1 -1
  3. data/bin/cloud-list +19 -7
  4. data/bin/cloud-provision +3 -0
  5. data/bin/cloud-run +37 -0
  6. data/bin/server-list-active +1 -1
  7. data/config/jeweler.rb +2 -2
  8. data/examples/basic.rb +4 -3
  9. data/examples/fairchild.rb +2 -2
  10. data/examples/metavirt_cloud.rb +18 -8
  11. data/examples/simple.rb +4 -3
  12. data/examples/vmrun_cloud.rb +2 -5
  13. data/lib/poolparty.rb +1 -1
  14. data/lib/poolparty/core/object.rb +6 -4
  15. data/lib/poolparty/core/string.rb +2 -1
  16. data/lib/poolparty/helpers/optioner.rb +1 -1
  17. data/lib/poolparty/modules/callbacks.rb +2 -0
  18. data/lib/poolparty/modules/cloud_resourcer.rb +4 -5
  19. data/lib/poolparty/modules/daemonizable.rb +4 -5
  20. data/lib/poolparty/modules/definable_resource.rb +1 -0
  21. data/lib/poolparty/modules/pinger.rb +5 -1
  22. data/lib/poolparty/monitors/monitor_daemon.rb +159 -0
  23. data/lib/poolparty/monitors/monitor_rack.rb +21 -11
  24. data/lib/poolparty/monitors/monitors/clock_monitor.rb +5 -0
  25. data/lib/poolparty/monitors/monitors/elections_monitor.rb +49 -0
  26. data/lib/poolparty/monitors/monitors/neighborhood_monitor.rb +7 -7
  27. data/lib/poolparty/monitors/monitors/stats_monitor.rb +15 -3
  28. data/lib/poolparty/net/init.rb +1 -1
  29. data/lib/poolparty/net/remote_instance.rb +43 -39
  30. data/lib/poolparty/net/remoter/connections.rb +6 -3
  31. data/lib/poolparty/net/remoter/interactive.rb +18 -11
  32. data/lib/poolparty/net/remoter_base.rb +39 -12
  33. data/lib/poolparty/net/remoter_bases/ec2/ec2.rb +23 -19
  34. data/lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb +15 -33
  35. data/lib/poolparty/net/remoter_bases/ec2/ec2_response_object.rb +28 -20
  36. data/lib/poolparty/net/remoter_bases/libvirt/libvirt.rb +73 -0
  37. data/lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb +64 -0
  38. data/lib/poolparty/net/remoter_bases/metavirt/metavirt.rb +27 -17
  39. data/lib/poolparty/net/remoter_bases/metavirt/metavirt_instance.rb +20 -35
  40. data/lib/poolparty/net/remoter_bases/vmrun/vmrun.rb +35 -17
  41. data/lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb +32 -24
  42. data/lib/poolparty/plugins/apache2/apache.rb +1 -1
  43. data/lib/poolparty/plugins/chef/chef.rb +12 -26
  44. data/lib/poolparty/plugins/chef/chef_deploy.rb +5 -23
  45. data/lib/poolparty/plugins/chef/chef_deploy_definition.rb +32 -0
  46. data/lib/poolparty/plugins/chef/chef_library.rb +7 -0
  47. data/lib/poolparty/plugins/chef/chef_recipe.rb +7 -0
  48. data/lib/poolparty/plugins/chef/include_chef_recipe.rb +14 -0
  49. data/lib/poolparty/{resources → plugins}/host.rb +5 -4
  50. data/lib/poolparty/plugins/line_in_file.rb +1 -1
  51. data/lib/poolparty/{resources → plugins}/sshkey.rb +10 -8
  52. data/lib/poolparty/poolparty/cloud.rb +7 -0
  53. data/lib/poolparty/poolparty/default.rb +0 -2
  54. data/lib/poolparty/poolparty/pool.rb +13 -3
  55. data/lib/poolparty/provision/boot_strapper.rb +8 -8
  56. data/lib/poolparty/resources/exec.rb +7 -0
  57. data/lib/poolparty/resources/group.rb +3 -3
  58. data/lib/poolparty/resources/user.rb +6 -1
  59. data/lib/poolparty/templates/monitor.ru +12 -0
  60. data/spec/poolparty/net/remoter_bases/ec2_remote_instance_spec.rb +0 -2
  61. data/spec/poolparty/net/remoter_bases/ec2_spec.rb +7 -4
  62. data/spec/poolparty/poolparty/example_spec.rb +21 -21
  63. data/spec/poolparty/poolparty/pool_spec.rb +2 -1
  64. data/spec/poolparty/resources/sshkey_spec.rb +39 -40
  65. data/tasks/poolparty.rake +27 -1
  66. data/test/fixtures/fake_clouds.rb +11 -0
  67. data/test/poolparty/dependency_resolver/chef_resolver_test.rb +82 -0
  68. data/test/poolparty/monitors/test_base_monitor.rb +2 -2
  69. data/test/poolparty/monitors/test_monitor_rack.rb +11 -24
  70. data/test/poolparty/net/remoter_base_test.rb +4 -5
  71. data/test/poolparty/net/remoter_bases/libvirt/libvirt_test.rb +70 -0
  72. data/test/poolparty/net/remoter_bases/metavirt/metavirt_test.rb +32 -3
  73. data/test/poolparty/plugins/chef_plugin_test.rb +23 -0
  74. data/test/poolparty/poolparty/pool_test.rb +22 -0
  75. data/vendor/gems/dslify/lib/dslify.rb +3 -0
  76. data/vendor/gems/dslify/test/dslify_test.rb +4 -15
  77. data/vendor/gems/git-style-binaries/README.markdown +6 -0
  78. data/vendor/gems/git-style-binaries/Rakefile +1 -1
  79. data/vendor/gems/git-style-binaries/VERSION.yml +1 -1
  80. data/vendor/gems/git-style-binaries/doc/gsb-screencast.png +0 -0
  81. data/vendor/gems/git-style-binaries/doc/poolparty-binaries.screenplay +11 -13
  82. data/vendor/gems/git-style-binaries/git-style-binaries.gemspec +12 -3
  83. data/vendor/gems/git-style-binaries/lib/git-style-binary.rb +15 -1
  84. data/vendor/gems/git-style-binaries/test/running_binaries_test.rb +2 -2
  85. data/vendor/gems/suitcase/VERSION.yml +1 -1
  86. data/vendor/gems/suitcase/lib/suitcase/zipper.rb +73 -25
  87. data/vendor/gems/suitcase/suitcase.gemspec +5 -5
  88. data/vendor/gems/suitcase/test/suitcase_test.rb +12 -6
  89. data/vendor/gems/suitcase/test/test_dir/gems/famoseagle-carrot-0.6.0.gem +0 -0
  90. metadata +24 -52
  91. data/spec/poolparty/resources/host_spec.rb +0 -35
  92. data/vendor/gems/rest-client/README.rdoc +0 -151
  93. data/vendor/gems/rest-client/Rakefile +0 -85
  94. data/vendor/gems/rest-client/bin/restclient +0 -87
  95. data/vendor/gems/rest-client/lib/rest_client.rb +0 -2
  96. data/vendor/gems/rest-client/lib/restclient.rb +0 -93
  97. data/vendor/gems/rest-client/lib/restclient/exceptions.rb +0 -84
  98. data/vendor/gems/rest-client/lib/restclient/mixin/response.rb +0 -43
  99. data/vendor/gems/rest-client/lib/restclient/raw_response.rb +0 -30
  100. data/vendor/gems/rest-client/lib/restclient/request.rb +0 -232
  101. data/vendor/gems/rest-client/lib/restclient/resource.rb +0 -146
  102. data/vendor/gems/rest-client/lib/restclient/response.rb +0 -20
  103. data/vendor/gems/rest-client/rest-client.gemspec +0 -21
  104. data/vendor/gems/rest-client/spec/base.rb +0 -4
  105. data/vendor/gems/rest-client/spec/exceptions_spec.rb +0 -54
  106. data/vendor/gems/rest-client/spec/mixin/response_spec.rb +0 -46
  107. data/vendor/gems/rest-client/spec/raw_response_spec.rb +0 -17
  108. data/vendor/gems/rest-client/spec/request_spec.rb +0 -442
  109. data/vendor/gems/rest-client/spec/resource_spec.rb +0 -75
  110. data/vendor/gems/rest-client/spec/response_spec.rb +0 -16
  111. data/vendor/gems/rest-client/spec/restclient_spec.rb +0 -53
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  class String
27
27
  def convert_from_ec2_to_ip
28
- self.gsub(/.compute-1.amazonaws.com*/, '').gsub(/ec2-/, '').gsub(/-/, '.')
28
+ self.match(/-(\d+-\d+-\d+-\d+)\./) ? $1.gsub(/-/, '.') : self
29
29
  end
30
30
  def parse_datetime
31
31
  DateTime.parse( self.chomp ) rescue self
@@ -74,16 +74,18 @@ module PoolParty
74
74
  set_vars_from_options o
75
75
  keypair_name ||= o[:keypair_name] || keypair || (clouds[o[:cloud_name]].keypair.basename if o[:cloud_name])
76
76
  raise "You must pass a keypair to launch an instance, or else you will not be able to login. options = #{o.inspect}" if !keypair_name
77
- o.merge!( dsl_options.merge(:key_name=>keypair_name) )
77
+ o.merge!( dsl_options.merge(:key_name=>keypair_name, :group_id => security_group) )
78
78
  instance = ec2(o).run_instances(o)
79
+
79
80
  begin
80
- h = EC2ResponseObject.get_hash_from_response(instance.instancesSet.item.first)
81
+ h = EC2ResponseObject.describe_instance(instance)
81
82
  #h = instance.instancesSet.item.first
82
83
  rescue Exception => e
83
- h = EC2ResponseObject.get_hash_from_response(instance) rescue instance
84
+ vputs "There was an error:\n\t#{e.inspect}"
85
+ h = EC2ResponseObject.describe_instance(instance) rescue instance
84
86
  # h = instance
85
87
  end
86
- h
88
+ Ec2RemoteInstance.new(h)
87
89
  end
88
90
 
89
91
  # Terminate an instance by id
@@ -200,21 +202,23 @@ module PoolParty
200
202
  # intersection of the unused ips and those, find the first one available
201
203
  # and return that, otherwise, return the first elastic ip available
202
204
  def next_unused_elastic_ip
203
- # [{"instanceId"=>nil, "publicIp"=>"174.129.212.93"}, {"instanceId"=>nil, "publicIp"=>"174.129.212.94"}]
204
- if addressesSet = ec2(dsl_options).describe_addresses["addressesSet"]
205
- begin
206
- empty_addresses = addressesSet["item"].select {|i| i["instanceId"].nil? }
207
- ips = empty_addresses.map {|addr| addr["publicIp"]}
208
- if elastic_ips
209
- ips_to_use = elastic_ips & ips
210
- ips_to_use.first
211
- else
212
- ips.first
205
+ if elastic_ips.empty?
206
+ nil
207
+ else
208
+ # [{"instanceId"=>nil, "publicIp"=>"174.129.212.93"}, {"instanceId"=>nil, "publicIp"=>"174.129.212.94"}]
209
+ if addressesSet = ec2(dsl_options).describe_addresses(:public_ip => elastic_ips)["addressesSet"]
210
+ begin
211
+ empty_addresses = addressesSet["item"].select {|i| i["instanceId"].nil? }
212
+ ips = empty_addresses.map {|addr| addr["publicIp"]}
213
+ if elastic_ips
214
+ ips_to_use = elastic_ips & ips
215
+ ips_to_use.first
216
+ end
217
+ rescue Exception => e
218
+ puts "Error: #{e}"
219
+ nil
213
220
  end
214
- rescue Exception => e
215
- puts "Error: #{e}"
216
- nil
217
- end
221
+ end
218
222
  end
219
223
  end
220
224
 
@@ -28,53 +28,35 @@ module PoolParty
28
28
  # If an instance is found, this instance's properties will be set to the properties provided
29
29
  # If the found instance has properties of the same key as the provided options, the found instance's values will override the passed in options
30
30
  def initialize(opts={})
31
+ opts.delete(:id) # metavirt passes an id that we do not want to set
31
32
  set_vars_from_options(opts) if opts.is_a?(Hash)
32
33
  @target_host = public_ip || internal_ip || ip #set this for the netssh commands
33
34
  # super(opts)
34
35
  end
35
36
 
36
37
  def keypair(*n)
37
- @keypair ||= Key.new(key_name)
38
+ dsl_options[:keypair] ||= Key.new(key_name)
38
39
  end
39
40
 
40
- ## hash like methods
41
- # TODO: move these into a module, or into dslify
42
- # include Enumerable
43
- def each
44
- dsl_options.each{ |k,v| yield k,v }
45
- end
46
- def [](k)
47
- dsl_options[k]
41
+ # Printing. This is how we extract the instances into the listing on the
42
+ # local side into the local listing file
43
+ def to_s
44
+ "#{name}\t#{ip}\t#{instance_id rescue ""}"
48
45
  end
49
46
 
50
- def []=(k,v)
51
- dsl_options[k] = v
47
+ # Class method to disect a neighborhood line
48
+ def self.hash_from_s(s)
49
+ arr = s.split("\t")
50
+ {:name => arr[0], :ip => arr[1]}
52
51
  end
53
52
 
54
- def keys
55
- dsl_options.keys
56
- end
57
-
58
- def values
59
- dsl_options.values
53
+ def self.to_s(hsh)
54
+ new(hsh).to_s
60
55
  end
61
- ##end of hash like methods
62
56
 
63
- # Is this instance running?
64
- def running?
65
- !(status =~ /running/).nil?
66
- end
67
- # Is this instance pending?
68
- def pending?
69
- !(status =~ /pending/).nil?
70
- end
71
- # Is this instance terminating?
72
- def terminating?
73
- !(status =~ /shutting/).nil?
74
- end
75
- # Has this instance been terminated?
76
- def terminated?
77
- !(status =~ /terminated/).nil?
57
+ def hosts_file_listing_for(cl)
58
+ string = (cl.name == cloud.name) ? "#{name}.#{my_cloud.name}\t#{name}" : "#{name}.#{my_cloud.name}"
59
+ "#{internal_ip}\t#{string}"
78
60
  end
79
61
 
80
62
  end
@@ -8,19 +8,19 @@ class EC2ResponseObject
8
8
  # puts rs.methods.sort - rs.ancestors.methods
9
9
  out = begin
10
10
  if rs.respond_to?(:instancesSet)
11
- [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item, group)]
11
+ [EC2ResponseObject.describe_instances(rs)]
12
12
  else
13
13
  rs.collect {|r|
14
14
  if r.instancesSet.item.class == Array
15
- r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t, group)}
15
+ r.instancesSet.item.map {|t| EC2ResponseObject.describe_instances(t)}
16
16
  else
17
- [EC2ResponseObject.get_hash_from_response(r.instancesSet.item, group)]
17
+ [EC2ResponseObject.describe_instances(r)]
18
18
  end
19
19
  }.flatten.reject {|a| a.nil? }
20
20
  end
21
21
  rescue Exception => e
22
22
  # Really weird bug with amazon's ec2 gem
23
- rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue []
23
+ rs.collect {|r| EC2ResponseObject.describe_instances(r)}.reject {|a| a.nil? } rescue []
24
24
  end
25
25
 
26
26
  out
@@ -67,25 +67,33 @@ class EC2ResponseObject
67
67
  #####
68
68
 
69
69
  # Convert the standard reponse into output similar to this example
70
- # {:dns_name=>"ec2-75-101-175-49.compute-1.amazonaws.com",
71
- # :private_dns_name=>"domU-11-31-39-00-DC-78.compute-1.internal",
72
- # :reason=>nil,
73
- # :instance_state=>{"name"=>"running", "code"=>"16"},
74
- # :kernel_id=>"aki-a71cf9ce",
75
- # :ramdisk_id=>"ari-a51cf9cc",
76
- # :placement=>{"availabilityZone"=>"us-east-1a"},
77
- # :product_codes=>nil,
78
- # :image_id=>"ami-bf5eb9d6",
79
- # :launch_time=>"2009-05-29T05:07:09.000Z",
80
- # :key_name=>"poolname_cloudname",
81
- # :instance_id=>"i-1b7b2942",
82
- # :ami_launch_index=>"0",
83
- # :instance_type=>"m1.small"}
70
+ # {:dns_name =>"ec2-75-101-175-49.compute-1.amazonaws.com",
71
+ # :private_dns_name =>"domU-11-31-39-00-DC-78.compute-1.internal",
72
+ # :reason =>nil,
73
+ # :instance_state =>{"name"=>"running", "code"=>"16"},
74
+ # :kernel_id =>"aki-a71cf9ce",
75
+ # :ramdisk_id =>"ari-a51cf9cc",
76
+ # :placement =>{"availabilityZone"=>"us-east-1a"},
77
+ # :product_codes =>nil,
78
+ # :image_id =>"ami-bf5eb9d6",
79
+ # :launch_time =>"2009-05-29T05:07:09.000Z",
80
+ # :key_name =>"poolname_cloudname",
81
+ # :instance_id =>"i-1b7b2942",
82
+ # :ami_launch_index =>"0",
83
+ # :instance_type =>"m1.small"}
84
84
  #
85
85
  # Selects the first instance if an index is not given.
86
86
  def self.describe_instance(response, index=0)
87
- inst=response['reservationSet']['item'].first['instancesSet']['item'][index]
88
- Ec2RemoteInstance.new(symbolize_and_snakecase(inst))
87
+ inst = if response.has_key?("reservationSet")
88
+ response['reservationSet']['item'].first['instancesSet']['item'][index]
89
+ elsif response.has_key?("instancesSet")
90
+ response['instancesSet']['item'][index]
91
+ else
92
+ raise StandardError.new("EC2ResponseObject was given a response it doesn't know about\n\t#{response.inspect}")
93
+ end
94
+
95
+ # Ec2RemoteInstance.new(
96
+ symbolize_and_snakecase(inst)
89
97
  end
90
98
 
91
99
  def self.describe_instances(response)
@@ -0,0 +1,73 @@
1
+ =begin rdoc
2
+
3
+ =end
4
+ require 'xmlsimple'
5
+
6
+ module PoolParty
7
+ module Remote
8
+ class Libvirt < Remote::RemoterBase
9
+ include Dslify
10
+
11
+ default_options :image_id => nil
12
+
13
+ def initialize(opts={}, &block)
14
+ set_vars_from_options opts
15
+ super
16
+ end
17
+
18
+ def self.launch_new_instance!(o={})
19
+ new(o).launch_new_instance!
20
+ end
21
+ def launch_new_instance!(o={})
22
+ `virsh start #{image_id}`
23
+ describe_instance :image_id=>image_id
24
+ end
25
+ # Terminate an instance by id
26
+ def self.terminate_instance!(o={})
27
+ new(o).terminate_instance!
28
+ end
29
+ def terminate_instance!(o={})
30
+ `virsh shutdown #{image_id}`
31
+ end
32
+
33
+ def self.describe_instance(o={})
34
+ new(o).describe_instance
35
+ end
36
+ def describe_instance(o={})
37
+ LibvirtInstance.new(o).description
38
+ end
39
+
40
+ # Returns an array of instance name => state
41
+ # For example:
42
+ # [{"i-3687065A" =>"shut off"},
43
+ # {"jaunty19" =>"shut off"},
44
+ # {"jauntykvm" =>"running"}]
45
+ def self.describe_instances(o={})
46
+ new(o).describe_instances
47
+ end
48
+ def describe_instances(o={})
49
+ output = `virsh list`.split("\n")
50
+ return [] if output.empty? || output.size < 3
51
+ output[2..-1].collect do |i|
52
+ d=i.split(' ')
53
+ LibvirtInstance.new(:name => d[1], :status => d[2..-1].join(' '))
54
+ end
55
+ end
56
+
57
+ # After launch callback
58
+ # This is called after a new instance is launched
59
+ def after_launched(force=false)
60
+ puts "new instance was launched"
61
+ end
62
+
63
+ # Before shutdown callback
64
+ # This is called before the cloud is contracted
65
+ def before_shutdown
66
+ end
67
+ def self.virsh
68
+ new({}).path_to_binary
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,64 @@
1
+ require 'xmlsimple'
2
+
3
+ module PoolParty
4
+ module Remote
5
+
6
+ class LibvirtInstance < RemoteInstance
7
+ include Dslify
8
+
9
+ dsl_methods :name,
10
+ :instance_id, # Libvirt UUID
11
+ :image_id,
12
+ :ip, # Ip of the remote instance, by default, the public_ip
13
+ :internal_ip, # Internal ip of the remote instance
14
+ :public_ip,
15
+ :status, # Status of the remote instance
16
+ :mac_address,
17
+ :keypair_name,
18
+ :cloud
19
+
20
+ def initialize(o={})
21
+ set_vars_from_options o
22
+ # super
23
+ end
24
+
25
+ def to_hash
26
+ dsl_options
27
+ end
28
+
29
+ def keypair(*n)
30
+ dsl_options[:keypair] ||= Key.new(keypair_name)
31
+ end
32
+
33
+ # TODO: this needs to be extended for selecting between multiple interfaces
34
+ def mac_address(hsh=nil)
35
+ mac_addresses.first(hsh)
36
+ end
37
+
38
+ def mac_addresses(hsh=nil)
39
+ data = hsh || description
40
+ data[:devices].select{|el|
41
+ el.has_key? :interface
42
+ }.collect{|eth|
43
+ eth.interface.collect{|n| n.mac}
44
+ }.flatten.collect{|c| c.values}.flatten
45
+ end
46
+
47
+ def description
48
+ p command = "virsh dumpxml #{instance_id || image_id || name}"
49
+ xml = `#{command}`
50
+ hsh = XmlSimple.xml_in(xml, 'KeyToSymbol'=>true)
51
+ hsh[:state] = `virsh domstate #{instance_id || image_id || name}`
52
+ hsh[:mac_address] = mac_addresses( hsh ).first
53
+ dsl_options.merge! hsh
54
+ self
55
+ end
56
+
57
+ def mac_address
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
@@ -11,21 +11,23 @@ module PoolParty
11
11
  include ::PoolParty::CloudResourcer
12
12
 
13
13
  default_options(
14
- # :machine_image => 'ubuntu-kvm',
15
- # :key => lambda {Key.new},
16
- # :keypair_name => lambda {key.basename},
17
- # :keypair_path => lambda {key.full_filepath},
18
- # :public_key => lambda { key.public_key.to_s },
19
- :keypair_name => nil,
20
- :keypair_path => nil,
21
14
  :authorized_keys => nil,
22
- :remoter_base => :vmrun,
15
+ :remoter_base => :libvirt,
23
16
  :server_config => {}
24
17
  )
25
18
 
26
19
  def initialize(o={}, &block)
27
20
  using o[:remoter_base], o.delete(:remote_base) if o.has_key?(:remoter_base)
28
21
  super
22
+ set_vars_from_options remote_base.dsl_options
23
+ end
24
+
25
+ def method_missing(m, args, &blk)
26
+ remote_base.respond_to?(m) ? remote_base.send(m, args, &blk) : super
27
+ end
28
+
29
+ def authorized_keys
30
+ keypair.public_key
29
31
  end
30
32
 
31
33
  def remote_base(n=nil)
@@ -35,15 +37,21 @@ module PoolParty
35
37
  @remote_base = n
36
38
  end
37
39
  end
38
-
40
+
41
+ def image_id
42
+ dsl_options[:remote_base].image_id
43
+ end
44
+
45
+ #Setup server instance that will talk to metavirt webservice
39
46
  def server
40
47
  if @server
41
48
  @server
42
49
  else
43
- opts = {:content_type =>'application/json',
44
- :accept => 'application/json',
45
- :host => 'http://localhost',
46
- :port => '3000'}.merge(server_config)
50
+ opts = { :content_type =>'application/json',
51
+ :accept => 'application/json',
52
+ :host => 'http://localhost',
53
+ :port => '3000'
54
+ }.merge(server_config)
47
55
  @uri = "#{opts.delete(:host)}:#{opts.delete(:port)}"
48
56
  @server = RestClient::Resource.new( @uri, opts)
49
57
  end
@@ -56,8 +64,9 @@ module PoolParty
56
64
  opts = to_hash.merge(o)
57
65
  result = JSON.parse(server['/run-instance'].put(opts.to_json)).symbolize_keys!
58
66
  @id = result[:instance_id]
59
- result
67
+ MetavirtInstance.new result
60
68
  end
69
+
61
70
  # Terminate an instance by id
62
71
  def self.terminate_instance!(o={})
63
72
  new(nil, o).terminate_instance!
@@ -65,7 +74,7 @@ module PoolParty
65
74
  def terminate_instance!(o={})
66
75
  opts = to_hash.merge(o)
67
76
  raise "id or instance_id must be set before calling describe_instace" if !id(o)
68
- server["/instance/#{id(o)}"].delete
77
+ MetavirtInstance.new server["/instances/#{id(o)}"].delete.json_parse
69
78
  end
70
79
 
71
80
  # Describe an instance's status, must pass :vmx_file in the options
@@ -75,7 +84,7 @@ module PoolParty
75
84
  def describe_instance(o={})
76
85
  opts = to_hash.merge(o)
77
86
  raise "id or instance_id must be set before calling describe_instace" if !id(o)
78
- server["/instance/#{id(o)}"].get.json_parse
87
+ MetavirtInstance.new server["/instances/#{id(o)}"].get.json_parse
79
88
  end
80
89
 
81
90
  def self.describe_instances(o={})
@@ -83,7 +92,8 @@ module PoolParty
83
92
  end
84
93
  def describe_instances(o={})
85
94
  opts = to_hash.merge(o)
86
- JSON.parse( server["/instances/"].get ).collect{|i| i.symbolize_keys!}
95
+ list = JSON.parse( server["/instances/"].get ).collect{|i| i.symbolize_keys!}
96
+ list.collect{|l| MetavirtInstance.new l}
87
97
  end
88
98
 
89
99
  def to_hash