fog-openstack 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/docs/orchestration.md +23 -0
  3. data/examples/event/basics.rb +22 -0
  4. data/gemfiles/Gemfile-1.9 +1 -0
  5. data/lib/fog/compute/openstack.rb +28 -2
  6. data/lib/fog/compute/openstack/models/os_interface.rb +15 -0
  7. data/lib/fog/compute/openstack/models/os_interfaces.rb +28 -0
  8. data/lib/fog/compute/openstack/models/server.rb +5 -0
  9. data/lib/fog/compute/openstack/requests/create_os_interface.rb +42 -0
  10. data/lib/fog/compute/openstack/requests/delete_key_pair.rb +1 -1
  11. data/lib/fog/compute/openstack/requests/delete_os_interface.rb +24 -0
  12. data/lib/fog/compute/openstack/requests/get_hypervisor.rb +64 -0
  13. data/lib/fog/compute/openstack/requests/get_key_pair.rb +1 -1
  14. data/lib/fog/compute/openstack/requests/get_os_interface.rb +24 -0
  15. data/lib/fog/compute/openstack/requests/list_hypervisor_servers.rb +42 -0
  16. data/lib/fog/compute/openstack/requests/list_hypervisors.rb +27 -0
  17. data/lib/fog/compute/openstack/requests/list_hypervisors_detail.rb +71 -0
  18. data/lib/fog/compute/openstack/requests/list_os_interfaces.rb +24 -0
  19. data/lib/fog/dns/openstack/v2/requests/create_zone.rb +1 -1
  20. data/lib/fog/event/openstack.rb +120 -0
  21. data/lib/fog/event/openstack/models/event.rb +16 -0
  22. data/lib/fog/event/openstack/models/events.rb +23 -0
  23. data/lib/fog/event/openstack/requests/get_event.rb +27 -0
  24. data/lib/fog/event/openstack/requests/list_events.rb +42 -0
  25. data/lib/fog/identity/openstack/v3/models/domains.rb +23 -11
  26. data/lib/fog/key_manager/openstack.rb +1 -1
  27. data/lib/fog/metering/openstack.rb +1 -0
  28. data/lib/fog/network/openstack.rb +10 -0
  29. data/lib/fog/network/openstack/models/subnet_pool.rb +47 -0
  30. data/lib/fog/network/openstack/models/subnet_pools.rb +33 -0
  31. data/lib/fog/network/openstack/requests/create_subnet_pool.rb +56 -0
  32. data/lib/fog/network/openstack/requests/delete_subnet_pool.rb +28 -0
  33. data/lib/fog/network/openstack/requests/get_subnet_pool.rb +29 -0
  34. data/lib/fog/network/openstack/requests/list_subnet_pools.rb +25 -0
  35. data/lib/fog/network/openstack/requests/update_subnet_pool.rb +46 -0
  36. data/lib/fog/openstack.rb +90 -68
  37. data/lib/fog/openstack/core.rb +53 -7
  38. data/lib/fog/openstack/version.rb +1 -1
  39. data/lib/fog/shared_file_system/openstack.rb +51 -8
  40. data/lib/fog/shared_file_system/openstack/models/share.rb +28 -0
  41. data/lib/fog/shared_file_system/openstack/models/share_access_rule.rb +35 -0
  42. data/lib/fog/shared_file_system/openstack/models/share_access_rules.rb +30 -0
  43. data/lib/fog/shared_file_system/openstack/requests/extend_share.rb +24 -0
  44. data/lib/fog/shared_file_system/openstack/requests/get_limits.rb +45 -0
  45. data/lib/fog/shared_file_system/openstack/requests/get_quota.rb +26 -0
  46. data/lib/fog/shared_file_system/openstack/requests/grant_share_access.rb +34 -0
  47. data/lib/fog/shared_file_system/openstack/requests/list_share_access_rules.rb +29 -0
  48. data/lib/fog/shared_file_system/openstack/requests/revoke_share_access.rb +24 -0
  49. data/lib/fog/shared_file_system/openstack/requests/share_action.rb +16 -0
  50. data/lib/fog/shared_file_system/openstack/requests/shrink_share.rb +24 -0
  51. data/lib/fog/shared_file_system/openstack/requests/update_quota.rb +30 -0
  52. metadata +36 -2
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Compute
3
+ class OpenStack
4
+ class Real
5
+ def list_os_interfaces(server_id)
6
+ request(
7
+ :expects => [200, 203],
8
+ :method => 'GET',
9
+ :path => "servers/#{server_id}/os-interface"
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def list_os_interfaces(server_id)
16
+ Excon::Response.new(
17
+ :body => {'interfaceAttachments' => data[:os_interfaces]},
18
+ :status => 200
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -9,7 +9,7 @@ module Fog
9
9
  'email' => email
10
10
  }
11
11
 
12
- vanilla_options = [:ttl, :description, :type, :masters]
12
+ vanilla_options = [:ttl, :description, :type, :masters, :attributes]
13
13
 
14
14
  vanilla_options.select { |o| options[o] }.each do |key|
15
15
  data[key] = options[key]
@@ -0,0 +1,120 @@
1
+ module Fog
2
+ module Event
3
+ class OpenStack < Fog::Service
4
+ SUPPORTED_VERSIONS = /v2/
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/event/openstack/models'
19
+
20
+ model :event
21
+ collection :events
22
+
23
+ request_path 'fog/event/openstack/requests'
24
+
25
+ request :get_event
26
+ request :list_events
27
+
28
+ class Mock
29
+ def self.data
30
+ @data ||= Hash.new do |hash, key|
31
+ hash[key] = {
32
+ :users => {},
33
+ :tenants => {}
34
+ }
35
+ end
36
+ end
37
+
38
+ def self.reset
39
+ @data = nil
40
+ end
41
+
42
+ def initialize(options = {})
43
+ @openstack_username = options[:openstack_username]
44
+ @openstack_tenant = options[:openstack_tenant]
45
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
46
+
47
+ @auth_token = Fog::Mock.random_base64(64)
48
+ @auth_token_expiration = (Time.now.utc + 86400).iso8601
49
+
50
+ management_url = URI.parse(options[:openstack_auth_url])
51
+ management_url.port = 8779
52
+ management_url.path = '/v2'
53
+ @openstack_management_url = management_url.to_s
54
+
55
+ @data ||= {:users => {}}
56
+ unless @data[:users].find { |u| u['name'] == options[:openstack_username] }
57
+ id = Fog::Mock.random_numbers(6).to_s
58
+ @data[:users][id] = {
59
+ 'id' => id,
60
+ 'name' => options[:openstack_username],
61
+ 'email' => "#{options[:openstack_username]}@mock.com",
62
+ 'tenantId' => Fog::Mock.random_numbers(6).to_s,
63
+ 'enabled' => true
64
+ }
65
+ end
66
+ end
67
+
68
+ def data
69
+ self.class.data[@openstack_username]
70
+ end
71
+
72
+ def reset_data
73
+ self.class.data.delete(@openstack_username)
74
+ end
75
+
76
+ def credentials
77
+ {:provider => 'openstack',
78
+ :openstack_auth_url => @openstack_auth_uri.to_s,
79
+ :openstack_auth_token => @auth_token,
80
+ :openstack_management_url => @openstack_management_url}
81
+ end
82
+ end
83
+
84
+ class Real
85
+ include Fog::OpenStack::Core
86
+
87
+ def self.not_found_class
88
+ Fog::Event::OpenStack::NotFound
89
+ end
90
+
91
+ def initialize(options = {})
92
+ initialize_identity options
93
+
94
+ @openstack_service_type = options[:openstack_service_type] || ['event']
95
+ @openstack_service_name = options[:openstack_service_name]
96
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
97
+
98
+ @connection_options = options[:connection_options] || {}
99
+
100
+ authenticate
101
+ set_api_path
102
+
103
+ @persistent = options[:persistent] || false
104
+ @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
105
+ end
106
+
107
+ def set_api_path
108
+ unless @path.match(SUPPORTED_VERSIONS)
109
+ @path = "/" + Fog::OpenStack.get_supported_version(
110
+ SUPPORTED_VERSIONS,
111
+ @openstack_management_uri,
112
+ @auth_token,
113
+ @connection_options
114
+ )
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,16 @@
1
+ require 'fog/openstack/models/model'
2
+
3
+ module Fog
4
+ module Event
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/event/openstack/models/event'
3
+
4
+ module Fog
5
+ module Event
6
+ class OpenStack
7
+ class Events < Fog::OpenStack::Collection
8
+ model Fog::Event::OpenStack::Event
9
+
10
+ def all(q = [])
11
+ load_response(service.list_events(q))
12
+ end
13
+
14
+ def find_by_id(message_id)
15
+ event = service.get_event(message_id).body
16
+ new(event)
17
+ rescue Fog::Event::OpenStack::NotFound
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Event
3
+ class OpenStack
4
+ class Real
5
+ def get_event(message_id)
6
+ request(
7
+ :expects => 200,
8
+ :method => 'GET',
9
+ :path => "events/#{message_id}"
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def get_event(_message_id)
16
+ response = Excon::Response.new
17
+ response.status = 200
18
+ response.body = {
19
+ 'event_type' => 'compute.instance.create',
20
+ 'message_id' => 'd646b40dea6347dfb8caee2da1484c56',
21
+ }
22
+ response
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ module Fog
2
+ module Event
3
+ class OpenStack
4
+ class Real
5
+ def list_events(options = [])
6
+ data = {
7
+ 'q' => []
8
+ }
9
+
10
+ options.each do |opt|
11
+ filter = {}
12
+
13
+ ['field', 'op', 'value'].each do |key|
14
+ filter[key] = opt[key] if opt[key]
15
+ end
16
+
17
+ data['q'] << filter unless filter.empty?
18
+ end
19
+
20
+ request(
21
+ :body => Fog::JSON.encode(data),
22
+ :expects => 200,
23
+ :method => 'GET',
24
+ :path => 'events'
25
+ )
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def list_events(_options = {})
31
+ response = Excon::Response.new
32
+ response.status = 200
33
+ response.body = [{
34
+ 'event_type' => 'compute.instance.create',
35
+ 'message_id' => 'd646b40dea6347dfb8caee2da1484c56',
36
+ }]
37
+ response
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -9,13 +9,19 @@ module Fog
9
9
  model Fog::Identity::OpenStack::V3::Domain
10
10
 
11
11
  def all(options = {})
12
- cache = Fog::Identity::OpenStack::V3::Domain.cache
13
- cached_domain, expires = cache[{:token => service.auth_token, :options => options}]
14
- return cached_domain if cached_domain && expires > Time.now
15
- domain_to_cache = load_response(service.list_domains(options), 'domains')
12
+ if service.openstack_cache_ttl > 0
13
+ cached_domain, expires = Fog::Identity::OpenStack::V3::Domain.cache[{:token => service.auth_token,
14
+ :options => options}]
15
+ return cached_domain if cached_domain && expires > Time.now
16
+ end
16
17
 
17
- cache[{:token => service.auth_token, :options => options}] = domain_to_cache, Time.now + 30 # 30-second TTL
18
- Fog::Identity::OpenStack::V3::Domain.cache = cache
18
+ domain_to_cache = load_response(service.list_domains(options), 'domains')
19
+ if service.openstack_cache_ttl > 0
20
+ cache = Fog::Identity::OpenStack::V3::Domain.cache
21
+ cache[{:token => service.auth_token, :options => options}] = [domain_to_cache,
22
+ Time.now + service.openstack_cache_ttl]
23
+ Fog::Identity::OpenStack::V3::Domain.cache = cache
24
+ end
19
25
  domain_to_cache
20
26
  end
21
27
 
@@ -28,15 +34,21 @@ module Fog
28
34
  end
29
35
 
30
36
  def find_by_id(id)
31
- cache = Fog::Identity::OpenStack::V3::Domain.cache
32
- cached_domain, expires = cache[{:token => service.auth_token, :id => id}]
33
- return cached_domain if cached_domain && expires > Time.now
37
+ if service.openstack_cache_ttl > 0
38
+ cached_domain, expires = Fog::Identity::OpenStack::V3::Domain.cache[{:token => service.auth_token,
39
+ :id => id}]
40
+ return cached_domain if cached_domain && expires > Time.now
41
+ end
34
42
  domain_hash = service.get_domain(id).body['domain']
35
43
  domain_to_cache = Fog::Identity::OpenStack::V3::Domain.new(
36
44
  domain_hash.merge(:service => service)
37
45
  )
38
- cache[{:token => service.auth_token, :id => id}] = domain_to_cache, Time.now + 30 # 30-second TTL
39
- Fog::Identity::OpenStack::V3::Domain.cache = cache
46
+
47
+ if service.openstack_cache_ttl > 0
48
+ cache = Fog::Identity::OpenStack::V3::Domain.cache
49
+ cache[{:token => service.auth_token, :id => id}] = [domain_to_cache, Time.now + service.openstack_cache_ttl]
50
+ Fog::Identity::OpenStack::V3::Domain.cache = cache
51
+ end
40
52
  domain_to_cache
41
53
  end
42
54
 
@@ -89,7 +89,7 @@ module Fog
89
89
  end
90
90
  end
91
91
 
92
- if version.blank?
92
+ if !version || version.empty?
93
93
  raise Fog::OpenStack::Errors::ServiceUnavailable.new(
94
94
  "OpenStack service only supports API versions #{supported_versions.inspect}")
95
95
  end
@@ -22,6 +22,7 @@ module Fog
22
22
  model :resource
23
23
  collection :resources
24
24
 
25
+ # Events extracted from Ceilometer (metering service) to Panko (event service) since Ocata release
25
26
  model :event
26
27
  collection :events
27
28
 
@@ -28,6 +28,8 @@ module Fog
28
28
  collection :ports
29
29
  model :subnet
30
30
  collection :subnets
31
+ model :subnet_pool
32
+ collection :subnet_pools
31
33
  model :floating_ip
32
34
  collection :floating_ips
33
35
  model :router
@@ -84,6 +86,13 @@ module Fog
84
86
  request :get_subnet
85
87
  request :update_subnet
86
88
 
89
+ # Subnet Pools CRUD
90
+ request :list_subnet_pools
91
+ request :create_subnet_pool
92
+ request :delete_subnet_pool
93
+ request :get_subnet_pool
94
+ request :update_subnet_pool
95
+
87
96
  # FloatingIp CRUD
88
97
  request :list_floating_ips
89
98
  request :create_floating_ip
@@ -296,6 +305,7 @@ module Fog
296
305
  'tenant_id' => tenant_id,
297
306
  }
298
307
  },
308
+ :subnet_pools => {},
299
309
  :floating_ips => {},
300
310
  :routers => {},
301
311
  :lb_pools => {},
@@ -0,0 +1,47 @@
1
+ require 'fog/openstack/models/model'
2
+
3
+ module Fog
4
+ module Network
5
+ class OpenStack
6
+ class SubnetPool < Fog::OpenStack::Model
7
+ identity :id
8
+
9
+ attribute :name
10
+ attribute :prefixes
11
+ attribute :description
12
+ attribute :address_scope_id
13
+ attribute :shared
14
+ attribute :ip_version
15
+ attribute :min_prefixlen
16
+ attribute :max_prefixlen
17
+ attribute :default_prefixlen
18
+ attribute :is_default
19
+ attribute :default_quota
20
+ attribute :created_at
21
+ attribute :updated_at
22
+ attribute :tenant_id
23
+
24
+ def create
25
+ requires :name, :prefixes
26
+ merge_attributes(service.create_subnet_pool(name,
27
+ prefixes,
28
+ attributes).body['subnetpool'])
29
+ self
30
+ end
31
+
32
+ def update
33
+ requires :id
34
+ merge_attributes(service.update_subnet_pool(id,
35
+ attributes).body['subnetpool'])
36
+ self
37
+ end
38
+
39
+ def destroy
40
+ requires :id
41
+ service.delete_subnet_pool(id)
42
+ true
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ require 'fog/openstack/models/collection'
2
+ require 'fog/network/openstack/models/subnet_pool'
3
+
4
+ module Fog
5
+ module Network
6
+ class OpenStack
7
+ class SubnetPools < Fog::OpenStack::Collection
8
+ attribute :filters
9
+
10
+ model Fog::Network::OpenStack::SubnetPool
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_subnet_pools(filters), 'subnetpools')
20
+ end
21
+
22
+ def get(subnet_pool_id)
23
+ subnet_pool = service.get_subnet_pool(subnet_pool_id).body['subnetpool']
24
+ if subnet_pool
25
+ new(subnet_pool)
26
+ end
27
+ rescue Fog::Network::OpenStack::NotFound
28
+ nil
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end