fog-openstack 0.1.15 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  3. data/README.md +36 -5
  4. data/docs/common/connection_params.md +45 -0
  5. data/docs/common/resources.md +11 -0
  6. data/docs/compute.md +2 -46
  7. data/docs/getting_started.md +11 -10
  8. data/docs/network.md +2 -47
  9. data/docs/orchestration.md +2 -2
  10. data/docs/planning.md +2 -47
  11. data/docs/shared_file_system.md +82 -0
  12. data/docs/storage.md +5 -51
  13. data/docs/workflow.md +4 -2
  14. data/examples/metric/basics.rb +42 -0
  15. data/examples/shared_file_system/basics.rb +68 -0
  16. data/gemfiles/Gemfile-1.9 +1 -0
  17. data/lib/fog/identity/openstack/v3/requests/list_groups.rb +1 -1
  18. data/lib/fog/image/openstack/v2/models/image.rb +60 -15
  19. data/lib/fog/image/openstack/v2/models/images.rb +1 -4
  20. data/lib/fog/metric/openstack.rb +126 -0
  21. data/lib/fog/metric/openstack/models/metric.rb +18 -0
  22. data/lib/fog/metric/openstack/models/metrics.rb +31 -0
  23. data/lib/fog/metric/openstack/models/resource.rb +16 -0
  24. data/lib/fog/metric/openstack/models/resources.rb +24 -0
  25. data/lib/fog/metric/openstack/requests/get_metric.rb +62 -0
  26. data/lib/fog/metric/openstack/requests/get_metric_measures.rb +38 -0
  27. data/lib/fog/metric/openstack/requests/get_resource.rb +37 -0
  28. data/lib/fog/metric/openstack/requests/get_resource_metric_measures.rb +46 -0
  29. data/lib/fog/metric/openstack/requests/list_metrics.rb +104 -0
  30. data/lib/fog/metric/openstack/requests/list_resources.rb +70 -0
  31. data/lib/fog/network/openstack.rb +12 -9
  32. data/lib/fog/network/openstack/models/rbac_policy.rb +0 -1
  33. data/lib/fog/network/openstack/requests/create_floating_ip.rb +1 -1
  34. data/lib/fog/network/openstack/requests/create_network.rb +3 -3
  35. data/lib/fog/openstack.rb +25 -15
  36. data/lib/fog/openstack/version.rb +1 -1
  37. data/lib/fog/orchestration/openstack/models/stack.rb +5 -1
  38. data/lib/fog/shared_file_system/openstack.rb +278 -0
  39. data/lib/fog/shared_file_system/openstack/models/network.rb +42 -0
  40. data/lib/fog/shared_file_system/openstack/models/networks.rb +28 -0
  41. data/lib/fog/shared_file_system/openstack/models/share.rb +63 -0
  42. data/lib/fog/shared_file_system/openstack/models/shares.rb +28 -0
  43. data/lib/fog/shared_file_system/openstack/models/snapshot.rb +45 -0
  44. data/lib/fog/shared_file_system/openstack/models/snapshots.rb +28 -0
  45. data/lib/fog/shared_file_system/openstack/requests/create_share.rb +49 -0
  46. data/lib/fog/shared_file_system/openstack/requests/create_share_network.rb +41 -0
  47. data/lib/fog/shared_file_system/openstack/requests/create_snapshot.rb +46 -0
  48. data/lib/fog/shared_file_system/openstack/requests/delete_share.rb +29 -0
  49. data/lib/fog/shared_file_system/openstack/requests/delete_share_network.rb +28 -0
  50. data/lib/fog/shared_file_system/openstack/requests/delete_snapshot.rb +30 -0
  51. data/lib/fog/shared_file_system/openstack/requests/get_share.rb +26 -0
  52. data/lib/fog/shared_file_system/openstack/requests/get_share_network.rb +26 -0
  53. data/lib/fog/shared_file_system/openstack/requests/get_snapshot.rb +26 -0
  54. data/lib/fog/shared_file_system/openstack/requests/list_share_networks.rb +25 -0
  55. data/lib/fog/shared_file_system/openstack/requests/list_share_networks_detail.rb +25 -0
  56. data/lib/fog/shared_file_system/openstack/requests/list_shares.rb +25 -0
  57. data/lib/fog/shared_file_system/openstack/requests/list_shares_detail.rb +25 -0
  58. data/lib/fog/shared_file_system/openstack/requests/list_snapshots.rb +25 -0
  59. data/lib/fog/shared_file_system/openstack/requests/list_snapshots_detail.rb +25 -0
  60. data/lib/fog/shared_file_system/openstack/requests/update_share.rb +39 -0
  61. data/lib/fog/shared_file_system/openstack/requests/update_share_network.rb +31 -0
  62. data/lib/fog/shared_file_system/openstack/requests/update_snapshot.rb +31 -0
  63. metadata +43 -2
data/docs/storage.md CHANGED
@@ -32,10 +32,13 @@ Next, create a connection to Swift:
32
32
  service = Fog::Storage::OpenStack.new({
33
33
  :openstack_username => USERNAME, # Your OpenStack Username
34
34
  :openstack_api_key => PASSWORD, # Your OpenStack Password
35
- :openstack_auth_url => 'http://YOUR_OPENSTACK_ENDPOINT:PORT/v2.0/tokens'
35
+ :openstack_auth_url => 'http://YOUR_OPENSTACK_ENDPOINT:PORT/v2.0/tokens',
36
+ :connection_options => {}
36
37
  })
37
38
  ```
38
39
 
40
+ Read more about the [Optional Connection Parameters](common/connection_params.md)
41
+
39
42
  Alternative regions are specified using the key `:openstack_region `. A list of regions available for Swift can be found by executing the following:
40
43
 
41
44
  ### Optional Service Parameters
@@ -73,46 +76,6 @@ The Storage service supports the following additional parameters:
73
76
  </tr>
74
77
  </table>
75
78
 
76
-
77
- ### Optional Connection Parameters
78
-
79
- Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
80
-
81
- <table>
82
- <tr>
83
- <th>Key</th>
84
- <th>Description</th>
85
- </tr>
86
- <tr>
87
- <td>:connect_timeout</td>
88
- <td>Connection timeout (default: 60 seconds)</td>
89
- </tr>
90
- <tr>
91
-
92
- </tr>
93
- <tr>
94
- <td>:write_timeout</td>
95
- <td>Write timeout for connection (default: 60 seconds)</td>
96
- </tr>
97
- <tr>
98
- <td>:proxy</td>
99
- <td>Proxy for HTTP and HTTPS connections</td>
100
- </tr>
101
- <tr>
102
- <td>:ssl_ca_path</td>
103
- <td>Path to SSL certificate authorities</td>
104
- </tr>
105
- <tr>
106
- <td>:ssl_ca_file</td>
107
- <td>SSL certificate authority file</td>
108
- </tr>
109
- <tr>
110
- <td>:ssl_verify_peer</td>
111
- <td>SSL verify peer (default: true)</td>
112
-
113
- </table>
114
-
115
-
116
79
  ## Fog Abstractions
117
80
 
118
81
  Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface.
@@ -439,14 +402,5 @@ file.destroy
439
402
 
440
403
  ## Additional Resources
441
404
 
442
- * [fog.io](http://fog.io/)
443
- * [Fog rdoc](http://rubydoc.info/gems/fog/)
444
- * [Fog Github repo](https://github.com/fog/fog)
445
- * [Fog Github Issues](https://github.com/fog/fog/issues)
446
- * [Excon Github repo](https://github.com/geemus/excon)
447
405
  * [Swift API](http://docs.openstack.org/api/openstack-object-storage/1.0/content/index.html)
448
-
449
- ## Support and Feedback
450
-
451
- Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues).
452
-
406
+ * [more resources and feedback](common/resources.md)
data/docs/workflow.md CHANGED
@@ -18,6 +18,8 @@ service = Fog::Workflow::OpenStack.new({
18
18
  })
19
19
  ```
20
20
 
21
+ Read more about the [Optional Connection Parameters](common/connection_params.md)
22
+
21
23
  ## Executions
22
24
 
23
25
  A Workflow is a composition of one or more actions.
@@ -120,10 +122,10 @@ In addition to workflows, the following Mistral resources are also supported:
120
122
  For examples on how to interact with these resources, please refer to
121
123
  https://github.com/fog/fog-openstack/tree/master/examples/workflow/workflow-examples.rb
122
124
 
123
- ## Information about Mistral
125
+ ## Additional Resources
124
126
 
125
127
  * [Mistral Wiki](https://wiki.openstack.org/wiki/Mistral)
126
128
  * [Mistral DSL v2](http://docs.openstack.org/developer/mistral/dsl/dsl_v2.html)
127
129
  * [Mistral API v2](http://docs.openstack.org/developer/mistral/developer/webapi/v2.html)
128
130
  * [Mistral python client](https://github.com/openstack/python-mistralclient) Can be useful to see how to interact with the API.
129
-
131
+ * [more resources and feedback](common/resources.md)
@@ -0,0 +1,42 @@
1
+ require 'fog/openstack'
2
+ require 'time'
3
+
4
+ auth_url = "http://10.0.0.13:5000/v3/auth/tokens"
5
+ username = 'admin'
6
+ password = 'njXDF8bKr68RQsfbANvURzkmT'
7
+ project = 'admin'
8
+
9
+ @connection_params = {
10
+ :openstack_auth_url => auth_url,
11
+ :openstack_username => username,
12
+ :openstack_api_key => password,
13
+ :openstack_project_name => project,
14
+ :openstack_domain_id => "default"
15
+ }
16
+
17
+ puts "### SERVICE CONNECTION ###"
18
+
19
+ metric = Fog::Metric::OpenStack.new(@connection_params)
20
+
21
+ p metric
22
+
23
+ puts "### RESOURCES ###"
24
+
25
+ p metric.list_resources
26
+
27
+ p metric.resources.all(details: true)
28
+
29
+ p metric.resources.find_by_id("3c6c53c9-25c1-4aca-984d-a20c1926b499")
30
+
31
+ p metric.get_resource_metric_measures("d1f84147-d4ef-465e-a679-265df36918ed", "disk.ephemeral.size", start: 0, stop: Time.now.iso8601, granularity: 300).body
32
+
33
+
34
+ puts "### METRICS ###"
35
+
36
+ p metric.metrics.all
37
+
38
+ p metric.metrics.find_by_id("7feff2ca-2edd-4ea5-96d7-2cc5262bb504")
39
+
40
+ p metric.get_metric_measures("d8e5e557-e3cc-41bd-9d87-dac3eedd0df7", start: 0, stop: Time.now.iso8601, granularity: 300).body
41
+
42
+ puts "### END ###"
@@ -0,0 +1,68 @@
1
+ require 'fog/openstack'
2
+ require 'pp'
3
+
4
+ #
5
+ # Creates a share network and a share
6
+ #
7
+ # Needs to be in an environment where keystone v3 is available
8
+ #
9
+ # You will need to source OpenStack credentials since the script
10
+ # reads the following envionment variables:
11
+ #
12
+ # OS_AUTH_URL
13
+ # OS_PASSWORD
14
+ # OS_USERNAME
15
+ # OS_USER_DOMAIN_NAME
16
+ # OS_PROJECT_NAME
17
+ # OS_REGION_NAME
18
+ #
19
+ # optionally disable SSL verification
20
+ # SSL_VERIFY=false
21
+
22
+ auth_options = {
23
+ :openstack_auth_url => "#{ENV['OS_AUTH_URL']}/auth/tokens",
24
+ :openstack_api_key => ENV['OS_PASSWORD'],
25
+ :openstack_username => ENV['OS_USERNAME'],
26
+ :openstack_domain_name => ENV['OS_USER_DOMAIN_NAME'],
27
+ :openstack_project_name => ENV['OS_PROJECT_NAME'],
28
+ :openstack_region => ENV['OS_REGION_NAME'],
29
+ :connection_options => {:ssl_verify_peer => ENV['SSL_VERIFY'] != 'false'}
30
+ }
31
+
32
+ network_service = Fog::Network::OpenStack.new(auth_options)
33
+ share_service = Fog::SharedFileSystem::OpenStack.new(auth_options)
34
+
35
+ net = network_service.networks.first
36
+ raise 'no network exists' if net.nil?
37
+
38
+ puts "Create share network in #{net.name}"
39
+ share_network = share_service.networks.create(
40
+ :neutron_net_id => net.id,
41
+ :neutron_subnet_id => net.subnets.first.id,
42
+ :name => 'fog_share_net'
43
+ )
44
+
45
+ pp share_network
46
+
47
+ puts 'Create share'
48
+ example_share = share_service.shares.create(
49
+ :share_proto => 'NFS',
50
+ :size => 1,
51
+ :name => 'fog_share',
52
+ :share_network_id => share_network.id
53
+ )
54
+
55
+ pp example_share
56
+
57
+ puts 'Create snapshot'
58
+ example_snap = share_service.snapshots.create(
59
+ :share_id => example_share.id,
60
+ :name => 'fog_share_snapshot'
61
+ )
62
+
63
+ pp example_snap
64
+
65
+ puts 'Removing snapshot, share and share network'
66
+ example_snap.destroy
67
+ example_share.destroy
68
+ share_network.destroy
data/gemfiles/Gemfile-1.9 CHANGED
@@ -17,4 +17,5 @@ group :development, :test do
17
17
  gem "json", "< 2.0"
18
18
  # TODO: remove when https://github.com/fog/fog-openstack/issues/202 is fixed
19
19
  # gem "coveralls", "< 0.8.15"
20
+ gem "public_suffix", "~> 1.4.6"
20
21
  end
@@ -7,7 +7,7 @@ module Fog
7
7
  user_id = options.delete('user_id') || options.delete(:user_id)
8
8
 
9
9
  path = if user_id
10
- "users/#{user_id}groups"
10
+ "users/#{user_id}/groups"
11
11
  else
12
12
  "groups"
13
13
  end
@@ -14,6 +14,7 @@ module Fog
14
14
 
15
15
  attribute :self
16
16
  attribute :size
17
+ attribute :virtual_size
17
18
  attribute :disk_format
18
19
  attribute :container_format
19
20
  attribute :id
@@ -45,6 +46,8 @@ module Fog
45
46
  attributes[method_sym]
46
47
  elsif attributes.key?(method_sym.to_s)
47
48
  attributes[method_sym.to_s]
49
+ elsif method_sym.to_s.end_with?('=')
50
+ attributes[method_sym.to_s.gsub(/=$/, '')] = arguments[0]
48
51
  else
49
52
  super
50
53
  end
@@ -55,6 +58,8 @@ module Fog
55
58
  true
56
59
  elsif attributes.key?(method_sym.to_s)
57
60
  true
61
+ elsif method_sym.to_s.end_with?('=')
62
+ true
58
63
  else
59
64
  super
60
65
  end
@@ -66,28 +71,32 @@ module Fog
66
71
  self
67
72
  end
68
73
 
69
- # This overrides the behaviour of Fog::OpenStack::Model::save() which tries to be clever and
70
- # assumes save=update if an ID is present - but Image V2 allows ID to specified on creation
71
- def identity
72
- nil
73
- end
74
-
75
- # Hash of attributes to update is passed in. Setting value to nil will delete that attribute.
76
- # Here we convert that hash into a form suitable for Glance's usage of JSON Patch (RFC6902)
77
- def update(attr = {})
74
+ # Here we convert 'attributes' into a form suitable for Glance's usage of JSON Patch (RFC6902).
75
+ # We fetch the existing attributes from the server to compute the delta (difference)
76
+ # Setting value to nil will delete that attribute from the server.
77
+ def update(attr = nil)
78
78
  requires :id
79
- json_patch = []
80
- attr.each do |key, value|
81
- op = (@attributes.keys.include? key) ? 'replace' : 'add'
82
- op = 'remove' if value.nil?
83
- json_patch << {:op => op, :path => "/#{key}", :value => value}
84
- end
79
+ client_attributes = attr || @attributes
80
+ server_attributes = service.images.get(id).attributes
81
+
82
+ json_patch = build_update_json_patch(client_attributes, server_attributes)
83
+
85
84
  merge_attributes(
86
85
  service.update_image(id, json_patch).body
87
86
  )
88
87
  self
89
88
  end
90
89
 
90
+ # This overrides the behaviour of Fog::OpenStack::Model::save() which tries to be clever and
91
+ # assumes save=update if an ID is present - but Image V2 allows ID to be specified on creation
92
+ def save
93
+ if @attributes[:self].nil?
94
+ create
95
+ else
96
+ update
97
+ end
98
+ end
99
+
91
100
  def destroy
92
101
  requires :id
93
102
  service.delete_image(id)
@@ -162,6 +171,42 @@ module Fog
162
171
  requires :id
163
172
  service.remove_tag_from_image(id, tag)
164
173
  end
174
+
175
+ private
176
+
177
+ def build_update_json_patch(client_attributes, server_attributes)
178
+ [
179
+ build_patch_operation('remove', patch_attributes_to_remove(client_attributes, server_attributes)),
180
+ build_patch_operation('add', patch_attributes_to_add(client_attributes, server_attributes)),
181
+ build_patch_operation('replace', patch_attributes_to_replace(client_attributes, server_attributes)),
182
+ ].flatten
183
+ end
184
+
185
+ def patch_attributes_to_remove(client_attributes, server_attributes)
186
+ client_attributes.select do |key, value|
187
+ value.nil? && !server_attributes[key].nil?
188
+ end
189
+ end
190
+
191
+ def patch_attributes_to_add(client_attributes, server_attributes)
192
+ client_attributes.reject do |key, _|
193
+ server_attributes.key?(key)
194
+ end
195
+ end
196
+
197
+ def patch_attributes_to_replace(client_attributes, server_attributes)
198
+ client_attributes.reject do |key, value|
199
+ value.nil? || server_attributes[key] == value
200
+ end
201
+ end
202
+
203
+ def build_patch_operation(op_name, attributes)
204
+ json_patch = []
205
+ attributes.each do |key, value|
206
+ json_patch << {:op => op_name, :path => "/#{key}", :value => value}
207
+ end
208
+ json_patch
209
+ end
165
210
  end
166
211
  end
167
212
  end
@@ -17,10 +17,7 @@ module Fog
17
17
  end
18
18
 
19
19
  def find_by_id(id)
20
- image_hash = service.get_image_by_id(id).body
21
- Fog::Image::OpenStack::V2::Image.new(
22
- image_hash.merge(:service => service)
23
- )
20
+ new(service.get_image_by_id(id).body)
24
21
  end
25
22
 
26
23
  alias get find_by_id
@@ -0,0 +1,126 @@
1
+ module Fog
2
+ module Metric
3
+ class OpenStack < Fog::Service
4
+ SUPPORTED_VERSIONS = /v1/
5
+
6
+ requires :openstack_auth_url
7
+ recognizes :openstack_auth_token, :openstack_management_url,
8
+ :persistent, :openstack_service_type, :openstack_service_name,
9
+ :openstack_tenant, :openstack_tenant_id,
10
+ :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
11
+ :current_user, :current_tenant, :openstack_region,
12
+ :openstack_endpoint_type, :openstack_cache_ttl,
13
+ :openstack_project_name, :openstack_project_id,
14
+ :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
15
+ :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
16
+ :openstack_identity_prefix
17
+
18
+ model_path 'fog/metric/openstack/models'
19
+
20
+ model :metric
21
+ collection :metrics
22
+ model :resource
23
+ collection :resources
24
+
25
+ request_path 'fog/metric/openstack/requests'
26
+
27
+ request :get_resource_metric_measures
28
+ request :get_metric_measures
29
+ request :get_metric
30
+ request :list_metrics
31
+ request :get_resource
32
+ request :list_resources
33
+
34
+ class Mock
35
+ def self.data
36
+ @data ||= Hash.new do |hash, key|
37
+ hash[key] = {
38
+ :users => {},
39
+ :tenants => {}
40
+ }
41
+ end
42
+ end
43
+
44
+ def self.reset
45
+ @data = nil
46
+ end
47
+
48
+ def initialize(options = {})
49
+ @openstack_username = options[:openstack_username]
50
+ @openstack_tenant = options[:openstack_tenant]
51
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
52
+
53
+ @auth_token = Fog::Mock.random_base64(64)
54
+ @auth_token_expiration = (Time.now.utc + 86400).iso8601
55
+
56
+ management_url = URI.parse(options[:openstack_auth_url])
57
+ management_url.port = 8041
58
+ management_url.path = '/v1'
59
+ @openstack_management_url = management_url.to_s
60
+
61
+ @data ||= {:users => {}}
62
+ unless @data[:users].find { |u| u['name'] == options[:openstack_username] }
63
+ id = Fog::Mock.random_numbers(6).to_s
64
+ @data[:users][id] = {
65
+ 'id' => id,
66
+ 'name' => options[:openstack_username],
67
+ 'email' => "#{options[:openstack_username]}@mock.com",
68
+ 'tenantId' => Fog::Mock.random_numbers(6).to_s,
69
+ 'enabled' => true
70
+ }
71
+ end
72
+ end
73
+
74
+ def data
75
+ self.class.data[@openstack_username]
76
+ end
77
+
78
+ def reset_data
79
+ self.class.data.delete(@openstack_username)
80
+ end
81
+
82
+ def credentials
83
+ {:provider => 'openstack',
84
+ :openstack_auth_url => @openstack_auth_uri.to_s,
85
+ :openstack_auth_token => @auth_token,
86
+ :openstack_management_url => @openstack_management_url}
87
+ end
88
+ end
89
+
90
+ class Real
91
+ include Fog::OpenStack::Core
92
+
93
+ def self.not_found_class
94
+ Fog::Metric::OpenStack::NotFound
95
+ end
96
+
97
+ def initialize(options = {})
98
+ initialize_identity options
99
+
100
+ @openstack_service_type = options[:openstack_service_type] || ['metric']
101
+ @openstack_service_name = options[:openstack_service_name]
102
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
103
+
104
+ @connection_options = options[:connection_options] || {}
105
+
106
+ authenticate
107
+ set_api_path
108
+
109
+ @persistent = options[:persistent] || false
110
+ @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
111
+ end
112
+
113
+ def set_api_path
114
+ unless @path.match(SUPPORTED_VERSIONS)
115
+ @path = Fog::OpenStack.get_supported_version_path(
116
+ SUPPORTED_VERSIONS,
117
+ @openstack_management_uri,
118
+ @auth_token,
119
+ @connection_options
120
+ )
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end