fog-openstack 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.hound.yml +2 -0
  4. data/.rubocop.yml +93 -0
  5. data/.travis.yml +13 -10
  6. data/{lib/fog/openstack/CHANGELOG.md → CHANGELOG.md} +0 -0
  7. data/CODE_OF_CONDUCT.md +1 -1
  8. data/Gemfile +2 -0
  9. data/README.md +497 -3
  10. data/Rakefile +5 -1
  11. data/fog-openstack.gemspec +8 -7
  12. data/gemfiles/Gemfile-1.9 +16 -0
  13. data/lib/fog/openstack.rb +55 -30
  14. data/lib/fog/openstack/docs/metering.md +29 -0
  15. data/lib/fog/openstack/metering.rb +6 -1
  16. data/lib/fog/openstack/models/metering/event.rb +16 -0
  17. data/lib/fog/openstack/models/metering/events.rb +23 -0
  18. data/lib/fog/openstack/models/network/floating_ip.rb +1 -24
  19. data/lib/fog/openstack/models/network/ike_policies.rb +32 -0
  20. data/lib/fog/openstack/models/network/ike_policy.rb +43 -0
  21. data/lib/fog/openstack/models/network/ipsec_policies.rb +32 -0
  22. data/lib/fog/openstack/models/network/ipsec_policy.rb +45 -0
  23. data/lib/fog/openstack/models/network/ipsec_site_connection.rb +51 -0
  24. data/lib/fog/openstack/models/network/ipsec_site_connections.rb +33 -0
  25. data/lib/fog/openstack/models/network/vpn_service.rb +42 -0
  26. data/lib/fog/openstack/models/network/vpn_services.rb +32 -0
  27. data/lib/fog/openstack/network.rb +52 -13
  28. data/lib/fog/openstack/requests/compute/create_volume.rb +28 -21
  29. data/lib/fog/openstack/requests/metering/get_event.rb +27 -0
  30. data/lib/fog/openstack/requests/metering/list_events.rb +42 -0
  31. data/lib/fog/openstack/requests/network/associate_floating_ip.rb +15 -10
  32. data/lib/fog/openstack/requests/network/create_floating_ip.rb +1 -1
  33. data/lib/fog/openstack/requests/network/create_ike_policy.rb +53 -0
  34. data/lib/fog/openstack/requests/network/create_ipsec_policy.rb +53 -0
  35. data/lib/fog/openstack/requests/network/create_ipsec_site_connection.rb +66 -0
  36. data/lib/fog/openstack/requests/network/create_vpn_service.rb +51 -0
  37. data/lib/fog/openstack/requests/network/delete_ike_policy.rb +28 -0
  38. data/lib/fog/openstack/requests/network/delete_ipsec_policy.rb +28 -0
  39. data/lib/fog/openstack/requests/network/delete_ipsec_site_connection.rb +29 -0
  40. data/lib/fog/openstack/requests/network/delete_vpn_service.rb +28 -0
  41. data/lib/fog/openstack/requests/network/disassociate_floating_ip.rb +15 -10
  42. data/lib/fog/openstack/requests/network/get_floating_ip.rb +12 -2
  43. data/lib/fog/openstack/requests/network/get_ike_policy.rb +28 -0
  44. data/lib/fog/openstack/requests/network/get_ipsec_policy.rb +28 -0
  45. data/lib/fog/openstack/requests/network/get_ipsec_site_connection.rb +28 -0
  46. data/lib/fog/openstack/requests/network/get_network.rb +1 -13
  47. data/lib/fog/openstack/requests/network/get_vpn_service.rb +28 -0
  48. data/lib/fog/openstack/requests/network/list_ike_policies.rb +25 -0
  49. data/lib/fog/openstack/requests/network/list_ipsec_policies.rb +25 -0
  50. data/lib/fog/openstack/requests/network/list_ipsec_site_connections.rb +25 -0
  51. data/lib/fog/openstack/requests/network/list_vpn_services.rb +25 -0
  52. data/lib/fog/openstack/requests/network/update_ike_policy.rb +49 -0
  53. data/lib/fog/openstack/requests/network/update_ipsec_policy.rb +52 -0
  54. data/lib/fog/openstack/requests/network/update_ipsec_site_connection.rb +64 -0
  55. data/lib/fog/openstack/requests/network/update_vpn_service.rb +46 -0
  56. data/lib/fog/openstack/storage.rb +2 -2
  57. data/lib/fog/openstack/version.rb +1 -1
  58. data/tests/helper.rb +3 -0
  59. data/tests/openstack/models/network/ike_policies_tests.rb +28 -0
  60. data/tests/openstack/models/network/ike_policy_tests.rb +36 -0
  61. data/tests/openstack/models/network/ipsec_policies_tests.rb +26 -0
  62. data/tests/openstack/models/network/ipsec_policy_tests.rb +36 -0
  63. data/tests/openstack/models/network/ipsec_site_connection_tests.rb +50 -0
  64. data/tests/openstack/models/network/ipsec_site_connections_tests.rb +32 -0
  65. data/tests/openstack/models/network/vpn_service_tests.rb +27 -0
  66. data/tests/openstack/models/network/vpn_services_tests.rb +22 -0
  67. data/tests/openstack/requests/metering/event_tests.rb +17 -0
  68. data/tests/openstack/requests/network/ike_policy_tests.rb +65 -0
  69. data/tests/openstack/requests/network/ipsec_policy_tests.rb +65 -0
  70. data/tests/openstack/requests/network/ipsec_site_connection_tests.rb +82 -0
  71. data/tests/openstack/requests/network/vpn_service_tests.rb +61 -0
  72. metadata +109 -47
  73. data/CONTRIBUTORS.md +0 -79
data/Rakefile CHANGED
@@ -1,7 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
2
5
 
3
6
  task :default => :test
4
7
 
8
+ desc 'Run fog-openstack unit tests'
5
9
  mock = ENV['FOG_MOCK'] || 'true'
6
10
  task :test do
7
11
  sh("export FOG_MOCK=#{mock} && bundle exec shindont")
@@ -19,15 +19,16 @@ 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_development_dependency 'bundler', '~> 1.6'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'shindo', '~> 0.3'
25
- spec.add_development_dependency 'rubyzip', '~> 0.9.9'
26
- spec.add_development_dependency "mime-types"
27
- spec.add_development_dependency "mime-types-data"
28
-
29
22
  spec.add_dependency 'fog-core', '>= 1.35'
30
23
  spec.add_dependency 'fog-json', '>= 1.0'
31
24
  spec.add_dependency 'fog-xml', '>= 0.1'
32
25
  spec.add_dependency 'ipaddress', '>= 0.8'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.6'
28
+ spec.add_development_dependency "mime-types"
29
+ spec.add_development_dependency "mime-types-data"
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'rubyzip', '~> 0.9.9'
33
+ spec.add_development_dependency 'shindo', '~> 0.3'
33
34
  end
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "coveralls", require: false
4
+
5
+ group :development, :test do
6
+ gem "fog-core", ">= 1.35"
7
+ gem "fog-json", ">= 1.0"
8
+ gem "fog-xml", ">= 0.1"
9
+ gem "ipaddress", ">= 0.8"
10
+ gem "bundler", "~> 1.6"
11
+ gem "mime-types", "2.6.2"
12
+ gem "rake", "~> 10.0"
13
+ gem "rubocop"
14
+ gem "rubyzip", "~> 0.9.9"
15
+ gem "shindo", "~> 0.3"
16
+ end
data/lib/fog/openstack.rb CHANGED
@@ -6,6 +6,22 @@ require 'fog/openstack/core'
6
6
  require 'fog/openstack/common'
7
7
  require 'fog/openstack/errors'
8
8
 
9
+ require 'fog/openstack/compute'
10
+ require 'fog/openstack/identity_v2'
11
+ require 'fog/openstack/identity_v3'
12
+ require 'fog/openstack/image'
13
+ require 'fog/openstack/image_v1'
14
+ require 'fog/openstack/image_v2'
15
+ require 'fog/openstack/metering'
16
+ require 'fog/openstack/network'
17
+ require 'fog/openstack/orchestration'
18
+ require 'fog/openstack/storage'
19
+ require 'fog/openstack/volume'
20
+ require 'fog/openstack/volume_v1'
21
+ require 'fog/openstack/volume_v2'
22
+ require 'fog/openstack/baremetal'
23
+ require 'fog/openstack/planning'
24
+
9
25
  module Fog
10
26
  module OpenStack
11
27
  extend Fog::Provider
@@ -284,11 +300,12 @@ module Fog
284
300
  end
285
301
 
286
302
  def self.retrieve_tokens_v2(options, connection_options = {})
287
- api_key = options[:openstack_api_key].to_s
288
- username = options[:openstack_username].to_s
289
- tenant_name = options[:openstack_tenant].to_s
290
- auth_token = options[:openstack_auth_token] || options[:unscoped_token]
291
- uri = options[:openstack_auth_uri]
303
+ api_key = options[:openstack_api_key].to_s
304
+ username = options[:openstack_username].to_s
305
+ tenant_name = options[:openstack_tenant].to_s
306
+ auth_token = options[:openstack_auth_token] || options[:unscoped_token]
307
+ uri = options[:openstack_auth_uri]
308
+ omit_default_port = options[:openstack_auth_omit_default_port]
292
309
 
293
310
  identity_v2_connection = Fog::Core::Connection.new(uri.to_s, false, connection_options)
294
311
  request_body = {:auth => Hash.new}
@@ -305,32 +322,36 @@ module Fog
305
322
  end
306
323
  request_body[:auth][:tenantName] = tenant_name if tenant_name
307
324
 
308
- response = identity_v2_connection.request({
309
- :expects => [200, 204],
310
- :headers => {'Content-Type' => 'application/json'},
311
- :body => Fog::JSON.encode(request_body),
312
- :method => 'POST',
313
- :path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0'
314
- })
325
+ request = {
326
+ :expects => [200, 204],
327
+ :headers => {'Content-Type' => 'application/json'},
328
+ :body => Fog::JSON.encode(request_body),
329
+ :method => 'POST',
330
+ :path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0'
331
+ }
332
+ request[:omit_default_port] = omit_default_port unless omit_default_port.nil?
333
+
334
+ response = identity_v2_connection.request(request)
315
335
 
316
336
  Fog::JSON.decode(response.body)
317
337
  end
318
338
 
319
339
  def self.retrieve_tokens_v3(options, connection_options = {})
320
340
 
321
- api_key = options[:openstack_api_key].to_s
322
- username = options[:openstack_username].to_s
323
- userid = options[:openstack_userid]
324
- domain_id = options[:openstack_domain_id]
325
- domain_name = options[:openstack_domain_name]
326
- project_domain = options[:openstack_project_domain]
341
+ api_key = options[:openstack_api_key].to_s
342
+ username = options[:openstack_username].to_s
343
+ userid = options[:openstack_userid]
344
+ domain_id = options[:openstack_domain_id]
345
+ domain_name = options[:openstack_domain_name]
346
+ project_domain = options[:openstack_project_domain]
327
347
  project_domain_id = options[:openstack_project_domain_id]
328
- user_domain = options[:openstack_user_domain]
329
- user_domain_id = options[:openstack_user_domain_id]
330
- project_name = options[:openstack_project_name]
331
- project_id = options[:openstack_project_id]
332
- auth_token = options[:openstack_auth_token] || options[:unscoped_token]
333
- uri = options[:openstack_auth_uri]
348
+ user_domain = options[:openstack_user_domain]
349
+ user_domain_id = options[:openstack_user_domain_id]
350
+ project_name = options[:openstack_project_name]
351
+ project_id = options[:openstack_project_id]
352
+ auth_token = options[:openstack_auth_token] || options[:unscoped_token]
353
+ uri = options[:openstack_auth_uri]
354
+ omit_default_port = options[:openstack_auth_omit_default_port]
334
355
 
335
356
  connection = Fog::Core::Connection.new(uri.to_s, false, connection_options)
336
357
  request_body = {:auth => {}}
@@ -389,12 +410,16 @@ module Fog
389
410
  response, expires = @@token_cache[{body: request_body, path: path}]
390
411
 
391
412
  unless response && expires > Time.now
392
- response = connection.request({ :expects => [201],
393
- :headers => {'Content-Type' => 'application/json'},
394
- :body => Fog::JSON.encode(request_body),
395
- :method => 'POST',
396
- :path => path
397
- })
413
+ request = {
414
+ :expects => [201],
415
+ :headers => {'Content-Type' => 'application/json'},
416
+ :body => Fog::JSON.encode(request_body),
417
+ :method => 'POST',
418
+ :path => path
419
+ }
420
+ request[:omit_default_port] = omit_default_port unless omit_default_port.nil?
421
+
422
+ response = connection.request(request)
398
423
  @@token_cache[{body: request_body, path: path}] = response, Time.now + 30 # 30-second TTL, enough for most requests
399
424
  end
400
425
 
@@ -0,0 +1,29 @@
1
+ # OpenStack Metering (Ceilometer)
2
+
3
+ This document explains how to get started using OpenStack Metering (Ceilometer) with Fog. It assumes you have read the [Getting Started with Fog and the OpenStack](getting_started.md) document.
4
+
5
+ Fog uses the [OpenStack Metering API](http://docs.openstack.org/developer/ceilometer/webapi/v2.html).
6
+
7
+ ## Metering Service
8
+
9
+ Get a handle on the Metering service:
10
+
11
+ ```ruby
12
+ service = Fog::Metering::OpenStack.new({
13
+ :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint
14
+ :openstack_username => OPEN_STACK_USER, # Your OpenStack Username
15
+ :openstack_tenant => OPEN_STACK_TENANT, # Your tenant id
16
+ :openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password
17
+ :connection_options => {} # Optional
18
+ })
19
+ ```
20
+
21
+ ## Events
22
+
23
+ * `service.events`: Return a list of events.
24
+ * `service.events.find_by_id(<message_id>)`: Return the event matching message_id, or nil if no such event exists.
25
+
26
+ ## Resources
27
+
28
+ * `service.resources`: Return a list of resources.
29
+ * `service.resources.find_by_id(<resource_id>)`: Return the resource matching resource_id, or nil if no such resource exists.
@@ -20,12 +20,17 @@ module Fog
20
20
  model :resource
21
21
  collection :resources
22
22
 
23
+ model :event
24
+ collection :events
25
+
23
26
  request_path 'fog/openstack/requests/metering'
24
27
 
25
28
  # Metering
29
+ request :get_event
26
30
  request :get_resource
27
31
  request :get_samples
28
32
  request :get_statistics
33
+ request :list_events
29
34
  request :list_meters
30
35
  request :list_resources
31
36
 
@@ -126,7 +131,7 @@ module Fog
126
131
  rescue Excon::Errors::HTTPStatusError => error
127
132
  raise case error
128
133
  when Excon::Errors::NotFound
129
- Fog::Compute::OpenStack::NotFound.slurp(error)
134
+ Fog::Metering::OpenStack::NotFound.slurp(error)
130
135
  else
131
136
  error
132
137
  end
@@ -0,0 +1,16 @@
1
+ require 'fog/openstack/models/model'
2
+
3
+ module Fog
4
+ module Metering
5
+ class OpenStack
6
+ class Event < Fog::OpenStack::Model
7
+ identity :message_id
8
+
9
+ attribute :event_type
10
+ attribute :generated
11
+ attribute :raw
12
+ attribute :traits
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require 'fog/openstack/models/collection'
2
+ require 'fog/openstack/models/metering/event'
3
+
4
+ module Fog
5
+ module Metering
6
+ class OpenStack
7
+ class Events < Fog::OpenStack::Collection
8
+ model Fog::Metering::OpenStack::Event
9
+
10
+ def all(detailed=true)
11
+ load_response(service.list_events)
12
+ end
13
+
14
+ def find_by_id(message_id)
15
+ event = service.get_event(message_id).body
16
+ new(event)
17
+ rescue Fog::Metering::OpenStack::NotFound
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -21,7 +21,7 @@ module Fog
21
21
  requires :floating_network_id
22
22
  merge_attributes(service.create_floating_ip(self.floating_network_id,
23
23
 
24
- self.attributes).body['floatingip'])
24
+ self.attributes).body['floatingip'])
25
25
  self
26
26
  end
27
27
 
@@ -34,29 +34,6 @@ module Fog
34
34
  service.delete_floating_ip(self.id)
35
35
  true
36
36
  end
37
-
38
- def associate(port_id, fixed_ip_address = nil)
39
- requires :id
40
- options = if !fixed_ip_address.nil?
41
- { 'fixed_ip_address': fixed_ip_address }
42
- else
43
- {}
44
- end
45
- merge_attributes(service.associate_floating_ip(self.id,
46
- port_id,
47
- options).body['floatingip'])
48
- end
49
-
50
- def disassociate(fixed_ip_address = nil)
51
- requires :id
52
- options = if !fixed_ip_address.nil?
53
- { 'fixed_ip_address': fixed_ip_address }
54
- else
55
- {}
56
- end
57
- merge_attributes(service.disassociate_floating_ip(self.id,
58
- options).body['floatingip'])
59
- end
60
37
  end
61
38
  end
62
39
  end
@@ -0,0 +1,32 @@
1
+ require 'fog/openstack/models/collection'
2
+ require 'fog/openstack/models/network/ike_policy'
3
+
4
+ module Fog
5
+ module Network
6
+ class OpenStack
7
+ class IkePolicies < Fog::OpenStack::Collection
8
+ attribute :filters
9
+
10
+ model Fog::Network::OpenStack::IkePolicy
11
+
12
+ def initialize(attributes)
13
+ self.filters ||= {}
14
+ super
15
+ end
16
+
17
+ def all(filters_arg = filters)
18
+ filters = filters_arg
19
+ load_response(service.list_ike_policies(filters), 'ikepolicies')
20
+ end
21
+
22
+ def get(ike_policy_id)
23
+ if ike_policy = service.get_ike_policy(ike_policy_id).body['ikepolicy']
24
+ new(ike_policy)
25
+ end
26
+ rescue Fog::Network::OpenStack::NotFound
27
+ nil
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require 'fog/openstack/models/model'
2
+
3
+ module Fog
4
+ module Network
5
+ class OpenStack
6
+ class IkePolicy < Fog::OpenStack::Model
7
+ identity :id
8
+
9
+ attribute :name
10
+ attribute :description
11
+ attribute :status
12
+ attribute :admin_state_up
13
+ attribute :tenant_id
14
+ attribute :auth_algorithm
15
+ attribute :encryption_algorithm
16
+ attribute :pfs
17
+ attribute :phase1_negotiation_mode
18
+ attribute :lifetime
19
+ attribute :ike_version
20
+
21
+ def create
22
+ requires :name, :auth_algorithm, :encryption_algorithm, :ike_version,
23
+ :lifetime, :pfs, :phase1_negotiation_mode
24
+ merge_attributes(service.create_ike_policy(attributes).body['ikepolicy'])
25
+ self
26
+ end
27
+
28
+ def update
29
+ requires :id, :name, :auth_algorithm, :encryption_algorithm, :ike_version,
30
+ :lifetime, :pfs, :phase1_negotiation_mode
31
+ merge_attributes(service.update_ike_policy(id, attributes).body['ikepolicy'])
32
+ self
33
+ end
34
+
35
+ def destroy
36
+ requires :id
37
+ service.delete_ike_policy(id)
38
+ true
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ require 'fog/openstack/models/collection'
2
+ require 'fog/openstack/models/network/ipsec_policy'
3
+
4
+ module Fog
5
+ module Network
6
+ class OpenStack
7
+ class IpsecPolicies < Fog::OpenStack::Collection
8
+ attribute :filters
9
+
10
+ model Fog::Network::OpenStack::IpsecPolicy
11
+
12
+ def initialize(attributes)
13
+ self.filters ||= {}
14
+ super
15
+ end
16
+
17
+ def all(filters_arg = filters)
18
+ filters = filters_arg
19
+ load_response(service.list_ipsec_policies(filters), 'ipsecpolicies')
20
+ end
21
+
22
+ def get(ipsec_policy_id)
23
+ if ipsec_policy = service.get_ipsec_policy(ipsec_policy_id).body['ipsecpolicy']
24
+ new(ipsec_policy)
25
+ end
26
+ rescue Fog::Network::OpenStack::NotFound
27
+ nil
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ require 'fog/openstack/models/model'
2
+
3
+ module Fog
4
+ module Network
5
+ class OpenStack
6
+ class IpsecPolicy < Fog::OpenStack::Model
7
+ identity :id
8
+
9
+ attribute :name
10
+ attribute :description
11
+ attribute :status
12
+ attribute :admin_state_up
13
+ attribute :tenant_id
14
+ attribute :auth_algorithm
15
+ attribute :encryption_algorithm
16
+ attribute :pfs
17
+ attribute :transform_protocol
18
+ attribute :encapsulation_mode
19
+ attribute :lifetime
20
+
21
+ def create
22
+ requires :name, :auth_algorithm, :encryption_algorithm,
23
+ :lifetime, :pfs, :transform_protocol,
24
+ :encapsulation_mode
25
+ merge_attributes(service.create_ipsec_policy(attributes).body['ipsecpolicy'])
26
+ self
27
+ end
28
+
29
+ def update
30
+ requires :id, :name, :auth_algorithm, :encryption_algorithm,
31
+ :lifetime, :pfs, :transform_protocol,
32
+ :encapsulation_mode
33
+ merge_attributes(service.update_ipsec_policy(id, attributes).body['ipsecpolicy'])
34
+ self
35
+ end
36
+
37
+ def destroy
38
+ requires :id
39
+ service.delete_ipsec_policy(id)
40
+ true
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end