vagrant-openstack-illuin-provider 0.12.0
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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rubocop.yml +40 -0
- data/CHANGELOG.md +282 -0
- data/Gemfile +18 -0
- data/RELEASE.md +15 -0
- data/Rakefile +25 -0
- data/Vagrantfile +20 -0
- data/dummy.box +0 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/functional_tests/Vagrantfile +58 -0
- data/functional_tests/keys/vagrant-openstack +27 -0
- data/functional_tests/keys/vagrant-openstack.pub +1 -0
- data/functional_tests/run_tests.sh +142 -0
- data/lib/vagrant-openstack-illuin-provider.rb +29 -0
- data/lib/vagrant-openstack-illuin-provider/action.rb +344 -0
- data/lib/vagrant-openstack-illuin-provider/action/abstract_action.rb +22 -0
- data/lib/vagrant-openstack-illuin-provider/action/connect_openstack.rb +60 -0
- data/lib/vagrant-openstack-illuin-provider/action/create_server.rb +187 -0
- data/lib/vagrant-openstack-illuin-provider/action/create_stack.rb +76 -0
- data/lib/vagrant-openstack-illuin-provider/action/delete_server.rb +53 -0
- data/lib/vagrant-openstack-illuin-provider/action/delete_stack.rb +73 -0
- data/lib/vagrant-openstack-illuin-provider/action/message.rb +19 -0
- data/lib/vagrant-openstack-illuin-provider/action/provision.rb +60 -0
- data/lib/vagrant-openstack-illuin-provider/action/read_ssh_info.rb +74 -0
- data/lib/vagrant-openstack-illuin-provider/action/read_state.rb +43 -0
- data/lib/vagrant-openstack-illuin-provider/action/resume.rb +24 -0
- data/lib/vagrant-openstack-illuin-provider/action/snapshot_cleanup.rb +32 -0
- data/lib/vagrant-openstack-illuin-provider/action/snapshot_delete.rb +32 -0
- data/lib/vagrant-openstack-illuin-provider/action/snapshot_list.rb +22 -0
- data/lib/vagrant-openstack-illuin-provider/action/snapshot_restore.rb +29 -0
- data/lib/vagrant-openstack-illuin-provider/action/snapshot_save.rb +51 -0
- data/lib/vagrant-openstack-illuin-provider/action/start_server.rb +24 -0
- data/lib/vagrant-openstack-illuin-provider/action/stop_server.rb +25 -0
- data/lib/vagrant-openstack-illuin-provider/action/suspend.rb +24 -0
- data/lib/vagrant-openstack-illuin-provider/action/sync_folders.rb +138 -0
- data/lib/vagrant-openstack-illuin-provider/action/wait_active.rb +33 -0
- data/lib/vagrant-openstack-illuin-provider/action/wait_stop.rb +33 -0
- data/lib/vagrant-openstack-illuin-provider/cap/snapshot_list.rb +15 -0
- data/lib/vagrant-openstack-illuin-provider/catalog/openstack_catalog.rb +90 -0
- data/lib/vagrant-openstack-illuin-provider/client/cinder.rb +39 -0
- data/lib/vagrant-openstack-illuin-provider/client/domain.rb +163 -0
- data/lib/vagrant-openstack-illuin-provider/client/glance.rb +65 -0
- data/lib/vagrant-openstack-illuin-provider/client/heat.rb +49 -0
- data/lib/vagrant-openstack-illuin-provider/client/http_utils.rb +116 -0
- data/lib/vagrant-openstack-illuin-provider/client/keystone.rb +128 -0
- data/lib/vagrant-openstack-illuin-provider/client/neutron.rb +48 -0
- data/lib/vagrant-openstack-illuin-provider/client/nova.rb +303 -0
- data/lib/vagrant-openstack-illuin-provider/client/openstack.rb +59 -0
- data/lib/vagrant-openstack-illuin-provider/client/request_logger.rb +23 -0
- data/lib/vagrant-openstack-illuin-provider/client/rest_utils.rb +28 -0
- data/lib/vagrant-openstack-illuin-provider/command/abstract_command.rb +51 -0
- data/lib/vagrant-openstack-illuin-provider/command/flavor_list.rb +24 -0
- data/lib/vagrant-openstack-illuin-provider/command/floatingip_list.rb +32 -0
- data/lib/vagrant-openstack-illuin-provider/command/image_list.rb +29 -0
- data/lib/vagrant-openstack-illuin-provider/command/main.rb +52 -0
- data/lib/vagrant-openstack-illuin-provider/command/network_list.rb +25 -0
- data/lib/vagrant-openstack-illuin-provider/command/openstack_command.rb +16 -0
- data/lib/vagrant-openstack-illuin-provider/command/reset.rb +20 -0
- data/lib/vagrant-openstack-illuin-provider/command/subnet_list.rb +22 -0
- data/lib/vagrant-openstack-illuin-provider/command/utils.rb +22 -0
- data/lib/vagrant-openstack-illuin-provider/command/volume_list.rb +25 -0
- data/lib/vagrant-openstack-illuin-provider/config.rb +505 -0
- data/lib/vagrant-openstack-illuin-provider/config/http.rb +39 -0
- data/lib/vagrant-openstack-illuin-provider/config_resolver.rb +334 -0
- data/lib/vagrant-openstack-illuin-provider/errors.rb +187 -0
- data/lib/vagrant-openstack-illuin-provider/logging.rb +39 -0
- data/lib/vagrant-openstack-illuin-provider/plugin.rb +58 -0
- data/lib/vagrant-openstack-illuin-provider/provider.rb +50 -0
- data/lib/vagrant-openstack-illuin-provider/utils.rb +81 -0
- data/lib/vagrant-openstack-illuin-provider/version.rb +15 -0
- data/lib/vagrant-openstack-illuin-provider/version_checker.rb +76 -0
- data/locales/en.yml +412 -0
- data/spec/vagrant-openstack-illuin-provider/action/connect_openstack_spec.rb +770 -0
- data/spec/vagrant-openstack-illuin-provider/action/create_server_spec.rb +260 -0
- data/spec/vagrant-openstack-illuin-provider/action/create_stack_spec.rb +99 -0
- data/spec/vagrant-openstack-illuin-provider/action/delete_server_spec.rb +89 -0
- data/spec/vagrant-openstack-illuin-provider/action/delete_stack_spec.rb +63 -0
- data/spec/vagrant-openstack-illuin-provider/action/message_spec.rb +33 -0
- data/spec/vagrant-openstack-illuin-provider/action/provision_spec.rb +97 -0
- data/spec/vagrant-openstack-illuin-provider/action/read_ssh_info_spec.rb +202 -0
- data/spec/vagrant-openstack-illuin-provider/action/read_state_spec.rb +81 -0
- data/spec/vagrant-openstack-illuin-provider/action/resume_server_spec.rb +49 -0
- data/spec/vagrant-openstack-illuin-provider/action/start_server_spec.rb +49 -0
- data/spec/vagrant-openstack-illuin-provider/action/stop_server_spec.rb +49 -0
- data/spec/vagrant-openstack-illuin-provider/action/suspend_server_spec.rb +49 -0
- data/spec/vagrant-openstack-illuin-provider/action/sync_folders_spec.rb +155 -0
- data/spec/vagrant-openstack-illuin-provider/action/wait_active_spec.rb +53 -0
- data/spec/vagrant-openstack-illuin-provider/action/wait_stop_spec.rb +53 -0
- data/spec/vagrant-openstack-illuin-provider/action_spec.rb +120 -0
- data/spec/vagrant-openstack-illuin-provider/client/cinder_spec.rb +129 -0
- data/spec/vagrant-openstack-illuin-provider/client/glance_spec.rb +145 -0
- data/spec/vagrant-openstack-illuin-provider/client/heat_spec.rb +130 -0
- data/spec/vagrant-openstack-illuin-provider/client/keystone_spec.rb +226 -0
- data/spec/vagrant-openstack-illuin-provider/client/neutron_spec.rb +173 -0
- data/spec/vagrant-openstack-illuin-provider/client/nova_spec.rb +760 -0
- data/spec/vagrant-openstack-illuin-provider/client/utils_spec.rb +176 -0
- data/spec/vagrant-openstack-illuin-provider/command/flavor_list_spec.rb +43 -0
- data/spec/vagrant-openstack-illuin-provider/command/floatingip_list_spec.rb +74 -0
- data/spec/vagrant-openstack-illuin-provider/command/image_list_spec.rb +95 -0
- data/spec/vagrant-openstack-illuin-provider/command/network_list_spec.rb +65 -0
- data/spec/vagrant-openstack-illuin-provider/command/reset_spec.rb +24 -0
- data/spec/vagrant-openstack-illuin-provider/command/subnet_list_spec.rb +45 -0
- data/spec/vagrant-openstack-illuin-provider/command/volume_list_spec.rb +40 -0
- data/spec/vagrant-openstack-illuin-provider/config_resolver_spec.rb +879 -0
- data/spec/vagrant-openstack-illuin-provider/config_spec.rb +416 -0
- data/spec/vagrant-openstack-illuin-provider/e2e_spec.rb.save +27 -0
- data/spec/vagrant-openstack-illuin-provider/provider_spec.rb +13 -0
- data/spec/vagrant-openstack-illuin-provider/spec_helper.rb +37 -0
- data/spec/vagrant-openstack-illuin-provider/utils_spec.rb +197 -0
- data/spec/vagrant-openstack-illuin-provider/version_checker_spec.rb +39 -0
- data/stackrc +25 -0
- data/vagrant-openstack-illuin-provider.gemspec +35 -0
- metadata +379 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module Openstack
|
|
3
|
+
class HttpConfig
|
|
4
|
+
UNSET_VALUE = Vagrant.plugin('2', :config).const_get(:UNSET_VALUE)
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# @return [Integer]
|
|
8
|
+
attr_accessor :open_timeout
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# @return [Integer]
|
|
12
|
+
attr_accessor :read_timeout
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@open_timeout = UNSET_VALUE
|
|
16
|
+
@read_timeout = UNSET_VALUE
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def finalize!
|
|
20
|
+
@open_timeout = 60 if @open_timeout == UNSET_VALUE
|
|
21
|
+
@read_timeout = 30 if @read_timeout == UNSET_VALUE
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def merge(other)
|
|
25
|
+
result = self.class.new
|
|
26
|
+
|
|
27
|
+
[self, other].each do |obj|
|
|
28
|
+
obj.instance_variables.each do |key|
|
|
29
|
+
next if key.to_s.start_with?('@__')
|
|
30
|
+
|
|
31
|
+
value = obj.instance_variable_get(key)
|
|
32
|
+
result.instance_variable_set(key, value) if value != UNSET_VALUE
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
result
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module Openstack
|
|
3
|
+
class ConfigResolver
|
|
4
|
+
def initialize
|
|
5
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::config_resolver')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def resolve_ssh_port(env)
|
|
9
|
+
machine_config = env[:machine].config
|
|
10
|
+
return machine_config.ssh.port if machine_config.ssh.port
|
|
11
|
+
22
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def resolve_flavor(env)
|
|
15
|
+
@logger.info 'Resolving flavor'
|
|
16
|
+
config = env[:machine].provider_config
|
|
17
|
+
nova = env[:openstack_client].nova
|
|
18
|
+
env[:ui].info(I18n.t('vagrant_openstack.finding_flavor'))
|
|
19
|
+
flavors = nova.get_all_flavors(env)
|
|
20
|
+
@logger.info "Finding flavor matching name '#{config.flavor}'"
|
|
21
|
+
flavor = find_matching(flavors, config.flavor)
|
|
22
|
+
fail Errors::NoMatchingFlavor unless flavor
|
|
23
|
+
flavor
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def resolve_image(env)
|
|
27
|
+
@logger.info 'Resolving image'
|
|
28
|
+
resolve_image_internal(env, env[:machine].provider_config.image)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def resolve_volume_boot_image(env)
|
|
32
|
+
@logger.info 'Resolving image to create a volume from'
|
|
33
|
+
resolve_image_internal(env, env[:machine].provider_config.volume_boot[:image])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def resolve_floating_ip(env)
|
|
37
|
+
config = env[:machine].provider_config
|
|
38
|
+
nova = env[:openstack_client].nova
|
|
39
|
+
return config.floating_ip if config.floating_ip
|
|
40
|
+
|
|
41
|
+
fail Errors::UnableToResolveFloatingIP if config.floating_ip_pool.nil? || config.floating_ip_pool.empty?
|
|
42
|
+
|
|
43
|
+
@logger.debug 'Searching for available ips'
|
|
44
|
+
free_ip = search_free_ip(config, nova, env)
|
|
45
|
+
config.floating_ip = free_ip
|
|
46
|
+
return free_ip unless free_ip.nil?
|
|
47
|
+
|
|
48
|
+
@logger.debug 'Allocate new ip anyway'
|
|
49
|
+
allocated_ip = allocate_ip(config, nova, env)
|
|
50
|
+
config.floating_ip = allocated_ip
|
|
51
|
+
return allocated_ip unless allocated_ip.nil?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def resolve_keypair(env)
|
|
55
|
+
config = env[:machine].provider_config
|
|
56
|
+
machine_config = env[:machine].config
|
|
57
|
+
nova = env[:openstack_client].nova
|
|
58
|
+
return nil unless machine_config.ssh.insert_key
|
|
59
|
+
return config.keypair_name if config.keypair_name
|
|
60
|
+
return nova.import_keypair_from_file(env, config.public_key_path) if config.public_key_path
|
|
61
|
+
generate_keypair(env)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def resolve_networks(env)
|
|
65
|
+
@logger.info 'Resolving network(s)'
|
|
66
|
+
config = env[:machine].provider_config
|
|
67
|
+
return [] if config.networks.nil? || config.networks.empty?
|
|
68
|
+
env[:ui].info(I18n.t('vagrant_openstack.finding_networks'))
|
|
69
|
+
return resolve_networks_without_network_service(env) unless env[:openstack_client].session.endpoints.key? :network
|
|
70
|
+
|
|
71
|
+
all_networks = env[:openstack_client].neutron.get_all_networks(env)
|
|
72
|
+
all_network_ids = all_networks.map(&:id)
|
|
73
|
+
|
|
74
|
+
networks = []
|
|
75
|
+
config.networks.each do |network|
|
|
76
|
+
networks << resolve_network(network, all_networks, all_network_ids)
|
|
77
|
+
end
|
|
78
|
+
@logger.debug("Resolved networks : #{networks.to_json}")
|
|
79
|
+
networks
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def resolve_volume_boot(env)
|
|
83
|
+
config = env[:machine].provider_config
|
|
84
|
+
return nil if config.volume_boot.nil?
|
|
85
|
+
return resolve_volume_without_volume_service(env, config.volume_boot, 'vda') unless env[:openstack_client].session.endpoints.key? :volume
|
|
86
|
+
|
|
87
|
+
volume_list = env[:openstack_client].cinder.get_all_volumes(env)
|
|
88
|
+
volume_ids = volume_list.map(&:id)
|
|
89
|
+
|
|
90
|
+
@logger.debug(volume_list)
|
|
91
|
+
|
|
92
|
+
volume = resolve_volume(config.volume_boot, volume_list, volume_ids)
|
|
93
|
+
|
|
94
|
+
device = (volume[:device].nil?) ? 'vda' : volume[:device]
|
|
95
|
+
size = (volume[:size].nil?) ? nil : volume[:size]
|
|
96
|
+
delete_on_destroy = (volume[:delete_on_destroy].nil?) ? nil : volume[:delete_on_destroy]
|
|
97
|
+
|
|
98
|
+
image = resolve_volume_boot_image(env) unless volume[:image].nil?
|
|
99
|
+
image_id = (image.nil?) ? nil : image.id
|
|
100
|
+
if image.nil?
|
|
101
|
+
return { id: volume[:id], device: device }
|
|
102
|
+
else
|
|
103
|
+
{ image: image_id, device: device, size: size, delete_on_destroy: delete_on_destroy }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def resolve_volumes(env)
|
|
108
|
+
@logger.info 'Resolving volume(s)'
|
|
109
|
+
config = env[:machine].provider_config
|
|
110
|
+
return [] if config.volumes.nil? || config.volumes.empty?
|
|
111
|
+
env[:ui].info(I18n.t('vagrant_openstack.finding_volumes'))
|
|
112
|
+
return resolve_volumes_without_volume_service(env) unless env[:openstack_client].session.endpoints.key? :volume
|
|
113
|
+
|
|
114
|
+
volume_list = env[:openstack_client].cinder.get_all_volumes(env)
|
|
115
|
+
volume_ids = volume_list.map(&:id)
|
|
116
|
+
|
|
117
|
+
@logger.debug(volume_list)
|
|
118
|
+
|
|
119
|
+
volumes = []
|
|
120
|
+
config.volumes.each do |volume|
|
|
121
|
+
volumes << resolve_volume(volume, volume_list, volume_ids)
|
|
122
|
+
end
|
|
123
|
+
@logger.debug("Resolved volumes : #{volumes.to_json}")
|
|
124
|
+
volumes
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def resolve_ssh_username(env)
|
|
128
|
+
config = env[:machine].provider_config
|
|
129
|
+
machine_config = env[:machine].config
|
|
130
|
+
return machine_config.ssh.username if machine_config.ssh.username
|
|
131
|
+
return config.ssh_username if config.ssh_username
|
|
132
|
+
fail Errors::NoMatchingSshUsername
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def resolve_security_groups(env)
|
|
136
|
+
groups = []
|
|
137
|
+
env[:machine].provider_config.security_groups.each do |group|
|
|
138
|
+
case group
|
|
139
|
+
when String
|
|
140
|
+
groups << { name: group }
|
|
141
|
+
when Hash
|
|
142
|
+
groups << group
|
|
143
|
+
end
|
|
144
|
+
end unless env[:machine].provider_config.security_groups.nil?
|
|
145
|
+
groups
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
private
|
|
149
|
+
|
|
150
|
+
def resolve_image_internal(env, image_name)
|
|
151
|
+
return nil if image_name.nil?
|
|
152
|
+
|
|
153
|
+
nova = env[:openstack_client].nova
|
|
154
|
+
env[:ui].info(I18n.t('vagrant_openstack.finding_image'))
|
|
155
|
+
images = nova.get_all_images(env)
|
|
156
|
+
image = find_matching(images, image_name)
|
|
157
|
+
fail Errors::NoMatchingImage unless image
|
|
158
|
+
image
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def search_free_ip(config, nova, env)
|
|
162
|
+
@logger.debug 'Retrieving all allocated floating ips on tenant'
|
|
163
|
+
all_floating_ips = nova.get_all_floating_ips(env)
|
|
164
|
+
all_floating_ips.each do |floating_ip|
|
|
165
|
+
log_attach = floating_ip.instance_id ? "attached to #{floating_ip.instance_id}" : 'not attached'
|
|
166
|
+
@logger.debug "#{floating_ip.ip} #{log_attach}" if config.floating_ip_pool.include? floating_ip.pool
|
|
167
|
+
return floating_ip.ip if (config.floating_ip_pool.include? floating_ip.pool) && floating_ip.instance_id.nil?
|
|
168
|
+
end unless config.floating_ip_pool_always_allocate
|
|
169
|
+
@logger.debug 'No free ip found'
|
|
170
|
+
nil
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def allocate_ip(config, nova, env)
|
|
174
|
+
allocation_error = nil
|
|
175
|
+
config.floating_ip_pool.each do |floating_ip_pool|
|
|
176
|
+
begin
|
|
177
|
+
@logger.debug "Allocating ip in pool #{floating_ip_pool}"
|
|
178
|
+
return nova.allocate_floating_ip(env, floating_ip_pool).ip
|
|
179
|
+
rescue Errors::VagrantOpenstackError => e
|
|
180
|
+
@logger.warn "Error allocating ip in pool #{floating_ip_pool} : #{e}"
|
|
181
|
+
allocation_error = e
|
|
182
|
+
next if e.extra_data[:code] == 404
|
|
183
|
+
raise allocation_error
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
@logger.warn 'Impossible to allocate a new IP'
|
|
187
|
+
fail allocation_error
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def generate_keypair(env)
|
|
191
|
+
key = SSHKey.generate
|
|
192
|
+
nova = env[:openstack_client].nova
|
|
193
|
+
generated_keyname = nova.import_keypair(env, key.ssh_public_key)
|
|
194
|
+
file_path = "#{env[:machine].data_dir}/#{generated_keyname}"
|
|
195
|
+
File.write(file_path, key.private_key)
|
|
196
|
+
File.chmod(0600, file_path)
|
|
197
|
+
generated_keyname
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def resolve_networks_without_network_service(env)
|
|
201
|
+
config = env[:machine].provider_config
|
|
202
|
+
networks = []
|
|
203
|
+
config.networks.each do |network|
|
|
204
|
+
case network
|
|
205
|
+
when String
|
|
206
|
+
env[:ui].info(I18n.t('vagrant_openstack.warn_network_identifier_is_assumed_to_be_an_id', network: network))
|
|
207
|
+
networks << { uuid: network }
|
|
208
|
+
when Hash
|
|
209
|
+
fail Errors::ConflictNetworkNameId, network: network if network.key?(:name) && network.key?(:id)
|
|
210
|
+
fail Errors::NetworkServiceUnavailable if network.key? :name
|
|
211
|
+
if network.key?(:address)
|
|
212
|
+
networks << { uuid: network[:id], fixed_ip: network[:address] }
|
|
213
|
+
else
|
|
214
|
+
networks << { uuid: network[:id] }
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
networks
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def resolve_network(network, network_list, network_ids)
|
|
222
|
+
return resolve_network_from_string(network, network_list) if network.is_a? String
|
|
223
|
+
return resolve_network_from_hash(network, network_list, network_ids) if network.is_a? Hash
|
|
224
|
+
fail Errors::InvalidNetworkObject, network: network
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def resolve_network_from_string(network, network_list)
|
|
228
|
+
found_network = find_matching(network_list, network)
|
|
229
|
+
fail Errors::UnresolvedNetwork, network: network if found_network.nil?
|
|
230
|
+
{ uuid: found_network.id }
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def resolve_network_from_hash(network, network_list, network_ids)
|
|
234
|
+
if network.key?(:id)
|
|
235
|
+
fail Errors::ConflictNetworkNameId, network: network if network.key?(:name)
|
|
236
|
+
network_id = network[:id]
|
|
237
|
+
fail Errors::UnresolvedNetworkId, id: network_id unless network_ids.include? network_id
|
|
238
|
+
elsif network.key?(:name)
|
|
239
|
+
network_list.each do |v|
|
|
240
|
+
next unless v.name.eql? network[:name]
|
|
241
|
+
fail Errors::MultipleNetworkName, name: network[:name] unless network_id.nil?
|
|
242
|
+
network_id = v.id
|
|
243
|
+
end
|
|
244
|
+
fail Errors::UnresolvedNetworkName, name: network[:name] unless network_ids.include? network_id
|
|
245
|
+
else
|
|
246
|
+
fail Errors::ConflictNetworkNameId, network: network
|
|
247
|
+
end
|
|
248
|
+
return { uuid: network_id, fixed_ip: network[:address] } if network.key?(:address)
|
|
249
|
+
{ uuid: network_id }
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def resolve_volumes_without_volume_service(env)
|
|
253
|
+
env[:machine].provider_config.volumes.map { |volume| resolve_volume_without_volume_service(env, volume) }
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def resolve_volume_without_volume_service(env, volume, default_device = nil)
|
|
257
|
+
case volume
|
|
258
|
+
when String
|
|
259
|
+
env[:ui].info(I18n.t('vagrant_openstack.warn_volume_identifier_is_assumed_to_be_an_id', volume: volume))
|
|
260
|
+
return { id: volume, device: default_device }
|
|
261
|
+
when Hash
|
|
262
|
+
fail Errors::ConflictVolumeNameId, volume: volume if volume.key?(:name) && volume.key?(:id)
|
|
263
|
+
fail Errors::VolumeServiceUnavailable if volume.key? :name
|
|
264
|
+
return { id: volume[:id], device: volume[:device] || default_device }
|
|
265
|
+
end
|
|
266
|
+
fail Errors::InvalidVolumeObject, volume: volume
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def resolve_volume(volume, volume_list, volume_ids)
|
|
270
|
+
return resolve_volume_from_string(volume, volume_list) if volume.is_a? String
|
|
271
|
+
return resolve_volume_from_hash(volume, volume_list, volume_ids) if volume.is_a? Hash
|
|
272
|
+
fail Errors::InvalidVolumeObject, volume: volume
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def resolve_volume_from_string(volume, volume_list)
|
|
276
|
+
found_volume = find_matching(volume_list, volume)
|
|
277
|
+
fail Errors::UnresolvedVolume, volume: volume if found_volume.nil?
|
|
278
|
+
{ id: found_volume.id, device: nil }
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def resolve_volume_from_hash(volume, volume_list, volume_ids)
|
|
282
|
+
device = nil
|
|
283
|
+
device = volume[:device] if volume.key?(:device)
|
|
284
|
+
delete_on_destroy = (volume[:delete_on_destroy].nil?) ? 'true' : volume[:delete_on_destroy]
|
|
285
|
+
|
|
286
|
+
volume_id = nil
|
|
287
|
+
if volume.key?(:id)
|
|
288
|
+
fail Errors::ConflictVolumeNameId, volume: volume if volume.key?(:name)
|
|
289
|
+
check_boot_volume_conflict(volume)
|
|
290
|
+
volume_id = volume[:id]
|
|
291
|
+
fail Errors::UnresolvedVolumeId, id: volume_id unless volume_ids.include? volume_id
|
|
292
|
+
elsif volume.key?(:name)
|
|
293
|
+
volume_list.each do |v|
|
|
294
|
+
next unless v.name.eql? volume[:name]
|
|
295
|
+
fail Errors::MultipleVolumeName, name: volume[:name] unless volume_id.nil?
|
|
296
|
+
check_boot_volume_conflict(volume)
|
|
297
|
+
volume_id = v.id
|
|
298
|
+
end
|
|
299
|
+
fail Errors::UnresolvedVolumeName, name: volume[:name] unless volume_ids.include? volume_id
|
|
300
|
+
elsif volume.key?(:image)
|
|
301
|
+
fail Errors::UnresolvedVolume, volume: volume unless volume.key?(:size)
|
|
302
|
+
fail Errors::ConflictBootVolume, volume: volume if volume.key?(:id)
|
|
303
|
+
fail Errors::ConflictBootVolume, volume: volume if volume.key?(:name)
|
|
304
|
+
return { image: volume[:image], device: device, size: volume[:size], delete_on_destroy: delete_on_destroy }
|
|
305
|
+
else
|
|
306
|
+
fail Errors::ConflictBootVolume, volume: volume
|
|
307
|
+
end
|
|
308
|
+
{ id: volume_id, device: device }
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def check_boot_volume_conflict(volume)
|
|
312
|
+
fail Errors::ConflictBootVolume, volume: volume if volume.key?(:image) || volume.key?(:size) || volume.key?(:delete_on_destroy)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# This method finds any matching _thing_ from a list of names
|
|
316
|
+
# in a collection of _things_. The first to match is the returned
|
|
317
|
+
# one. Names in list can be a regexp, a partial match is chosen
|
|
318
|
+
# as well.
|
|
319
|
+
|
|
320
|
+
def find_matching(collection, name_or_names)
|
|
321
|
+
name_or_names = [name_or_names] if name_or_names.class != Array
|
|
322
|
+
name_or_names.each do |name|
|
|
323
|
+
collection.each do |single|
|
|
324
|
+
return single if single.id == name
|
|
325
|
+
return single if single.name == name
|
|
326
|
+
return single if name.is_a?(Regexp) && name =~ single.name
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
@logger.error "No element of '#{name_or_names}' found in collection #{collection}"
|
|
330
|
+
nil
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
end
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
require 'vagrant'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Openstack
|
|
5
|
+
module Errors
|
|
6
|
+
class VagrantOpenstackError < Vagrant::Errors::VagrantError
|
|
7
|
+
#
|
|
8
|
+
# Added for vagrant 1.4.x compatibility This attribute had been
|
|
9
|
+
# added in Vagrant::Errors::VagrantError form the version 1.5.0
|
|
10
|
+
#
|
|
11
|
+
attr_accessor :extra_data
|
|
12
|
+
|
|
13
|
+
def initialize(args = nil)
|
|
14
|
+
@extra_data = args
|
|
15
|
+
super(args)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
error_namespace('vagrant_openstack.errors')
|
|
19
|
+
error_key(:default)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Timeout < VagrantOpenstackError
|
|
23
|
+
error_key(:timeout)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class AuthenticationRequired < VagrantOpenstackError
|
|
27
|
+
error_key(:authentication_required)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class AuthenticationFailed < VagrantOpenstackError
|
|
31
|
+
error_key(:authentication_failed)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class BadAuthenticationEndpoint < VagrantOpenstackError
|
|
35
|
+
error_key(:bad_authentication_endpoint)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class NoMatchingApiVersion < VagrantOpenstackError
|
|
39
|
+
error_key(:no_matching_api_version)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class CreateBadState < VagrantOpenstackError
|
|
43
|
+
error_key(:create_bad_state)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class NoMatchingFlavor < VagrantOpenstackError
|
|
47
|
+
error_key(:no_matching_flavor)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class NoMatchingImage < VagrantOpenstackError
|
|
51
|
+
error_key(:no_matching_image)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class ConflictBootVolume < VagrantOpenstackError
|
|
55
|
+
error_key(:conflict_boot_volume)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class SyncMethodError < VagrantOpenstackError
|
|
59
|
+
error_key(:sync_method_error)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class RsyncError < VagrantOpenstackError
|
|
63
|
+
error_key(:rsync_error)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class SshUnavailable < VagrantOpenstackError
|
|
67
|
+
error_key(:ssh_unavailble)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class NoArgRequiredForCommand < VagrantOpenstackError
|
|
71
|
+
error_key(:no_arg_required_for_command)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class UnrecognizedArgForCommand < VagrantOpenstackError
|
|
75
|
+
error_key(:unrecognized_arg_for_command)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class UnableToResolveFloatingIP < VagrantOpenstackError
|
|
79
|
+
error_key(:unable_to_resolve_floating_ip)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class UnableToResolveIP < VagrantOpenstackError
|
|
83
|
+
error_key(:unable_to_resolve_ip)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class UnableToResolveSSHKey < VagrantOpenstackError
|
|
87
|
+
error_key(:unable_to_resolve_ssh_key)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class InvalidNetworkObject < VagrantOpenstackError
|
|
91
|
+
error_key(:invalid_network_format)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class UnresolvedNetwork < VagrantOpenstackError
|
|
95
|
+
error_key(:unresolved_network)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class UnresolvedNetworkId < VagrantOpenstackError
|
|
99
|
+
error_key(:unresolved_network_id)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
class UnresolvedNetworkName < VagrantOpenstackError
|
|
103
|
+
error_key(:unresolved_network_name)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class ConflictNetworkNameId < VagrantOpenstackError
|
|
107
|
+
error_key(:conflict_network_name_id)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class MultipleNetworkName < VagrantOpenstackError
|
|
111
|
+
error_key(:multiple_network_name)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
class InvalidVolumeObject < VagrantOpenstackError
|
|
115
|
+
error_key(:invalid_volume_format)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class UnresolvedVolume < VagrantOpenstackError
|
|
119
|
+
error_key(:unresolved_volume)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
class UnresolvedVolumeId < VagrantOpenstackError
|
|
123
|
+
error_key(:unresolved_volume_id)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
class UnresolvedVolumeName < VagrantOpenstackError
|
|
127
|
+
error_key(:unresolved_volume_name)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
class ConflictVolumeNameId < VagrantOpenstackError
|
|
131
|
+
error_key(:conflict_volume_name_id)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
class MultipleVolumeName < VagrantOpenstackError
|
|
135
|
+
error_key(:multiple_volume_name)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
class MissingBootOption < VagrantOpenstackError
|
|
139
|
+
error_key(:missing_boot_option)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
class ConflictBootOption < VagrantOpenstackError
|
|
143
|
+
error_key(:conflict_boot_option)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class NoMatchingSshUsername < VagrantOpenstackError
|
|
147
|
+
error_key(:ssh_username_missing)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
class InstanceNotFound < VagrantOpenstackError
|
|
151
|
+
error_key(:instance_not_found)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
class StackNotFound < VagrantOpenstackError
|
|
155
|
+
error_key(:stack_not_found)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
class NetworkServiceUnavailable < VagrantOpenstackError
|
|
159
|
+
error_key(:nerwork_service_unavailable)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
class VolumeServiceUnavailable < VagrantOpenstackError
|
|
163
|
+
error_key(:volume_service_unavailable)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
class FloatingIPAlreadyAssigned < VagrantOpenstackError
|
|
167
|
+
error_key(:floating_ip_already_assigned)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
class FloatingIPNotAvailable < VagrantOpenstackError
|
|
171
|
+
error_key(:floating_ip_not_available)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
class ServerStatusError < VagrantOpenstackError
|
|
175
|
+
error_key(:server_status_error)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
class StackStatusError < VagrantOpenstackError
|
|
179
|
+
error_key(:stack_status_error)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
class MissingNovaEndpoint < VagrantOpenstackError
|
|
183
|
+
error_key(:missing_nova_endpoint)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|