openstack 1.1.2 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +58 -0
- data/README.md +19 -0
- data/VERSION +1 -0
- data/lib/openstack.rb +5 -19
- data/lib/openstack/compute/connection.rb +74 -31
- data/lib/openstack/compute/flavor.rb +18 -30
- data/lib/openstack/compute/server.rb +98 -0
- data/lib/openstack/connection.rb +45 -8
- data/lib/openstack/core_ext/to_query.rb +84 -0
- data/lib/openstack/identity/connection.rb +69 -0
- data/lib/openstack/identity/tenant.rb +17 -0
- data/lib/openstack/identity/user.rb +19 -0
- data/lib/openstack/network/network.rb +21 -22
- data/lib/openstack/network/router.rb +3 -5
- data/lib/openstack/swift/connection.rb +10 -4
- data/lib/openstack/volume/connection.rb +25 -0
- data/test/runner.rb +10 -0
- data/test/test_helper.rb +6 -9
- metadata +33 -35
- data/README.rdoc +0 -462
- data/lib/openstack/version.rb +0 -3
- data/test/authentication_test.rb +0 -120
- data/test/connection_test.rb +0 -39
- data/test/exception_test.rb +0 -49
- data/test/metadata_test.rb +0 -210
- data/test/servers_test.rb +0 -210
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6aa4981b8693d6fd48912f20b6c43afe6d18a95e
|
4
|
+
data.tar.gz: 0f45c93f9539a94b55d8d5f4e0bbdf381f03d874
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abb9b0882bf767eda9fc9e892ae5dc11966b69cd164c4a0370f9fa83ee4f4f98960871acd46647516577e9d3a6b5aeea0b402a8f96f20b0f252087e8d372094b
|
7
|
+
data.tar.gz: 0dd7ef4e9cf3b9dce4ed747338a31125ffd83e21bebd0aefdc8ede1ce976c2b9f3170f989508e75a3dcf153f489f2e28d724045b01a558cb9ec4eaa8d9fd8370
|
data/CHANGELOG
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
Tue Dec 03 2013 Marios Andreou (marios@redhat.com) - 1.1.2
|
2
|
+
- much networking contributions and fixes from Ivan Ponomarev zipfer, pull 30
|
3
|
+
|
4
|
+
*Tue Jul 09 2013 Marios Andreou (marios@redhat.com) - 1.1.1
|
5
|
+
- Adds floating-ips support ("os-floating-ips" extension for nova) - pull 28
|
6
|
+
- Add 'status' attribute to volume object - pull 29
|
7
|
+
|
8
|
+
*Fri Apr 12 2013 Marios Andreou (marios@redhat.com) - 1.1.0
|
9
|
+
- adds Quantum support - see pull request 23
|
10
|
+
- bugfix for nginx support with 0length content body (pull request 22)
|
11
|
+
|
12
|
+
*Thu Feb 07 2013 Marios Andreou (marios@redhat.com) - 1.0.9
|
13
|
+
- various bug fixes/improvements: pull requests 20, 19, 18, 16
|
14
|
+
- adds 'regions_list' hash to connection object (see pull request 19)
|
15
|
+
|
16
|
+
*Wed Jan 23 2013 Marios Andreou (marios@redhat.com) - 1.0.8
|
17
|
+
- Adds support for storage snapshots
|
18
|
+
|
19
|
+
*Mon Nov 19 2012 Marios Andreou (marios@redhat.com) - 1.0.7
|
20
|
+
- Adds support for storage-volumes https://github.com/ruby-openstack/ruby-openstack/pull/15
|
21
|
+
- Adds support for multi-version deployments(https://github.com/ruby-openstack/ruby-openstack/pull/14)
|
22
|
+
|
23
|
+
*Fri Sep 21 2012 Marios Andreou (marios@redhat.com) - 1.0.6
|
24
|
+
- fixes related to https://github.com/ruby-openstack/ruby-openstack/pull/14
|
25
|
+
multi-version deployments - grab only greatest API version endpoints.
|
26
|
+
Thanks to andronat
|
27
|
+
|
28
|
+
*Thu Sep 13 2012 Marios Andreou <marios@redhat.com> - 1.0.6
|
29
|
+
- major bug in gemspec meant jeweler created circular reference to gem itself
|
30
|
+
(described here: https://github.com/technicalpickles/jeweler/issues/188)
|
31
|
+
|
32
|
+
*Thu Sep 13 2012 Marios Andreou <marios@redhat.com> - 1.0.5
|
33
|
+
- bug fix/feature - adds a check to see if requested service is deployed
|
34
|
+
(e.g. set 'service_type' to 'object-store' but swift not deployed
|
35
|
+
=> 501 Not Implemented)
|
36
|
+
https://github.com/ruby-openstack/ruby-openstack/pull/13
|
37
|
+
|
38
|
+
*Wed Sep 06 2012 Marios Andreou <marios@redhat.com> - 1.0.4
|
39
|
+
- bug fixes: https://github.com/ruby-openstack/ruby-openstack/issues/9,
|
40
|
+
- https://github.com/ruby-openstack/ruby-openstack/pull/10
|
41
|
+
|
42
|
+
* Fri Aug 24 2012 Marios Andreou <marios@redhat.com> - 1.0.3
|
43
|
+
- bugfix - missed case when provider doesn't support security groups (null pointer
|
44
|
+
trying to grab non existing key from /server/id response)
|
45
|
+
|
46
|
+
* Fri Aug 24 2012 Marios Andreou <marios@redhat.com> - 1.0.2
|
47
|
+
- adds support for security_groups api extension
|
48
|
+
- fixes labelling of IP addresses - public/private
|
49
|
+
- first pass at fixing tests - they run, but aren't complete.
|
50
|
+
|
51
|
+
* Fri June 22 2012 Marios Andreou <marios@redhat.com> - 1.0.1 #version bump
|
52
|
+
- adds support for api_extensions - keypairs (list/create/delete and include in server instance params)
|
53
|
+
|
54
|
+
* Mon June 18 2012 Marios Andreou <marios@redhat.com> - 1.0.0
|
55
|
+
- adds key based authentication (ec2 style key/priv. key) - also allows for authtenant_id instead of authtenant/authtenant_name
|
56
|
+
|
57
|
+
* Wed May 23 2012 Marios Andreou <marios@redhat.com> - 1.0.0
|
58
|
+
- initial checkin of merged code - rackspace/ruby-cloudfiles and rackspace/ruby-openstack-compute
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Ruby OpenStack
|
2
|
+
|
3
|
+
Ruby OpenStack Compute, Object-Store, Block Storage and Network bindings for the OpenStack API. It supports Keystone Authentication (v1.0 and v2.0), Nova and Swift. See the [getting started](https://github.com/ruby-openstack/ruby-openstack/wiki) for documentation.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/ruby-openstack/ruby-openstack.svg?branch=next)](https://travis-ci.org/ruby-openstack/ruby-openstack)
|
6
|
+
|
7
|
+
## Authors
|
8
|
+
|
9
|
+
* Marios Andreou (marios@redhat.com)
|
10
|
+
* Dan Prince (dprince@redhat.com)
|
11
|
+
* Naveed Massjouni (naveedm9@gmail.com)
|
12
|
+
* Aaron Fischer (aaron.fischer@marbis.net)
|
13
|
+
* Alexander Birkner (alexander.birkner@marbis.net)
|
14
|
+
|
15
|
+
Initial code checkin on May 23rd 2012 - code refactored from and based on the Rackspace [Cloud Servers gem](https://github.com/rackspace/ruby-openstack-compute) and [Rackspace Cloud Files gem](https://github.com/rackspace/ruby-cloudfiles). Since Nov 2015 maintained by [Marbis GmbH](http://nitrado.net/).
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
See COPYING for license information.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.2
|
data/lib/openstack.rb
CHANGED
@@ -1,23 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# == Ruby OpenStack API
|
4
|
-
#
|
5
|
-
# See COPYING for license information.
|
6
|
-
# ----
|
7
|
-
#
|
8
|
-
# === Documentation & Examples
|
9
|
-
# To begin reviewing the available methods and examples, view the README.rdoc file
|
10
|
-
#
|
11
|
-
# Example:
|
12
|
-
# os = OpenStack::Connection.create({:username => "herp@derp.com", :api_key=>"password",
|
13
|
-
# :auth_url => "https://region-a.geo-1.identity.cloudsvc.com:35357/v2.0/",
|
14
|
-
# :authtenant=>"herp@derp.com-default-tenant", :service_type=>"object-store")
|
15
|
-
#
|
16
|
-
# will return a handle to the object-storage service swift. Alternatively, passing
|
17
|
-
# :service_type=>"compute" will return a handle to the compute service nova.
|
18
2
|
|
19
3
|
module OpenStack
|
20
|
-
|
21
4
|
require 'net/http'
|
22
5
|
require 'net/https'
|
23
6
|
require 'uri'
|
@@ -50,7 +33,11 @@ module OpenStack
|
|
50
33
|
require 'openstack/network/subnet'
|
51
34
|
require 'openstack/network/router'
|
52
35
|
require 'openstack/network/port'
|
53
|
-
require 'openstack/
|
36
|
+
require 'openstack/identity/connection'
|
37
|
+
require 'openstack/identity/tenant'
|
38
|
+
require 'openstack/identity/user'
|
39
|
+
require 'openstack/core_ext/to_query'
|
40
|
+
|
54
41
|
# Constants that set limits on server creation
|
55
42
|
MAX_PERSONALITY_ITEMS = 5
|
56
43
|
MAX_PERSONALITY_FILE_SIZE = 10240
|
@@ -111,5 +98,4 @@ module OpenStack
|
|
111
98
|
end
|
112
99
|
url
|
113
100
|
end
|
114
|
-
|
115
101
|
end
|
@@ -33,17 +33,19 @@ module Compute
|
|
33
33
|
|
34
34
|
# Returns an array of hashes, one for each server that exists under this account. The hash keys are :name and :id.
|
35
35
|
#
|
36
|
-
# You can also provide :limit and :offset
|
36
|
+
# You can also provide :limit and :offset and :"changes-since" and :image and :flavor and :name and :status
|
37
|
+
# and :host and :limit and :marker parameters to handle pagination.
|
38
|
+
# http://developer.openstack.org/api-ref-compute-v2.1.html
|
37
39
|
#
|
38
40
|
# >> cs.list_servers
|
39
41
|
# => [{:name=>"MyServer", :id=>110917}]
|
40
42
|
#
|
41
|
-
# >> cs.list_servers(:limit => 2, :offset => 3)
|
43
|
+
# >> cs.list_servers(:limit => 2, :offset => 3, :name => "MyServer", :status => "ACTIVE")
|
42
44
|
# => [{:name=>"demo-standingcloud-lts", :id=>168867},
|
43
45
|
# {:name=>"demo-aicache1", :id=>187853}]
|
44
46
|
def list_servers(options = {})
|
45
47
|
anti_cache_param="cacheid=#{Time.now.to_i}"
|
46
|
-
path =
|
48
|
+
path = options.empty? ? "#{@connection.service_path}/servers?#{anti_cache_param}" : "#{@connection.service_path}/servers?#{options.to_query}&#{anti_cache_param}"
|
47
49
|
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
|
48
50
|
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
49
51
|
OpenStack.symbolize_keys(JSON.parse(response.body)["servers"])
|
@@ -54,15 +56,17 @@ module Compute
|
|
54
56
|
# includes public and private IP addresses, status, hostID, and more. All hash keys are symbols except for the metadata
|
55
57
|
# hash, which are verbatim strings.
|
56
58
|
#
|
57
|
-
# You can also provide :limit and :offset
|
59
|
+
# You can also provide :limit and :offset and :"changes-since" and :image and :flavor and :name and :status and :host
|
60
|
+
# and :limit and :marker parameters to handle pagination.
|
61
|
+
# http://developer.openstack.org/api-ref-compute-v2.1.html
|
58
62
|
# >> cs.list_servers_detail
|
59
63
|
# => [{:name=>"MyServer", :addresses=>{:public=>["67.23.42.37"], :private=>["10.176.241.237"]}, :metadata=>{"MyData" => "Valid"}, :imageRef=>10, :progress=>100, :hostId=>"36143b12e9e48998c2aef79b50e144d2", :flavorRef=>1, :id=>110917, :status=>"ACTIVE"}]
|
60
64
|
#
|
61
|
-
# >> cs.list_servers_detail(:limit => 2, :offset => 3)
|
65
|
+
# >> cs.list_servers_detail(:limit => 2, :offset => 3, :name => "MyServer", :flavor => 1, :status => "ACTIVE")
|
62
66
|
# => [{:status=>"ACTIVE", :imageRef=>10, :progress=>100, :metadata=>{}, :addresses=>{:public=>["x.x.x.x"], :private=>["x.x.x.x"]}, :name=>"demo-standingcloud-lts", :id=>168867, :flavorRef=>1, :hostId=>"xxxxxx"},
|
63
67
|
# {:status=>"ACTIVE", :imageRef=>8, :progress=>100, :metadata=>{}, :addresses=>{:public=>["x.x.x.x"], :private=>["x.x.x.x"]}, :name=>"demo-aicache1", :id=>187853, :flavorRef=>3, :hostId=>"xxxxxx"}]
|
64
68
|
def list_servers_detail(options = {})
|
65
|
-
path =
|
69
|
+
path = options.empty? ? "#{@connection.service_path}/servers/detail" : "#{@connection.service_path}/servers/detail?#{options.to_query}"
|
66
70
|
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
|
67
71
|
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
68
72
|
json_server_list = JSON.parse(response.body)["servers"]
|
@@ -127,18 +131,19 @@ module Compute
|
|
127
131
|
# Returns an array of hashes listing available server images that you have access too,
|
128
132
|
# including stock OpenStack Compute images and any that you have created. The "id" key
|
129
133
|
# in the hash can be used where imageRef is required. You can also provide :limit and
|
130
|
-
# :offset
|
134
|
+
# :offset and :"changes-since" and :server and :name and :status :minDisk and :minRam
|
135
|
+
# and :type and :limit and :marker parameters to handle pagination.
|
131
136
|
#
|
132
137
|
# >> cs.list_images
|
133
138
|
# => [{:name=>"CentOS 5.2", :id=>2, :updated=>"2009-07-20T09:16:57-05:00", :status=>"ACTIVE", :created=>"2009-07-20T09:16:57-05:00"},
|
134
139
|
# {:name=>"Gentoo 2008.0", :id=>3, :updated=>"2009-07-20T09:16:57-05:00", :status=>"ACTIVE", :created=>"2009-07-20T09:16:57-05:00"},...
|
135
140
|
#
|
136
|
-
# >> cs.list_images(:limit => 3, :offset => 2)
|
141
|
+
# >> cs.list_images(:limit => 3, :offset => 2, :status => "ACTIVE")
|
137
142
|
# => [{:status=>"ACTIVE", :name=>"Fedora 11 (Leonidas)", :updated=>"2009-12-08T13:50:45-06:00", :id=>13},
|
138
143
|
# {:status=>"ACTIVE", :name=>"CentOS 5.3", :updated=>"2009-08-26T14:59:52-05:00", :id=>7},
|
139
144
|
# {:status=>"ACTIVE", :name=>"CentOS 5.4", :updated=>"2009-12-16T01:02:17-06:00", :id=>187811}]
|
140
145
|
def list_images(options = {})
|
141
|
-
path =
|
146
|
+
path = options.empty? ? "#{@connection.service_path}/images/detail" : "#{@connection.service_path}/images/detail?#{options.to_query}"
|
142
147
|
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
|
143
148
|
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
144
149
|
OpenStack.symbolize_keys(JSON.parse(response.body)['images'])
|
@@ -157,6 +162,7 @@ module Compute
|
|
157
162
|
# Returns an array of hashes listing all available server flavors. The :id key in the hash can be used when flavorRef is required.
|
158
163
|
#
|
159
164
|
# You can also provide :limit and :offset parameters to handle pagination.
|
165
|
+
# http://developer.openstack.org/api-ref-compute-v2.1.html
|
160
166
|
#
|
161
167
|
# >> cs.list_flavors
|
162
168
|
# => [{:name=>"256 server", :id=>1, :ram=>256, :disk=>10},
|
@@ -167,7 +173,7 @@ module Compute
|
|
167
173
|
# {:ram=>2048, :disk=>80, :name=>"2GB server", :id=>4},
|
168
174
|
# {:ram=>4096, :disk=>160, :name=>"4GB server", :id=>5}]
|
169
175
|
def list_flavors(options = {})
|
170
|
-
path =
|
176
|
+
path = options.empty? ? "#{@connection.service_path}/flavors/detail" : "#{@connection.service_path}/flavors/detail?#{options.to_query}"
|
171
177
|
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
|
172
178
|
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
173
179
|
OpenStack.symbolize_keys(JSON.parse(response.body)['flavors'])
|
@@ -179,10 +185,40 @@ module Compute
|
|
179
185
|
# >> flavor = cs.flavor(1)
|
180
186
|
# => #<OpenStack::Compute::Flavor:0x10156dcc0 @name="256 server", @disk=10, @id=1, @ram=256>
|
181
187
|
def get_flavor(id)
|
182
|
-
|
188
|
+
response = @connection.req('GET', "/flavors/#{id}")
|
189
|
+
flavor_info = JSON.parse(response.body)['flavor']
|
190
|
+
OpenStack::Compute::Flavor.new(flavor_info)
|
183
191
|
end
|
184
192
|
alias :flavor :get_flavor
|
185
193
|
|
194
|
+
# nova.create_flavor({name: 'small', vcpus: 2, ram: 1024, disk: 1}, true)
|
195
|
+
# :name - must be unique, :ram - MB, :disk - GB
|
196
|
+
# => #<OpenStack::Compute::Flavor:0x007ff95333e268 @id="0c0c393b-3acd-4569-baae-7a7afbe398f6", @name="small", @ram=1024, @disk=1, @vcpus=2>
|
197
|
+
def create_flavor(options, public = false)
|
198
|
+
raise OpenStack::Exception::MissingArgument, 'Flavor name, vcpus, ram and disk, must be supplied' unless (options[:name] && options[:vcpus] && options[:ram] && options[:disk])
|
199
|
+
data = JSON.generate(:flavor => options.merge!({'os-flavor-access:is_public' => public}))
|
200
|
+
response = @connection.req('POST', '/flavors', {data: data})
|
201
|
+
flavor_info = JSON.parse(response.body)['flavor']
|
202
|
+
OpenStack::Compute::Flavor.new(flavor_info)
|
203
|
+
end
|
204
|
+
|
205
|
+
def delete_flavor(id)
|
206
|
+
@connection.req('DELETE', "/flavors/#{id}")
|
207
|
+
true
|
208
|
+
end
|
209
|
+
|
210
|
+
def add_tenant_to_flavor(flavor_id, tenant_id)
|
211
|
+
data = JSON.generate({'addTenantAccess' => {'tenant' => tenant_id}})
|
212
|
+
response = @connection.req('POST', "/flavors/#{flavor_id}/action", {data: data})
|
213
|
+
JSON.parse(response.body)
|
214
|
+
end
|
215
|
+
|
216
|
+
def delete_tenant_from_flavor(flavor_id, tenant_id)
|
217
|
+
data = JSON.generate({'removeTenantAccess' => {'tenant' => tenant_id}})
|
218
|
+
response = @connection.req('POST', "/flavors/#{flavor_id}/action", {data: data})
|
219
|
+
JSON.parse(response.body)
|
220
|
+
end
|
221
|
+
|
186
222
|
# Returns the current state of the programatic API limits. Each account has certain limits on the number of resources
|
187
223
|
# allowed in the account, and a rate of API operations.
|
188
224
|
#
|
@@ -212,12 +248,12 @@ module Compute
|
|
212
248
|
OpenStack.symbolize_keys(JSON.parse(response.body)['limits'])
|
213
249
|
end
|
214
250
|
|
215
|
-
# ==============================
|
216
|
-
# API EXTENSIONS
|
217
|
-
#
|
218
|
-
# http://nova.openstack.org/api_ext/index.html
|
219
|
-
# http://api.openstack.org/ (grep 'Compute API Extensions')
|
220
|
-
#
|
251
|
+
# ==============================
|
252
|
+
# API EXTENSIONS
|
253
|
+
#
|
254
|
+
# http://nova.openstack.org/api_ext/index.html
|
255
|
+
# http://api.openstack.org/ (grep 'Compute API Extensions')
|
256
|
+
#
|
221
257
|
|
222
258
|
|
223
259
|
#query the openstack provider for any implemented extensions to the compute API
|
@@ -364,9 +400,17 @@ module Compute
|
|
364
400
|
{res[:security_group][:id].to_s => res[:security_group]}
|
365
401
|
end
|
366
402
|
|
403
|
+
def update_security_group(id, name, description)
|
404
|
+
raise OpenStack::Exception::NotImplemented.new("os-security-groups not implemented by #{@connection.http.keys.first}", 501, "NOT IMPLEMENTED") unless api_extensions[:"os-security-groups"] or api_extensions[:security_groups]
|
405
|
+
data = JSON.generate(:security_group => { "name" => name, "description" => description})
|
406
|
+
response = @connection.req("PUT", "/os-security-groups/#{id}", {:data => data})
|
407
|
+
res = OpenStack.symbolize_keys(JSON.parse(response.body))
|
408
|
+
{res[:security_group][:id].to_s => res[:security_group]}
|
409
|
+
end
|
410
|
+
|
367
411
|
def delete_security_group(id)
|
368
412
|
raise OpenStack::Exception::NotImplemented.new("os-security-groups not implemented by #{@connection.http.keys.first}", 501, "NOT IMPLEMENTED") unless api_extensions[:"os-security-groups"] or api_extensions[:security_groups]
|
369
|
-
|
413
|
+
@connection.req("DELETE", "/os-security-groups/#{id}")
|
370
414
|
true
|
371
415
|
end
|
372
416
|
|
@@ -384,15 +428,15 @@ module Compute
|
|
384
428
|
|
385
429
|
def delete_security_group_rule(id)
|
386
430
|
raise OpenStack::Exception::NotImplemented.new("os-security-groups not implemented by #{@connection.http.keys.first}", 501, "NOT IMPLEMENTED") unless api_extensions[:"os-security-groups"] or api_extensions[:security_groups]
|
387
|
-
|
431
|
+
@connection.req("DELETE", "/os-security-group-rules/#{id}")
|
388
432
|
true
|
389
433
|
end
|
390
434
|
|
391
|
-
#VOLUMES - attach detach
|
435
|
+
#VOLUMES - attach detach
|
392
436
|
def attach_volume(server_id, volume_id, device_id)
|
393
437
|
raise OpenStack::Exception::NotImplemented.new("os-volumes not implemented by #{@connection.http.keys.first}", 501, "NOT IMPLEMENTED") unless api_extensions[:"os-volumes"]
|
394
438
|
data = JSON.generate(:volumeAttachment => {"volumeId" => volume_id, "device"=> device_id})
|
395
|
-
|
439
|
+
@connection.req("POST", "/servers/#{server_id}/os-volume_attachments", {:data=>data})
|
396
440
|
true
|
397
441
|
end
|
398
442
|
|
@@ -404,13 +448,13 @@ module Compute
|
|
404
448
|
|
405
449
|
def detach_volume(server_id, attachment_id)
|
406
450
|
raise OpenStack::Exception::NotImplemented.new("os-volumes not implemented by #{@connection.http.keys.first}", 501, "NOT IMPLEMENTED") unless api_extensions[:"os-volumes"]
|
407
|
-
|
451
|
+
@connection.req("DELETE", "/servers/#{server_id}/os-volume_attachments/#{attachment_id}")
|
408
452
|
true
|
409
453
|
end
|
410
454
|
|
411
455
|
|
412
|
-
#FLOATING IPs:
|
413
|
-
|
456
|
+
#FLOATING IPs:
|
457
|
+
#list all float ips associated with tennant or account
|
414
458
|
def get_floating_ips
|
415
459
|
check_extension("os-floating-ips")
|
416
460
|
response = @connection.req("GET", "/os-floating-ips")
|
@@ -428,7 +472,6 @@ module Compute
|
|
428
472
|
end
|
429
473
|
alias :floating_ip :get_floating_ip
|
430
474
|
|
431
|
-
|
432
475
|
#can optionally pass the :pool parameter
|
433
476
|
def create_floating_ip(opts={})
|
434
477
|
check_extension("os-floating-ips")
|
@@ -442,7 +485,7 @@ module Compute
|
|
442
485
|
#delete or deallocate a floating IP using its id
|
443
486
|
def delete_floating_ip(id)
|
444
487
|
check_extension("os-floating-ips")
|
445
|
-
|
488
|
+
@connection.req("DELETE", "/os-floating-ips/#{id}")
|
446
489
|
true
|
447
490
|
end
|
448
491
|
|
@@ -452,7 +495,7 @@ module Compute
|
|
452
495
|
#first get the address:
|
453
496
|
addr = get_floating_ip(opts[:ip_id]).ip
|
454
497
|
data = JSON.generate({:addFloatingIp=>{:address=>addr}})
|
455
|
-
|
498
|
+
@connection.req("POST", "/servers/#{opts[:server_id]}/action", {:data=>data})
|
456
499
|
true
|
457
500
|
end
|
458
501
|
|
@@ -461,14 +504,14 @@ module Compute
|
|
461
504
|
#first get the address:
|
462
505
|
addr = get_floating_ip(opts[:ip_id]).ip
|
463
506
|
data = JSON.generate({:removeFloatingIp=>{:address=>addr}})
|
464
|
-
|
507
|
+
@connection.req("POST", "/servers/#{opts[:server_id]}/action", {:data=>data})
|
465
508
|
true
|
466
509
|
end
|
467
510
|
|
468
511
|
def get_floating_ip_polls
|
469
512
|
check_extension 'os-floating-ip-pools'
|
470
513
|
response = @connection.req('GET', '/os-floating-ip-pools')
|
471
|
-
|
514
|
+
JSON.parse(response.body)['floating_ip_pools']
|
472
515
|
end
|
473
516
|
|
474
517
|
def get_floating_ips_bulk
|
@@ -493,7 +536,7 @@ module Compute
|
|
493
536
|
data = JSON.generate(opts)
|
494
537
|
check_extension 'os-floating-ips-bulk'
|
495
538
|
response = @connection.req('POST', '/os-floating-ips-bulk/delete', {:data => data})
|
496
|
-
|
539
|
+
JSON.generate(response)
|
497
540
|
end
|
498
541
|
|
499
542
|
private
|
@@ -503,7 +546,7 @@ module Compute
|
|
503
546
|
true
|
504
547
|
end
|
505
548
|
|
506
|
-
end
|
549
|
+
end
|
507
550
|
|
508
551
|
end
|
509
552
|
end
|
@@ -1,35 +1,23 @@
|
|
1
1
|
module OpenStack
|
2
|
-
module Compute
|
3
|
-
|
2
|
+
module Compute
|
3
|
+
class Flavor
|
4
|
+
attr_reader :id
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :ram
|
7
|
+
attr_reader :disk
|
8
|
+
attr_reader :vcpus
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# This is called from the get_flavor method on a OpenStack::Compute::Connection object, returns a OpenStack::Compute::Flavor object, and will likely not be called directly.
|
17
|
-
#
|
18
|
-
# >> flavor = cs.get_flavor(1)
|
19
|
-
# => #<OpenStack::Compute::Flavor:0x1014f8bc8 @name="256 server", @disk=10, @id=1, @ram=256>
|
20
|
-
# >> flavor.name
|
21
|
-
# => "256 server"
|
22
|
-
def initialize(compute,id)
|
23
|
-
response = compute.connection.csreq("GET",compute.connection.service_host,"#{compute.connection.service_path}/flavors/#{URI.escape(id.to_s)}",compute.connection.service_port,compute.connection.service_scheme)
|
24
|
-
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
25
|
-
data = JSON.parse(response.body)['flavor']
|
26
|
-
@id = data['id']
|
27
|
-
@name = data['name']
|
28
|
-
@ram = data['ram']
|
29
|
-
@disk = data['disk']
|
30
|
-
@vcpus = data['vcpus']
|
10
|
+
# This class provides an object for the "Flavor" of a server. The Flavor can generally be taken as the server specification,
|
11
|
+
# providing information on things like memory and disk space.
|
12
|
+
#
|
13
|
+
# The disk attribute is an integer representing the disk space in GB. The memory attribute is an integer representing the RAM in MB.
|
14
|
+
def initialize(flavor_info = {})
|
15
|
+
@id = flavor_info['id']
|
16
|
+
@name = flavor_info['name']
|
17
|
+
@ram = flavor_info['ram']
|
18
|
+
@disk = flavor_info['disk']
|
19
|
+
@vcpus = flavor_info['vcpus']
|
20
|
+
end
|
31
21
|
end
|
32
|
-
|
33
22
|
end
|
34
23
|
end
|
35
|
-
end
|
@@ -95,6 +95,34 @@ module Compute
|
|
95
95
|
self.reboot("HARD")
|
96
96
|
end
|
97
97
|
|
98
|
+
# Sends an API request to stop (suspend) the server.
|
99
|
+
#
|
100
|
+
# Returns true if the API call succeeds.
|
101
|
+
#
|
102
|
+
# >> server.stop()
|
103
|
+
# => true
|
104
|
+
def stop()
|
105
|
+
data = JSON.generate(:suspend => nil)
|
106
|
+
puts data
|
107
|
+
pp "About to post ACTION"
|
108
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
109
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
113
|
+
# Sends an API request to start (resume) the server.
|
114
|
+
#
|
115
|
+
# Returns true if the API call succeeds.
|
116
|
+
#
|
117
|
+
# >> server.start()
|
118
|
+
# => true
|
119
|
+
def start()
|
120
|
+
data = JSON.generate(:resume => nil)
|
121
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
122
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
123
|
+
true
|
124
|
+
end
|
125
|
+
|
98
126
|
# Updates various parameters about the server. Currently, the only operations supported are changing the server name (not the actual hostname
|
99
127
|
# on the server, but simply the label in the Servers API) and the administrator password (note: changing the admin password will trigger
|
100
128
|
# a reboot of the server). Other options are ignored. One or both key/value pairs may be provided. Keys are case-sensitive.
|
@@ -251,6 +279,76 @@ module Compute
|
|
251
279
|
address_list
|
252
280
|
end
|
253
281
|
|
282
|
+
#Get novnc console URL
|
283
|
+
#Return Hash with type and URL
|
284
|
+
def get_console
|
285
|
+
data = JSON.generate("os-getVNCConsole" => {:type => "novnc"})
|
286
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
287
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
288
|
+
JSON::parse(response.body)["console"]
|
289
|
+
end
|
290
|
+
|
291
|
+
#Get console output
|
292
|
+
#Return output string object
|
293
|
+
def get_console_output(length=50)
|
294
|
+
data = JSON.generate("os-getConsoleOutput" => {:length => length})
|
295
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
296
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
297
|
+
JSON::parse(response.body)["output"]
|
298
|
+
end
|
299
|
+
|
300
|
+
# Sends an API request to pause this server.
|
301
|
+
#
|
302
|
+
# Returns true if the API call succeeds.
|
303
|
+
#
|
304
|
+
# >> server.pause
|
305
|
+
# => true
|
306
|
+
def pause
|
307
|
+
data = JSON.generate(:pause => nil)
|
308
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
309
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
310
|
+
true
|
311
|
+
end
|
312
|
+
|
313
|
+
# Sends an API request to unpause this server.
|
314
|
+
#
|
315
|
+
# Returns true if the API call succeeds.
|
316
|
+
#
|
317
|
+
# >> server.unpause
|
318
|
+
# => true
|
319
|
+
def unpause
|
320
|
+
data = JSON.generate(:unpause => nil)
|
321
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
322
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
323
|
+
true
|
324
|
+
end
|
325
|
+
|
326
|
+
# Sends an API request to suspend this server.
|
327
|
+
#
|
328
|
+
# Returns true if the API call succeeds.
|
329
|
+
#
|
330
|
+
# >> server.suspend
|
331
|
+
# => true
|
332
|
+
def suspend
|
333
|
+
data = JSON.generate(:suspend => nil)
|
334
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
335
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
336
|
+
true
|
337
|
+
end
|
338
|
+
|
339
|
+
# Sends an API request to resume this server.
|
340
|
+
#
|
341
|
+
# Returns true if the API call succeeds.
|
342
|
+
#
|
343
|
+
# >> server.resume
|
344
|
+
# => true
|
345
|
+
def resume
|
346
|
+
data = JSON.generate(:resume => nil)
|
347
|
+
response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
|
348
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
349
|
+
true
|
350
|
+
end
|
351
|
+
|
254
352
|
end
|
255
353
|
end
|
256
354
|
end
|