fog-openstack 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +6 -2
  4. data/README.md +4 -0
  5. data/Rakefile +10 -2
  6. data/fog-openstack.gemspec +2 -3
  7. data/gemfiles/Gemfile-1.9 +1 -1
  8. data/lib/fog/openstack.rb +14 -6
  9. data/lib/fog/openstack/baremetal.rb +1 -1
  10. data/lib/fog/openstack/common.rb +0 -2
  11. data/lib/fog/openstack/compute.rb +78 -75
  12. data/lib/fog/openstack/core.rb +2 -1
  13. data/lib/fog/openstack/docs/compute.md +1 -1
  14. data/lib/fog/openstack/docs/network.md +283 -0
  15. data/lib/fog/openstack/docs/nfv.md +144 -0
  16. data/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb +4 -4
  17. data/lib/fog/openstack/examples/network/network_add_port.rb +21 -0
  18. data/lib/fog/openstack/examples/network/network_rbac.rb +69 -0
  19. data/lib/fog/openstack/identity.rb +14 -22
  20. data/lib/fog/openstack/identity_v2.rb +1 -1
  21. data/lib/fog/openstack/image_v1.rb +13 -28
  22. data/lib/fog/openstack/image_v2.rb +15 -17
  23. data/lib/fog/openstack/introspection.rb +1 -1
  24. data/lib/fog/openstack/metering.rb +1 -1
  25. data/lib/fog/openstack/models/collection.rb +4 -1
  26. data/lib/fog/openstack/models/compute/availability_zone.rb +5 -0
  27. data/lib/fog/openstack/models/compute/flavor.rb +21 -9
  28. data/lib/fog/openstack/models/compute/server.rb +64 -77
  29. data/lib/fog/openstack/models/compute/snapshot.rb +6 -6
  30. data/lib/fog/openstack/models/compute/volume_attachment.rb +15 -0
  31. data/lib/fog/openstack/models/compute/volume_attachments.rb +20 -0
  32. data/lib/fog/openstack/models/identity_v3/projects.rb +1 -1
  33. data/lib/fog/openstack/models/identity_v3/users.rb +2 -2
  34. data/lib/fog/openstack/models/image_v2/image.rb +41 -22
  35. data/lib/fog/openstack/models/network/floating_ip.rb +1 -0
  36. data/lib/fog/openstack/models/network/rbac_policies.rb +33 -0
  37. data/lib/fog/openstack/models/network/rbac_policy.rb +35 -0
  38. data/lib/fog/openstack/models/nfv/vnf.rb +58 -0
  39. data/lib/fog/openstack/models/nfv/vnfd.rb +53 -0
  40. data/lib/fog/openstack/models/nfv/vnfds.rb +28 -0
  41. data/lib/fog/openstack/models/nfv/vnfs.rb +28 -0
  42. data/lib/fog/openstack/models/volume/snapshot.rb +38 -0
  43. data/lib/fog/openstack/models/volume/snapshots.rb +26 -0
  44. data/lib/fog/openstack/models/volume/volume.rb +32 -2
  45. data/lib/fog/openstack/models/volume/volume_type.rb +3 -4
  46. data/lib/fog/openstack/models/volume_v1/snapshot.rb +43 -0
  47. data/lib/fog/openstack/models/volume_v1/snapshots.rb +16 -0
  48. data/lib/fog/openstack/models/volume_v1/volume.rb +12 -2
  49. data/lib/fog/openstack/models/volume_v2/snapshot.rb +43 -0
  50. data/lib/fog/openstack/models/volume_v2/snapshots.rb +16 -0
  51. data/lib/fog/openstack/models/volume_v2/volume.rb +12 -3
  52. data/lib/fog/openstack/network.rb +53 -46
  53. data/lib/fog/openstack/nfv.rb +158 -0
  54. data/lib/fog/openstack/orchestration.rb +1 -1
  55. data/lib/fog/openstack/planning.rb +1 -1
  56. data/lib/fog/openstack/requests/compute/create_server.rb +1 -1
  57. data/lib/fog/openstack/requests/compute/{create_volume_snapshot.rb → create_snapshot.rb} +16 -16
  58. data/lib/fog/openstack/requests/compute/delete_flavor_metadata.rb +30 -0
  59. data/lib/fog/openstack/requests/compute/evacuate_server.rb +8 -7
  60. data/lib/fog/openstack/requests/compute/get_key_pair.rb +49 -0
  61. data/lib/fog/openstack/requests/compute/list_availability_zones.rb +23 -0
  62. data/lib/fog/openstack/requests/compute/list_volume_attachments.rb +31 -0
  63. data/lib/fog/openstack/requests/compute/update_flavor_metadata.rb +33 -0
  64. data/lib/fog/openstack/requests/network/create_rbac_policy.rb +42 -0
  65. data/lib/fog/openstack/requests/network/delete_rbac_policy.rb +28 -0
  66. data/lib/fog/openstack/requests/network/get_rbac_policy.rb +28 -0
  67. data/lib/fog/openstack/requests/network/list_rbac_policies.rb +25 -0
  68. data/lib/fog/openstack/requests/network/update_port.rb +8 -7
  69. data/lib/fog/openstack/requests/network/update_rbac_policy.rb +41 -0
  70. data/lib/fog/openstack/requests/nfv/create_vnf.rb +37 -0
  71. data/lib/fog/openstack/requests/nfv/create_vnfd.rb +35 -0
  72. data/lib/fog/openstack/requests/nfv/delete_vnf.rb +23 -0
  73. data/lib/fog/openstack/requests/nfv/delete_vnfd.rb +23 -0
  74. data/lib/fog/openstack/requests/nfv/get_vnf.rb +24 -0
  75. data/lib/fog/openstack/requests/nfv/get_vnfd.rb +24 -0
  76. data/lib/fog/openstack/requests/nfv/list_vnfds.rb +25 -0
  77. data/lib/fog/openstack/requests/nfv/list_vnfs.rb +25 -0
  78. data/lib/fog/openstack/requests/nfv/update_vnf.rb +35 -0
  79. data/lib/fog/openstack/requests/volume/action.rb +16 -0
  80. data/lib/fog/openstack/requests/volume/create_snapshot.rb +18 -0
  81. data/lib/fog/openstack/requests/volume/delete_metadata.rb +15 -0
  82. data/lib/fog/openstack/requests/volume/delete_snapshot.rb +5 -5
  83. data/lib/fog/openstack/requests/volume/delete_snapshot_metadata.rb +15 -0
  84. data/lib/fog/openstack/requests/volume/replace_metadata.rb +20 -0
  85. data/lib/fog/openstack/requests/volume/update_metadata.rb +20 -0
  86. data/lib/fog/openstack/requests/volume/update_snapshot.rb +37 -0
  87. data/lib/fog/openstack/requests/volume/update_snapshot_metadata.rb +20 -0
  88. data/lib/fog/openstack/requests/volume/update_volume.rb +25 -0
  89. data/lib/fog/openstack/requests/volume_v1/action.rb +2 -0
  90. data/lib/fog/openstack/requests/volume_v1/create_snapshot.rb +45 -0
  91. data/lib/fog/openstack/requests/volume_v1/delete_metadata.rb +2 -0
  92. data/lib/fog/openstack/requests/volume_v1/delete_snapshot_metadata.rb +2 -0
  93. data/lib/fog/openstack/requests/volume_v1/replace_metadata.rb +2 -0
  94. data/lib/fog/openstack/requests/volume_v1/update_metadata.rb +2 -0
  95. data/lib/fog/openstack/requests/volume_v1/update_snapshot.rb +2 -0
  96. data/lib/fog/openstack/requests/volume_v1/update_snapshot_metadata.rb +2 -0
  97. data/lib/fog/openstack/requests/volume_v1/update_volume.rb +2 -0
  98. data/lib/fog/openstack/requests/volume_v2/action.rb +2 -0
  99. data/lib/fog/openstack/requests/volume_v2/create_snapshot.rb +45 -0
  100. data/lib/fog/openstack/requests/volume_v2/delete_metadata.rb +2 -0
  101. data/lib/fog/openstack/requests/volume_v2/delete_snapshot_metadata.rb +2 -0
  102. data/lib/fog/openstack/requests/volume_v2/replace_metadata.rb +2 -0
  103. data/lib/fog/openstack/requests/volume_v2/update_metadata.rb +2 -0
  104. data/lib/fog/openstack/requests/volume_v2/update_snapshot.rb +2 -0
  105. data/lib/fog/openstack/requests/volume_v2/update_snapshot_metadata.rb +2 -0
  106. data/lib/fog/openstack/requests/volume_v2/update_volume.rb +2 -0
  107. data/lib/fog/openstack/storage.rb +1 -1
  108. data/lib/fog/openstack/version.rb +1 -1
  109. data/lib/fog/openstack/volume.rb +1 -1
  110. data/lib/fog/openstack/volume_v1.rb +29 -21
  111. data/lib/fog/openstack/volume_v2.rb +29 -21
  112. data/supported.md +54 -0
  113. data/tests/openstack/models/identity/ec2_credential_tests.rb +1 -1
  114. data/tests/openstack/models/identity/ec2_credentials_tests.rb +1 -1
  115. data/tests/openstack/models/identity/role_tests.rb +8 -3
  116. data/tests/openstack/models/identity/roles_tests.rb +5 -4
  117. data/tests/openstack/models/identity/tenant_tests.rb +7 -4
  118. data/tests/openstack/models/identity/tenants_tests.rb +10 -5
  119. data/tests/openstack/models/identity/user_tests.rb +4 -3
  120. data/tests/openstack/models/identity/users_tests.rb +10 -6
  121. data/tests/openstack/models/nfv/vnf_tests.rb +35 -0
  122. data/tests/openstack/models/nfv/vnfd_tests.rb +23 -0
  123. data/tests/openstack/models/nfv/vnfds_tests.rb +31 -0
  124. data/tests/openstack/models/nfv/vnfs_tests.rb +38 -0
  125. data/tests/openstack/requests/identity/ec2_credentials_tests.rb +6 -9
  126. data/tests/openstack/requests/identity/helper.rb +12 -4
  127. data/tests/openstack/requests/identity/role_tests.rb +13 -10
  128. data/tests/openstack/requests/identity/tenant_tests.rb +10 -9
  129. data/tests/openstack/requests/identity/user_tests.rb +11 -6
  130. data/tests/openstack/requests/image/image_tests.rb +1 -0
  131. data/tests/openstack/requests/nfv/vnf_tests.rb +70 -0
  132. data/tests/openstack/requests/nfv/vnfd_tests.rb +44 -0
  133. metadata +81 -31
  134. data/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +0 -26
  135. data/lib/fog/openstack/requests/volume_v1/create_volume_snapshot.rb +0 -44
  136. data/lib/fog/openstack/requests/volume_v2/create_volume_snapshot.rb +0 -43
  137. data/tests/openstack/authenticate_tests.rb +0 -200
  138. data/tests/openstack/identity_version_tests.rb +0 -25
  139. data/tests/openstack/storage_tests.rb +0 -18
  140. data/tests/openstack/version_tests.rb +0 -55
  141. data/tests/openstack/volume_tests.rb +0 -18
@@ -0,0 +1,21 @@
1
+ require 'fog/openstack'
2
+
3
+ # Add additional port to an Openstack node
4
+
5
+ def create_virtual_address_pairing(username, password, auth_url, tenant, device_id, device_ip_address, network_id)
6
+ network_driver = Fog::Network.new(:provider => :openstack,
7
+ :openstack_api_key => password,
8
+ :openstack_username => username,
9
+ :openstack_auth_url => auth_url,
10
+ :openstack_tenant => tenant)
11
+
12
+ virtual_ip_address = network_driver.create_port(network_id)
13
+
14
+ server_nics = network_driver.list_ports('device_id' => device_id).data[:body]['ports']
15
+ port = (server_nics.select do |network_port|
16
+ network_port['mac_address'] == server.attributes['macaddress']
17
+ end).first
18
+
19
+ network_driver.update_port(port['id'], :allowed_address_pairs => [{:ip_address => device_ip_address},
20
+ {:ip_address => virtual_ip_address}])
21
+ end
@@ -0,0 +1,69 @@
1
+ require 'fog/openstack'
2
+ require 'pp'
3
+
4
+ #
5
+ # Creates a private network and shares it with another project via RBAC policy
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
+ identity_service = Fog::Identity::OpenStack::V3.new(auth_options)
33
+ network_service = Fog::Network::OpenStack.new(auth_options)
34
+
35
+ own_project = identity_service.projects.select { |p| p.name == ENV['OS_PROJECT_NAME'] }.first
36
+ other_project = identity_service.projects.select { |p| p.name != ENV['OS_PROJECT_NAME'] }.first
37
+
38
+ puts "Create network in #{own_project.name}"
39
+ foonet = network_service.networks.create(:name => 'foo-net23', :tenant_id => own_project.id)
40
+
41
+ puts "Share network with #{other_project.name}"
42
+ rbac = network_service.rbac_policies.create(
43
+ :object_type => 'network',
44
+ :object_id => foonet.id,
45
+ :tenant_id => own_project.id,
46
+ :target_tenant => other_project.id,
47
+ :action => 'access_as_shared'
48
+ )
49
+
50
+ puts "Get RBAC policy"
51
+ rbac = network_service.rbac_policies.find_by_id(rbac.id)
52
+ pp rbac
53
+
54
+ puts "Change share to own project"
55
+ rbac.target_tenant = own_project.id
56
+ rbac.save
57
+
58
+ puts "Get network and see that it is now shared"
59
+ foonet = network_service.networks.get(foonet.id)
60
+ pp foonet
61
+
62
+ puts "Remove the share via RBAC"
63
+ rbac.destroy
64
+
65
+ puts "Get network and see that it is no longer shared"
66
+ foonet.reload
67
+ pp foonet
68
+
69
+ foonet.destroy
@@ -11,19 +11,24 @@ module Fog
11
11
  :openstack_user_domain, :openstack_project_domain,
12
12
  :openstack_user_domain_id, :openstack_project_domain_id,
13
13
  :openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username,
14
- :current_user, :current_user_id, :current_tenant,
14
+ :current_user, :current_user_id, :current_tenant, :openstack_cache_ttl,
15
15
  :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches
16
16
 
17
- # Fog::Identity::OpenStack.new() will return a Fog::Identity::OpenStack::V2 or a Fog::Identity::OpenStack::V3,
18
- # depending on whether the auth URL is for an OpenStack Identity V2 or V3 API endpoint
17
+ # Fog::Identity::OpenStack.new() will return a Fog::Identity::OpenStack::V3 by default
19
18
  def self.new(args = {})
20
- if self.inspect == 'Fog::Identity::OpenStack'
21
- identity = super
22
- config = identity.config
23
- service = identity.v3? ? Fog::Identity::OpenStack::V3.new(config) : Fog::Identity::OpenStack::V2.new(config)
24
- else
25
- service = Fog::Service.new(args)
19
+ version = '3'
20
+ url = Fog.credentials[:openstack_auth_url] || args[:openstack_auth_url]
21
+ if url
22
+ uri = URI(url)
23
+ version = '2.0' if uri.path =~ /v2\.0/
26
24
  end
25
+
26
+ service = case version
27
+ when '2.0'
28
+ Fog::Identity::OpenStack::V2.new(args)
29
+ else
30
+ Fog::Identity::OpenStack::V3.new(args)
31
+ end
27
32
  service
28
33
  end
29
34
 
@@ -32,17 +37,8 @@ module Fog
32
37
 
33
38
  def initialize(options = {})
34
39
  @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
35
- @openstack_identity_prefix = options[:openstack_identity_prefix]
36
40
  @config = options
37
41
  end
38
-
39
- def v3?
40
- if @openstack_identity_prefix
41
- @openstack_identity_prefix =~ /v3/
42
- else
43
- @openstack_auth_uri && @openstack_auth_uri.path =~ %r{/v3}
44
- end
45
- end
46
42
  end
47
43
 
48
44
  class Real
@@ -80,10 +76,6 @@ module Fog
80
76
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
81
77
  end
82
78
 
83
- def v3?
84
- @path && @path =~ %r{/v3}
85
- end
86
-
87
79
  def config_service?
88
80
  true
89
81
  end
@@ -13,7 +13,7 @@ module Fog
13
13
  :openstack_tenant, :openstack_tenant_id,
14
14
  :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
15
15
  :current_user, :current_tenant, :openstack_region,
16
- :openstack_endpoint_type,
16
+ :openstack_endpoint_type, :openstack_cache_ttl,
17
17
  :openstack_project_name, :openstack_project_id,
18
18
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
19
19
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
@@ -6,7 +6,6 @@ module Fog
6
6
  module Image
7
7
  class OpenStack
8
8
  class V1 < Fog::Service
9
-
10
9
  SUPPORTED_VERSIONS = /v1(\.(0|1))*/
11
10
 
12
11
  requires :openstack_auth_url
@@ -15,7 +14,7 @@ module Fog
15
14
  :openstack_tenant, :openstack_tenant_id,
16
15
  :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
17
16
  :current_user, :current_tenant, :openstack_region,
18
- :openstack_endpoint_type,
17
+ :openstack_endpoint_type, :openstack_cache_ttl,
19
18
  :openstack_project_name, :openstack_project_id,
20
19
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
21
20
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
@@ -55,7 +54,7 @@ module Fog
55
54
  @data = nil
56
55
  end
57
56
 
58
- def initialize(options={})
57
+ def initialize(options = {})
59
58
  @openstack_username = options[:openstack_username]
60
59
  @openstack_tenant = options[:openstack_tenant]
61
60
  @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@@ -68,8 +67,8 @@ module Fog
68
67
  management_url.path = '/v1'
69
68
  @openstack_management_url = management_url.to_s
70
69
 
71
- @data ||= { :users => {} }
72
- unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
70
+ @data ||= {:users => {}}
71
+ unless @data[:users].detect { |u| u['name'] == options[:openstack_username] }
73
72
  id = Fog::Mock.random_numbers(6).to_s
74
73
  @data[:users][id] = {
75
74
  'id' => id,
@@ -90,11 +89,11 @@ module Fog
90
89
  end
91
90
 
92
91
  def credentials
93
- { :provider => 'openstack',
94
- :openstack_auth_url => @openstack_auth_uri.to_s,
95
- :openstack_auth_token => @auth_token,
96
- :openstack_region => @openstack_region,
97
- :openstack_management_url => @openstack_management_url }
92
+ {:provider => 'openstack',
93
+ :openstack_auth_url => @openstack_auth_uri.to_s,
94
+ :openstack_auth_token => @auth_token,
95
+ :openstack_region => @openstack_region,
96
+ :openstack_management_url => @openstack_management_url}
98
97
  end
99
98
  end
100
99
 
@@ -106,7 +105,7 @@ module Fog
106
105
  end
107
106
  include Fog::OpenStack::Common
108
107
 
109
- def initialize(options={})
108
+ def initialize(options = {})
110
109
  initialize_identity options
111
110
 
112
111
  @openstack_service_type = options[:openstack_service_type] || ['image']
@@ -117,30 +116,16 @@ module Fog
117
116
 
118
117
  authenticate
119
118
 
120
- process_path @openstack_management_uri
121
119
  unless @path.match(SUPPORTED_VERSIONS)
122
120
  @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
123
- @openstack_management_uri,
124
- @auth_token,
125
- @connection_options)
121
+ @openstack_management_uri,
122
+ @auth_token,
123
+ @connection_options)
126
124
  end
127
125
 
128
126
  @persistent = options[:persistent] || false
129
127
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
130
128
  end
131
-
132
- def process_path uri
133
- unless @path.match(SUPPORTED_VERSIONS)
134
- @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS,
135
- uri,
136
- @auth_token,
137
- @connection_options)
138
- end
139
- @path
140
- end
141
-
142
- private
143
-
144
129
  end
145
130
  end
146
131
  end
@@ -6,7 +6,6 @@ module Fog
6
6
  module Image
7
7
  class OpenStack
8
8
  class V2 < Fog::Service
9
-
10
9
  SUPPORTED_VERSIONS = /v2(\.(0|1|2|3))*/
11
10
 
12
11
  requires :openstack_auth_url
@@ -15,7 +14,7 @@ module Fog
15
14
  :openstack_tenant, :openstack_tenant_id,
16
15
  :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
17
16
  :current_user, :current_tenant, :openstack_region,
18
- :openstack_endpoint_type,
17
+ :openstack_endpoint_type, :openstack_cache_ttl,
19
18
  :openstack_project_name, :openstack_project_id,
20
19
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
21
20
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
@@ -61,7 +60,7 @@ module Fog
61
60
  @data = nil
62
61
  end
63
62
 
64
- def initialize(options={})
63
+ def initialize(options = {})
65
64
  @openstack_username = options[:openstack_username]
66
65
  @openstack_tenant = options[:openstack_tenant]
67
66
  @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@@ -74,8 +73,8 @@ module Fog
74
73
  management_url.path = '/v2'
75
74
  @openstack_management_url = management_url.to_s
76
75
 
77
- @data ||= { :users => {} }
78
- unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
76
+ @data ||= {:users => {}}
77
+ unless @data[:users].detect { |u| u['name'] == options[:openstack_username] }
79
78
  id = Fog::Mock.random_numbers(6).to_s
80
79
  @data[:users][id] = {
81
80
  'id' => id,
@@ -96,13 +95,15 @@ module Fog
96
95
  end
97
96
 
98
97
  def credentials
99
- { :provider => 'openstack',
100
- :openstack_auth_url => @openstack_auth_uri.to_s,
101
- :openstack_auth_token => @auth_token,
102
- :openstack_region => @openstack_region,
103
- :openstack_management_url => @openstack_management_url }
98
+ {:provider => 'openstack',
99
+ :openstack_auth_url => @openstack_auth_uri.to_s,
100
+ :openstack_auth_token => @auth_token,
101
+ :openstack_region => @openstack_region,
102
+ :openstack_management_url => @openstack_management_url}
104
103
  end
105
104
  end
105
+ class Upload # Exists for image_v2_upload_spec "describe"
106
+ end
106
107
 
107
108
  class Real
108
109
  include Fog::OpenStack::Core
@@ -111,7 +112,7 @@ module Fog
111
112
  end
112
113
  include Fog::OpenStack::Common
113
114
 
114
- def initialize(options={})
115
+ def initialize(options = {})
115
116
  initialize_identity options
116
117
 
117
118
  @openstack_service_type = options[:openstack_service_type] || ['image']
@@ -124,17 +125,14 @@ module Fog
124
125
 
125
126
  unless @path.match(SUPPORTED_VERSIONS)
126
127
  @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
127
- @openstack_management_uri,
128
- @auth_token,
129
- @connection_options)
128
+ @openstack_management_uri,
129
+ @auth_token,
130
+ @connection_options)
130
131
  end
131
132
 
132
133
  @persistent = options[:persistent] || false
133
134
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
134
135
  end
135
-
136
- private
137
-
138
136
  end
139
137
  end
140
138
  end
@@ -11,7 +11,7 @@ module Fog
11
11
  :openstack_tenant, :openstack_tenant_id,
12
12
  :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
13
13
  :current_user, :current_tenant, :openstack_region,
14
- :openstack_endpoint_type,
14
+ :openstack_endpoint_type, :openstack_cache_ttl,
15
15
  :openstack_project_name, :openstack_project_id,
16
16
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
17
17
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id
@@ -9,7 +9,7 @@ module Fog
9
9
  :openstack_tenant, :openstack_tenant_id,
10
10
  :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
11
11
  :current_user, :current_tenant, :openstack_region,
12
- :openstack_endpoint_type,
12
+ :openstack_endpoint_type, :openstack_cache_ttl,
13
13
  :openstack_project_name, :openstack_project_id,
14
14
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
15
15
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
@@ -34,7 +34,10 @@ module Fog
34
34
  def get(uuid)
35
35
  raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :get is not implemented')
36
36
  end
37
- alias_method :find_by_id, :get
37
+
38
+ def find_by_id(uuid)
39
+ get(uuid)
40
+ end
38
41
 
39
42
  # Destroys record given record's UUID
40
43
  def destroy(uuid)
@@ -7,7 +7,12 @@ module Fog
7
7
  identity :zoneName
8
8
 
9
9
  attribute :hosts
10
+ attribute :zoneLabel
10
11
  attribute :zoneState
12
+
13
+ def to_s
14
+ zoneName
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -20,29 +20,41 @@ module Fog
20
20
 
21
21
  def save
22
22
  requires :name, :ram, :vcpus, :disk
23
- attributes[:ephemeral] = self.ephemeral || 0
24
- attributes[:is_public] = self.is_public || false
25
- attributes[:disabled] = self.disabled || false
26
- attributes[:swap] = self.swap || 0
27
- attributes[:rxtx_factor] = self.rxtx_factor || 1.0
28
- merge_attributes(service.create_flavor(self.attributes).body['flavor'])
23
+ attributes[:ephemeral] = ephemeral || 0
24
+ attributes[:is_public] = is_public || false
25
+ attributes[:disabled] = disabled || false
26
+ attributes[:swap] = swap || 0
27
+ attributes[:rxtx_factor] = rxtx_factor || 1.0
28
+ merge_attributes(service.create_flavor(attributes).body['flavor'])
29
29
  self
30
30
  end
31
31
 
32
32
  def destroy
33
33
  requires :id
34
- service.delete_flavor(self.id)
34
+ service.delete_flavor(id)
35
35
  true
36
36
  end
37
37
 
38
38
  def metadata
39
- service.get_flavor_metadata(self.id).body['extra_specs']
39
+ service.get_flavor_metadata(id).body['extra_specs']
40
40
  rescue Fog::Compute::OpenStack::NotFound
41
41
  nil
42
42
  end
43
43
 
44
44
  def create_metadata(metadata)
45
- service.create_flavor_metadata(self.id, metadata)
45
+ service.create_flavor_metadata(id, metadata)
46
+ rescue Fog::Compute::OpenStack::NotFound
47
+ nil
48
+ end
49
+
50
+ def update_metadata(key, value)
51
+ service.update_flavor_metadata(id, key, value)
52
+ rescue Fog::Compute::OpenStack::NotFound
53
+ nil
54
+ end
55
+
56
+ def delete_metadata(key)
57
+ service.delete_flavor_metadata(id, key)
46
58
  rescue Fog::Compute::OpenStack::NotFound
47
59
  nil
48
60
  end
@@ -10,7 +10,7 @@ module Fog
10
10
 
11
11
  attribute :addresses
12
12
  attribute :flavor
13
- attribute :host_id, :aliases => 'hostId'
13
+ attribute :host_id, :aliases => 'hostId'
14
14
  attribute :image
15
15
  attribute :metadata
16
16
  attribute :links
@@ -18,7 +18,8 @@ module Fog
18
18
 
19
19
  # @!attribute [rw] personality
20
20
  # @note This attribute is only used for server creation. This field will be nil on subsequent retrievals.
21
- # @return [Hash] Hash containing data to inject into the file system of the cloud server instance during server creation.
21
+ # @return [Hash] Hash containing data to inject into the file system of the cloud server instance during
22
+ # server creation.
22
23
  # @example To inject fog.txt into file system
23
24
  # :personality => [{ :path => '/root/fog.txt',
24
25
  # :contents => Base64.encode64('Fog was here!')
@@ -52,11 +53,11 @@ module Fog
52
53
  attr_writer :image_ref, :flavor_ref, :nics, :os_scheduler_hints
53
54
  attr_accessor :block_device_mapping, :block_device_mapping_v2
54
55
 
55
- # In some cases it's handy to be able to store the project for the record, e.g. swift doesn't contain project info
56
- # in the result, so we can track it in this attribute based on what project was used in the request
56
+ # In some cases it's handy to be able to store the project for the record, e.g. swift doesn't contain project
57
+ # info in the result, so we can track it in this attribute based on what project was used in the request
57
58
  attr_accessor :project
58
59
 
59
- def initialize(attributes={})
60
+ def initialize(attributes = {})
60
61
  # Old 'connection' is renamed as service and should be used instead
61
62
  prepare_service_value(attributes)
62
63
 
@@ -73,17 +74,15 @@ module Fog
73
74
 
74
75
  def metadata
75
76
  @metadata ||= begin
76
- Fog::Compute::OpenStack::Metadata.new({
77
- :service => service,
78
- :parent => self
79
- })
77
+ Fog::Compute::OpenStack::Metadata.new(:service => service,
78
+ :parent => self)
80
79
  end
81
80
  end
82
81
 
83
- def metadata=(new_metadata={})
82
+ def metadata=(new_metadata = {})
84
83
  return unless new_metadata
85
84
  metas = []
86
- new_metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} }
85
+ new_metadata.each_pair { |k, v| metas << {"key" => k, "value" => v} }
87
86
  @metadata = metadata.load(metas)
88
87
  end
89
88
 
@@ -106,7 +105,7 @@ module Fog
106
105
  # currently openstack API does not tell us what is a floating ip vs a fixed ip for the vm listing,
107
106
  # we fall back to get all addresses and filter sadly.
108
107
  # Only includes manually-assigned addresses, not auto-assigned
109
- @all_addresses ||= service.list_all_addresses.body["floating_ips"].select{|data| data['instance_id'] == id}
108
+ @all_addresses ||= service.list_all_addresses.body["floating_ips"].select { |data| data['instance_id'] == id }
110
109
  end
111
110
 
112
111
  def reload
@@ -117,31 +116,38 @@ module Fog
117
116
  # returns all ip_addresses for a given instance
118
117
  # this includes both the fixed ip(s) and the floating ip(s)
119
118
  def ip_addresses
120
- addresses.values.flatten.map{|x| x['addr']}
119
+ addresses ? addresses.values.flatten.collect { |x| x['addr'] } : []
121
120
  end
122
121
 
123
122
  def floating_ip_addresses
124
- all_floating=addresses.values.flatten.select{ |data| data["OS-EXT-IPS:type"]=="floating" }.map{|addr| addr["addr"] }
123
+ all_floating = if addresses
124
+ flattened_values = addresses.values.flatten
125
+ flattened_values.select { |d| d["OS-EXT-IPS:type"] == "floating" }.collect { |a| a["addr"] }
126
+ else
127
+ []
128
+ end
125
129
 
126
130
  # Return them all, leading with manually assigned addresses
127
- manual = all_addresses.map{|addr| addr["ip"]}
131
+ manual = all_addresses.collect { |addr| addr["ip"] }
128
132
 
129
- all_floating.sort{ |a,b|
133
+ all_floating.sort do |a, b|
130
134
  a_manual = manual.include? a
131
135
  b_manual = manual.include? b
132
136
 
133
- if a_manual and !b_manual
137
+ if a_manual && !b_manual
134
138
  -1
135
- elsif !a_manual and b_manual
139
+ elsif !a_manual && b_manual
136
140
  1
137
- else 0 end
138
- }
141
+ else
142
+ 0
143
+ end
144
+ end
139
145
  all_floating.empty? ? manual : all_floating
140
146
  end
141
147
 
142
148
  def public_ip_addresses
143
149
  if floating_ip_addresses.empty?
144
- addresses.find_all{|s| s[0] =~ /public/i}.map{|a| a[1][0]['addr']}
150
+ addresses.select { |s| s[0] =~ /public/i }.collect { |a| a[1][0]['addr'] }
145
151
  else
146
152
  floating_ip_addresses
147
153
  end
@@ -158,35 +164,27 @@ module Fog
158
164
  def private_ip_addresses
159
165
  rfc1918_regexp = /(^10\.|^172\.1[6-9]\.|^172\.2[0-9]\.|^172.3[0-1]\.|^192\.168\.)/
160
166
  almost_private = ip_addresses - public_ip_addresses - floating_ip_addresses
161
- almost_private.find_all{ |ip| rfc1918_regexp.match ip }
167
+ almost_private.select { |ip| rfc1918_regexp.match ip }
162
168
  end
163
169
 
164
170
  def private_ip_address
165
171
  private_ip_addresses.first
166
172
  end
167
173
 
168
- def image_ref
169
- @image_ref
170
- end
174
+ attr_reader :image_ref
171
175
 
172
- def image_ref=(new_image_ref)
173
- @image_ref = new_image_ref
174
- end
176
+ attr_writer :image_ref
175
177
 
176
- def flavor_ref
177
- @flavor_ref
178
- end
178
+ attr_reader :flavor_ref
179
179
 
180
- def flavor_ref=(new_flavor_ref)
181
- @flavor_ref = new_flavor_ref
182
- end
180
+ attr_writer :flavor_ref
183
181
 
184
182
  def ready?
185
- self.state == 'ACTIVE'
183
+ state == 'ACTIVE'
186
184
  end
187
185
 
188
186
  def failed?
189
- self.state == 'ERROR'
187
+ state == 'ERROR'
190
188
  end
191
189
 
192
190
  def change_password(admin_password)
@@ -195,7 +193,7 @@ module Fog
195
193
  true
196
194
  end
197
195
 
198
- def rebuild(image_ref, name, admin_pass=nil, metadata=nil, personality=nil)
196
+ def rebuild(image_ref, name, admin_pass = nil, metadata = nil, personality = nil)
199
197
  requires :id
200
198
  service.rebuild_server(id, image_ref, name, admin_pass, metadata, personality)
201
199
  true
@@ -225,13 +223,11 @@ module Fog
225
223
  groups = service.list_security_groups(:server_id => id).body['security_groups']
226
224
 
227
225
  groups.map do |group|
228
- Fog::Compute::OpenStack::SecurityGroup.new group.merge({:service => service})
226
+ Fog::Compute::OpenStack::SecurityGroup.new group.merge(:service => service)
229
227
  end
230
228
  end
231
229
 
232
- def security_groups=(new_security_groups)
233
- @security_groups = new_security_groups
234
- end
230
+ attr_writer :security_groups
235
231
 
236
232
  def reboot(type = 'SOFT')
237
233
  requires :id
@@ -282,7 +278,7 @@ module Fog
282
278
  service.shelve_offload_server(id)
283
279
  end
284
280
 
285
- def create_image(name, metadata={})
281
+ def create_image(name, metadata = {})
286
282
  requires :id
287
283
  service.create_image(id, name, metadata)
288
284
  end
@@ -302,7 +298,7 @@ module Fog
302
298
  service.live_migrate_server(id, host, block_migration, disk_over_commit)
303
299
  end
304
300
 
305
- def evacuate(host = nil, on_shared_storage = true, admin_password = nil)
301
+ def evacuate(host = nil, on_shared_storage = nil, admin_password = nil)
306
302
  requires :id
307
303
  service.evacuate_server(id, host, on_shared_storage, admin_password)
308
304
  end
@@ -322,13 +318,9 @@ module Fog
322
318
  service.reset_server_state id, vm_state
323
319
  end
324
320
 
325
- def min_count=(new_min_count)
326
- @min_count = new_min_count
327
- end
321
+ attr_writer :min_count
328
322
 
329
- def max_count=(new_max_count)
330
- @max_count = new_max_count
331
- end
323
+ attr_writer :max_count
332
324
 
333
325
  def networks
334
326
  service.networks(:server => self)
@@ -359,27 +351,27 @@ module Fog
359
351
  end
360
352
 
361
353
  def save
362
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
354
+ raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted?
363
355
  requires :flavor_ref, :name
364
356
  requires_one :image_ref, :block_device_mapping, :block_device_mapping_v2
365
357
  options = {
366
- 'personality' => personality,
367
- 'accessIPv4' => accessIPv4,
368
- 'accessIPv6' => accessIPv6,
369
- 'availability_zone' => availability_zone,
370
- 'user_data' => user_data_encoded,
371
- 'key_name' => key_name,
372
- 'config_drive' => config_drive,
373
- 'security_groups' => @security_groups,
374
- 'min_count' => @min_count,
375
- 'max_count' => @max_count,
376
- 'nics' => @nics,
377
- 'os:scheduler_hints' => @os_scheduler_hints,
378
- 'block_device_mapping' => @block_device_mapping,
358
+ 'personality' => personality,
359
+ 'accessIPv4' => accessIPv4,
360
+ 'accessIPv6' => accessIPv6,
361
+ 'availability_zone' => availability_zone,
362
+ 'user_data' => user_data_encoded,
363
+ 'key_name' => key_name,
364
+ 'config_drive' => config_drive,
365
+ 'security_groups' => @security_groups,
366
+ 'min_count' => @min_count,
367
+ 'max_count' => @max_count,
368
+ 'nics' => @nics,
369
+ 'os:scheduler_hints' => @os_scheduler_hints,
370
+ 'block_device_mapping' => @block_device_mapping,
379
371
  'block_device_mapping_v2' => @block_device_mapping_v2,
380
372
  }
381
373
  options['metadata'] = metadata.to_hash unless @metadata.nil?
382
- options = options.reject {|key, value| value.nil?}
374
+ options = options.reject { |_key, value| value.nil? }
383
375
  data = service.create_server(name, image_ref, flavor_ref, options)
384
376
  merge_attributes(data.body['server'])
385
377
  true
@@ -387,23 +379,18 @@ module Fog
387
379
 
388
380
  def setup(credentials = {})
389
381
  requires :ssh_ip_address, :identity, :public_key, :username
390
- Fog::SSH.new(ssh_ip_address, username, credentials).run([
391
- %{mkdir .ssh},
392
- %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
393
- %{passwd -l #{username}},
394
- %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
395
- %{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
396
- ])
382
+ ssh = Fog::SSH.new(ssh_ip_address, username, credentials)
383
+ ssh.run([
384
+ %(mkdir .ssh),
385
+ %(echo "#{public_key}" >> ~/.ssh/authorized_keys),
386
+ %(passwd -l #{username}),
387
+ %(echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json),
388
+ %(echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json)
389
+ ])
397
390
  rescue Errno::ECONNREFUSED
398
391
  sleep(1)
399
392
  retry
400
393
  end
401
-
402
- private
403
-
404
- def adminPass=(new_admin_pass)
405
- @password = new_admin_pass
406
- end
407
394
  end
408
395
  end
409
396
  end