openstack 1.1.0 → 1.1.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.
data/README.rdoc CHANGED
@@ -127,6 +127,8 @@ See the class definitions for documentation on specific methods and operations.
127
127
  :namespace=>"http://docs.openstack.org/ext/floating_ips/api/v1.1", :name=>"Floating_ips", :alias=>"os-floating-ips"},
128
128
  ... }
129
129
 
130
+ ==== Compute API keypairs extension
131
+
130
132
  # Get list of keypairs for current tenant/account:
131
133
  >> os.keypairs
132
134
  => { :key_one => { :fingerprint => "3f:12:4d:d1:54:f1:f4:3f:fe:a8:12:ec:1a:fb:35:b2",
@@ -156,6 +158,8 @@ See the class definitions for documentation on specific methods and operations.
156
158
  >> os.delete_keypair("test_key_imported")
157
159
  => true
158
160
 
161
+ ==== Compute API security groups extension
162
+
159
163
  # List all security groups:
160
164
  >> os.security_groups
161
165
  => { "1381" => { :tenant_id=>"12345678909876", :id=>1381, :name=>"default", :description=>"default",
@@ -191,6 +195,8 @@ See the class definitions for documentation on specific methods and operations.
191
195
  >> os.delete_security_group(9571)
192
196
  => true
193
197
 
198
+ ==== Compute API volumes extension:
199
+
194
200
  #Attach a volume to a server - params in order are: server_id, volume_id, attachment_point
195
201
 
196
202
  >> os.attach_volume(704289, 90805, "/dev/sde")
@@ -205,6 +211,33 @@ See the class definitions for documentation on specific methods and operations.
205
211
  >> os.detach_volume(704289, 90805)
206
212
  => true
207
213
 
214
+ ==== Compute API floating IPs extension:
215
+
216
+ #List all floating IPs
217
+ irb(main):003:0> nova.get_floating_ips
218
+ => [#<OpenStack::Compute::FloatingIPAddress:0x000000031d07b0 @fixed_ip=nil, @id=3714, @instance_id=nil, @ip="15.185.110.129", @pool=nil>, #<OpenStack::Compute::FloatingIPAddress:0x00000003210478 @fixed_ip=nil, @id=4034, @instance_id=nil, @ip="15.185.111.193", @pool=nil>]
219
+
220
+ #Get a specific floating IP:
221
+ irb(main):004:0> nova.get_floating_ip(4034)
222
+ => #<OpenStack::Compute::FloatingIPAddress:0x00000002349958 @fixed_ip=nil, @id=4034, @instance_id=nil, @ip="15.185.111.193", @pool=nil>
223
+
224
+ #Create floating IP - optionally specifying 'pool' as {:pool=>"foo"}
225
+ irb(main):003:0> addr = nova.create_floating_ip
226
+ => #<OpenStack::Compute::FloatingIPAddress:0x00000001882c68 @fixed_ip=nil, @id=3932, @instance_id=nil, @ip="15.185.111.91", @pool=nil>
227
+
228
+ #Delete a floating IP by ID:
229
+ irb(main):004:0> nova.delete_floating_ip(addr.id)
230
+ => true
231
+
232
+ #Attach floating IP to running server - hash param speciried :server_id and :ip_id
233
+ irb(main):014:0> nova.attach_floating_ip({:server_id=>"73c12492-e966-4af0-a5e9-b5d1e436fe61", :ip_id=>"3932"})
234
+ => true
235
+
236
+ #Detach floating IP from server - hash param as above for attach
237
+ irb(main):014:0> nova.detach_floating_ip({:server_id=>"73c12492-e966-4af0-a5e9-b5d1e436fe61", :ip_id=>"3932"})
238
+ => true
239
+
240
+
208
241
  == Examples for Volumes and Snaphots:
209
242
 
210
243
  #NOTE - attach/detach operations are implemented for the compute service as the OS API defines these operations as extensions to Openstack Compute.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -60,6 +60,23 @@ module Compute
60
60
  end
61
61
  end
62
62
 
63
+ end
64
+
65
+ class FloatingIPAddress
66
+
67
+ attr_reader :fixed_ip
68
+ attr_reader :id
69
+ attr_reader :instance_id
70
+ attr_reader :ip
71
+ attr_reader :pool
72
+
73
+ def initialize(addr_hash)
74
+ @fixed_ip = addr_hash["fixed_ip"]
75
+ @id = addr_hash["id"]
76
+ @instance_id = addr_hash["instance_id"]
77
+ @ip = addr_hash["ip"]
78
+ @pool = addr_hash["pool"]
79
+ end
63
80
 
64
81
 
65
82
  end
@@ -407,6 +407,73 @@ module Compute
407
407
  response = @connection.req("DELETE", "/servers/#{server_id}/os-volume_attachments/#{attachment_id}")
408
408
  true
409
409
  end
410
- end
410
+
411
+
412
+ #FLOATING IPs:
413
+ #list all float ips associated with tennant or account
414
+ def get_floating_ips
415
+ check_extension("os-floating-ips")
416
+ response = @connection.req("GET", "/os-floating-ips")
417
+ res = JSON.parse(response.body)["floating_ips"]
418
+ res.inject([]){|result, c| result<< OpenStack::Compute::FloatingIPAddress.new(c) ; result }
419
+ end
420
+ alias :floating_ips :get_floating_ips
421
+
422
+ #get details of a specific floating_ip by its id
423
+ def get_floating_ip(id)
424
+ check_extension("os-floating-ips")
425
+ response = @connection.req("GET", "/os-floating-ips/#{id}")
426
+ res = JSON.parse(response.body)["floating_ip"]
427
+ OpenStack::Compute::FloatingIPAddress.new(res)
428
+ end
429
+ alias :floating_ip :get_floating_ip
430
+
431
+
432
+ #can optionally pass the :pool parameter
433
+ def create_floating_ip(opts={})
434
+ check_extension("os-floating-ips")
435
+ data = opts[:pool] ? JSON.generate(opts) : JSON.generate({:pool=>nil})
436
+ response = @connection.req("POST", "/os-floating-ips",{:data=>data} )
437
+ res = JSON.parse(response.body)["floating_ip"]
438
+ OpenStack::Compute::FloatingIPAddress.new(res)
439
+ end
440
+ alias :allocate_floating_ip :create_floating_ip
441
+
442
+ #delete or deallocate a floating IP using its id
443
+ def delete_floating_ip(id)
444
+ check_extension("os-floating-ips")
445
+ response = @connection.req("DELETE", "/os-floating-ips/#{id}")
446
+ true
447
+ end
448
+
449
+ #add or attach a floating IP to a runnin g server
450
+ def attach_floating_ip(opts={:server_id=>"", :ip_id => ""})
451
+ check_extension("os-floating-ips")
452
+ #first get the address:
453
+ addr = get_floating_ip(opts[:ip_id]).ip
454
+ data = JSON.generate({:addFloatingIp=>{:address=>addr}})
455
+ response = @connection.req("POST", "/servers/#{opts[:server_id]}/action", {:data=>data})
456
+ true
457
+ end
458
+
459
+ def detach_floating_ip(opts={:server_id=>"", :ip_id => ""})
460
+ check_extension("os-floating-ips")
461
+ #first get the address:
462
+ addr = get_floating_ip(opts[:ip_id]).ip
463
+ data = JSON.generate({:removeFloatingIp=>{:address=>addr}})
464
+ response = @connection.req("POST", "/servers/#{opts[:server_id]}/action", {:data=>data})
465
+ true
466
+ end
467
+
468
+ private
469
+
470
+ def check_extension(name)
471
+ raise OpenStack::Exception::NotImplemented.new("#{name} not implemented by #{@connection.http.keys.first}", 501, "NOT IMPLEMENTED") unless api_extensions[name.to_sym]
472
+ true
473
+ end
474
+
475
+
476
+ end
477
+
411
478
  end
412
479
  end
@@ -12,6 +12,7 @@ module OpenStack
12
12
  attr_reader :snapshot_id
13
13
  attr_reader :attachments
14
14
  attr_reader :created_at
15
+ attr_reader :status
15
16
 
16
17
  def initialize(volume_info)
17
18
  @id = volume_info["id"]
@@ -24,6 +25,7 @@ module OpenStack
24
25
  @snapshot_id = volume_info["snapshot_id"] || volume_info["snapshotId"]
25
26
  @attachments = volume_info["attachments"]
26
27
  @created_at = volume_info["created_at"] || volume_info["createdAt"]
28
+ @status = volume_info["status"]
27
29
  end
28
30
 
29
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-21 00:00:00.000000000 Z
13
+ date: 2013-07-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mocha
@@ -123,4 +123,3 @@ signing_key:
123
123
  specification_version: 3
124
124
  summary: OpenStack Ruby API
125
125
  test_files: []
126
- has_rdoc: