fog-openstack 0.1.2 → 0.1.3

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/fog-openstack.gemspec +1 -1
  3. data/lib/fog/openstack.rb +46 -33
  4. data/lib/fog/openstack/docs/compute.md +2 -3
  5. data/lib/fog/openstack/docs/getting_started.md +5 -5
  6. data/lib/fog/openstack/docs/introspection.md +251 -0
  7. data/lib/fog/openstack/docs/metering.md +15 -1
  8. data/lib/fog/openstack/docs/planning.md +2 -2
  9. data/lib/fog/openstack/docs/storage.md +3 -4
  10. data/lib/fog/openstack/examples/compute/basics.rb +1 -1
  11. data/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb +1 -3
  12. data/lib/fog/openstack/examples/identity/basics.rb +6 -7
  13. data/lib/fog/openstack/examples/image/upload-test-image.rb +5 -8
  14. data/lib/fog/openstack/examples/introspection/basics.rb +75 -0
  15. data/lib/fog/openstack/examples/planning/basics.rb +1 -1
  16. data/lib/fog/openstack/examples/storage/set-account-quota.rb +7 -9
  17. data/lib/fog/openstack/identity.rb +99 -5
  18. data/lib/fog/openstack/identity_v2.rb +4 -23
  19. data/lib/fog/openstack/identity_v3.rb +10 -22
  20. data/lib/fog/openstack/introspection.rb +133 -0
  21. data/lib/fog/openstack/models/introspection/rules.rb +29 -0
  22. data/lib/fog/openstack/models/introspection/rules_collection.rb +32 -0
  23. data/lib/fog/openstack/models/metering/events.rb +2 -2
  24. data/lib/fog/openstack/models/network/floating_ip.rb +24 -3
  25. data/lib/fog/openstack/network.rb +1 -0
  26. data/lib/fog/openstack/requests/compute/get_volume_details.rb +4 -0
  27. data/lib/fog/openstack/requests/introspection/abort_introspection.rb +25 -0
  28. data/lib/fog/openstack/requests/introspection/create_introspection.rb +35 -0
  29. data/lib/fog/openstack/requests/introspection/create_rules.rb +37 -0
  30. data/lib/fog/openstack/requests/introspection/delete_rules.rb +23 -0
  31. data/lib/fog/openstack/requests/introspection/delete_rules_all.rb +23 -0
  32. data/lib/fog/openstack/requests/introspection/get_introspection.rb +24 -0
  33. data/lib/fog/openstack/requests/introspection/get_introspection_details.rb +24 -0
  34. data/lib/fog/openstack/requests/introspection/get_rules.rb +24 -0
  35. data/lib/fog/openstack/requests/introspection/list_rules.rb +24 -0
  36. data/lib/fog/openstack/version.rb +1 -1
  37. data/tests/fixtures/introspection.yaml +287 -0
  38. data/tests/openstack/identity_version_tests.rb +25 -0
  39. data/tests/openstack/models/network/floating_ip_tests.rb +14 -1
  40. data/tests/openstack/requests/introspection/introspection_tests.rb +297 -0
  41. data/tests/openstack/requests/introspection/rules_tests.rb +46 -0
  42. metadata +22 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3c4d1c427e750aa77389354355ca0f437fc70e0
4
- data.tar.gz: bbeae160627a5fcf20fdf5278bbcf766a3a60e49
3
+ metadata.gz: 9a3a52ccf8ef9aec1efe22b6cee7d6cfa6ca1a28
4
+ data.tar.gz: 29297c4505150b3a29f696dfd31620369b8d6544
5
5
  SHA512:
6
- metadata.gz: 5e2d9bb935bcbee9cde4705d8c40ceb0c74ccda1f4965cbb270be9c31d7bda7e453878fd3340082aff9725ba1745029b90b8140b70878919c1297fa3ef4be51c
7
- data.tar.gz: deb48e9bac485300c4349e463a3865facc4fc157f8096f5a856e57c3b4a3bedb5e1ff5f66f3e14c38821459e583a1a94f9e33686b14ced362851ad7aff08a4a6
6
+ metadata.gz: ca9f9563a28b33ed86c16ff22c7c37be97a63c67898c408918b2f054478304252628d10260174e8a786d56d65773c2e2d2e622b49e4c93b1477e59eb4f4dff59
7
+ data.tar.gz: eedee34b9856b255b2996071a6f8d907221d135d44ecec5b46f5c18593dc4300f5bb02d5f805e7c1e8e9e3fcd90550efd2a5426ed22e87103d406770a061471c
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency 'fog-core', '>= 1.35'
22
+ spec.add_dependency 'fog-core', '>= 1.37'
23
23
  spec.add_dependency 'fog-json', '>= 1.0'
24
24
  spec.add_dependency 'fog-xml', '>= 0.1'
25
25
  spec.add_dependency 'ipaddress', '>= 0.8'
@@ -9,42 +9,54 @@ require 'fog/openstack/errors'
9
9
  require 'fog/openstack/compute'
10
10
  require 'fog/openstack/identity_v2'
11
11
  require 'fog/openstack/identity_v3'
12
- require 'fog/openstack/image'
13
12
  require 'fog/openstack/image_v1'
14
13
  require 'fog/openstack/image_v2'
15
- require 'fog/openstack/metering'
16
- require 'fog/openstack/network'
17
- require 'fog/openstack/orchestration'
18
14
  require 'fog/openstack/storage'
19
- require 'fog/openstack/volume'
20
15
  require 'fog/openstack/volume_v1'
21
16
  require 'fog/openstack/volume_v2'
22
- require 'fog/openstack/baremetal'
23
17
  require 'fog/openstack/planning'
24
18
 
25
19
  module Fog
20
+ module Compute
21
+ autoload :OpenStack, File.expand_path('../openstack/compute', __FILE__)
22
+ end
23
+
24
+ module Identity
25
+ autoload :OpenStack, File.expand_path('../openstack/identity', __FILE__)
26
+ end
27
+
28
+ module Image
29
+ autoload :OpenStack, File.expand_path('../openstack/image', __FILE__)
30
+ end
31
+
32
+ module Metering
33
+ autoload :OpenStack, File.expand_path('../openstack/metering', __FILE__)
34
+ end
35
+
36
+ module Network
37
+ autoload :OpenStack, File.expand_path('../openstack/network', __FILE__)
38
+ end
39
+
40
+ module Orchestration
41
+ autoload :OpenStack, File.expand_path('../openstack/orchestration', __FILE__)
42
+ end
43
+
44
+ module Volume
45
+ autoload :OpenStack, File.expand_path('../openstack/volume', __FILE__)
46
+ end
47
+
48
+ module Baremetal
49
+ autoload :OpenStack, File.expand_path('../openstack/baremetal', __FILE__)
50
+ end
51
+
52
+ module Introspection
53
+ autoload :OpenStack, File.expand_path('../openstack/introspection', __FILE__)
54
+ end
55
+
26
56
  module OpenStack
27
57
  extend Fog::Provider
28
58
 
29
- # `require` is necessary until they can be refactored into autoload
30
- require 'fog/openstack/image_v1'
31
- require 'fog/openstack/storage'
32
- require 'fog/openstack/volume_v1'
33
- require 'fog/openstack/volume_v2'
34
- require 'fog/openstack/planning'
35
-
36
- autoload :Compute, File.expand_path('../openstack/compute', __FILE__)
37
- autoload :IdentityV2, File.expand_path('../openstack/identity_v2', __FILE__)
38
- autoload :IdentityV3, File.expand_path('../openstack/identity_v3', __FILE__)
39
- autoload :Image, File.expand_path('../openstack/image', __FILE__)
40
- autoload :ImageV2, File.expand_path('../openstack/image_v2', __FILE__)
41
- autoload :Metering, File.expand_path('../openstack/metering', __FILE__)
42
- autoload :Network, File.expand_path('../openstack/network', __FILE__)
43
- autoload :Orchestration, File.expand_path('../openstack/orchestration', __FILE__)
44
- autoload :Volume, File.expand_path('../openstack/volume', __FILE__)
45
- autoload :Baremetal, File.expand_path('../openstack/baremetal', __FILE__)
46
-
47
- service(:compute , 'Compute')
59
+ service(:compute, 'Compute')
48
60
  service(:image, 'Image')
49
61
  service(:identity, 'Identity')
50
62
  service(:network, 'Network')
@@ -54,6 +66,7 @@ module Fog
54
66
  service(:orchestration, 'Orchestration')
55
67
  service(:baremetal, 'Baremetal')
56
68
  service(:planning, 'Planning')
69
+ service(:introspection, 'Introspection')
57
70
 
58
71
  @@token_cache = {}
59
72
 
@@ -137,14 +150,6 @@ module Fog
137
150
 
138
151
  end
139
152
 
140
- service['endpoints'] = service['endpoints'].select do |endpoint|
141
- endpoint['region'] == openstack_region
142
- end if openstack_region
143
-
144
- if service['endpoints'].empty?
145
- raise Fog::Errors::NotFound.new("No endpoints available for region '#{openstack_region}'")
146
- end if openstack_region
147
-
148
153
  unless service
149
154
  available = body['access']['serviceCatalog'].map { |endpoint|
150
155
  endpoint['type']
@@ -157,6 +162,14 @@ module Fog
157
162
  raise Fog::Errors::NotFound, message
158
163
  end
159
164
 
165
+ service['endpoints'] = service['endpoints'].select do |endpoint|
166
+ endpoint['region'] == openstack_region
167
+ end if openstack_region
168
+
169
+ if service['endpoints'].empty?
170
+ raise Fog::Errors::NotFound.new("No endpoints available for region '#{openstack_region}'")
171
+ end if openstack_region
172
+
160
173
  regions = service["endpoints"].map{ |e| e['region'] }.uniq
161
174
  if regions.count > 1
162
175
  raise Fog::Errors::NotFound.new("Multiple regions available choose one of these '#{regions.join(',')}'")
@@ -10,14 +10,13 @@ Start by executing the following command:
10
10
 
11
11
  Once `irb` has launched you need to require the Fog library by executing:
12
12
 
13
- require 'fog'
13
+ require 'fog/openstack'
14
14
 
15
15
  ## Create Service
16
16
 
17
17
  Next, create a connection to the Compute Service:
18
18
 
19
- service = Fog::Compute.new({
20
- :provider => 'openstack', # OpenStack Fog provider
19
+ service = Fog::Compute::OpenStack.new({
21
20
  :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint
22
21
  :openstack_username => OPEN_STACK_USER, # Your OpenStack Username
23
22
  :openstack_tenant => OPEN_STACK_TENANT, # Your tenant id
@@ -20,16 +20,16 @@ Bundler helps manage gem dependencies and is recommended for new projects. For m
20
20
 
21
21
  ## Installation
22
22
 
23
- To install Fog via RubyGems run the following command:
23
+ To install Fog-Openstack via RubyGems run the following command:
24
24
 
25
- $ gem install fog
25
+ $ gem install fog-openstack
26
26
 
27
27
  To install Fog via Bundler add `gem 'fog'` to your `Gemfile`. This is a sample `Gemfile` to install Fog:
28
28
 
29
29
  ```ruby
30
30
  source 'https://rubygems.org'
31
31
 
32
- gem 'fog'
32
+ gem 'fog-openstack'
33
33
  ```
34
34
 
35
35
  After creating your `Gemfile` execute the following command to install the libraries:
@@ -50,13 +50,13 @@ If using Ruby 1.8.x execute the following command:
50
50
 
51
51
  ```ruby
52
52
  require 'rubygems'
53
- require 'fog'
53
+ require 'fog/openstack'
54
54
  ```
55
55
 
56
56
  If using Ruby 1.9.x execute the following command:
57
57
 
58
58
  ```ruby
59
- require 'fog'
59
+ require 'fog/openstack'
60
60
  ```
61
61
 
62
62
  You should now be able to execute the following command to see a list of services Fog provides for the Rackspace Open Cloud:
@@ -0,0 +1,251 @@
1
+ # Introspection
2
+
3
+ This document explains how to get started using introspection with
4
+ fog-openstack.
5
+
6
+ Please also refer to the
7
+ [Getting Started with Fog and the OpenStack](getting_started.md) document.
8
+
9
+ Introspection service is implemented by the OpenStack ironic-inspector project.
10
+ Introspection is strongly related to the Baremetal service (Ironic project).
11
+ Effectively, Instrospection communicates and operates on nodes defined by the
12
+ Baremetal layer (Ironic).
13
+
14
+ # OpenStack setup
15
+
16
+ ## The catalog
17
+ For the fog-openstack's introspection service to work, the corresponding
18
+ service must be defined in the OpenStack catalog.
19
+
20
+ ```bash
21
+ openstack catalog show inspector
22
+ +-----------+-----------------------------------------+
23
+ | Field | Value |
24
+ +-----------+-----------------------------------------+
25
+ | endpoints | regionOne |
26
+ | | publicURL: http://192.0.2.1:5050/v1 |
27
+ | | internalURL: http://192.0.2.1:5050/v1 |
28
+ | | adminURL: http://192.0.2.1:5050/v1 |
29
+ | | |
30
+ | name | inspector |
31
+ | type | introspection |
32
+ +-----------+-----------------------------------------+
33
+ ```
34
+
35
+ Depending on the OpenStack release, the introspection service might be installed
36
+ but not defined yet in the catalog. In such case, you must add the service and
37
+ corresponding endpoints to create the catalog entry:
38
+
39
+ ```bash
40
+ source ./stackrc
41
+ openstack service create --name inspector --description "OpenStack Introspection" introspection
42
+ openstack endpoint create --region regionOne inspector --publicurl http://example.com:5050/v1 --internalurl http://example.com:5050/v1 --adminurl http://example.com:5050/v1
43
+ ```
44
+
45
+ ## The introspection timeout
46
+ The default timeout value after which introspection is considered failed is set
47
+ by an 1 hour (3600 s) default. Although in production environment, baremetal
48
+ introspection requires time, testing in virtual environment doesn't, this is why
49
+ if you are in the latter case the timeout value can be reduced for speeding
50
+ results:
51
+
52
+ ```bash
53
+ sudo openstack-config --set /etc/ironic-inspector/inspector.conf DEFAULT timeout 300
54
+ ```
55
+
56
+ # Work flow
57
+ Assuming Baremetal nodes have been defined (imported), a usual work-flow might
58
+ consist of:
59
+ * Start introspection
60
+ * Check introspection status or abort introspection
61
+ * Retrieve introspection data
62
+ * optionally, pre-defined DSL based rules can be defined and applied during
63
+ introspection.
64
+
65
+ For more details about this process please refer to
66
+ http://docs.openstack.org/developer/ironic-inspector/workflow.html
67
+
68
+
69
+ Using 'irb', we start with authentication:
70
+
71
+ ```ruby
72
+ @user = "admin"
73
+ @project = "admin"
74
+ @password = "secret"
75
+ @base_url = "http://keystone.example.com:5000/v3/auth/tokens"
76
+
77
+ require 'rubygems'
78
+ require 'fog/openstack'
79
+
80
+ @connection_params = {
81
+ :openstack_auth_url => @base_url,
82
+ :openstack_username => @user,
83
+ :openstack_api_key => @password,
84
+ :openstack_project_name => @project,
85
+ :openstack_domain_id => "default"
86
+ }
87
+ ```
88
+ ## Baremetal node introspection
89
+
90
+ ### Baremetal nodes
91
+
92
+ Find the available Baremetal nodes.
93
+
94
+ ```ruby
95
+ iron = Fog::Baremetal::OpenStack.new(@connection_params)
96
+
97
+ nodes = iron.node_list
98
+ ```
99
+
100
+ ### Start introspection
101
+
102
+ Let's start introspection using the first available node.
103
+
104
+ Note: To be introspected, a node must be in "manage" state. If needed, use Baremetal Service
105
+ to change the state with set_node_provision_state.
106
+
107
+ For more information, please refer to
108
+ http://docs.openstack.org/developer/ironic/deploy/install-guide.html#hardware-inspection
109
+
110
+ ```ruby
111
+ node_id = nodes.body["nodes"][0]["uuid"]
112
+ inspector = Fog::Introspection::OpenStack.new(@connection_params)
113
+
114
+ introspection1 = inspector.create_introspection(node_id)
115
+ ```
116
+ If everything went well the status returned by the request must be 202 which
117
+ means accepted:
118
+ ```ruby
119
+ introspection1.status
120
+ => 202
121
+ ```
122
+
123
+ ### Check introspection status
124
+
125
+ To check the status of the introspection:
126
+ ```ruby
127
+ inspector.get_introspection(node_id)
128
+ ```
129
+
130
+ The body returned has 2 fields:
131
+ * finished: A boolean, set to true if introspection process is finished
132
+ * error: A null string unless an error occurred or the process was canceled by
133
+ the operator (in case introspection was aborted)
134
+
135
+ ### Abort an ongoing introspection
136
+
137
+ To abort a node introspection:
138
+ ```ruby
139
+ inspector.abort_introspection(node_id)
140
+ ```
141
+
142
+ ### Retrieve introspected data
143
+
144
+ ```ruby
145
+ inspector.get_introspection_details(node_id)
146
+ ```
147
+ The response body will provide a *very* long list of information about the node.
148
+
149
+ ## DSL rules
150
+
151
+ ### Create rules
152
+
153
+ ```ruby
154
+ rule_set1 = {
155
+ "description" => "Successful Rule",
156
+ "actions" => [
157
+ {
158
+ "action" => "set-attribute",
159
+ "path" => "/extra/rule_success",
160
+ "value" => "yes"
161
+ }
162
+ ],
163
+ "conditions" => [
164
+ {
165
+ "field" => "memory_mb",
166
+ "op" => "ge",
167
+ "value" => 256
168
+ },
169
+ {
170
+ "field" => "local_gb",
171
+ "op" => "ge",
172
+ "value" => 1
173
+ }
174
+ ]
175
+ }
176
+
177
+ rule_set2 = {
178
+ "description" => "Failing Rule",
179
+ "actions" => [
180
+ {
181
+ "action" => "set-attribute",
182
+ "path" => "/extra/rule_success",
183
+ "value" => "no"
184
+ },
185
+ {
186
+ "action" => "fail",
187
+ "message" => "This rule should not have run"
188
+ }
189
+ ],
190
+ "conditions" => [
191
+ {
192
+ "field" => "memory_mb",
193
+ "op" => "lt",
194
+ "value" => 42
195
+ },
196
+ {
197
+ "field" => "local_gb",
198
+ "op" => "eq",
199
+ "value" => 0
200
+ }
201
+ ],
202
+ }
203
+
204
+ inspector.create_rules(rule_set1)
205
+ inspector.create_rules(rule_set2)
206
+ ```
207
+
208
+ ### List all rules
209
+
210
+ ```ruby
211
+ inspector.list_rules.body
212
+ => {"rules"=>
213
+ [{"description"=>"Successful Rule",
214
+ "links"=>[{"href"=>"/v1/rules/4bf1bf40-d30f-4f31-a970-f0290d7e751b", "rel"=>"self"}],
215
+ "uuid"=>"4bf1bf40-d30f-4f31-a970-f0290d7e751b"},
216
+ {"description"=>"Failing Rule",
217
+ "links"=>[{"href"=>"/v1/rules/0d6e6687-3f69-4c14-8cab-ea6ada78036f", "rel"=>"self"}],
218
+ "uuid"=>"0d6e6687-3f69-4c14-8cab-ea6ada78036f"}]}
219
+ ```
220
+
221
+ ### Show rules details
222
+
223
+ ```ruby
224
+ inspector.get_rules('0d6e6687-3f69-4c14-8cab-ea6ada78036f').body
225
+ => {"actions"=>
226
+ [{"action"=>"set-attribute", "path"=>"/extra/rule_success", "value"=>"no"},
227
+ {"action"=>"fail", "message"=>"This rule should not have run"}],
228
+ "conditions"=>[{"field"=>"memory_mb", "op"=>"lt", "value"=>42}, {"field"=>"local_gb", "op"=>"eq", "value"=>0}],
229
+ "description"=>"Failing Rule",
230
+ "links"=>[{"href"=>"/v1/rules/0d6e6687-3f69-4c14-8cab-ea6ada78036f", "rel"=>"self"}],
231
+ "uuid"=>"0d6e6687-3f69-4c14-8cab-ea6ada78036f"}
232
+ ```
233
+
234
+ ### Delete a specific rules set
235
+
236
+ ```ruby
237
+ inspector.delete_rules'0d6e6687-3f69-4c14-8cab-ea6ada78036f')
238
+ inspector.list_rules.body
239
+ => {"rules"=>
240
+ [{"description"=>"Successful Rule",
241
+ "links"=>[{"href"=>"/v1/rules/4bf1bf40-d30f-4f31-a970-f0290d7e751b", "rel"=>"self"}],
242
+ "uuid"=>"4bf1bf40-d30f-4f31-a970-f0290d7e751b"}]}
243
+ ```
244
+
245
+ ### Destroys all rules
246
+
247
+ ```ruby
248
+ inspector.delete_rules_all
249
+ inspector.list_rules.body
250
+ => {"rules"=>[]}
251
+ ```
@@ -20,9 +20,23 @@ service = Fog::Metering::OpenStack.new({
20
20
 
21
21
  ## Events
22
22
 
23
- * `service.events`: Return a list of events.
23
+ * `service.events([<query_filter>])`: Return a list of events.
24
24
  * `service.events.find_by_id(<message_id>)`: Return the event matching message_id, or nil if no such event exists.
25
25
 
26
+ ### Filter events example
27
+
28
+ Return events newer than 2016-03-17T09:59:44.606000.
29
+
30
+ ```ruby
31
+ query_filter = [{
32
+ 'field' => 'start_timestamp',
33
+ 'op' => 'gt',
34
+ 'value' => '2016-03-17T09:59:44.606000'
35
+ }]
36
+
37
+ service.events(query_filter)
38
+ ```
39
+
26
40
  ## Resources
27
41
 
28
42
  * `service.resources`: Return a list of resources.