fog-openstack 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/examples/container_infra/basics.rb +61 -0
  4. data/examples/identity/basics_v3.rb +83 -0
  5. data/lib/fog/container_infra/openstack.rb +163 -0
  6. data/lib/fog/container_infra/openstack/models/base.rb +19 -0
  7. data/lib/fog/container_infra/openstack/models/bay.rb +56 -0
  8. data/lib/fog/container_infra/openstack/models/bay_model.rb +62 -0
  9. data/lib/fog/container_infra/openstack/models/bay_models.rb +23 -0
  10. data/lib/fog/container_infra/openstack/models/bays.rb +23 -0
  11. data/lib/fog/container_infra/openstack/models/certificate.rb +20 -0
  12. data/lib/fog/container_infra/openstack/models/certificates.rb +25 -0
  13. data/lib/fog/container_infra/openstack/models/cluster.rb +56 -0
  14. data/lib/fog/container_infra/openstack/models/cluster_template.rb +61 -0
  15. data/lib/fog/container_infra/openstack/models/cluster_templates.rb +24 -0
  16. data/lib/fog/container_infra/openstack/models/clusters.rb +24 -0
  17. data/lib/fog/container_infra/openstack/requests/create_bay.rb +27 -0
  18. data/lib/fog/container_infra/openstack/requests/create_bay_model.rb +56 -0
  19. data/lib/fog/container_infra/openstack/requests/create_certificate.rb +29 -0
  20. data/lib/fog/container_infra/openstack/requests/create_cluster.rb +27 -0
  21. data/lib/fog/container_infra/openstack/requests/create_cluster_template.rb +56 -0
  22. data/lib/fog/container_infra/openstack/requests/delete_bay.rb +24 -0
  23. data/lib/fog/container_infra/openstack/requests/delete_bay_model.rb +24 -0
  24. data/lib/fog/container_infra/openstack/requests/delete_cluster.rb +24 -0
  25. data/lib/fog/container_infra/openstack/requests/delete_cluster_template.rb +24 -0
  26. data/lib/fog/container_infra/openstack/requests/get_bay.rb +51 -0
  27. data/lib/fog/container_infra/openstack/requests/get_bay_model.rb +55 -0
  28. data/lib/fog/container_infra/openstack/requests/get_certificate.rb +27 -0
  29. data/lib/fog/container_infra/openstack/requests/get_cluster.rb +41 -0
  30. data/lib/fog/container_infra/openstack/requests/get_cluster_template.rb +55 -0
  31. data/lib/fog/container_infra/openstack/requests/list_bay_models.rb +69 -0
  32. data/lib/fog/container_infra/openstack/requests/list_bays.rb +55 -0
  33. data/lib/fog/container_infra/openstack/requests/list_cluster_templates.rb +59 -0
  34. data/lib/fog/container_infra/openstack/requests/list_clusters.rb +37 -0
  35. data/lib/fog/container_infra/openstack/requests/update_bay.rb +27 -0
  36. data/lib/fog/container_infra/openstack/requests/update_bay_model.rb +56 -0
  37. data/lib/fog/container_infra/openstack/requests/update_cluster.rb +27 -0
  38. data/lib/fog/container_infra/openstack/requests/update_cluster_template.rb +56 -0
  39. data/lib/fog/key_manager/openstack.rb +103 -0
  40. data/lib/fog/key_manager/openstack/models/container.rb +44 -0
  41. data/lib/fog/key_manager/openstack/models/containers.rb +25 -0
  42. data/lib/fog/key_manager/openstack/models/secret.rb +53 -0
  43. data/lib/fog/key_manager/openstack/models/secrets.rb +25 -0
  44. data/lib/fog/key_manager/openstack/requests/create_container.rb +19 -0
  45. data/lib/fog/key_manager/openstack/requests/create_secret.rb +19 -0
  46. data/lib/fog/key_manager/openstack/requests/delete_container.rb +18 -0
  47. data/lib/fog/key_manager/openstack/requests/delete_secret.rb +18 -0
  48. data/lib/fog/key_manager/openstack/requests/get_container.rb +18 -0
  49. data/lib/fog/key_manager/openstack/requests/get_secret.rb +18 -0
  50. data/lib/fog/key_manager/openstack/requests/get_secret_metadata.rb +18 -0
  51. data/lib/fog/key_manager/openstack/requests/get_secret_payload.rb +21 -0
  52. data/lib/fog/key_manager/openstack/requests/list_containers.rb +19 -0
  53. data/lib/fog/key_manager/openstack/requests/list_secrets.rb +19 -0
  54. data/lib/fog/network/openstack.rb +50 -1
  55. data/lib/fog/network/openstack/requests/create_lbaas_healthmonitor.rb +57 -0
  56. data/lib/fog/network/openstack/requests/create_lbaas_listener.rb +55 -0
  57. data/lib/fog/network/openstack/requests/create_lbaas_loadbalancer.rb +52 -0
  58. data/lib/fog/network/openstack/requests/create_lbaas_pool.rb +53 -0
  59. data/lib/fog/network/openstack/requests/create_lbaas_pool_member.rb +49 -0
  60. data/lib/fog/network/openstack/requests/delete_lbaas_healthmonitor.rb +28 -0
  61. data/lib/fog/network/openstack/requests/delete_lbaas_listener.rb +28 -0
  62. data/lib/fog/network/openstack/requests/delete_lbaas_loadbalancer.rb +28 -0
  63. data/lib/fog/network/openstack/requests/delete_lbaas_pool.rb +28 -0
  64. data/lib/fog/network/openstack/requests/delete_lbaas_pool_member.rb +28 -0
  65. data/lib/fog/network/openstack/requests/get_lbaas_healthmonitor.rb +28 -0
  66. data/lib/fog/network/openstack/requests/get_lbaas_listener.rb +28 -0
  67. data/lib/fog/network/openstack/requests/get_lbaas_loadbalancer.rb +28 -0
  68. data/lib/fog/network/openstack/requests/get_lbaas_pool.rb +28 -0
  69. data/lib/fog/network/openstack/requests/get_lbaas_pool_member.rb +28 -0
  70. data/lib/fog/network/openstack/requests/list_lbaas_healthmonitors.rb +25 -0
  71. data/lib/fog/network/openstack/requests/list_lbaas_listeners.rb +25 -0
  72. data/lib/fog/network/openstack/requests/list_lbaas_loadbalancers.rb +25 -0
  73. data/lib/fog/network/openstack/requests/list_lbaas_pool_members.rb +25 -0
  74. data/lib/fog/network/openstack/requests/list_lbaas_pools.rb +25 -0
  75. data/lib/fog/network/openstack/requests/update_lbaas_healthmonitor.rb +43 -0
  76. data/lib/fog/network/openstack/requests/update_lbaas_listener.rb +45 -0
  77. data/lib/fog/network/openstack/requests/update_lbaas_loadbalancer.rb +41 -0
  78. data/lib/fog/network/openstack/requests/update_lbaas_pool.rb +40 -0
  79. data/lib/fog/network/openstack/requests/update_lbaas_pool_member.rb +39 -0
  80. data/lib/fog/openstack.rb +10 -0
  81. data/lib/fog/openstack/version.rb +7 -1
  82. metadata +78 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33930f096ce867d0d328ccfcf748104caefefcf8
4
- data.tar.gz: a0ffe19cfb27b239d8a1376c18711433c341015e
3
+ metadata.gz: 8ad255185b61e76ee76ad8d89711b167918a27f7
4
+ data.tar.gz: b02a996a6244f9d382d619086358f15209d5ce27
5
5
  SHA512:
6
- metadata.gz: 8c0529686e26404cd6d80ac858c78adcb16a275383031959bec90a161887be1ae043140c1d9921fe2cd3f55a2856370561c0c9d4b808440e1c925a8601f29294
7
- data.tar.gz: 3317ae20e8b81989572b91af05fd5298a13da6a604028e3b50f8ccc840da268f507d4b84359cf63c7f9b57bf871c3c52356752b4d05ce27be63f9ec86d528dd9
6
+ metadata.gz: 0a4dace55598a9e1da519522da4d133d53b617e64f7b4f9492fdb0e559074b21abc0f00d64163a40544b0c75160ea231af452664ecda648cc104c612f727d92c
7
+ data.tar.gz: 1bed7b31da6d4529b432d4e55254dc56259e7810a60e9731895cb2d839b34380379c4c5aa86d3bec8cd5cda77f813e72073e5071ffba81201735169439987fc8
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  gemfiles/Gemfile-1.9.lock
11
11
  .DS_Store
12
12
  .idea/
13
+ vendor/bundle
@@ -0,0 +1,61 @@
1
+ # OpenStack Container Infra (Magnum) Example
2
+ require 'fog/openstack'
3
+
4
+ # Initialize a connection to the Magnum API
5
+ params = {
6
+ openstack_auth_url: 'https://example.net/v3/auth/tokens',
7
+ openstack_username: 'username',
8
+ openstack_api_key: 'password',
9
+ openstack_project_name: 'magnum'
10
+ }
11
+
12
+ container_infra = Fog::ContainerInfra::OpenStack.new(params)
13
+
14
+ # Get the Fedora Atomic image
15
+ image = Fog::Image::OpenStack.new(params)
16
+
17
+ unless image.images.map(&:name).include?("fedora-atomic-latest")
18
+ puts "Couldn't find Fedora Atomic. Uploading to Glance..."
19
+ fedora = image.images.create name: "fedora-atomic-latest",
20
+ disk_format: "qcow2",
21
+ visibility: 'public',
22
+ container_format: 'bare',
23
+ copy_from: 'https://fedorapeople.org/groups/magnum/fedora-atomic-latest.qcow2',
24
+ properties: {'os_distro' => 'fedora-atomic'}.to_json
25
+ fedora.wait_for { status == "active" }
26
+ end
27
+
28
+ # Create a cluster template for using Docker Swarm and Fedora Atomic
29
+ params = {
30
+ name: 'swarm-cluster-template',
31
+ image_id: 'fedora-atomic-latest',
32
+ keypair_id: 'YOUR_KEYPAIR_NAME',
33
+ external_network_id: 'public',
34
+ master_flavor_id: 'm1.small',
35
+ flavor_id: 'm1.small',
36
+ coe: 'swarm',
37
+ docker_volume_size: 3,
38
+ dns_nameserver: '8.8.8.8',
39
+ tls_disabled: true
40
+ }
41
+
42
+ cluster_template = container_infra.cluster_templates.create(params)
43
+ puts "Created cluster template #{cluster_template.name} (#{cluster_template.uuid})"
44
+
45
+ # Create a swarm cluster and wait for it to build
46
+ params = {
47
+ name: 'swarm-cluster',
48
+ cluster_template_id: 'swarm-cluster-template',
49
+ master_count: 1,
50
+ node_count: 1
51
+ }
52
+
53
+ cluster = container_infra.clusters.create(params)
54
+ start = Time.now
55
+ puts "Building cluster #{cluster.name} (#{cluster.uuid})"
56
+
57
+ cluster.wait_for { status != 'CREATE_IN_PROGRESS' }
58
+
59
+ puts "Finished building #{cluster.name} in #{(Time.now - start).round} seconds. Status: #{cluster.status}."
60
+
61
+ puts "More info: #{cluster.status_reason}" if cluster.status == 'CREATE_FAILED'
@@ -0,0 +1,83 @@
1
+ # OpenStack Identity Service (Keystone) Example
2
+
3
+ require 'fog/openstack'
4
+ require 'pp'
5
+
6
+ auth_url = "https://example.net:35357/v3/auth/tokens"
7
+ username = 'admin@example.net'
8
+ password = 'secret'
9
+ project = 'admin'
10
+ domain = 'Default'
11
+
12
+
13
+
14
+ keystone = Fog::Identity::OpenStack.new :openstack_auth_url => auth_url,
15
+ :openstack_username => username,
16
+ :openstack_api_key => password,
17
+ :openstack_project_name => project,
18
+ :openstack_domain_name => domain
19
+ # Optional, self-signed certs
20
+ #:connection_options => { :ssl_verify_peer => false }
21
+
22
+ #
23
+ # List keystone projects
24
+ #
25
+ keystone.projects.each do |project|
26
+ #<Fog::Identity::OpenStack::V3::Project
27
+ # id="17775c",
28
+ # domain_id="default",
29
+ # description="admin tenant",
30
+ # enabled=true,
31
+ # name="admin",
32
+ # links={"self"=>"http://example.net:35357/..."},
33
+ # parent_id=nil,
34
+ # subtree=nil,
35
+ # parents=nil
36
+ #>
37
+ # ...
38
+ pp project
39
+ end
40
+
41
+ #
42
+ # List users
43
+ #
44
+ keystone.users.each do |user|
45
+ #<Fog::Identity::OpenStack::V3::User
46
+ # id="02124b...",
47
+ # default_project_id=2f534e...,
48
+ # description=nil,
49
+ # domain_id="default",
50
+ # email="quantum@example.net",
51
+ # enabled=true,
52
+ # name="quantum",
53
+ # links={"self"=>"http://example.net:35357/..."},
54
+ # password=nil
55
+ #>
56
+ # ...
57
+ pp user
58
+ end
59
+
60
+ #
61
+ # Create a new tenant
62
+ #
63
+ project = keystone.projects.create :name => 'rubiojr@example.net',
64
+ :description => 'My foo tenant'
65
+
66
+ #
67
+ # Create a new user
68
+ #
69
+ user = keystone.users.create :name => 'rubiojr@example.net',
70
+ :default_project_id => project.id,
71
+ :password => 'rubiojr@example.net',
72
+ :email => 'rubiojr@example.net',
73
+ :domain_id => 'Default'
74
+
75
+ # Find the recently created tenant
76
+ project = keystone.projects.find { |t| t.name == 'rubiojr@example.net' }
77
+ # Destroy the tenant
78
+ project.destroy
79
+
80
+ # Find the recently created user
81
+ user = keystone.users.find { |u| u.name == 'rubiojr@example.net' }
82
+ # Destroy the user
83
+ user.destroy
@@ -0,0 +1,163 @@
1
+ module Fog
2
+ module ContainerInfra
3
+ class OpenStack < Fog::Service
4
+ SUPPORTED_VERSIONS = /v1/
5
+ SUPPORTED_MICROVERSION = '1.3'
6
+
7
+ requires :openstack_auth_url
8
+ recognizes :openstack_auth_token, :openstack_management_url,
9
+ :persistent, :openstack_service_type, :openstack_service_name,
10
+ :openstack_tenant, :openstack_tenant_id,
11
+ :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
12
+ :current_user, :current_tenant, :openstack_region,
13
+ :openstack_endpoint_type, :openstack_cache_ttl,
14
+ :openstack_project_name, :openstack_project_id,
15
+ :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
16
+ :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
17
+ :openstack_identity_prefix
18
+
19
+ model_path 'fog/container_infra/openstack/models'
20
+
21
+ model :bay
22
+ collection :bays
23
+ model :bay_model
24
+ collection :bay_models
25
+ model :certificate
26
+ collection :certificates
27
+ model :cluster
28
+ collection :clusters
29
+ model :cluster_template
30
+ collection :cluster_templates
31
+
32
+ request_path 'fog/container_infra/openstack/requests'
33
+
34
+ # Bay CRUD
35
+ request :create_bay
36
+ request :delete_bay
37
+ request :get_bay
38
+ request :list_bays
39
+ request :update_bay
40
+
41
+ # Bay Model CRUD
42
+ request :create_bay_model
43
+ request :delete_bay_model
44
+ request :get_bay_model
45
+ request :list_bay_models
46
+ request :update_bay_model
47
+
48
+ # Certificate CRUD
49
+ request :create_certificate
50
+ request :get_certificate
51
+
52
+ # Cluster CRUD
53
+ request :create_cluster
54
+ request :delete_cluster
55
+ request :get_cluster
56
+ request :list_clusters
57
+ request :update_cluster
58
+
59
+ # Cluster Template CRUD
60
+ request :create_cluster_template
61
+ request :delete_cluster_template
62
+ request :get_cluster_template
63
+ request :list_cluster_templates
64
+ request :update_cluster_template
65
+
66
+ class Mock
67
+ def self.data
68
+ @data ||= Hash.new do |hash, key|
69
+ hash[key] = {
70
+ :users => {},
71
+ :tenants => {}
72
+ }
73
+ end
74
+ end
75
+
76
+ def self.reset
77
+ @data = nil
78
+ end
79
+
80
+ def initialize(options = {})
81
+ @openstack_username = options[:openstack_username]
82
+ @openstack_tenant = options[:openstack_tenant]
83
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
84
+
85
+ @auth_token = Fog::Mock.random_base64(64)
86
+ @auth_token_expiration = (Time.now.utc + 86400).iso8601
87
+
88
+ management_url = URI.parse(options[:openstack_auth_url])
89
+ management_url.port = 9511
90
+ management_url.path = '/v1'
91
+ @openstack_management_url = management_url.to_s
92
+
93
+ @data ||= {:users => {}}
94
+ unless @data[:users].find { |u| u['name'] == options[:openstack_username] }
95
+ id = Fog::Mock.random_numbers(6).to_s
96
+ @data[:users][id] = {
97
+ 'id' => id,
98
+ 'name' => options[:openstack_username],
99
+ 'email' => "#{options[:openstack_username]}@mock.com",
100
+ 'tenantId' => Fog::Mock.random_numbers(6).to_s,
101
+ 'enabled' => true
102
+ }
103
+ end
104
+ end
105
+
106
+ def data
107
+ self.class.data[@openstack_username]
108
+ end
109
+
110
+ def reset_data
111
+ self.class.data.delete(@openstack_username)
112
+ end
113
+
114
+ def credentials
115
+ {:provider => 'openstack',
116
+ :openstack_auth_url => @openstack_auth_uri.to_s,
117
+ :openstack_auth_token => @auth_token,
118
+ :openstack_management_url => @openstack_management_url}
119
+ end
120
+ end
121
+
122
+ class Real
123
+ include Fog::OpenStack::Core
124
+
125
+ def self.not_found_class
126
+ Fog::ContainerInfra::OpenStack::NotFound
127
+ end
128
+
129
+ def initialize(options = {})
130
+ initialize_identity options
131
+
132
+ @openstack_service_type = options[:openstack_service_type] || ['container-infra']
133
+ @openstack_service_name = options[:openstack_service_name]
134
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
135
+
136
+ @connection_options = options[:connection_options] || {}
137
+
138
+ authenticate
139
+ set_api_path
140
+
141
+ @persistent = options[:persistent] || false
142
+ @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
143
+ end
144
+
145
+ def request(options = {})
146
+ options[:headers] = {'OpenStack-API-Version' => "container-infra #{SUPPORTED_MICROVERSION}"}
147
+ super(options)
148
+ end
149
+
150
+ def set_api_path
151
+ unless @path.match(SUPPORTED_VERSIONS)
152
+ @path = Fog::OpenStack.get_supported_version_path(
153
+ SUPPORTED_VERSIONS,
154
+ @openstack_management_uri,
155
+ @auth_token,
156
+ @connection_options
157
+ )
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,19 @@
1
+ require 'fog/openstack/models/model'
2
+
3
+ module Fog
4
+ module ContainerInfra
5
+ class OpenStack
6
+ class Base < Fog::OpenStack::Model
7
+ def convert_update_params(params)
8
+ params = params.map do |key, value|
9
+ {
10
+ "path" => "/#{key}",
11
+ "op" => value ? "replace" : "remove"
12
+ }.merge(value ? {"value" => value} : {})
13
+ end
14
+ params.each {|k,v| params[k] = v.to_s.capitalize if [true, false].include?(v)}
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'base'
2
+
3
+ module Fog
4
+ module ContainerInfra
5
+ class OpenStack
6
+ class Bay < Fog::ContainerInfra::OpenStack::Base
7
+ identity :uuid
8
+
9
+ attribute :api_address
10
+ attribute :coe_version
11
+ attribute :baymodel_id
12
+ attribute :create_timeout
13
+ attribute :created_at
14
+ attribute :discovery_url
15
+ attribute :master_addresses
16
+ attribute :master_count
17
+ attribute :name
18
+ attribute :node_addresses
19
+ attribute :node_count
20
+ attribute :stack_id
21
+ attribute :status
22
+ attribute :status_reason
23
+ attribute :updated_at
24
+
25
+ def create
26
+ requires :name, :baymodel_id
27
+ merge_attributes(service.create_bay(attributes).body)
28
+ self
29
+ end
30
+
31
+ def update
32
+ requires :uuid, :name, :baymodel_id
33
+ attrs = attributes.select{|k,_| allowed_update_attributes.include? k}
34
+ attrs = convert_update_params(attrs)
35
+ merge_attributes(service.update_bay(uuid, attrs).body)
36
+ self
37
+ end
38
+
39
+ def destroy
40
+ requires :uuid
41
+ service.delete_bay(uuid)
42
+ true
43
+ end
44
+
45
+ private
46
+
47
+ def allowed_update_attributes
48
+ [
49
+ :node_count
50
+ ]
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'base'
2
+
3
+ module Fog
4
+ module ContainerInfra
5
+ class OpenStack
6
+ class BayModel < Fog::ContainerInfra::OpenStack::Base
7
+ identity :uuid
8
+
9
+ attribute :apiserver_port
10
+ attribute :cluster_distro
11
+ attribute :coe
12
+ attribute :created_at
13
+ attribute :dns_nameserver
14
+ attribute :docker_storage_driver
15
+ attribute :docker_volume_size
16
+ attribute :external_network_id
17
+ attribute :fixed_network
18
+ attribute :fixed_subnet
19
+ attribute :flavor_id
20
+ attribute :floating_ip_enabled
21
+ attribute :http_proxy
22
+ attribute :https_proxy
23
+ attribute :image_id
24
+ attribute :insecure_registry
25
+ attribute :keypair_id
26
+ attribute :labels
27
+ attribute :master_flavor_id
28
+ attribute :master_lb_enabled
29
+ attribute :name
30
+ attribute :network_driver
31
+ attribute :no_proxy
32
+ attribute :public
33
+ attribute :registry_enabled
34
+ attribute :server_type
35
+ attribute :tls_disabled
36
+ attribute :updated_at
37
+ attribute :volume_driver
38
+
39
+ def create
40
+ requires :name, :keypair_id, :flavor_id, :image_id,
41
+ :external_network_id, :coe
42
+ merge_attributes(service.create_bay_model(attributes).body)
43
+ self
44
+ end
45
+
46
+ def update
47
+ requires :uuid, :name, :keypair_id, :flavor_id, :image_id,
48
+ :external_network_id, :coe
49
+ attrs = convert_update_params(attributes)
50
+ merge_attributes(service.update_bay_model(uuid, attrs).body)
51
+ self
52
+ end
53
+
54
+ def destroy
55
+ requires :uuid
56
+ service.delete_bay_model(uuid)
57
+ true
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end