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,22 @@
|
|
|
1
|
+
require 'colorize'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Openstack
|
|
5
|
+
module Action
|
|
6
|
+
class AbstractAction
|
|
7
|
+
def call(env)
|
|
8
|
+
execute(env)
|
|
9
|
+
# rubocop:disable Style/SpecialGlobalVars
|
|
10
|
+
# rubocop:disable Lint/RescueException
|
|
11
|
+
rescue Errors::VagrantOpenstackError, SystemExit, Interrupt => e
|
|
12
|
+
raise e
|
|
13
|
+
rescue Exception => e
|
|
14
|
+
puts I18n.t('vagrant_openstack.global_error').red unless e.message && e.message.start_with?('Catched Error:')
|
|
15
|
+
raise $!, "Catched Error: #{$!}", $!.backtrace
|
|
16
|
+
end
|
|
17
|
+
# rubocop:enable Lint/RescueException
|
|
18
|
+
# rubocop:enable Style/SpecialGlobalVars
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'log4r'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
require 'vagrant-openstack-illuin-provider/client/openstack'
|
|
5
|
+
require 'vagrant-openstack-illuin-provider/client/request_logger'
|
|
6
|
+
require 'vagrant-openstack-illuin-provider/action/abstract_action'
|
|
7
|
+
require 'vagrant-openstack-illuin-provider/catalog/openstack_catalog'
|
|
8
|
+
|
|
9
|
+
module VagrantPlugins
|
|
10
|
+
module Openstack
|
|
11
|
+
module Action
|
|
12
|
+
class ConnectOpenstack < AbstractAction
|
|
13
|
+
include VagrantPlugins::Openstack::HttpUtils::RequestLogger
|
|
14
|
+
include VagrantPlugins::Openstack::Catalog
|
|
15
|
+
|
|
16
|
+
def initialize(app, env, catalog_reader = OpenstackCatalog.new)
|
|
17
|
+
@app = app
|
|
18
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::connect_openstack')
|
|
19
|
+
@catalog_reader = catalog_reader
|
|
20
|
+
env[:openstack_client] = VagrantPlugins::Openstack
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def execute(env)
|
|
24
|
+
client = env[:openstack_client]
|
|
25
|
+
if client.session.token.nil?
|
|
26
|
+
catalog = client.keystone.authenticate(env)
|
|
27
|
+
@catalog_reader.read(env, catalog)
|
|
28
|
+
override_endpoint_catalog_with_user_config(env)
|
|
29
|
+
check_configuration(env)
|
|
30
|
+
log_endpoint_catalog(env)
|
|
31
|
+
end
|
|
32
|
+
@app.call(env) unless @app.nil?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def override_endpoint_catalog_with_user_config(env)
|
|
38
|
+
client = env[:openstack_client]
|
|
39
|
+
config = env[:machine].provider_config
|
|
40
|
+
endpoints = client.session.endpoints
|
|
41
|
+
endpoints[:compute] = config.openstack_compute_url unless config.openstack_compute_url.nil?
|
|
42
|
+
endpoints[:network] = config.openstack_network_url unless config.openstack_network_url.nil?
|
|
43
|
+
endpoints[:volume] = config.openstack_volume_url unless config.openstack_volume_url.nil?
|
|
44
|
+
endpoints[:image] = config.openstack_image_url unless config.openstack_image_url.nil?
|
|
45
|
+
endpoints.delete_if { |_, value| value.nil? || value.empty? }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def check_configuration(env)
|
|
49
|
+
fail Errors::MissingNovaEndpoint unless env[:openstack_client].session.endpoints.key? :compute
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def log_endpoint_catalog(env)
|
|
53
|
+
env[:openstack_client].session.endpoints.each do |key, value|
|
|
54
|
+
@logger.info(" -- #{key.to_s.ljust 15}: #{value}")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
require 'log4r'
|
|
2
|
+
require 'socket'
|
|
3
|
+
require 'timeout'
|
|
4
|
+
require 'sshkey'
|
|
5
|
+
|
|
6
|
+
require 'vagrant-openstack-illuin-provider/config_resolver'
|
|
7
|
+
require 'vagrant-openstack-illuin-provider/utils'
|
|
8
|
+
require 'vagrant-openstack-illuin-provider/action/abstract_action'
|
|
9
|
+
require 'vagrant/util/retryable'
|
|
10
|
+
|
|
11
|
+
module VagrantPlugins
|
|
12
|
+
module Openstack
|
|
13
|
+
module Action
|
|
14
|
+
class CreateServer < AbstractAction
|
|
15
|
+
include Vagrant::Util::Retryable
|
|
16
|
+
|
|
17
|
+
def initialize(app, _env, resolver = ConfigResolver.new, utils = Utils.new)
|
|
18
|
+
@app = app
|
|
19
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::create_server')
|
|
20
|
+
@resolver = resolver
|
|
21
|
+
@utils = utils
|
|
22
|
+
@@mutex = Mutex.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def execute(env)
|
|
26
|
+
@logger.info 'Start create server action'
|
|
27
|
+
|
|
28
|
+
config = env[:machine].provider_config
|
|
29
|
+
|
|
30
|
+
fail Errors::MissingBootOption if config.image.nil? && config.volume_boot.nil?
|
|
31
|
+
fail Errors::ConflictBootOption unless config.image.nil? || config.volume_boot.nil?
|
|
32
|
+
|
|
33
|
+
options = {
|
|
34
|
+
flavor: @resolver.resolve_flavor(env),
|
|
35
|
+
image: @resolver.resolve_image(env),
|
|
36
|
+
volume_boot: @resolver.resolve_volume_boot(env),
|
|
37
|
+
networks: @resolver.resolve_networks(env),
|
|
38
|
+
volumes: @resolver.resolve_volumes(env),
|
|
39
|
+
keypair_name: @resolver.resolve_keypair(env),
|
|
40
|
+
availability_zone: env[:machine].provider_config.availability_zone,
|
|
41
|
+
scheduler_hints: env[:machine].provider_config.scheduler_hints,
|
|
42
|
+
security_groups: @resolver.resolve_security_groups(env),
|
|
43
|
+
user_data: env[:machine].provider_config.user_data,
|
|
44
|
+
metadata: env[:machine].provider_config.metadata
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
server_id = create_server(env, options)
|
|
48
|
+
|
|
49
|
+
# Store the ID right away so we can track it
|
|
50
|
+
env[:machine].id = server_id
|
|
51
|
+
|
|
52
|
+
waiting_for_server_to_be_built(env, server_id)
|
|
53
|
+
@@mutex.synchronize do
|
|
54
|
+
assign_floating_ip(env, server_id)
|
|
55
|
+
waiting_for_floating_ip_to_be_assigned(env, server_id)
|
|
56
|
+
end
|
|
57
|
+
attach_volumes(env, server_id, options[:volumes]) unless options[:volumes].empty?
|
|
58
|
+
|
|
59
|
+
@app.call(env)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def create_server(env, options)
|
|
65
|
+
config = env[:machine].provider_config
|
|
66
|
+
nova = env[:openstack_client].nova
|
|
67
|
+
server_name = config.server_name || env[:machine].name
|
|
68
|
+
|
|
69
|
+
env[:ui].info(I18n.t('vagrant_openstack.launching_server'))
|
|
70
|
+
env[:ui].info(" -- Tenant : #{config.tenant_name}")
|
|
71
|
+
env[:ui].info(" -- Name : #{server_name}")
|
|
72
|
+
env[:ui].info(" -- Flavor : #{options[:flavor].name}")
|
|
73
|
+
env[:ui].info(" -- FlavorRef : #{options[:flavor].id}")
|
|
74
|
+
unless options[:image].nil?
|
|
75
|
+
env[:ui].info(" -- Image : #{options[:image].name}")
|
|
76
|
+
env[:ui].info(" -- ImageRef : #{options[:image].id}")
|
|
77
|
+
end
|
|
78
|
+
env[:ui].info(" -- Boot volume : #{options[:volume_boot][:id]} (#{options[:volume_boot][:device]})") unless options[:volume_boot].nil?
|
|
79
|
+
env[:ui].info(" -- KeyPair : #{options[:keypair_name]}") unless options[:keypair_name].nil?
|
|
80
|
+
|
|
81
|
+
unless options[:networks].empty?
|
|
82
|
+
formated_networks = ' -- '
|
|
83
|
+
if options[:networks].size == 1
|
|
84
|
+
formated_networks << 'Network : '
|
|
85
|
+
else
|
|
86
|
+
formated_networks << 'Networks : '
|
|
87
|
+
end
|
|
88
|
+
formated_networks << options[:networks].map do |n|
|
|
89
|
+
if n.key? :fixed_ip
|
|
90
|
+
"#{n[:uuid]} (#{n[:fixed_ip]})"
|
|
91
|
+
else
|
|
92
|
+
n[:uuid]
|
|
93
|
+
end
|
|
94
|
+
end.join(', ')
|
|
95
|
+
env[:ui].info(formated_networks)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
unless options[:volumes].empty?
|
|
99
|
+
options[:volumes].each do |volume|
|
|
100
|
+
device = volume[:device]
|
|
101
|
+
device = :auto if device.nil?
|
|
102
|
+
env[:ui].info(" -- Volume attached : #{volume[:id]} => #{device}")
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
log = "Launching server '#{server_name}' in project '#{config.tenant_name}' "
|
|
107
|
+
log << "with flavor '#{options[:flavor].name}' (#{options[:flavor].id}), "
|
|
108
|
+
unless options[:image].nil?
|
|
109
|
+
log << "image '#{options[:image].name}' (#{options[:image].id}) "
|
|
110
|
+
end
|
|
111
|
+
unless options[:keypair_name].nil?
|
|
112
|
+
log << "and keypair '#{options[:keypair_name]}'"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
@logger.info(log)
|
|
116
|
+
|
|
117
|
+
image_ref = options[:image].id unless options[:image].nil?
|
|
118
|
+
|
|
119
|
+
create_opts = {
|
|
120
|
+
name: server_name,
|
|
121
|
+
image_ref: image_ref,
|
|
122
|
+
volume_boot: options[:volume_boot],
|
|
123
|
+
flavor_ref: options[:flavor].id,
|
|
124
|
+
keypair: options[:keypair_name],
|
|
125
|
+
availability_zone: options[:availability_zone],
|
|
126
|
+
networks: options[:networks],
|
|
127
|
+
scheduler_hints: options[:scheduler_hints],
|
|
128
|
+
security_groups: options[:security_groups],
|
|
129
|
+
user_data: options[:user_data],
|
|
130
|
+
metadata: options[:metadata]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
nova.create_server(env, create_opts)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def waiting_for_server_to_be_built(env, server_id, retry_interval = 3)
|
|
137
|
+
@logger.info "Waiting for the server with id #{server_id} to be built..."
|
|
138
|
+
env[:ui].info(I18n.t('vagrant_openstack.waiting_for_build'))
|
|
139
|
+
config = env[:machine].provider_config
|
|
140
|
+
Timeout.timeout(config.server_create_timeout, Errors::Timeout) do
|
|
141
|
+
server_status = 'WAITING'
|
|
142
|
+
until server_status == 'ACTIVE'
|
|
143
|
+
@logger.debug('Waiting for server to be ACTIVE')
|
|
144
|
+
server_status = env[:openstack_client].nova.get_server_details(env, server_id)['status']
|
|
145
|
+
fail Errors::ServerStatusError, server: server_id if server_status == 'ERROR'
|
|
146
|
+
sleep retry_interval
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def assign_floating_ip(env, server_id)
|
|
152
|
+
floating_ip = @resolver.resolve_floating_ip(env)
|
|
153
|
+
return if !floating_ip || floating_ip.empty?
|
|
154
|
+
@logger.info "Using floating IP #{floating_ip}"
|
|
155
|
+
env[:ui].info(I18n.t('vagrant_openstack.using_floating_ip', floating_ip: floating_ip))
|
|
156
|
+
env[:openstack_client].nova.add_floating_ip(env, server_id, floating_ip)
|
|
157
|
+
rescue Errors::UnableToResolveFloatingIP
|
|
158
|
+
@logger.info 'Vagrant was unable to resolve FloatingIP, continue assuming it is not necessary'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def waiting_for_floating_ip_to_be_assigned(env, server_id, retry_interval = 3)
|
|
162
|
+
floating_ip = @resolver.resolve_floating_ip(env)
|
|
163
|
+
return if !floating_ip || floating_ip.empty?
|
|
164
|
+
@logger.info "Waiting for floating IP #{floating_ip} to be assigned"
|
|
165
|
+
env[:ui].info(I18n.t('vagrant_openstack.waiting_for_floating_ip', floating_ip: floating_ip))
|
|
166
|
+
config = env[:machine].provider_config
|
|
167
|
+
Timeout.timeout(config.floating_ip_assign_timeout, Errors::Timeout) do
|
|
168
|
+
until env[:openstack_client].nova.check_assigned_floating_ip(env, server_id, floating_ip)
|
|
169
|
+
sleep retry_interval
|
|
170
|
+
end
|
|
171
|
+
return
|
|
172
|
+
end
|
|
173
|
+
rescue Errors::UnableToResolveFloatingIP
|
|
174
|
+
@logger.info 'Vagrant was unable to resolve FloatingIP, not waiting for assignment'
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def attach_volumes(env, server_id, volumes)
|
|
178
|
+
@logger.info("Attaching volumes #{volumes} to server #{server_id}")
|
|
179
|
+
volumes.each do |volume|
|
|
180
|
+
@logger.debug("Attaching volumes #{volume}")
|
|
181
|
+
env[:openstack_client].nova.attach_volume(env, server_id, volume[:id], volume[:device])
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'log4r'
|
|
2
|
+
require 'socket'
|
|
3
|
+
require 'timeout'
|
|
4
|
+
require 'sshkey'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
|
|
7
|
+
require 'vagrant-openstack-illuin-provider/config_resolver'
|
|
8
|
+
require 'vagrant-openstack-illuin-provider/utils'
|
|
9
|
+
require 'vagrant-openstack-illuin-provider/action/abstract_action'
|
|
10
|
+
require 'vagrant/util/retryable'
|
|
11
|
+
|
|
12
|
+
module VagrantPlugins
|
|
13
|
+
module Openstack
|
|
14
|
+
module Action
|
|
15
|
+
class CreateStack < AbstractAction
|
|
16
|
+
@@is_created = false
|
|
17
|
+
|
|
18
|
+
def initialize(app, _env)
|
|
19
|
+
@app = app
|
|
20
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::create_stack')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def execute(env)
|
|
24
|
+
if @@is_created
|
|
25
|
+
@app.call(env)
|
|
26
|
+
return
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@logger.info 'Start create stacks action'
|
|
30
|
+
|
|
31
|
+
config = env[:machine].provider_config
|
|
32
|
+
|
|
33
|
+
heat = env[:openstack_client].heat
|
|
34
|
+
|
|
35
|
+
config.stacks.each do |stack|
|
|
36
|
+
env[:ui].info(I18n.t('vagrant_openstack.create_stack'))
|
|
37
|
+
env[:ui].info(" -- Stack Name : #{stack[:name]}")
|
|
38
|
+
env[:ui].info(" -- Template : #{stack[:template]}")
|
|
39
|
+
|
|
40
|
+
create_opts = {
|
|
41
|
+
name: stack[:name],
|
|
42
|
+
template: YAML.load_file(stack[:template])
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
stack_id = heat.create_stack(env, create_opts)
|
|
46
|
+
|
|
47
|
+
file_path = "#{env[:machine].data_dir}/stack_#{stack[:name]}_id"
|
|
48
|
+
File.write(file_path, stack_id)
|
|
49
|
+
|
|
50
|
+
waiting_for_stack_to_be_created(env, stack[:name], stack_id)
|
|
51
|
+
end unless config.stacks.nil?
|
|
52
|
+
|
|
53
|
+
@@is_created = true
|
|
54
|
+
@app.call(env)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def waiting_for_stack_to_be_created(env, stack_name, stack_id, retry_interval = 3)
|
|
60
|
+
@logger.info "Waiting for the stack with id #{stack_id} to be built..."
|
|
61
|
+
env[:ui].info(I18n.t('vagrant_openstack.waiting_for_stack'))
|
|
62
|
+
config = env[:machine].provider_config
|
|
63
|
+
Timeout.timeout(config.stack_create_timeout, Errors::Timeout) do
|
|
64
|
+
stack_status = 'CREATE_IN_PROGRESS'
|
|
65
|
+
until stack_status == 'CREATE_COMPLETE'
|
|
66
|
+
@logger.debug('Waiting for stack to be CREATED')
|
|
67
|
+
stack_status = env[:openstack_client].heat.get_stack_details(env, stack_name, stack_id)['stack_status']
|
|
68
|
+
fail Errors::StackStatusError, stack: stack_id if stack_status == 'CREATE_FAILED'
|
|
69
|
+
sleep retry_interval
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'log4r'
|
|
2
|
+
|
|
3
|
+
require 'vagrant-openstack-illuin-provider/action/abstract_action'
|
|
4
|
+
|
|
5
|
+
module VagrantPlugins
|
|
6
|
+
module Openstack
|
|
7
|
+
module Action
|
|
8
|
+
# This deletes the running server, if there is one.
|
|
9
|
+
class DeleteServer < AbstractAction
|
|
10
|
+
def initialize(app, _env)
|
|
11
|
+
@app = app
|
|
12
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::delete_server')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def execute(env)
|
|
16
|
+
if env[:machine].id
|
|
17
|
+
@logger.info "Deleting server #{env[:machine].id}..."
|
|
18
|
+
env[:ui].info(I18n.t('vagrant_openstack.deleting_server'))
|
|
19
|
+
env[:openstack_client].nova.delete_server(env, env[:machine].id)
|
|
20
|
+
env[:openstack_client].nova.delete_keypair_if_vagrant(env, env[:machine].id)
|
|
21
|
+
|
|
22
|
+
waiting_for_instance_to_be_deleted(env, env[:machine].id)
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@app.call(env)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def waiting_for_instance_to_be_deleted(env, instance_id, retry_interval = 3)
|
|
32
|
+
@logger.info "Waiting for the instance with id #{instance_id} to be deleted..."
|
|
33
|
+
env[:ui].info(I18n.t('vagrant_openstack.waiting_deleted'))
|
|
34
|
+
config = env[:machine].provider_config
|
|
35
|
+
Timeout.timeout(config.server_delete_timeout, Errors::Timeout) do
|
|
36
|
+
delete_ok = false
|
|
37
|
+
until delete_ok
|
|
38
|
+
begin
|
|
39
|
+
@logger.debug('Waiting for instance to be DELETED')
|
|
40
|
+
server_status = env[:openstack_client].nova.get_server_details(env, instance_id)['status']
|
|
41
|
+
fail Errors::ServerStatusError, server: instance_id if server_status == 'ERROR'
|
|
42
|
+
break if server_status == 'DELETED'
|
|
43
|
+
sleep retry_interval
|
|
44
|
+
rescue Errors::InstanceNotFound
|
|
45
|
+
delete_ok = true
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'log4r'
|
|
2
|
+
require 'socket'
|
|
3
|
+
require 'timeout'
|
|
4
|
+
require 'sshkey'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
|
|
7
|
+
require 'vagrant-openstack-illuin-provider/config_resolver'
|
|
8
|
+
require 'vagrant-openstack-illuin-provider/utils'
|
|
9
|
+
require 'vagrant-openstack-illuin-provider/action/abstract_action'
|
|
10
|
+
require 'vagrant/util/retryable'
|
|
11
|
+
|
|
12
|
+
module VagrantPlugins
|
|
13
|
+
module Openstack
|
|
14
|
+
module Action
|
|
15
|
+
class DeleteStack < AbstractAction
|
|
16
|
+
def initialize(app, _env)
|
|
17
|
+
@app = app
|
|
18
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::delete_stack')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def execute(env)
|
|
22
|
+
@logger.info 'Start delete stacks action'
|
|
23
|
+
|
|
24
|
+
heat = env[:openstack_client].heat
|
|
25
|
+
|
|
26
|
+
list_stack_files(env).each do |stack|
|
|
27
|
+
env[:ui].info(I18n.t('vagrant_openstack.delete_stack'))
|
|
28
|
+
env[:ui].info(" -- Stack Name : #{stack[:name]}")
|
|
29
|
+
env[:ui].info(" -- Stack ID : #{stack[:id]}")
|
|
30
|
+
|
|
31
|
+
heat.delete_stack(env, stack[:name], stack[:id])
|
|
32
|
+
|
|
33
|
+
waiting_for_stack_to_be_deleted(env, stack[:name], stack[:id])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# This will remove all files in the .vagrant instance directory
|
|
37
|
+
env[:machine].id = nil
|
|
38
|
+
|
|
39
|
+
@app.call(env)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def list_stack_files(env)
|
|
45
|
+
stack_files = []
|
|
46
|
+
Dir.glob("#{env[:machine].data_dir}/stack_*_id") do |stack_file|
|
|
47
|
+
file_name = stack_file.split('/')[-1]
|
|
48
|
+
stack_files << {
|
|
49
|
+
name: file_name[6, (file_name.length) - 9],
|
|
50
|
+
id: File.read("#{stack_file}")
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
stack_files
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def waiting_for_stack_to_be_deleted(env, stack_name, stack_id, retry_interval = 3)
|
|
57
|
+
@logger.info "Waiting for the stack with id #{stack_id} to be deleted..."
|
|
58
|
+
env[:ui].info(I18n.t('vagrant_openstack.waiting_for_stack_deleted'))
|
|
59
|
+
config = env[:machine].provider_config
|
|
60
|
+
Timeout.timeout(config.stack_delete_timeout, Errors::Timeout) do
|
|
61
|
+
stack_status = 'DELETE_IN_PROGRESS'
|
|
62
|
+
until stack_status == 'DELETE_COMPLETE'
|
|
63
|
+
@logger.debug('Waiting for stack to be DELETED')
|
|
64
|
+
stack_status = env[:openstack_client].heat.get_stack_details(env, stack_name, stack_id)['stack_status']
|
|
65
|
+
fail Errors::StackStatusError, stack: stack_id if stack_status == 'DELETE_FAILED'
|
|
66
|
+
sleep retry_interval
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|