openstack 1.1.2 → 2.0.2
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.
- 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
data/test/runner.rb
ADDED
data/test/test_helper.rb
CHANGED
@@ -1,22 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
-
require 'mocha'
|
3
|
+
require 'mocha/test_unit'
|
4
|
+
|
4
5
|
$:.unshift File.dirname(__FILE__) + '/../lib'
|
6
|
+
|
5
7
|
require 'openstack'
|
6
8
|
|
7
9
|
module TestConnection
|
8
|
-
|
9
|
-
def get_test_connection
|
10
|
-
|
10
|
+
def get_test_connection
|
11
11
|
conn_response = {'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token'}
|
12
12
|
conn_response.stubs(:code).returns('204')
|
13
|
-
#server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
14
13
|
server = mock(:start => true, :finish => true)
|
15
14
|
server.stubs(:get => conn_response, :use_ssl= => true, :verify_mode= => true)
|
16
|
-
|
15
|
+
|
17
16
|
Net::HTTP.stubs(:new).returns(server)
|
18
17
|
OpenStack::Connection.create(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => "http://a.b.c")
|
19
|
-
|
20
|
-
end
|
21
|
-
|
18
|
+
end
|
22
19
|
end
|
metadata
CHANGED
@@ -1,93 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dan Prince
|
9
8
|
- Marios Andreou
|
9
|
+
- Naveed Massjouni
|
10
|
+
- Aaron Fischer
|
11
|
+
- Alexander Birkner
|
10
12
|
autorequire:
|
11
13
|
bindir: bin
|
12
14
|
cert_chain: []
|
13
|
-
date:
|
15
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
14
16
|
dependencies:
|
15
17
|
- !ruby/object:Gem::Dependency
|
16
18
|
name: mocha
|
17
19
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
20
|
requirements:
|
20
|
-
- -
|
21
|
+
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
23
|
version: '0'
|
23
24
|
type: :development
|
24
25
|
prerelease: false
|
25
26
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '0'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rake
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
34
|
requirements:
|
36
|
-
- -
|
35
|
+
- - ">="
|
37
36
|
- !ruby/object:Gem::Version
|
38
37
|
version: '0'
|
39
38
|
type: :development
|
40
39
|
prerelease: false
|
41
40
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
41
|
requirements:
|
44
|
-
- -
|
42
|
+
- - ">="
|
45
43
|
- !ruby/object:Gem::Version
|
46
44
|
version: '0'
|
47
45
|
- !ruby/object:Gem::Dependency
|
48
46
|
name: test-unit
|
49
47
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
48
|
requirements:
|
52
|
-
- -
|
49
|
+
- - ">="
|
53
50
|
- !ruby/object:Gem::Version
|
54
51
|
version: '0'
|
55
52
|
type: :development
|
56
53
|
prerelease: false
|
57
54
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
55
|
requirements:
|
60
|
-
- -
|
56
|
+
- - ">="
|
61
57
|
- !ruby/object:Gem::Version
|
62
58
|
version: '0'
|
63
59
|
- !ruby/object:Gem::Dependency
|
64
60
|
name: json
|
65
61
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
62
|
requirements:
|
68
|
-
- -
|
63
|
+
- - ">="
|
69
64
|
- !ruby/object:Gem::Version
|
70
65
|
version: '0'
|
71
66
|
type: :runtime
|
72
67
|
prerelease: false
|
73
68
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
69
|
requirements:
|
76
|
-
- -
|
70
|
+
- - ">="
|
77
71
|
- !ruby/object:Gem::Version
|
78
72
|
version: '0'
|
79
|
-
description: API
|
73
|
+
description: API Bindings for OpenStack.
|
80
74
|
email:
|
81
75
|
- dprince@redhat.com
|
82
76
|
- marios@redhat.com
|
77
|
+
- naveedm9@gmail.com
|
78
|
+
- aaron.fischer@marbis.net
|
79
|
+
- alexander.birkner@marbis.net
|
83
80
|
executables: []
|
84
81
|
extensions: []
|
85
82
|
extra_rdoc_files:
|
86
|
-
-
|
83
|
+
- CHANGELOG
|
84
|
+
- README.md
|
87
85
|
files:
|
86
|
+
- CHANGELOG
|
88
87
|
- COPYING
|
89
|
-
- README.
|
90
|
-
-
|
88
|
+
- README.md
|
89
|
+
- VERSION
|
91
90
|
- lib/openstack.rb
|
92
91
|
- lib/openstack/compute/address.rb
|
93
92
|
- lib/openstack/compute/connection.rb
|
@@ -97,46 +96,45 @@ files:
|
|
97
96
|
- lib/openstack/compute/personalities.rb
|
98
97
|
- lib/openstack/compute/server.rb
|
99
98
|
- lib/openstack/connection.rb
|
99
|
+
- lib/openstack/core_ext/to_query.rb
|
100
|
+
- lib/openstack/identity/connection.rb
|
101
|
+
- lib/openstack/identity/tenant.rb
|
102
|
+
- lib/openstack/identity/user.rb
|
100
103
|
- lib/openstack/image/connection.rb
|
101
104
|
- lib/openstack/network/connection.rb
|
102
105
|
- lib/openstack/network/network.rb
|
103
106
|
- lib/openstack/network/port.rb
|
104
|
-
- lib/openstack/network/subnet.rb
|
105
107
|
- lib/openstack/network/router.rb
|
108
|
+
- lib/openstack/network/subnet.rb
|
106
109
|
- lib/openstack/swift/connection.rb
|
107
110
|
- lib/openstack/swift/container.rb
|
108
111
|
- lib/openstack/swift/storage_object.rb
|
109
112
|
- lib/openstack/volume/connection.rb
|
110
113
|
- lib/openstack/volume/snapshot.rb
|
111
114
|
- lib/openstack/volume/volume.rb
|
112
|
-
- test/
|
113
|
-
- test/connection_test.rb
|
114
|
-
- test/exception_test.rb
|
115
|
-
- test/metadata_test.rb
|
116
|
-
- test/servers_test.rb
|
115
|
+
- test/runner.rb
|
117
116
|
- test/test_helper.rb
|
118
117
|
homepage: https://github.com/ruby-openstack/ruby-openstack
|
119
118
|
licenses: []
|
119
|
+
metadata: {}
|
120
120
|
post_install_message:
|
121
121
|
rdoc_options: []
|
122
122
|
require_paths:
|
123
123
|
- lib
|
124
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
125
|
requirements:
|
127
|
-
- -
|
126
|
+
- - ">="
|
128
127
|
- !ruby/object:Gem::Version
|
129
128
|
version: '0'
|
130
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
130
|
requirements:
|
133
|
-
- -
|
131
|
+
- - ">="
|
134
132
|
- !ruby/object:Gem::Version
|
135
133
|
version: '0'
|
136
134
|
requirements: []
|
137
135
|
rubyforge_project:
|
138
|
-
rubygems_version:
|
136
|
+
rubygems_version: 2.4.5.1
|
139
137
|
signing_key:
|
140
|
-
specification_version:
|
138
|
+
specification_version: 4
|
141
139
|
summary: OpenStack Ruby API
|
142
140
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,462 +0,0 @@
|
|
1
|
-
= Ruby OpenStack
|
2
|
-
|
3
|
-
== Description
|
4
|
-
|
5
|
-
Ruby Openstack Compute, Object-Store, Block Storage and Network (Quantum) bindings for the OpenStack API.
|
6
|
-
a
|
7
|
-
http://api.openstack.org/api-reference.html
|
8
|
-
|
9
|
-
Currently supports both v1.0 and v2.0 (keystone) auth.
|
10
|
-
|
11
|
-
Use OpenStack::Connection.create to get a handle to an OpenStack service - set the :service_type parameter to 'compute', 'object-store', 'volume' or 'network' (defaults to 'compute'). If the requested service is not deployed the gem will throw a OpenStack::Exception::NotImplemented (501) - e.g. :service_type is 'object-store' but swift service isn't deployed.
|
12
|
-
|
13
|
-
The OpenStack::Connection.create class method is a factory constructor which will return the appropriate Connection object, depending on the ':service_type' parameter passed with the options hash: set to either 'compute', 'volume', or 'object-store' (defaults to 'compute') - see below for examples.
|
14
|
-
|
15
|
-
Other parameters for the create method:
|
16
|
-
|
17
|
-
* :auth_url - the OpenStack service provider specific authentication url endpoint.
|
18
|
-
* :auth_method - the type of authentication to be used with the above auth_url - either 'password' (username/password, 'key' (ec2 style key/private key) or 'rax-kskey'.
|
19
|
-
* :authtenant_name OR :authtenant_id - one of these MUST be specified when talking to a v2 authentication endpoint (keystone) - depending on whether you use tenant name (or tenant ID). Passing only :authtenant will result in that parameter being used as tenant name.
|
20
|
-
* :username - the username or public key (depending on auth_method)
|
21
|
-
* :api_key - the password or private key (denending on auth_method).
|
22
|
-
|
23
|
-
=== Try it out:
|
24
|
-
|
25
|
-
sudo gem install openstack
|
26
|
-
[sudo] password for herp:
|
27
|
-
Successfully installed openstack-1.0.0
|
28
|
-
|
29
|
-
[herp@name lib]$ irb -rubygems
|
30
|
-
irb(main):001:0> require 'openstack'
|
31
|
-
=> true
|
32
|
-
|
33
|
-
irb(main):002:0> os = OpenStack::Connection.create({:username => "herp@derp.net", :api_key=>"1234abcd", :auth_method=>"password", :auth_url => "https://regionerer-g.go-bar.identity.dacloudfoo.herpy:13327/v2.0/", :authtenant_name =>"herp@derp.net-default-tenant", :service_type=>"compute"})
|
34
|
-
|
35
|
-
=> #<OpenStack::Compute::Connection:0xb7339070 @connection=#<OpenStack::Connection:0xb73392dc @service_scheme="https", @auth_host="regionerer-g.go-bar.identity.dacloudfoo.herpy", @http={}, @service_name=nil, @authuser="herp@derp.net", @proxy_port=nil, @auth_path="/v2.0/", @authtenant={:type=>"tenantName", :value=>"herp@derp.net-default-tenant"}, @service_port=443, @authkey="1235abcd", @authok=true, @service_type="compute", @auth_method="password", @auth_scheme="https", @service_host="az-2.region-a.geo-1.dacloudfoo.herpy", @is_debug=nil, @proxy_host=nil, @service_path="/v1.1/482195756462871", @auth_port=35357, @auth_url="https://regionerer-g.go-bar.identity.dacloudfoo.herpy:13327/v2.0/", @region=nil, @authtoken="Auth_543254fdsasabd546543a3", @retry_auth=nil>>
|
36
|
-
|
37
|
-
irb(main):003:0> os.servers
|
38
|
-
=> []
|
39
|
-
|
40
|
-
irb(main):004:0> os = OpenStack::Connection.create({:username => "AWHFDADHJ32EL6V23GFK", :api_key=>"jd823jFDJEY2/82jfhYteG52AKJAUEY184JHRfeR", :auth_method=> "key", :auth_url => "https://regionerer-g.go-bar.identity.dacloudfoo.herpy:13327/v2.0/", :authtenant_id =>"482195756462871", :service_type=>"object-store"})
|
41
|
-
|
42
|
-
=> #<OpenStack::Swift::Connection:0xb72ff2a8 @connection=#<OpenStack::Connection:0xb72ff460 @service_scheme="https", @auth_host="regionerer-g.go-bar.identity.dacloudfoo.herpy", @http={}, @service_name=nil, @authuser="AWHFDADHJ32EL6V23GFK", @proxy_port=nil, @auth_path="/v2.0/", @authtenant={:type=>"tenantId", :value=>"482195756462871"}, @service_port=443, @authkey="jd823jFDJEY2/82jfhYteG52AKJAUEY184JHRfeR", @authok=true, @service_type="object-store", @auth_method="key", @auth_scheme="https", @service_host="region-a.geo-1.objects.dacloudfoo.herpy", @is_debug=nil, @proxy_host=nil, @service_path="/v1.0/482195756462871", @auth_port=35357, @auth_url="https://regionerer-g.go-bar.identity.dacloudfoo.herpy:13327/v2.0/", @region=nil, @authtoken="Auth_543254fdsasabd546543a3", @retry_auth=nil>>
|
43
|
-
|
44
|
-
irb(main):006:0> os.containers
|
45
|
-
=> ["herpy_Foo_container", "derpy_bar_bucket"]
|
46
|
-
|
47
|
-
irb(main):003:0> os.connection.regions_list
|
48
|
-
=> {"region-a.geo-1" => [ {:service=>"object-store", :versionId=>"1.0"}, {:service=>"identity", :versionId=>"2.0"}],
|
49
|
-
"region-b.geo-1"=>[{:service=>"identity", :versionId=>"2.0"}],
|
50
|
-
"az-2.region-a.geo-1"=>[{:service=>"image", :versionId=>"1.0"}, {:service=>"volume", :versionId=>"1.1"}, {:service=>"compute", :versionId=>"1.1"}],
|
51
|
-
"az-1.region-a.geo-1"=>[{:service=>"image", :versionId=>"1.0"}, {:service=>"volume", :versionId=>"1.1"}, {:service=>"compute", :versionId=>"1.1"}]}
|
52
|
-
|
53
|
-
irb(main):005:0> os.connection.regions_list["region-a.geo-1"]
|
54
|
-
=> [{:service=>"object-store", :versionId=>"1.0"}, {:service=>"identity", :versionId=>"2.0"}]
|
55
|
-
|
56
|
-
|
57
|
-
== Examples
|
58
|
-
|
59
|
-
== For Compute:
|
60
|
-
|
61
|
-
See the class definitions for documentation on specific methods and operations.
|
62
|
-
|
63
|
-
require 'openstack'
|
64
|
-
|
65
|
-
os = OpenStack::Connection.create(:username => USERNAME, :api_key => API_KEY, :authtenant => TENANT, :auth_url => API_URL, :service_type => "compute")
|
66
|
-
|
67
|
-
# Get a listing of all current servers
|
68
|
-
>> os.servers
|
69
|
-
=> [{:name=>"Server1", :id=>110917}]
|
70
|
-
|
71
|
-
# Access a specific server
|
72
|
-
>> server = os.server(110917)
|
73
|
-
>> server.name
|
74
|
-
=> "Server1"
|
75
|
-
|
76
|
-
# See what type of server this is
|
77
|
-
>> server.flavor.name
|
78
|
-
=> "256 server"
|
79
|
-
>> server.image.name
|
80
|
-
=> "Ubuntu 8.04.2 LTS (hardy)"
|
81
|
-
|
82
|
-
# Soft-reboot the server
|
83
|
-
>> server.reboot
|
84
|
-
=> true
|
85
|
-
|
86
|
-
# Create a new 512MB CentOS 5.2 server. The root password is returned in the adminPass method.
|
87
|
-
>> image = os.get_image(8)
|
88
|
-
=> #<OpenStack::Compute::Image:0x1014a8060 ...>, status"ACTIVE"
|
89
|
-
>> image.name
|
90
|
-
=> "CentOS 5.2"
|
91
|
-
>> flavor = os.get_flavor(2)
|
92
|
-
=> #<OpenStack::Compute::Flavor:0x101469130 @disk=20, @name="512 server", @id=2, @ram=512>
|
93
|
-
>> flavor.name
|
94
|
-
=> "512 server"
|
95
|
-
>> newserver = os.create_server(:name => "New Server", :imageRef => image.id, :flavorRef => flavor.id)
|
96
|
-
=> #<OpenStack::Compute::Server:0x101433f08 ....
|
97
|
-
>> newserver.status
|
98
|
-
=> "BUILD"
|
99
|
-
>> newserver.progress
|
100
|
-
=> 0
|
101
|
-
>> newserver.adminPass
|
102
|
-
=> "NewServerMbhzUnO"
|
103
|
-
>> newserver.refresh
|
104
|
-
=> true
|
105
|
-
>> newserver.progress
|
106
|
-
=> 12
|
107
|
-
|
108
|
-
# Create a new server and specify the keyname and security_groups to be used (dependent on provider support for these API extensions):
|
109
|
-
>> server = os.create_server({:imageRef=>14075, :flavorRef=>100, :key_name=>"my_default_key", :security_groups=>["test", "default"], :name=>"marios_server"})
|
110
|
-
=> #<OpenStack::Compute::Server:0x101433f08 ....
|
111
|
-
>> server.key_name
|
112
|
-
=> "my_default_key"
|
113
|
-
>> server.security_groups
|
114
|
-
|
115
|
-
# Delete the new server
|
116
|
-
>> newserver.delete!
|
117
|
-
=> true
|
118
|
-
|
119
|
-
=== Compute API extensions.
|
120
|
-
|
121
|
-
# Get info on extensions offered by the given OpenStack provider:
|
122
|
-
>> os.api_extensions
|
123
|
-
=> { :os-keypairs => { :links=>[], :updated=>"2011-08-08T00:00:00+00:00", :description=>"Keypair Support",
|
124
|
-
:namespace=>"http://docs.openstack.org/ext/keypairs/api/v1.1", :name=>"Keypairs",
|
125
|
-
:alias=>"os-keypairs" },
|
126
|
-
:os-floating_ips => { :links=>[], :updated=>"2011-06-16T00:00:00+00:00", :description=>"Floating IPs support",
|
127
|
-
:namespace=>"http://docs.openstack.org/ext/floating_ips/api/v1.1", :name=>"Floating_ips", :alias=>"os-floating-ips"},
|
128
|
-
... }
|
129
|
-
|
130
|
-
==== Compute API keypairs extension
|
131
|
-
|
132
|
-
# Get list of keypairs for current tenant/account:
|
133
|
-
>> os.keypairs
|
134
|
-
=> { :key_one => { :fingerprint => "3f:12:4d:d1:54:f1:f4:3f:fe:a8:12:ec:1a:fb:35:b2",
|
135
|
-
:public_key => "ssh-rsa AAAAB3Nza923kJ ...
|
136
|
-
:name => "key_one"},
|
137
|
-
:key_two => { ... },
|
138
|
-
... }
|
139
|
-
|
140
|
-
# Create new keypair:
|
141
|
-
>> os.create_keypair({:name=>"test_key"})
|
142
|
-
=> { :name => "test_key",
|
143
|
-
:fingerprint => "f1:f3:a2:d3:ca:75:da:f1:06:f4:f7:dc:cc:7d:e1:ca",
|
144
|
-
:user_id => "dev_41247879706381",$
|
145
|
-
:public_key => "ssh-rsa AAAAB3NzaC1y ...
|
146
|
-
:private_key => "-----BEGIN RSA PRIVATE KEY-----\nMIICXwIBA ... -----END RSA PRIVATE KEY-----\n"
|
147
|
-
}
|
148
|
-
|
149
|
-
# Import keypair:
|
150
|
-
>> os.create_keypair({:name=>"test_key_imported", :public_key=>"sh-rsa AAAAB3Nza923kJ ..."})
|
151
|
-
=> { :name => "test_key_imported",
|
152
|
-
:fingerprint => "f1:f3:a2:d3:ca:75:da:f1:06:f4:f7:dc:cc:7d:e1:ca",
|
153
|
-
:user_id => "dev_41247879706381",$
|
154
|
-
:public_key => "ssh-rsa AAAAB3Nza ...
|
155
|
-
}
|
156
|
-
|
157
|
-
# Delete Keypair:
|
158
|
-
>> os.delete_keypair("test_key_imported")
|
159
|
-
=> true
|
160
|
-
|
161
|
-
==== Compute API security groups extension
|
162
|
-
|
163
|
-
# List all security groups:
|
164
|
-
>> os.security_groups
|
165
|
-
=> { "1381" => { :tenant_id=>"12345678909876", :id=>1381, :name=>"default", :description=>"default",
|
166
|
-
:rules=> [
|
167
|
-
{:from_port=>22, :group=>{}, :ip_protocol=>"tcp", :to_port=>22,
|
168
|
-
:parent_group_id=>1381, :ip_range=>{:cidr=>"0.0.0.0/0"}, :id=>4902},
|
169
|
-
]
|
170
|
-
},
|
171
|
-
"1234" => { ... } }
|
172
|
-
|
173
|
-
# Get a specific security group:
|
174
|
-
>> os.security_group(1381)
|
175
|
-
=> { "1381" => { :tenant_id=>"12345678909876", :id=>1381, :name=>"default", :description=>"default",
|
176
|
-
:rules=> [
|
177
|
-
{:from_port=>22, :group=>{}, :ip_protocol=>"tcp", :to_port=>22,
|
178
|
-
:parent_group_id=>1381, :ip_range=>{:cidr=>"0.0.0.0/0"}, :id=>4902},
|
179
|
-
]
|
180
|
-
}}
|
181
|
-
|
182
|
-
#Create a new security group:
|
183
|
-
>> os.create_security_group("devel_group", "all development machines")
|
184
|
-
=> {"9573"=>{:rules=>[], :tenant_id=>"46871569847393", :id=>9573, :name=>"devel_group", :description=>"all development machines"}}
|
185
|
-
|
186
|
-
#Create a new security group rule - first param is id of the security group for this rule. Instead of :cidr you may specify :group_id to use another group as source:
|
187
|
-
>> os.create_security_group_rule(9567, {:ip_protocol=>"tcp", :from_port=>"123", :to_port=>"123", :cidr=>"192.168.0.1/16" })
|
188
|
-
=> => {"27375"=>{:from_port=>123, :group=>{}, :ip_protocol=>"tcp", :to_port=>123, :parent_group_id=>9573, :ip_range=>{:cidr=>"192.168.0.1/16"}, :id=>27375}}
|
189
|
-
|
190
|
-
#Delete a security group rule:
|
191
|
-
>> os.delete_security_group_rule(27375)
|
192
|
-
=> true
|
193
|
-
|
194
|
-
#Delete a security group:
|
195
|
-
>> os.delete_security_group(9571)
|
196
|
-
=> true
|
197
|
-
|
198
|
-
==== Compute API volumes extension:
|
199
|
-
|
200
|
-
#Attach a volume to a server - params in order are: server_id, volume_id, attachment_point
|
201
|
-
|
202
|
-
>> os.attach_volume(704289, 90805, "/dev/sde")
|
203
|
-
=> true
|
204
|
-
|
205
|
-
#List attachments for a server:
|
206
|
-
|
207
|
-
>> os.list_attachments 704289
|
208
|
-
=> {:volumeAttachments=>[{:device=>"/dev/sde", :serverId=>704289, :id=>90805, :volumeId=>90805}]}
|
209
|
-
|
210
|
-
#Detach volume from server - params in order are server_id and attachment_id
|
211
|
-
>> os.detach_volume(704289, 90805)
|
212
|
-
=> true
|
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
|
-
|
241
|
-
== Examples for Volumes and Snaphots:
|
242
|
-
|
243
|
-
#NOTE - attach/detach operations are implemented for the compute service as the OS API defines these operations as extensions to Openstack Compute.
|
244
|
-
|
245
|
-
vs = OpenStack::Connection.create({:username => "username", :api_key=>"pass", :auth_url => "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/", :authtenant=>"username-default-tenant", :service_type=>"volume"})
|
246
|
-
|
247
|
-
# Create a volume: - MUST specify display_name and size parameters... optional params are {:display_description, :metadata=>{:key=>val, ...}, :availability_zone, :volume_type }
|
248
|
-
|
249
|
-
>> volume = vs.create_volume({:display_name=>"marios volume", :size=>1, :display_description=>"some new volume bla"})
|
250
|
-
=> #<OpenStack::Volume::Volume:0x8a3c534 @id=90805, @display_name="marios volume", @display_description="some new volume bla", @size=1, @volume_type=nil, @metadata={}, @availability_zone="nova", @snapshot_id="", @attachments=[{}], @created_at="2012-11-15 13:51:23">
|
251
|
-
|
252
|
-
>> volume.size
|
253
|
-
=> 1
|
254
|
-
|
255
|
-
>> volume.attachments
|
256
|
-
=> [{}]
|
257
|
-
|
258
|
-
# List volumes:
|
259
|
-
|
260
|
-
>> vs.list_volumes #aliased as just 'volumes' ... vs.volumes
|
261
|
-
=> [#<OpenStack::Volume::Volume:0x8aad2e8 @id=90625, @display_name="marios volume", @display_description="attach test volume", @size=1, @volume_type=nil, @metadata={}, @availability_zone="nova", @snapshot_id="", @attachments=[{}], @created_at="2012-11-15 09:54:58">, #<OpenStack::Volume::Volume:0x8aad144 @id=90805, @display_name="marios volume", @display_description="some new volume bla", @size=1, @volume_type=nil, @metadata={}, @availability_zone="nova", @snapshot_id="", @attachments=[{}], @created_at="2012-11-15 13:51:23">]
|
262
|
-
|
263
|
-
# Get a particular volume - must specify ID:
|
264
|
-
|
265
|
-
>> vs.get_volume(90625) #aliased as 'volume'
|
266
|
-
=> #<OpenStack::Volume::Volume:0x8abd4a4 @id=90625, @display_name="marios volume", @display_description="attach test volume", @size=1, @volume_type=nil, @metadata={}, @availability_zone="nova", @snapshot_id="", @attachments=[{}], @created_at="2012-11-15 09:54:58">
|
267
|
-
|
268
|
-
# Delete a volume:
|
269
|
-
|
270
|
-
>> vs.delete_volume(90805)
|
271
|
-
=> true
|
272
|
-
|
273
|
-
# Create a snapshot: - must specify display_name and volume_id parameters... optionally also :display_description
|
274
|
-
>> vs.create_snapshot({:volume_id=>"3b38b570-a4ff-4444-984a-3566cbdc8ab2", :display_name=>"marios_snapshot"})
|
275
|
-
=> #<OpenStack::Volume::Snapshot:0xa0cfea4 @id=223, @display_name="marios_snapshot", @display_description=nil, @volume_id="3b38b570-a4ff-4444-984a-3566cbdc8ab2", @status="creating", @size=1, @created_at="2013-01-23 14:25:02.654217">
|
276
|
-
|
277
|
-
# List snapshots: - aliased as just 'snapshots' ... vs.snapshots
|
278
|
-
>> vs.list_snapshots
|
279
|
-
=> [#<OpenStack::Volume::Snapshot:0x9a6e4fc @id="0e76dacb-2fcf-4565-84a3-aa3d7bd16224", @display_name="marios_snapshot", @display_description=nil, @volume_id="3b38b570-a4ff-4444-984a-3566cbdc8ab2", @status="creating", @size=1, @created_at="2013-01-23T14:18:13.000000">]
|
280
|
-
|
281
|
-
# Get a specific snapshot: - aliased as 'snapshot'
|
282
|
-
>> vs.get_snapshot("0e76dacb-2fcf-4565-84a3-aa3d7bd16224")
|
283
|
-
=> #<OpenStack::Volume::Snapshot:0x9a890b8 @id="0e76dacb-2fcf-4565-84a3-aa3d7bd16224", @display_name="marios_snapshot", @display_description=nil, @volume_id="3b38b570-a4ff-4444-984a-3566cbdc8ab2", @status="creating", @size=1, @created_at="2013-01-23T14:18:13.000000">
|
284
|
-
|
285
|
-
# Delete a snapshot:
|
286
|
-
>> vs.delete_snapshot("0e76dacb-2fcf-4565-84a3-aa3d7bd16224")
|
287
|
-
=> true
|
288
|
-
|
289
|
-
== Examples for Object-Store:
|
290
|
-
|
291
|
-
|
292
|
-
os = OpenStack::Connection.create(:username => USERNAME, :api_key => API_KEY, :authtenant => TENANT, :auth_url => API_URL, :service_type => "object-store")
|
293
|
-
|
294
|
-
# Get info on container count and bytes:
|
295
|
-
>> os.get_info
|
296
|
-
=> {:count=>2, :bytes=>495041}
|
297
|
-
|
298
|
-
# Get list of containers under this account:
|
299
|
-
>> os.containers
|
300
|
-
=> ["another_containerfoo", "marios_test_container"]
|
301
|
-
|
302
|
-
# Get details of containers under this account:
|
303
|
-
>> os.containers_detail
|
304
|
-
=>=> {"another_containerfoo"=>{:count=>"3", :bytes=>"1994"}, "marios_test_container"=>{:count=>"2", :bytes=>"493047"}}
|
305
|
-
|
306
|
-
# Check if a container exists
|
307
|
-
>> os.container_exists?("no_such_thing")
|
308
|
-
=> false
|
309
|
-
|
310
|
-
# Create new container
|
311
|
-
>> os.create_container("foo")
|
312
|
-
=> => #<OpenStack::Swift::Container:0xb7275c38 ...... (rest of OpenStack::Swift::Container object)
|
313
|
-
|
314
|
-
# Delete container
|
315
|
-
>> os.delete_container("foo")
|
316
|
-
=> true
|
317
|
-
|
318
|
-
# Get a container (OpenStack::Swift::Container object):
|
319
|
-
>> cont = os.container("foo")
|
320
|
-
=> #<OpenStack::Swift::Container:0xb7262124 ...... (rest of OpenStack::Swift::Container object)
|
321
|
-
|
322
|
-
# Retrieve container metadata:
|
323
|
-
>> cont.container_metadata
|
324
|
-
=>{:count=>"2", :bytes=>"493047", :metadata=>{"foo"=>"bar", "author"=>"foobar", "jj"=>"foobar", "date"=>"today", "owner"=>"foo"}}
|
325
|
-
|
326
|
-
# Retrieve user defined metadata:
|
327
|
-
>> cont.metadata
|
328
|
-
=> {"foo"=>"bar", "author"=>"foobar", "jj"=>"foobar", "date"=>"today", "owner"=>"foo"}
|
329
|
-
|
330
|
-
# Set user defined metadata:
|
331
|
-
>> cont.set_metadata({"X-Container-Meta-Author"=> "msa", "version"=>"1.2", :date=>"today"})
|
332
|
-
=> true
|
333
|
-
|
334
|
-
# Get list of objects:
|
335
|
-
>> cont.objects
|
336
|
-
=> ["fosdem2012.pdf", "moved_object"]
|
337
|
-
|
338
|
-
# Get list of objects with details:
|
339
|
-
>> cont.objects_detail
|
340
|
-
=> {"fosdem2012.pdf"=>{:bytes=>"493009", :content_type=>"application/json", :hash=>"494e444f92a8082dabac80a74cdf2c3b", :last_modified=>"2012-04-26T09:22:51.611230"}, "moved_object"=>{:bytes=>"38", :content_type=>"application/json", :hash=>"a7942f97fe6bd34920a4f61fe5e604a5", :last_modified=>"2012-04-26T09:35:33.839920"}}
|
341
|
-
|
342
|
-
# Check if container is empty:
|
343
|
-
>> cont.empty?
|
344
|
-
=> false
|
345
|
-
|
346
|
-
# Check if object exists:
|
347
|
-
>> cont.object_exists?("foo")
|
348
|
-
=> false
|
349
|
-
|
350
|
-
# Create new object
|
351
|
-
>> new_obj = cont.create_object("foo", {:metadata=>{"herpy"=>"derp"}, :content_type=>"text/plain"}, "this is the data") [can also supply File.open(/path/to/file) and the data]
|
352
|
-
=> #<OpenStack::Swift::StorageObject:0xb72fdac0 ... etc
|
353
|
-
|
354
|
-
# Delete object
|
355
|
-
>> cont.delete_object("foo")
|
356
|
-
=> true
|
357
|
-
|
358
|
-
# Get handle to an OpenStack::Swift::StorageObject Object
|
359
|
-
>> obj = cont.object("foo")
|
360
|
-
=> #<OpenStack::Swift::StorageObject:0xb72fdac0 ... etc
|
361
|
-
|
362
|
-
# Get object metadata
|
363
|
-
>> obj.object_metadata
|
364
|
-
=>
|
365
|
-
|
366
|
-
# Get user defined metadata pairs
|
367
|
-
>> obj.metadata
|
368
|
-
=>
|
369
|
-
|
370
|
-
# Get data (non streaming - returned as a String)
|
371
|
-
>> obj.data
|
372
|
-
=> "This is the text stored in the file"
|
373
|
-
|
374
|
-
# Get data (streaming - requires a block)
|
375
|
-
>> data = ""; object.data_stream do |chunk| data += chunk end
|
376
|
-
=> #<Net::HTTPOK 200 OK readbody=true>
|
377
|
-
>> data
|
378
|
-
=> "This is the text stored in the file"
|
379
|
-
|
380
|
-
# Set user defined metadata
|
381
|
-
>> obj.set_metadata({:foo=>"bar", "X-Object-Meta-herpa"=>"derp", "author"=>"me"})
|
382
|
-
=> true
|
383
|
-
|
384
|
-
# (Over)Write object data
|
385
|
-
>> object.write("This is new data")
|
386
|
-
=> true
|
387
|
-
>> object.data
|
388
|
-
=> "This is new data"
|
389
|
-
|
390
|
-
# Copy object:
|
391
|
-
>>copied = obj.copy('copied_object', "destination_container", {:content_type=>"text/plain", :metadata=>{:herp=>"derp", "X-Object-Meta-foo"=>"bar} } )
|
392
|
-
=> #<OpenStack::Swift::StorageObject:0xb728974c ..... etc
|
393
|
-
|
394
|
-
# Move object: (copy and then delete original):
|
395
|
-
>> moved = obj.move('moved_object', "destination_container", {:content_type=>"text/plain", :metadata=>{:herp=>"derp", "X-Object-Meta-foo"=>"bar"} } )
|
396
|
-
=> #<OpenStack::Swift::StorageObject:0xb7266bd4 ...
|
397
|
-
>> moved.metadata
|
398
|
-
=> {"foo"=>"bar", "herp"=>"derp", "herpy"=>"derp"}
|
399
|
-
>> obj.metadata
|
400
|
-
=> OpenStack::Exception::ItemNotFound: The resource could not be found
|
401
|
-
|
402
|
-
|
403
|
-
== Examples for Network (Quantum):
|
404
|
-
|
405
|
-
quantum = OpenStack::Connection.create({:username => "admin", :api_key=>"le-password", :auth_method=>"password", :auth_url => "http://192.168.1.21:5000/v2.0/", :authtenant_name =>"admin", :service_type=>"network"})
|
406
|
-
|
407
|
-
#Create a network:
|
408
|
-
>> net2 = quantum.create_network("my_net")
|
409
|
-
=> #<OpenStack::Network::Network:0xa8aff70 @id="6b09a5b3-02d3-4996-9933-4792bd4ca11e",@name="my_net", @admin_state_up=true, @status="ACTIVE", @subnets=[], @shared=false, @tenant_id="7be215d541ea4db4a23b3a84b0882408">
|
410
|
-
|
411
|
-
#List networks:
|
412
|
-
>> quantum.networks
|
413
|
-
=> [#<OpenStack::Network::Network:0xa7c8f94 @id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="net_1363343212", @admin_state_up=true, @status="ACTIVE",
|
414
|
-
@subnets=["34ea9f1e-d71a-48bd-89b0-af2f5c051912","7780f890-8334-43a1-934c-f1ce5edc4561"], @shared=false, @tenant_id="7be215d541ea4db4a23b3a84b0882408">, #<OpenStack::Network::Network:0xa7c8ef4 @id="1cfad632-3473-4c5b-b2d3-405cc3093286", @name="net_1363344435", @admin_state_up=true, @status="ACTIVE", @subnets=["c4293c24-07d0-47dc-bead-ec8d3934b8db"], @shared=false, @tenant_id="7be215d541ea4db4a23b3a84b0882408">]
|
415
|
-
|
416
|
-
>> net1 = quantum.network("b4abfaff-9e24-4192-9219-a4a60819aba2")
|
417
|
-
=> #<OpenStack::Network::Network:0xa7f28e4 @id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="net_1363343212", @admin_state_up=true, @status="ACTIVE", @subnets=["34ea9f1e-d71a-48bd-89b0-af2f5c051912", "7780f890-8334-43a1-934c-f1ce5edc4561"], @shared=false, @tenant_id="7be215d541ea4db4a23b3a84b0882408">
|
418
|
-
|
419
|
-
#Delete a Network:
|
420
|
-
>> quantum.delete_network("6b09a5b3-02d3-4996-9933-4792bd4ca11e")
|
421
|
-
=> true
|
422
|
-
|
423
|
-
#Create a Subnet:
|
424
|
-
>> subnet1 = quantum.create_subnet("b4abfaff-9e24-4192-9219-a4a60819aba2","192.168.1.0/24")
|
425
|
-
=> #<OpenStack::Network::Subnet:0xa772a2c @id="e978da1c-9c95-4e58-b4b6-4dcce4640a7f", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4, @cidr="192.168.1.0/24", @gateway_ip="192.168.1.1", @dns_nameservers=[], @allocation_pools=[{"start"=>"192.168.1.2", "end"=>"192.168.1.254"}], @host_routes=[], @enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">
|
426
|
-
|
427
|
-
#List Subnets:
|
428
|
-
>> quantum.subnets
|
429
|
-
=> [#<OpenStack::Network::Subnet:0xa850958 @id="34ea9f1e-d71a-48bd-89b0-af2f5c051912", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4, @cidr="123.123.0.0/16", @gateway_ip="123.123.0.1", @dns_nameservers=[], @allocation_pools=[{"start"=>"123.123.0.2", "end"=>"123.123.255.254"}], @host_routes=[], @enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">, #<OpenStack::Network::Subnet:0xa850868 @id="7780f890-8334-43a1-934c-f1ce5edc4561", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4, @cidr="192.168.1.0/24", @gateway_ip="192.168.1.1", @dns_nameservers=[], @allocation_pools=[{"start"=>"192.168.1.2", "end"=>"192.168.1.254"}], @host_routes=[], @enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">]
|
430
|
-
|
431
|
-
>> subnet1 = quantum.subnet("34ea9f1e-d71a-48bd-89b0-af2f5c051912")
|
432
|
-
=> #<OpenStack::Network::Subnet:0xa88ec1c @id="34ea9f1e-d71a-48bd-89b0-af2f5c051912", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4, @cidr="123.123.0.0/16", @gateway_ip="123.123.0.1", @dns_nameservers=[], @allocation_pools=[{"start"=>"123.123.0.2", "end"=>"123.123.255.254"}], @host_routes=[], @enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">
|
433
|
-
|
434
|
-
#Delete a Subnet:
|
435
|
-
>> quantum.delete_subnet("89136e4d-da26-4495-9384-0fd1309e274a")
|
436
|
-
=> true
|
437
|
-
|
438
|
-
#Create a Port:
|
439
|
-
>> created_port = quantum.create_port(network.id, {"fixed_ips"=>[{"subnet_id"=>subnet.id}], "device_id"=>machine.id})
|
440
|
-
=> #<OpenStack::Network::Port:0x95a833c @id="d601db9e-c936-4811-904a-bb5a27d105f3", @network_id="c4dfe90e-a7ce-41f7-b9b2-2f9773f42a6b", @name="", @admin_state_up=true, @status="ACTIVE", @mac_address="fa:16:3e:f4:e8:bc", @fixed_ips=[{"subnet_id"=>"f78bfc05-ead0-40a6-8325-a35eb2b535c3", "ip_address"=>"10.0.0.4"}], @device_id="fe4022fa-a77c-4adf-be45-6e069fb3a314", @device_owner="", @tenant_id="7be215d541ea4db4a23b3a84b0882408">
|
441
|
-
|
442
|
-
#List Ports:
|
443
|
-
>> quantum.ports
|
444
|
-
=> [#<OpenStack::Network::Port:0xa73bdd8 @id="f0db2c95-9449-4eb3-8b12-c66b23c8de41", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @admin_state_up=true, @status="ACTIVE", @mac_address="fa:16:3e:7e:e0:1b", @fixed_ips=[{"subnet_id"=>"34ea9f1e-d71a-48bd-89b0-af2f5c051912", "ip_address"=>"123.123.0.2"}], @device_id="4357665c-e2fe-4bf0-8a69-b531d11add2d", @device_owner="compute:nova", @tenant_id="7be215d541ea4db4a23b3a84b0882408">, #<OpenStack::Network::Port:0xa73bcac @id="93c210cd-b086-49e1-aa12-d207aa28a981", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @admin_state_up=true, @status="ACTIVE", @mac_address="fa:16:3e:08:eb:92", @fixed_ips=[{"subnet_id"=>"34ea9f1e-d71a-48bd-89b0-af2f5c051912", "ip_address"=>"123.123.0.3"}], @device_id="5a114ba2-4f49-4655-93f9-96954632cb67", @device_owner="compute:nova", @tenant_id="7be215d541ea4db4a23b3a84b0882408">]
|
445
|
-
|
446
|
-
>> port1 = quantum.port("f0db2c95-9449-4eb3-8b12-c66b23c8de41")
|
447
|
-
=> #<OpenStack::Network::Port:0xa70f51c @id="f0db2c95-9449-4eb3-8b12-c66b23c8de41", @network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @admin_state_up=true, @status="ACTIVE", @mac_address="fa:16:3e:7e:e0:1b", @fixed_ips=[{"subnet_id"=>"34ea9f1e-d71a-48bd-89b0-af2f5c051912", "ip_address"=>"123.123.0.2"}], @device_id="4357665c-e2fe-4bf0-8a69-b531d11add2d", @device_owner="compute:nova", @tenant_id="7be215d541ea4db4a23b3a84b0882408">
|
448
|
-
|
449
|
-
#Delete a Port:
|
450
|
-
>> quantum.delete_port("f0db2c95-9449-4eb3-8b12-c66b23c8de41")
|
451
|
-
=> true
|
452
|
-
|
453
|
-
== Authors
|
454
|
-
|
455
|
-
By Marios Andreou (marios@redhat.com), Dan Prince <dprince@redhat.com>, Naveed Massjouni <naveedm9@gmail.com>
|
456
|
-
|
457
|
-
Initial code checkin on May 23rd 2012 - code refactored from and based on the Rackspace Cloud Servers gem
|
458
|
-
(https://github.com/rackspace/ruby-openstack-compute) and Rackspace Cloud Files gem (https://github.com/rackspace/ruby-cloudfiles).
|
459
|
-
|
460
|
-
== License
|
461
|
-
|
462
|
-
See COPYING for license information.
|