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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +6 -2
- data/README.md +4 -0
- data/Rakefile +10 -2
- data/fog-openstack.gemspec +2 -3
- data/gemfiles/Gemfile-1.9 +1 -1
- data/lib/fog/openstack.rb +14 -6
- data/lib/fog/openstack/baremetal.rb +1 -1
- data/lib/fog/openstack/common.rb +0 -2
- data/lib/fog/openstack/compute.rb +78 -75
- data/lib/fog/openstack/core.rb +2 -1
- data/lib/fog/openstack/docs/compute.md +1 -1
- data/lib/fog/openstack/docs/network.md +283 -0
- data/lib/fog/openstack/docs/nfv.md +144 -0
- data/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb +4 -4
- data/lib/fog/openstack/examples/network/network_add_port.rb +21 -0
- data/lib/fog/openstack/examples/network/network_rbac.rb +69 -0
- data/lib/fog/openstack/identity.rb +14 -22
- data/lib/fog/openstack/identity_v2.rb +1 -1
- data/lib/fog/openstack/image_v1.rb +13 -28
- data/lib/fog/openstack/image_v2.rb +15 -17
- data/lib/fog/openstack/introspection.rb +1 -1
- data/lib/fog/openstack/metering.rb +1 -1
- data/lib/fog/openstack/models/collection.rb +4 -1
- data/lib/fog/openstack/models/compute/availability_zone.rb +5 -0
- data/lib/fog/openstack/models/compute/flavor.rb +21 -9
- data/lib/fog/openstack/models/compute/server.rb +64 -77
- data/lib/fog/openstack/models/compute/snapshot.rb +6 -6
- data/lib/fog/openstack/models/compute/volume_attachment.rb +15 -0
- data/lib/fog/openstack/models/compute/volume_attachments.rb +20 -0
- data/lib/fog/openstack/models/identity_v3/projects.rb +1 -1
- data/lib/fog/openstack/models/identity_v3/users.rb +2 -2
- data/lib/fog/openstack/models/image_v2/image.rb +41 -22
- data/lib/fog/openstack/models/network/floating_ip.rb +1 -0
- data/lib/fog/openstack/models/network/rbac_policies.rb +33 -0
- data/lib/fog/openstack/models/network/rbac_policy.rb +35 -0
- data/lib/fog/openstack/models/nfv/vnf.rb +58 -0
- data/lib/fog/openstack/models/nfv/vnfd.rb +53 -0
- data/lib/fog/openstack/models/nfv/vnfds.rb +28 -0
- data/lib/fog/openstack/models/nfv/vnfs.rb +28 -0
- data/lib/fog/openstack/models/volume/snapshot.rb +38 -0
- data/lib/fog/openstack/models/volume/snapshots.rb +26 -0
- data/lib/fog/openstack/models/volume/volume.rb +32 -2
- data/lib/fog/openstack/models/volume/volume_type.rb +3 -4
- data/lib/fog/openstack/models/volume_v1/snapshot.rb +43 -0
- data/lib/fog/openstack/models/volume_v1/snapshots.rb +16 -0
- data/lib/fog/openstack/models/volume_v1/volume.rb +12 -2
- data/lib/fog/openstack/models/volume_v2/snapshot.rb +43 -0
- data/lib/fog/openstack/models/volume_v2/snapshots.rb +16 -0
- data/lib/fog/openstack/models/volume_v2/volume.rb +12 -3
- data/lib/fog/openstack/network.rb +53 -46
- data/lib/fog/openstack/nfv.rb +158 -0
- data/lib/fog/openstack/orchestration.rb +1 -1
- data/lib/fog/openstack/planning.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_server.rb +1 -1
- data/lib/fog/openstack/requests/compute/{create_volume_snapshot.rb → create_snapshot.rb} +16 -16
- data/lib/fog/openstack/requests/compute/delete_flavor_metadata.rb +30 -0
- data/lib/fog/openstack/requests/compute/evacuate_server.rb +8 -7
- data/lib/fog/openstack/requests/compute/get_key_pair.rb +49 -0
- data/lib/fog/openstack/requests/compute/list_availability_zones.rb +23 -0
- data/lib/fog/openstack/requests/compute/list_volume_attachments.rb +31 -0
- data/lib/fog/openstack/requests/compute/update_flavor_metadata.rb +33 -0
- data/lib/fog/openstack/requests/network/create_rbac_policy.rb +42 -0
- data/lib/fog/openstack/requests/network/delete_rbac_policy.rb +28 -0
- data/lib/fog/openstack/requests/network/get_rbac_policy.rb +28 -0
- data/lib/fog/openstack/requests/network/list_rbac_policies.rb +25 -0
- data/lib/fog/openstack/requests/network/update_port.rb +8 -7
- data/lib/fog/openstack/requests/network/update_rbac_policy.rb +41 -0
- data/lib/fog/openstack/requests/nfv/create_vnf.rb +37 -0
- data/lib/fog/openstack/requests/nfv/create_vnfd.rb +35 -0
- data/lib/fog/openstack/requests/nfv/delete_vnf.rb +23 -0
- data/lib/fog/openstack/requests/nfv/delete_vnfd.rb +23 -0
- data/lib/fog/openstack/requests/nfv/get_vnf.rb +24 -0
- data/lib/fog/openstack/requests/nfv/get_vnfd.rb +24 -0
- data/lib/fog/openstack/requests/nfv/list_vnfds.rb +25 -0
- data/lib/fog/openstack/requests/nfv/list_vnfs.rb +25 -0
- data/lib/fog/openstack/requests/nfv/update_vnf.rb +35 -0
- data/lib/fog/openstack/requests/volume/action.rb +16 -0
- data/lib/fog/openstack/requests/volume/create_snapshot.rb +18 -0
- data/lib/fog/openstack/requests/volume/delete_metadata.rb +15 -0
- data/lib/fog/openstack/requests/volume/delete_snapshot.rb +5 -5
- data/lib/fog/openstack/requests/volume/delete_snapshot_metadata.rb +15 -0
- data/lib/fog/openstack/requests/volume/replace_metadata.rb +20 -0
- data/lib/fog/openstack/requests/volume/update_metadata.rb +20 -0
- data/lib/fog/openstack/requests/volume/update_snapshot.rb +37 -0
- data/lib/fog/openstack/requests/volume/update_snapshot_metadata.rb +20 -0
- data/lib/fog/openstack/requests/volume/update_volume.rb +25 -0
- data/lib/fog/openstack/requests/volume_v1/action.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/create_snapshot.rb +45 -0
- data/lib/fog/openstack/requests/volume_v1/delete_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/delete_snapshot_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/replace_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/update_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/update_snapshot.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/update_snapshot_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v1/update_volume.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/action.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/create_snapshot.rb +45 -0
- data/lib/fog/openstack/requests/volume_v2/delete_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/delete_snapshot_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/replace_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/update_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/update_snapshot.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/update_snapshot_metadata.rb +2 -0
- data/lib/fog/openstack/requests/volume_v2/update_volume.rb +2 -0
- data/lib/fog/openstack/storage.rb +1 -1
- data/lib/fog/openstack/version.rb +1 -1
- data/lib/fog/openstack/volume.rb +1 -1
- data/lib/fog/openstack/volume_v1.rb +29 -21
- data/lib/fog/openstack/volume_v2.rb +29 -21
- data/supported.md +54 -0
- data/tests/openstack/models/identity/ec2_credential_tests.rb +1 -1
- data/tests/openstack/models/identity/ec2_credentials_tests.rb +1 -1
- data/tests/openstack/models/identity/role_tests.rb +8 -3
- data/tests/openstack/models/identity/roles_tests.rb +5 -4
- data/tests/openstack/models/identity/tenant_tests.rb +7 -4
- data/tests/openstack/models/identity/tenants_tests.rb +10 -5
- data/tests/openstack/models/identity/user_tests.rb +4 -3
- data/tests/openstack/models/identity/users_tests.rb +10 -6
- data/tests/openstack/models/nfv/vnf_tests.rb +35 -0
- data/tests/openstack/models/nfv/vnfd_tests.rb +23 -0
- data/tests/openstack/models/nfv/vnfds_tests.rb +31 -0
- data/tests/openstack/models/nfv/vnfs_tests.rb +38 -0
- data/tests/openstack/requests/identity/ec2_credentials_tests.rb +6 -9
- data/tests/openstack/requests/identity/helper.rb +12 -4
- data/tests/openstack/requests/identity/role_tests.rb +13 -10
- data/tests/openstack/requests/identity/tenant_tests.rb +10 -9
- data/tests/openstack/requests/identity/user_tests.rb +11 -6
- data/tests/openstack/requests/image/image_tests.rb +1 -0
- data/tests/openstack/requests/nfv/vnf_tests.rb +70 -0
- data/tests/openstack/requests/nfv/vnfd_tests.rb +44 -0
- metadata +81 -31
- data/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +0 -26
- data/lib/fog/openstack/requests/volume_v1/create_volume_snapshot.rb +0 -44
- data/lib/fog/openstack/requests/volume_v2/create_volume_snapshot.rb +0 -43
- data/tests/openstack/authenticate_tests.rb +0 -200
- data/tests/openstack/identity_version_tests.rb +0 -25
- data/tests/openstack/storage_tests.rb +0 -18
- data/tests/openstack/version_tests.rb +0 -55
- 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::
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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 ||= {
|
72
|
-
unless @data[:users].
|
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
|
-
{
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
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 ||= {
|
78
|
-
unless @data[:users].
|
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
|
-
{
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
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)
|
@@ -20,29 +20,41 @@ module Fog
|
|
20
20
|
|
21
21
|
def save
|
22
22
|
requires :name, :ram, :vcpus, :disk
|
23
|
-
attributes[:ephemeral] =
|
24
|
-
attributes[:is_public] =
|
25
|
-
attributes[:disabled] =
|
26
|
-
attributes[:swap] =
|
27
|
-
attributes[:rxtx_factor] =
|
28
|
-
merge_attributes(service.create_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(
|
34
|
+
service.delete_flavor(id)
|
35
35
|
true
|
36
36
|
end
|
37
37
|
|
38
38
|
def metadata
|
39
|
-
service.get_flavor_metadata(
|
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(
|
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,
|
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
|
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
|
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
|
-
|
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.
|
119
|
+
addresses ? addresses.values.flatten.collect { |x| x['addr'] } : []
|
121
120
|
end
|
122
121
|
|
123
122
|
def floating_ip_addresses
|
124
|
-
all_floating=
|
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.
|
131
|
+
manual = all_addresses.collect { |addr| addr["ip"] }
|
128
132
|
|
129
|
-
all_floating.sort
|
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
|
137
|
+
if a_manual && !b_manual
|
134
138
|
-1
|
135
|
-
elsif !a_manual
|
139
|
+
elsif !a_manual && b_manual
|
136
140
|
1
|
137
|
-
else
|
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.
|
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.
|
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
|
-
|
169
|
-
@image_ref
|
170
|
-
end
|
174
|
+
attr_reader :image_ref
|
171
175
|
|
172
|
-
|
173
|
-
@image_ref = new_image_ref
|
174
|
-
end
|
176
|
+
attr_writer :image_ref
|
175
177
|
|
176
|
-
|
177
|
-
@flavor_ref
|
178
|
-
end
|
178
|
+
attr_reader :flavor_ref
|
179
179
|
|
180
|
-
|
181
|
-
@flavor_ref = new_flavor_ref
|
182
|
-
end
|
180
|
+
attr_writer :flavor_ref
|
183
181
|
|
184
182
|
def ready?
|
185
|
-
|
183
|
+
state == 'ACTIVE'
|
186
184
|
end
|
187
185
|
|
188
186
|
def failed?
|
189
|
-
|
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(
|
226
|
+
Fog::Compute::OpenStack::SecurityGroup.new group.merge(:service => service)
|
229
227
|
end
|
230
228
|
end
|
231
229
|
|
232
|
-
|
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 =
|
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
|
-
|
326
|
-
@min_count = new_min_count
|
327
|
-
end
|
321
|
+
attr_writer :min_count
|
328
322
|
|
329
|
-
|
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
|
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'
|
367
|
-
'accessIPv4'
|
368
|
-
'accessIPv6'
|
369
|
-
'availability_zone'
|
370
|
-
'user_data'
|
371
|
-
'key_name'
|
372
|
-
'config_drive'
|
373
|
-
'security_groups'
|
374
|
-
'min_count'
|
375
|
-
'max_count'
|
376
|
-
'nics'
|
377
|
-
'os:scheduler_hints'
|
378
|
-
'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 {|
|
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)
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
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
|