fog 1.27.0 → 1.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/Rakefile +2 -2
  4. data/bin/fog +2 -2
  5. data/fog.gemspec +4 -3
  6. data/lib/fog/bin/clodo.rb +1 -1
  7. data/lib/fog/bin/openstack.rb +5 -0
  8. data/lib/fog/digitalocean/examples/getting_started.md +46 -4
  9. data/lib/fog/digitalocean/models/compute/server.rb +1 -3
  10. data/lib/fog/digitalocean/models/compute/servers.rb +30 -0
  11. data/lib/fog/fogdocker/compute.rb +3 -2
  12. data/lib/fog/fogdocker/requests/compute/container_action.rb +1 -1
  13. data/lib/fog/fogdocker/requests/compute/container_all.rb +1 -1
  14. data/lib/fog/fogdocker/requests/compute/container_commit.rb +1 -1
  15. data/lib/fog/fogdocker/requests/compute/container_create.rb +1 -1
  16. data/lib/fog/fogdocker/requests/compute/container_delete.rb +1 -1
  17. data/lib/fog/fogdocker/requests/compute/container_get.rb +1 -1
  18. data/lib/fog/fogdocker/requests/compute/image_all.rb +1 -1
  19. data/lib/fog/fogdocker/requests/compute/image_create.rb +1 -1
  20. data/lib/fog/fogdocker/requests/compute/image_delete.rb +1 -1
  21. data/lib/fog/fogdocker/requests/compute/image_get.rb +1 -1
  22. data/lib/fog/fogdocker/requests/compute/image_search.rb +1 -1
  23. data/lib/fog/google/compute.rb +2 -1
  24. data/lib/fog/google/core.rb +42 -12
  25. data/lib/fog/google/dns.rb +2 -1
  26. data/lib/fog/google/monitoring.rb +1 -1
  27. data/lib/fog/google/sql.rb +1 -1
  28. data/lib/fog/hp/requests/storage/get_object.rb +5 -3
  29. data/lib/fog/joyent/compute.rb +2 -0
  30. data/lib/fog/openstack.rb +1 -0
  31. data/lib/fog/openstack/baremetal.rb +370 -0
  32. data/lib/fog/openstack/core.rb +1 -0
  33. data/lib/fog/openstack/docs/orchestration.md +318 -0
  34. data/lib/fog/openstack/docs/storage.md +1 -7
  35. data/lib/fog/openstack/models/baremetal/chassis.rb +60 -0
  36. data/lib/fog/openstack/models/baremetal/chassis_collection.rb +38 -0
  37. data/lib/fog/openstack/models/baremetal/driver.rb +30 -0
  38. data/lib/fog/openstack/models/baremetal/drivers.rb +21 -0
  39. data/lib/fog/openstack/models/baremetal/node.rb +85 -0
  40. data/lib/fog/openstack/models/baremetal/nodes.rb +38 -0
  41. data/lib/fog/openstack/models/baremetal/port.rb +61 -0
  42. data/lib/fog/openstack/models/baremetal/ports.rb +38 -0
  43. data/lib/fog/openstack/models/orchestration/event.rb +20 -0
  44. data/lib/fog/openstack/models/orchestration/events.rb +28 -0
  45. data/lib/fog/openstack/models/orchestration/resource.rb +32 -0
  46. data/lib/fog/openstack/models/orchestration/resource_schemas.rb +17 -0
  47. data/lib/fog/openstack/models/orchestration/resources.rb +35 -0
  48. data/lib/fog/openstack/models/orchestration/stack.rb +91 -24
  49. data/lib/fog/openstack/models/orchestration/stacks.rb +38 -4
  50. data/lib/fog/openstack/models/orchestration/template.rb +15 -0
  51. data/lib/fog/openstack/models/orchestration/templates.rb +44 -0
  52. data/lib/fog/openstack/orchestration.rb +48 -2
  53. data/lib/fog/openstack/requests/baremetal/create_chassis.rb +44 -0
  54. data/lib/fog/openstack/requests/baremetal/create_node.rb +54 -0
  55. data/lib/fog/openstack/requests/baremetal/create_port.rb +46 -0
  56. data/lib/fog/openstack/requests/baremetal/delete_chassis.rb +25 -0
  57. data/lib/fog/openstack/requests/baremetal/delete_node.rb +25 -0
  58. data/lib/fog/openstack/requests/baremetal/delete_port.rb +25 -0
  59. data/lib/fog/openstack/requests/baremetal/get_chassis.rb +24 -0
  60. data/lib/fog/openstack/requests/baremetal/get_driver.rb +24 -0
  61. data/lib/fog/openstack/requests/baremetal/get_driver_properties.rb +40 -0
  62. data/lib/fog/openstack/requests/baremetal/get_node.rb +24 -0
  63. data/lib/fog/openstack/requests/baremetal/get_port.rb +24 -0
  64. data/lib/fog/openstack/requests/baremetal/list_chassis.rb +48 -0
  65. data/lib/fog/openstack/requests/baremetal/list_chassis_detailed.rb +31 -0
  66. data/lib/fog/openstack/requests/baremetal/list_drivers.rb +24 -0
  67. data/lib/fog/openstack/requests/baremetal/list_nodes.rb +40 -0
  68. data/lib/fog/openstack/requests/baremetal/list_nodes_detailed.rb +31 -0
  69. data/lib/fog/openstack/requests/baremetal/list_ports.rb +48 -0
  70. data/lib/fog/openstack/requests/baremetal/list_ports_detailed.rb +31 -0
  71. data/lib/fog/openstack/requests/baremetal/patch_chassis.rb +42 -0
  72. data/lib/fog/openstack/requests/baremetal/patch_node.rb +41 -0
  73. data/lib/fog/openstack/requests/baremetal/patch_port.rb +41 -0
  74. data/lib/fog/openstack/requests/compute/create_server.rb +1 -0
  75. data/lib/fog/openstack/requests/orchestration/abandon_stack.rb +15 -0
  76. data/lib/fog/openstack/requests/orchestration/build_info.rb +15 -0
  77. data/lib/fog/openstack/requests/orchestration/create_stack.rb +31 -12
  78. data/lib/fog/openstack/requests/orchestration/delete_stack.rb +28 -5
  79. data/lib/fog/openstack/requests/orchestration/get_stack_template.rb +20 -0
  80. data/lib/fog/openstack/requests/orchestration/list_resource_events.rb +23 -0
  81. data/lib/fog/openstack/requests/orchestration/list_resource_types.rb +26 -0
  82. data/lib/fog/openstack/requests/orchestration/list_resources.rb +23 -0
  83. data/lib/fog/openstack/requests/orchestration/list_stack_data.rb +27 -0
  84. data/lib/fog/openstack/requests/orchestration/list_stack_events.rb +23 -0
  85. data/lib/fog/openstack/requests/orchestration/preview_stack.rb +16 -0
  86. data/lib/fog/openstack/requests/orchestration/show_event_details.rb +26 -0
  87. data/lib/fog/openstack/requests/orchestration/show_resource_data.rb +26 -0
  88. data/lib/fog/openstack/requests/orchestration/show_resource_metadata.rb +26 -0
  89. data/lib/fog/openstack/requests/orchestration/show_resource_schema.rb +15 -0
  90. data/lib/fog/openstack/requests/orchestration/show_resource_template.rb +20 -0
  91. data/lib/fog/openstack/requests/orchestration/show_stack_details.rb +26 -0
  92. data/lib/fog/openstack/requests/orchestration/update_stack.rb +34 -7
  93. data/lib/fog/openstack/requests/orchestration/validate_template.rb +16 -0
  94. data/lib/fog/openstack/volume.rb +0 -1
  95. data/lib/fog/ovirt/compute.rb +6 -0
  96. data/lib/fog/ovirt/models/compute/server.rb +10 -0
  97. data/lib/fog/ovirt/models/compute/template.rb +1 -0
  98. data/lib/fog/ovirt/models/compute/volumes.rb +1 -2
  99. data/lib/fog/ovirt/requests/compute/attach_volume.rb +22 -0
  100. data/lib/fog/ovirt/requests/compute/detach_volume.rb +22 -0
  101. data/lib/fog/ovirt/requests/compute/list_volumes.rb +19 -0
  102. data/lib/fog/ovirt/requests/compute/mock_files/disks.xml +58 -0
  103. data/lib/fog/vcloud_director/models/compute/task.rb +2 -2
  104. data/lib/fog/version.rb +1 -1
  105. data/lib/fog/vsphere/compute.rb +3 -0
  106. data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +20 -11
  107. data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +41 -0
  108. data/lib/fog/vsphere/requests/compute/get_network.rb +35 -6
  109. data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +1 -1
  110. data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +19 -13
  111. data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +92 -0
  112. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +16 -11
  113. data/lib/fog/vsphere/requests/compute/vm_clone.rb +6 -5
  114. data/lib/fog/xenserver/requests/compute/create_sr.rb +3 -4
  115. data/lib/tasks/changelog_task.rb +1 -0
  116. data/tests/helper.rb +3 -3
  117. data/tests/helpers/mock_helper.rb +0 -4
  118. data/tests/openstack/requests/baremetal/chassis_tests.rb +48 -0
  119. data/tests/openstack/requests/baremetal/driver_tests.rb +40 -0
  120. data/tests/openstack/requests/baremetal/node_tests.rb +65 -0
  121. data/tests/openstack/requests/baremetal/port_tests.rb +56 -0
  122. data/tests/openstack/requests/compute/server_tests.rb +2 -0
  123. data/tests/openstack/requests/orchestration/stack_tests.rb +2 -2
  124. data/tests/vsphere/requests/compute/get_network_tests.rb +48 -0
  125. metadata +88 -23
  126. data/lib/fog/aws.rb +0 -23
  127. data/lib/fog/bin/riakcs.rb +0 -25
  128. data/lib/fog/openstack/requests/orchestration/list_stacks.rb +0 -47
  129. data/lib/fog/riakcs.rb +0 -2
  130. data/lib/fog/riakcs/core.rb +0 -121
  131. data/lib/fog/riakcs/provisioning.rb +0 -98
  132. data/lib/fog/riakcs/requests/provisioning/create_user.rb +0 -77
  133. data/lib/fog/riakcs/requests/provisioning/disable_user.rb +0 -23
  134. data/lib/fog/riakcs/requests/provisioning/enable_user.rb +0 -23
  135. data/lib/fog/riakcs/requests/provisioning/get_user.rb +0 -41
  136. data/lib/fog/riakcs/requests/provisioning/list_users.rb +0 -43
  137. data/lib/fog/riakcs/requests/provisioning/regrant_secret.rb +0 -23
  138. data/lib/fog/riakcs/requests/provisioning/update_user.rb +0 -23
  139. data/lib/fog/riakcs/requests/usage/get_usage.rb +0 -68
  140. data/lib/fog/riakcs/usage.rb +0 -62
  141. data/tests/riakcs/requests/provisioning/provisioning_tests.rb +0 -174
  142. data/tests/riakcs/requests/usage/usage_tests.rb +0 -29
@@ -4,7 +4,8 @@ module Fog
4
4
  module DNS
5
5
  class Google < Fog::Service
6
6
  requires :google_project
7
- recognizes :app_name, :app_version, :google_client_email, :google_key_location, :google_key_string, :google_client
7
+ recognizes :app_name, :app_version, :google_client_email, :google_key_location, :google_key_string,
8
+ :google_client, :google_json_key_location, :google_json_key_string
8
9
 
9
10
  GOOGLE_DNS_API_VERSION = 'v1beta1'
10
11
  GOOGLE_DNS_BASE_URL = 'https://www.googleapis.com/dns/'
@@ -5,7 +5,7 @@ module Fog
5
5
  class Monitoring < Fog::Service
6
6
  requires :google_project
7
7
  recognizes :google_client_email, :google_key_location, :google_key_string, :google_client,
8
- :app_name, :app_version
8
+ :app_name, :app_version, :google_json_key_location, :google_json_key_string
9
9
 
10
10
  GOOGLE_MONITORING_API_VERSION = 'v2beta1'
11
11
  GOOGLE_MONITORING_BASE_URL = 'https://www.googleapis.com/cloudmonitoring/'
@@ -5,7 +5,7 @@ module Fog
5
5
  class SQL < Fog::Service
6
6
  requires :google_project
7
7
  recognizes :google_client_email, :google_key_location, :google_key_string, :google_client,
8
- :app_name, :app_version
8
+ :app_name, :app_version, :google_json_key_location, :google_json_key_string
9
9
 
10
10
  GOOGLE_SQL_API_VERSION = 'v1beta3'
11
11
  GOOGLE_SQL_BASE_URL = 'https://www.googleapis.com/sql/'
@@ -8,17 +8,19 @@ module Fog
8
8
  # * container<~String> - Name of container to look in
9
9
  # * object<~String> - Name of object to look for
10
10
  #
11
- def get_object(container, object, &block)
11
+ def get_object(container, object, options = {}, &block)
12
12
  if block_given?
13
13
  response = request(
14
14
  :response_block => block,
15
- :expects => 200,
15
+ :expects => [200, 206],
16
+ :headers => options,
16
17
  :method => 'GET',
17
18
  :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
18
19
  )
19
20
  else
20
21
  response = request({
21
- :expects => 200,
22
+ :expects => [200, 206],
23
+ :headers => options,
22
24
  :method => 'GET',
23
25
  :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
24
26
  }, false, &block)
@@ -247,6 +247,8 @@ module Fog
247
247
 
248
248
  def raise_if_error!(request, response)
249
249
  case response.status
250
+ when 400 then
251
+ raise Joyent::Errors::BadRequest.new('Bad Request', request, response)
250
252
  when 401 then
251
253
  raise Joyent::Errors::Unauthorized.new('Invalid credentials were used', request, response)
252
254
  when 403 then
@@ -6,3 +6,4 @@ require 'fog/openstack/network'
6
6
  require 'fog/openstack/orchestration'
7
7
  require 'fog/openstack/storage'
8
8
  require 'fog/openstack/volume'
9
+ require 'fog/openstack/baremetal'
@@ -0,0 +1,370 @@
1
+ require 'fog/openstack/core'
2
+
3
+ module Fog
4
+ module Baremetal
5
+ class OpenStack < Fog::Service
6
+ SUPPORTED_VERSIONS = /(.)*/
7
+
8
+ requires :openstack_auth_url
9
+ recognizes :openstack_auth_token, :openstack_management_url, :persistent,
10
+ :openstack_service_type, :openstack_service_name, :openstack_tenant,
11
+ :openstack_api_key, :openstack_username,
12
+ :current_user, :current_tenant, :openstack_endpoint_type, :openstack_region
13
+
14
+ ## MODELS
15
+ #
16
+ model_path 'fog/openstack/models/baremetal'
17
+ model :chassis
18
+ collection :chassis_collection
19
+ model :driver
20
+ collection :drivers
21
+ model :node
22
+ collection :nodes
23
+ model :port
24
+ collection :ports
25
+
26
+ ## REQUESTS
27
+ #
28
+ request_path 'fog/openstack/requests/baremetal'
29
+
30
+ # Node requests
31
+ request :create_node
32
+ request :delete_node
33
+ request :get_node
34
+ request :list_nodes
35
+ request :list_nodes_detailed
36
+ request :patch_node
37
+
38
+ # Chassis requests
39
+ request :create_chassis
40
+ request :delete_chassis
41
+ request :get_chassis
42
+ request :list_chassis
43
+ request :list_chassis_detailed
44
+ request :patch_chassis
45
+
46
+ # Driver requests
47
+ request :get_driver
48
+ request :get_driver_properties
49
+ request :list_drivers
50
+
51
+ # Port requests
52
+ request :create_port
53
+ request :delete_port
54
+ request :get_port
55
+ request :list_ports
56
+ request :list_ports_detailed
57
+ request :patch_port
58
+
59
+ ## TODO not implemented API requests:
60
+ ## Chassis
61
+ # request :list_chassis_nodes
62
+ # request :list_chassis_nodes_details
63
+
64
+ ## Node requests
65
+ # request :validate_node
66
+ # request :set_maintenance
67
+ # request :unset_maintenance
68
+ # request :get_boot_device
69
+ # request :set_boot_device
70
+ # request :list_supported_boot_devices
71
+ # request :list_node_states
72
+ # request :set_power_state
73
+ # request :provision_node
74
+ # request :get_console_info
75
+ # request :change_console_state
76
+ # request :get_vendor_passthru_methods
77
+
78
+ ## Driver requests
79
+ # request :get_vendor_passthru_methods
80
+
81
+ class Mock
82
+ def self.data
83
+ @data ||= Hash.new do |hash, key|
84
+ chassis_uuid = Fog::UUID.uuid
85
+ instance_uuid = Fog::UUID.uuid
86
+ node_uuid = Fog::UUID.uuid
87
+
88
+ hash[key] = {
89
+ :chassis_collection => [
90
+ {
91
+ "created_at" => "2000-01-01T12:00:00",
92
+ "description" => "Sample chassis",
93
+ "extra" => {},
94
+ "links" => [
95
+ {
96
+ "href" => "http://localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89",
97
+ "rel" => "self"
98
+ },
99
+ {
100
+ "href" => "http://localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89",
101
+ "rel" => "bookmark"
102
+ }
103
+ ],
104
+ "nodes" => [
105
+ {
106
+ "href" => "http://localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89/nodes",
107
+ "rel" => "self"
108
+ },
109
+ {
110
+ "href" => "http://localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89/nodes",
111
+ "rel" => "bookmark"
112
+ }
113
+ ],
114
+ "updated_at" => "2000-01-01T12:00:00",
115
+ "uuid" => chassis_uuid
116
+ }
117
+ ],
118
+ :drivers => [
119
+ {
120
+ "hosts" => [
121
+ "fake-host"
122
+ ],
123
+ "name" => "sample-driver"
124
+ }
125
+ ],
126
+ :nodes => [{
127
+ "chassis_uuid" => chassis_uuid,
128
+ "console_enabled" => false,
129
+ "created_at" => "2000-01-01T12:00:00",
130
+ "driver" => "sample-driver",
131
+ "driver_info" => {},
132
+ "extra" => {},
133
+ "instance_info" => {},
134
+ "instance_uuid" => instance_uuid,
135
+ "last_error" => nil,
136
+ "links" => [
137
+ {
138
+ "href" => "http://localhost:6385/v1/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123",
139
+ "rel" => "self"
140
+ },
141
+ {
142
+ "href" => "http://localhost:6385/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123",
143
+ "rel" => "bookmark"
144
+ }
145
+ ],
146
+ "maintenance" => false,
147
+ "maintenance_reason" => nil,
148
+ "ports" => [
149
+ {
150
+ "href" => "http://localhost:6385/v1/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/ports",
151
+ "rel" => "self"
152
+ },
153
+ {
154
+ "href" => "http://localhost:6385/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/ports",
155
+ "rel" => "bookmark"
156
+ }
157
+ ],
158
+ "power_state" => "power on",
159
+ "properties" => {
160
+ "cpus" => "1",
161
+ "local_gb" => "10",
162
+ "memory_mb" => "1024"
163
+ },
164
+ "provision_state" => "active",
165
+ "provision_updated_at" => "2000-01-01T12:00:00",
166
+ "reservation" => nil,
167
+ "target_power_state" => nil,
168
+ "target_provision_state" => nil,
169
+ "updated_at" => "2000-01-01T12:00:00",
170
+ "uuid" => node_uuid
171
+ }],
172
+ :ports => [{
173
+ "address" => "fe:54:00:77:07:d9",
174
+ "created_at" => "2014-12-23T19:35:30.734116",
175
+ "extra" => {
176
+ "foo" => "bar"
177
+ },
178
+ "links" => [
179
+ {
180
+ "href" => "http://localhost:6385/v1/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c",
181
+ "rel" => "self"
182
+ },
183
+ {
184
+ "href" => "http://localhost:6385/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c",
185
+ "rel" => "bookmark"
186
+ }
187
+ ],
188
+ "node_uuid" => "7ae81bb3-dec3-4289-8d6c-da80bd8001ae",
189
+ "updated_at" => "2014-12-23T19:35:30.734119",
190
+ "uuid" => "27e3153e-d5bf-4b7e-b517-fb518e17f34c"
191
+ }]
192
+ }
193
+ end
194
+ end
195
+
196
+ def self.reset
197
+ @data = nil
198
+ end
199
+
200
+ def initialize(options={})
201
+ @openstack_username = options[:openstack_username]
202
+ @openstack_tenant = options[:openstack_tenant]
203
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
204
+
205
+ @auth_token = Fog::Mock.random_base64(64)
206
+ @auth_token_expiration = (Time.now.utc + 86400).iso8601
207
+
208
+ management_url = URI.parse(options[:openstack_auth_url])
209
+ management_url.port = 9292
210
+ management_url.path = '/v1'
211
+ @openstack_management_url = management_url.to_s
212
+
213
+ @data ||= { :users => {} }
214
+ unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
215
+ id = Fog::Mock.random_numbers(6).to_s
216
+ @data[:users][id] = {
217
+ 'id' => id,
218
+ 'name' => options[:openstack_username],
219
+ 'email' => "#{options[:openstack_username]}@mock.com",
220
+ 'tenantId' => Fog::Mock.random_numbers(6).to_s,
221
+ 'enabled' => true
222
+ }
223
+ end
224
+ end
225
+
226
+ def data
227
+ self.class.data[@openstack_username]
228
+ end
229
+
230
+ def reset_data
231
+ self.class.data.delete(@openstack_username)
232
+ end
233
+
234
+ def credentials
235
+ { :provider => 'openstack',
236
+ :openstack_auth_url => @openstack_auth_uri.to_s,
237
+ :openstack_auth_token => @auth_token,
238
+ :openstack_region => @openstack_region,
239
+ :openstack_management_url => @openstack_management_url }
240
+ end
241
+ end
242
+
243
+ class Real
244
+ attr_reader :current_user
245
+ attr_reader :current_tenant
246
+
247
+ def initialize(options={})
248
+ @openstack_auth_token = options[:openstack_auth_token]
249
+
250
+ unless @openstack_auth_token
251
+ missing_credentials = Array.new
252
+ @openstack_api_key = options[:openstack_api_key]
253
+ @openstack_username = options[:openstack_username]
254
+
255
+ missing_credentials << :openstack_api_key unless @openstack_api_key
256
+ missing_credentials << :openstack_username unless @openstack_username
257
+ raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
258
+ end
259
+
260
+ @openstack_tenant = options[:openstack_tenant]
261
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
262
+ @openstack_management_url = options[:openstack_management_url]
263
+ @openstack_must_reauthenticate = false
264
+ @openstack_service_type = options[:openstack_service_type] || ['baremetal']
265
+ @openstack_service_name = options[:openstack_service_name]
266
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
267
+ @openstack_region = options[:openstack_region]
268
+
269
+ @connection_options = options[:connection_options] || {}
270
+
271
+ @current_user = options[:current_user]
272
+ @current_tenant = options[:current_tenant]
273
+
274
+ authenticate
275
+
276
+ @persistent = options[:persistent] || false
277
+ @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
278
+ end
279
+
280
+ def credentials
281
+ { :provider => 'openstack',
282
+ :openstack_auth_url => @openstack_auth_uri.to_s,
283
+ :openstack_auth_token => @auth_token,
284
+ :openstack_management_url => @openstack_management_url,
285
+ :current_user => @current_user,
286
+ :current_tenant => @current_tenant }
287
+ end
288
+
289
+ def reload
290
+ @connection.reset
291
+ end
292
+
293
+ def request(params)
294
+ begin
295
+ response = @connection.request(params.merge({
296
+ :headers => {
297
+ 'Content-Type' => 'application/json',
298
+ 'X-Auth-Token' => @auth_token
299
+ }.merge!(params[:headers] || {}),
300
+ :path => "#{@path}/#{params[:path]}"#,
301
+ }))
302
+ rescue Excon::Errors::Unauthorized => error
303
+ if error.response.body != 'Bad username or password' # token expiration
304
+ @openstack_must_reauthenticate = true
305
+ authenticate
306
+ retry
307
+ else # bad credentials
308
+ raise error
309
+ end
310
+ rescue Excon::Errors::HTTPStatusError => error
311
+ raise case error
312
+ when Excon::Errors::NotFound
313
+ Fog::Compute::OpenStack::NotFound.slurp(error)
314
+ else
315
+ error
316
+ end
317
+ end
318
+ unless response.body.empty?
319
+ response.body = Fog::JSON.decode(response.body)
320
+ end
321
+ response
322
+ end
323
+
324
+ private
325
+
326
+ def authenticate
327
+ if !@openstack_management_url || @openstack_must_reauthenticate
328
+ options = {
329
+ :openstack_tenant => @openstack_tenant,
330
+ :openstack_api_key => @openstack_api_key,
331
+ :openstack_username => @openstack_username,
332
+ :openstack_auth_uri => @openstack_auth_uri,
333
+ :openstack_region => @openstack_region,
334
+ :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token,
335
+ :openstack_service_type => @openstack_service_type,
336
+ :openstack_service_name => @openstack_service_name,
337
+ :openstack_endpoint_type => @openstack_endpoint_type
338
+ }
339
+
340
+ credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
341
+
342
+ @current_user = credentials[:user]
343
+ @current_tenant = credentials[:tenant]
344
+
345
+ @openstack_must_reauthenticate = false
346
+ @auth_token = credentials[:token]
347
+ @openstack_management_url = credentials[:server_management_url]
348
+ uri = URI.parse(@openstack_management_url)
349
+ else
350
+ @auth_token = @openstack_auth_token
351
+ uri = URI.parse(@openstack_management_url)
352
+ end
353
+
354
+ @host = uri.host
355
+ @path = uri.path
356
+ @path.sub!(/\/$/, '')
357
+ unless @path.match(SUPPORTED_VERSIONS)
358
+ @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS,
359
+ uri,
360
+ @auth_token,
361
+ @connection_options)
362
+ end
363
+ @port = uri.port
364
+ @scheme = uri.scheme
365
+ true
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
@@ -50,6 +50,7 @@ module Fog
50
50
  service(:volume, 'Volume')
51
51
  service(:metering, 'Metering')
52
52
  service(:orchestration, 'Orchestration')
53
+ service(:baremetal, 'Baremetal')
53
54
 
54
55
  def self.authenticate(options, connection_options = {})
55
56
  case options[:openstack_auth_uri].path
@@ -0,0 +1,318 @@
1
+ # OpenStack Orchestration
2
+ The mission of the OpenStack Orchestration program is to create a human- and machine-accessible service for managing the entire lifecycle of infrastructure and applications within OpenStack clouds.
3
+
4
+ ## Heat
5
+ Heat is the main project in the OpenStack Orchestration program. It implements an orchestration engine to launch multiple composite cloud applications based on templates in the form of text files that can be treated like code. A native Heat template format is evolving, but Heat also endeavours to provide compatibility with the AWS CloudFormation template format, so that many existing CloudFormation templates can be launched on OpenStack. Heat provides both an OpenStack-native ReST API and a CloudFormation-compatible Query API.
6
+
7
+ *Why ‘Heat’? It makes the clouds rise!*
8
+
9
+ **How it works**
10
+
11
+ * A Heat template describes the infrastructure for a cloud application in a text file that is readable and writable by humans, and can be checked into version control, diffed, &c.
12
+ * Infrastructure resources that can be described include: servers, floating ips, volumes, security groups, users, etc.
13
+ * Heat also provides an autoscaling service that integrates with Ceilometer, so you can include a scaling group as a resource in a template.
14
+ * Templates can also specify the relationships between resources (e.g. this volume is connected to this server). This enables Heat to call out to the OpenStack APIs to create all of your infrastructure in the correct order to completely launch your application.
15
+ * Heat manages the whole lifecycle of the application - when you need to change your infrastructure, simply modify the template and use it to update your existing stack. Heat knows how to make the necessary changes. It will delete all of the resources when you are finished with the application, too.
16
+ * Heat primarily manages infrastructure, but the templates integrate well with software configuration management tools such as Puppet and Chef. The Heat team is working on providing even better integration between infrastructure and software.
17
+
18
+ _Source: [OpenStack Wiki](https://wiki.openstack.org/wiki/Heat)_
19
+
20
+ # OpenStack Orchestration (Heat) Client
21
+
22
+ [Full OpenStack Orchestration/Heat API Docs](http://developer.openstack.org/api-ref-orchestration-v1.html)
23
+
24
+ ## Orchestration Service
25
+ Get a handle on the Orchestration service:
26
+
27
+ ```ruby
28
+ service = Fog::Orchestration::OpenStack.new({
29
+ :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint
30
+ :openstack_username => OPEN_STACK_USER, # Your OpenStack Username
31
+ :openstack_tenant => OPEN_STACK_TENANT, # Your tenant id
32
+ :openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password
33
+ :connection_options => {} # Optional
34
+ })
35
+ ```
36
+ We will use this `service` to interact with the Orchestration resources, `stack`, `event`, `resource`, and `template`
37
+
38
+ ## Stacks
39
+
40
+ Get a list of stacks you own:
41
+
42
+ ```ruby
43
+ service.stacks
44
+ ```
45
+ This returns a list of stacks with minimum attributes, leaving other attributes empty
46
+ ```ruby
47
+ => <Fog::Orchestration::OpenStack::Stacks
48
+ [
49
+ <Fog::Orchestration::OpenStack::Stack
50
+ id="0b8e4060-419b-416b-a927-097d4afbf26d",
51
+ capabilities=nil,
52
+ description="Simple template to deploy a single compute instance",
53
+ disable_rollback=nil,
54
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "rel"=>"self"}],
55
+ notification_topics=nil,
56
+ outputs=nil,
57
+ parameters=nil,
58
+ stack_name="stack4",
59
+ stack_status="UPDATE_COMPLETE",
60
+ stack_status_reason="Stack successfully updated",
61
+ template_description=nil,
62
+ timeout_mins=nil,
63
+ creation_time="2014-08-27T21:25:56Z",
64
+ updated_time="2015-01-30T20:10:43Z"
65
+ >,
66
+ ...
67
+ ```
68
+
69
+ Create a new `stack` with a [Heat Template (HOT)](http://docs.openstack.org/developer/heat/template_guide/hot_guide.html) or an AWS CloudFormation Template (CFN):
70
+
71
+ ```ruby
72
+ raw_template = File.read(TEMPLATE_FILE)
73
+ service.stacks.new.save({
74
+ :stack_name => "a_name_for_stack",
75
+ :template => raw_template,
76
+ :parameters => {"flavor" => "m1.small", "image" => "cirror"}
77
+ })
78
+ ```
79
+ This returns a JSON blob filled with information about our new stack:
80
+
81
+ ```ruby
82
+ {"id"=>"53b35fbe-34f7-4837-b0f8-8863b7263b7d",
83
+ "links"=>[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d",
84
+ "rel"=>"self"}]}
85
+ ```
86
+
87
+ We can get a reference to the stack using its `stack_name` and `id`:
88
+
89
+ ```ruby
90
+ stack = service.stacks.get("stack4", "0b8e4060-419b-416b-a927-097d4afbf26d")
91
+ ```
92
+ This returns a stack with all attributes filled
93
+ ```ruby
94
+ => <Fog::Orchestration::OpenStack::Stack
95
+ id="0b8e4060-419b-416b-a927-097d4afbf26d",
96
+ capabilities=[],
97
+ description="Simple template to deploy a single compute instance",
98
+ disable_rollback=true,
99
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "rel"=>"self"}],
100
+ notification_topics=[],
101
+ outputs=[],
102
+ parameters={"AWS::StackId"=>"arn:openstack:heat::5d139d95546240748508b2a518aa5bef:stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "AWS::Region"=>"ap-southeast-1", "AWS::StackName"=>"stack4"},
103
+ stack_name="stack4",
104
+ stack_status="UPDATE_COMPLETE",
105
+ stack_status_reason="Stack successfully updated",
106
+ template_description="Simple template to deploy a single compute instance",
107
+ timeout_mins=60,
108
+ creation_time="2014-08-27T21:25:56Z",
109
+ updated_time="2015-01-30T20:10:43Z"
110
+ >
111
+ ```
112
+ It can be also obtained through the details method of a simple stack object
113
+ ```ruby
114
+ stack.details
115
+ ```
116
+
117
+ A stack knows about related `events`:
118
+
119
+ ```ruby
120
+ stack.events
121
+ => <Fog::Orchestration::OpenStack::Events
122
+ [
123
+ <Fog::Orchestration::OpenStack::Event
124
+ id="251",
125
+ resource_name="my_instance",
126
+ event_time="2015-01-21T20:08:51Z",
127
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d/resources/my_instance/events/251", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d", "rel"=>"stack"}],
128
+ logical_resource_id="my_instance",
129
+ resource_status="CREATE_IN_PROGRESS",
130
+ resource_status_reason="state changed",
131
+ physical_resource_id=nil
132
+ >,
133
+ ```
134
+ A stack knows about related `resources`:
135
+
136
+ ```ruby
137
+ stack.resources
138
+ => <Fog::Orchestration::OpenStack::Resources
139
+ [
140
+ <Fog::Orchestration::OpenStack::Resource
141
+ id=nil,
142
+ resource_name="my_instance",
143
+ description=nil,
144
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
145
+ logical_resource_id="my_instance",
146
+ resource_status="CREATE_COMPLETE",
147
+ updated_time="2014-09-12T20:44:06Z",
148
+ required_by=[],
149
+ resource_status_reason="state changed",
150
+ resource_type="OS::Nova::Server"
151
+ >
152
+ ]
153
+ >
154
+ ```
155
+
156
+ You can get a stack's `template`
157
+
158
+ ```ruby
159
+ stack.template
160
+ => <Fog::Orchestration::OpenStack::Template
161
+ format="HOT",
162
+ description="Simple template to deploy a single compute instance",
163
+ template_version="2013-05-23",
164
+ parameters=nil,
165
+ resources=...
166
+ ```
167
+
168
+ You can just delete a stack. This deletes associated `resources` :
169
+
170
+ ```ruby
171
+ stack.delete
172
+ => #<Excon::Response:0x007fe1066b2af8 @data={:body=>"", :headers=>{"Content-Type"=>"text/html; charset=UTF-8", "Content-Length"=>"0", "Date"=>"Wed, 21 Jan 2015 20:38:00 GMT"}, :status=>204, :reason_phrase=>"No Content", :remote_ip=>"10.8.96.4", :local_port=>59628, :local_address=>"10.17.68.186"}, @body="", @headers={"Content-Type"=>"text/html; charset=UTF-8", "Content-Length"=>"0", "Date"=>"Wed, 21 Jan 2015 20:38:00 GMT"}, @status=204, @remote_ip="10.8.96.4", @local_port=59628, @local_address="10.17.68.186">
173
+ ```
174
+
175
+ Reload any object by calling `reload` on it:
176
+
177
+ ```ruby
178
+ stacks.reload
179
+ => <Fog::Orchestration::OpenStack::Stacks
180
+ [...]
181
+ >
182
+ ```
183
+
184
+ ## Events
185
+
186
+ You can list `Events` of a `stack`:
187
+
188
+ ```ruby
189
+ stack.events
190
+ => <Fog::Orchestration::OpenStack::Events
191
+ [
192
+ <Fog::Orchestration::OpenStack::Event
193
+ id="15",
194
+ resource_name="my_instance",
195
+ event_time="2014-09-12T20:43:58Z",
196
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance/events/15", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
197
+ logical_resource_id="my_instance",
198
+ resource_status="CREATE_IN_PROGRESS",
199
+ resource_status_reason="state changed",
200
+ physical_resource_id=nil
201
+ >,
202
+ ```
203
+
204
+ `Event` can be got through corresponding `resource`
205
+
206
+ ```ruby
207
+ event = service.events.get(stack, resource, event_id)
208
+ => <Fog::Orchestration::OpenStack::Event
209
+ id="15",
210
+ resource_name="my_instance",
211
+ event_time="2014-09-12T20:43:58Z",
212
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance/events/15", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
213
+ logical_resource_id="my_instance",
214
+ resource_status="CREATE_IN_PROGRESS",
215
+ resource_status_reason="state changed",
216
+ physical_resource_id=nil
217
+ >
218
+ ```
219
+
220
+ An `event` knows about its associated `stack`:
221
+
222
+ ```ruby
223
+ event.stack
224
+ => <Fog::Orchestration::OpenStack::Stack
225
+ id="0c9ee370-ef64-4a80-a6cc-65d2277caeb9",
226
+ description="Simple template to deploy a single compute instance",
227
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"self"}],
228
+ stack_status_reason="Stack create completed successfully",
229
+ stack_name="progenerated",
230
+ creation_time="2014-09-12T20:43:58Z",
231
+ updated_time="2014-09-12T20:44:06Z"
232
+ >
233
+ ```
234
+ An `event` has an associated `resource`:
235
+
236
+ ```ruby
237
+ resource = event.resource
238
+ => <Fog::Orchestration::OpenStack::Resource
239
+ id=nil,
240
+ resource_name="my_instance",
241
+ description="",
242
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
243
+ logical_resource_id="my_instance",
244
+ resource_status="CREATE_COMPLETE",
245
+ updated_time="2014-09-12T20:44:06Z",
246
+ required_by=[],
247
+ resource_status_reason="state changed",
248
+ resource_type="OS::Nova::Server"
249
+ >
250
+ ```
251
+
252
+ ## Resource
253
+
254
+ `resources` might be nested:
255
+
256
+ ```ruby
257
+ service.resources.all(stack, {:nested_depth => 1})
258
+ => <Fog::Orchestration::OpenStack::Resources
259
+ [
260
+ <Fog::Orchestration::OpenStack::Resource
261
+ id=nil,
262
+ resource_name="my_instance",
263
+ description=nil,
264
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
265
+ logical_resource_id="my_instance",
266
+ resource_status="CREATE_COMPLETE",
267
+ updated_time="2014-09-12T20:44:06Z",
268
+ required_by=[],
269
+ resource_status_reason="state changed",
270
+ resource_type="OS::Nova::Server"
271
+ >
272
+ ]
273
+ >
274
+ ```
275
+
276
+ A `resource` knows about its associated `stack`:
277
+
278
+ ```ruby
279
+ resource.stack
280
+ => <Fog::Orchestration::OpenStack::Stack
281
+ id="0c9ee370-ef64-4a80-a6cc-65d2277caeb9",
282
+ description="Simple template to deploy a single compute instance",
283
+ links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"self"}],
284
+ stack_status_reason="Stack create completed successfully",
285
+ stack_name="progenerated",
286
+ creation_time="2014-09-12T20:43:58Z",
287
+ updated_time="2014-09-12T20:44:06Z"
288
+ >
289
+ ```
290
+
291
+ Resource metadata is visible:
292
+
293
+ ```ruby
294
+ irb: resource.metadata
295
+ => {}
296
+ ```
297
+
298
+ A `resource's` template is visible (if one exists)
299
+
300
+ ```ruby
301
+ irb: resource.template
302
+ => nil
303
+ ```
304
+
305
+ ## Validation
306
+ You can validate a template (either HOT or CFN) before using it:
307
+
308
+ ```ruby
309
+ service.templates.validate(:template => content)
310
+ => <Fog::Orchestration::OpenStack::Template
311
+ format=nil,
312
+ description="Simple template to deploy a single compute instance",
313
+ template_version=nil,
314
+ parameters={},
315
+ resources=nil,
316
+ content=nil
317
+ >
318
+ ```