vagrant-openstack-provider 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/lib/vagrant-openstack-provider.rb +2 -31
- data/lib/vagrant-openstack-provider/action.rb +21 -7
- data/lib/vagrant-openstack-provider/action/abstract_action.rb +22 -0
- data/lib/vagrant-openstack-provider/action/connect_openstack.rb +19 -40
- data/lib/vagrant-openstack-provider/action/create_server.rb +10 -6
- data/lib/vagrant-openstack-provider/action/create_stack.rb +67 -0
- data/lib/vagrant-openstack-provider/action/delete_server.rb +28 -3
- data/lib/vagrant-openstack-provider/action/delete_stack.rb +72 -0
- data/lib/vagrant-openstack-provider/action/message.rb +4 -2
- data/lib/vagrant-openstack-provider/action/read_ssh_info.rb +4 -2
- data/lib/vagrant-openstack-provider/action/read_state.rb +9 -4
- data/lib/vagrant-openstack-provider/action/resume.rb +4 -2
- data/lib/vagrant-openstack-provider/action/start_server.rb +4 -2
- data/lib/vagrant-openstack-provider/action/stop_server.rb +4 -2
- data/lib/vagrant-openstack-provider/action/suspend.rb +4 -2
- data/lib/vagrant-openstack-provider/action/sync_folders.rb +17 -13
- data/lib/vagrant-openstack-provider/action/wait_accessible.rb +5 -2
- data/lib/vagrant-openstack-provider/action/wait_active.rb +5 -3
- data/lib/vagrant-openstack-provider/action/wait_stop.rb +5 -3
- data/lib/vagrant-openstack-provider/catalog/openstack_catalog.rb +66 -0
- data/lib/vagrant-openstack-provider/client/domain.rb +41 -1
- data/lib/vagrant-openstack-provider/client/glance.rb +63 -0
- data/lib/vagrant-openstack-provider/client/heat.rb +50 -0
- data/lib/vagrant-openstack-provider/client/http_utils.rb +18 -0
- data/lib/vagrant-openstack-provider/client/neutron.rb +9 -15
- data/lib/vagrant-openstack-provider/client/nova.rb +3 -3
- data/lib/vagrant-openstack-provider/client/openstack.rb +10 -0
- data/lib/vagrant-openstack-provider/command/abstract_command.rb +7 -0
- data/lib/vagrant-openstack-provider/command/image_list.rb +12 -2
- data/lib/vagrant-openstack-provider/command/main.rb +1 -0
- data/lib/vagrant-openstack-provider/command/network_list.rb +3 -3
- data/lib/vagrant-openstack-provider/command/subnet_list.rb +25 -0
- data/lib/vagrant-openstack-provider/config.rb +78 -7
- data/lib/vagrant-openstack-provider/config_resolver.rb +36 -5
- data/lib/vagrant-openstack-provider/errors.rb +30 -2
- data/lib/vagrant-openstack-provider/logging.rb +39 -0
- data/lib/vagrant-openstack-provider/version.rb +1 -1
- data/locales/en.yml +107 -4
- data/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb +255 -8
- data/spec/vagrant-openstack-provider/action/create_server_spec.rb +6 -1
- data/spec/vagrant-openstack-provider/action/create_stack_spec.rb +97 -0
- data/spec/vagrant-openstack-provider/action/delete_server_spec.rb +34 -6
- data/spec/vagrant-openstack-provider/action/delete_stack_spec.rb +64 -0
- data/spec/vagrant-openstack-provider/action/read_state_spec.rb +13 -1
- data/spec/vagrant-openstack-provider/action/sync_folders_spec.rb +1 -0
- data/spec/vagrant-openstack-provider/action/wait_active_spec.rb +1 -1
- data/spec/vagrant-openstack-provider/action/wait_stop_spec.rb +1 -1
- data/spec/vagrant-openstack-provider/client/glance_spec.rb +128 -0
- data/spec/vagrant-openstack-provider/client/heat_spec.rb +124 -0
- data/spec/vagrant-openstack-provider/client/neutron_spec.rb +33 -1
- data/spec/vagrant-openstack-provider/client/nova_spec.rb +2 -2
- data/spec/vagrant-openstack-provider/command/image_list_spec.rb +75 -23
- data/spec/vagrant-openstack-provider/command/subnet_list_spec.rb +46 -0
- data/spec/vagrant-openstack-provider/config_resolver_spec.rb +85 -19
- data/spec/vagrant-openstack-provider/config_spec.rb +177 -1
- data/spec/vagrant-openstack-provider/spec_helper.rb +3 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fcb72c6f544989dbe6afa13b2320eb81f35505e
|
4
|
+
data.tar.gz: 5f04da4d1e21da40d5d7ad6bb83e471e654292f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4427ad7ce03abf95ebbc7f1dabc6188d66cb5daf5a8c5b07f9ff21c6bc44b8fdb62767ff4549bdb99c26bca4b775aad0d648d7df13865420e2ec440217705b9
|
7
|
+
data.tar.gz: 98450beaed75447f516f1be64dd46b399d6aa4e856d999a01f213fe7a0594693fe74d6108034efd1f200d191e0d597e637c7147a057752304a0295e48bc0d28e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# 0.6.0 (November 28, 2014)
|
2
|
+
|
3
|
+
FEATURES:
|
4
|
+
|
5
|
+
- First implementation of Heat Stacks [#170](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/170)
|
6
|
+
- Allow public and private networks to be specified [#148](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/148)
|
7
|
+
- Add custom command "subnet-list" [#160](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/160)
|
8
|
+
- Allow public and private networks to be specified [#148](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/148)
|
9
|
+
- Add config parameter os.region [#128](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/128)
|
10
|
+
|
11
|
+
IMPROVEMENTS:
|
12
|
+
|
13
|
+
- Rsync all files [#166](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/166)
|
14
|
+
- Support glance API v1 [#168](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/168)
|
15
|
+
- Replace fail <string> by fail Errors::... [#152](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/152)
|
16
|
+
- When an unknown error occurs, provide information to debug and submit issue [#115](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/115)
|
17
|
+
- Print more information for command "vagrant openstack image-list" [#104](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/104)
|
18
|
+
- Cannot 'resume' while instance is in vm_state active [#91](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/91)
|
19
|
+
- Allow config.floating_ip_pool to take an array as input [#90](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/90)
|
20
|
+
- Display the current task value in the status option [#89](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/89)
|
21
|
+
|
22
|
+
BUG FIXES:
|
23
|
+
|
24
|
+
- Fix ssh_disabled [#182](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/182)
|
25
|
+
- Avoid printing contribution message on user interruption [#169](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/169)
|
26
|
+
- Network configuration is lost when machine definition overrides provider's configuration [#146](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/146)
|
27
|
+
- When VM status is "ERROR" continue waiting for startup [#62](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/62)
|
28
|
+
|
29
|
+
DOCUMENTATION:
|
30
|
+
|
31
|
+
- Add a CONTRIBUTING.md file [#151](https://github.com/ggiamarchi/vagrant-openstack-provider/pull/151)
|
32
|
+
|
1
33
|
# 0.5.2 (November 6, 2014)
|
2
34
|
|
3
35
|
BUG FIXES:
|
@@ -32,6 +64,8 @@ BUG FIXES:
|
|
32
64
|
- user_data needs to be Base64 encoded in Nova.createServer [#122](https://github.com/ggiamarchi/vagrant-openstack-provider/issues/122)
|
33
65
|
- SSH failures after port 22 is open because user doesn't exist yet [#106](https://github.com/ggiamarchi/vagrant-openstack-provider/issues/106)
|
34
66
|
- Floating IP should not be mandatory [#55](https://github.com/ggiamarchi/vagrant-openstack-provider/issues/55)
|
67
|
+
- sync_folders error under windows 7 [#119](https://github.com/ggiamarchi/vagrant-openstack-provider/issues/119)
|
68
|
+
- Ansible provisionner doesn't use our generated SSH key [#133](https://github.com/ggiamarchi/vagrant-openstack-provider/issues/133)
|
35
69
|
|
36
70
|
# 0.4.1 (October 3, 2014)
|
37
71
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
3
|
require 'vagrant-openstack-provider/plugin'
|
4
|
+
require 'vagrant-openstack-provider/logging'
|
4
5
|
|
5
6
|
module VagrantPlugins
|
6
7
|
module Openstack
|
@@ -14,38 +15,8 @@ module VagrantPlugins
|
|
14
15
|
I18n.reload!
|
15
16
|
end
|
16
17
|
|
17
|
-
# This initializes the logging so that our logs are outputted at
|
18
|
-
# the same level as Vagrant core logs.
|
19
18
|
def self.init_logging
|
20
|
-
|
21
|
-
level = nil
|
22
|
-
begin
|
23
|
-
level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
|
24
|
-
rescue NameError
|
25
|
-
# This means that the logging constant wasn't found,
|
26
|
-
# which is fine. We just keep `level` as `nil`. But
|
27
|
-
# we tell the user.
|
28
|
-
begin
|
29
|
-
level = Log4r.const_get(ENV['VAGRANT_OPENSTACK_LOG'].upcase)
|
30
|
-
rescue NameError
|
31
|
-
level = nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Some constants, such as "true" resolve to booleans, so the
|
36
|
-
# above error checking doesn't catch it. This will check to make
|
37
|
-
# sure that the log level is an integer, as Log4r requires.
|
38
|
-
level = nil unless level.is_a?(Integer)
|
39
|
-
|
40
|
-
# Set the logging level
|
41
|
-
# logs as long as we have a valid level.
|
42
|
-
if level
|
43
|
-
logger = Log4r::Logger.new('vagrant_openstack')
|
44
|
-
out = Log4r::Outputter.stdout
|
45
|
-
out.formatter = Log4r::PatternFormatter.new(pattern: '%d | %5l | %m', date_pattern: '%Y-%m-%d %H:%M')
|
46
|
-
logger.outputters = out
|
47
|
-
logger.level = level
|
48
|
-
end
|
19
|
+
Logging.init
|
49
20
|
end
|
50
21
|
|
51
22
|
# This returns the path to the source of this plugin.
|
@@ -18,6 +18,7 @@ module VagrantPlugins
|
|
18
18
|
b2.use Message, I18n.t('vagrant_openstack.not_created')
|
19
19
|
else
|
20
20
|
b2.use DeleteServer
|
21
|
+
b2.use DeleteStack
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -97,10 +98,13 @@ module VagrantPlugins
|
|
97
98
|
b.use Call, ReadState do |env, b2|
|
98
99
|
case env[:machine_state_id]
|
99
100
|
when :not_created
|
100
|
-
|
101
|
+
ssh_disabled = env[:machine].provider_config.ssh_disabled
|
102
|
+
b2.use Provision unless ssh_disabled
|
101
103
|
b2.use SyncFolders
|
104
|
+
b2.use CreateStack
|
102
105
|
b2.use CreateServer
|
103
|
-
b2.use
|
106
|
+
b2.use Message, I18n.t('vagrant_openstack.ssh_disabled_provisioning') if ssh_disabled
|
107
|
+
b2.use WaitForServerToBeAccessible unless ssh_disabled
|
104
108
|
when :shutoff
|
105
109
|
b2.use StartServer
|
106
110
|
when :suspended
|
@@ -128,17 +132,21 @@ module VagrantPlugins
|
|
128
132
|
|
129
133
|
# This is the action that is primarily responsible for suspending
|
130
134
|
# the virtual machine.
|
135
|
+
# Vm cannot be suspended when the machine_state_id is not "active" (typically a task is ongoing)
|
131
136
|
def self.action_suspend
|
132
137
|
new_builder.tap do |b|
|
133
138
|
b.use ConfigValidate
|
134
139
|
b.use ConnectOpenstack
|
135
140
|
b.use Call, ReadState do |env, b2|
|
136
|
-
|
141
|
+
case env[:machine_state_id]
|
142
|
+
when :not_created
|
137
143
|
b2.use Message, I18n.t('vagrant_openstack.not_created')
|
138
|
-
|
144
|
+
when :suspended
|
139
145
|
b2.use Message, I18n.t('vagrant_openstack.already_suspended')
|
140
|
-
|
146
|
+
when :active
|
141
147
|
b2.use Suspend
|
148
|
+
else
|
149
|
+
b2.use Message, I18n.t('vagrant_openstack.ongoing_task')
|
142
150
|
end
|
143
151
|
end
|
144
152
|
end
|
@@ -146,15 +154,19 @@ module VagrantPlugins
|
|
146
154
|
|
147
155
|
# This is the action that is primarily responsible for resuming
|
148
156
|
# suspended machines.
|
157
|
+
# Vm cannot be resumed when the machine_state_id is not suspended.
|
149
158
|
def self.action_resume
|
150
159
|
new_builder.tap do |b|
|
151
160
|
b.use ConfigValidate
|
152
161
|
b.use ConnectOpenstack
|
153
162
|
b.use Call, ReadState do |env, b2|
|
154
|
-
|
163
|
+
case env[:machine_state_id]
|
164
|
+
when :not_created
|
155
165
|
b2.use Message, I18n.t('vagrant_openstack.not_created')
|
156
|
-
|
166
|
+
when :suspended
|
157
167
|
b2.use Resume
|
168
|
+
else
|
169
|
+
b2.use Message, I18n.t('vagrant_openstack.not_suspended')
|
158
170
|
end
|
159
171
|
end
|
160
172
|
end
|
@@ -190,6 +202,8 @@ module VagrantPlugins
|
|
190
202
|
autoload :Message, action_root.join('message')
|
191
203
|
autoload :ConnectOpenstack, action_root.join('connect_openstack')
|
192
204
|
autoload :CreateServer, action_root.join('create_server')
|
205
|
+
autoload :CreateStack, action_root.join('create_stack')
|
206
|
+
autoload :DeleteStack, action_root.join('delete_stack')
|
193
207
|
autoload :DeleteServer, action_root.join('delete_server')
|
194
208
|
autoload :StopServer, action_root.join('stop_server')
|
195
209
|
autoload :StartServer, action_root.join('start_server')
|
@@ -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
|
@@ -4,25 +4,30 @@ require 'json'
|
|
4
4
|
|
5
5
|
require 'vagrant-openstack-provider/client/openstack'
|
6
6
|
require 'vagrant-openstack-provider/client/request_logger'
|
7
|
+
require 'vagrant-openstack-provider/action/abstract_action'
|
8
|
+
require 'vagrant-openstack-provider/catalog/openstack_catalog'
|
7
9
|
|
8
10
|
module VagrantPlugins
|
9
11
|
module Openstack
|
10
12
|
module Action
|
11
|
-
class ConnectOpenstack
|
13
|
+
class ConnectOpenstack < AbstractAction
|
12
14
|
include VagrantPlugins::Openstack::HttpUtils::RequestLogger
|
15
|
+
include VagrantPlugins::Openstack::Catalog
|
13
16
|
|
14
|
-
def initialize(app, env)
|
17
|
+
def initialize(app, env, catalog_reader = OpenstackCatalog.new)
|
15
18
|
@app = app
|
16
19
|
@logger = Log4r::Logger.new('vagrant_openstack::action::connect_openstack')
|
20
|
+
@catalog_reader = catalog_reader
|
17
21
|
env[:openstack_client] = VagrantPlugins::Openstack
|
18
22
|
end
|
19
23
|
|
20
|
-
def
|
24
|
+
def execute(env)
|
21
25
|
client = env[:openstack_client]
|
22
26
|
if client.session.token.nil?
|
23
27
|
catalog = client.keystone.authenticate(env)
|
24
|
-
|
28
|
+
@catalog_reader.read(env, catalog)
|
25
29
|
override_endpoint_catalog_with_user_config(env)
|
30
|
+
check_configuration(env)
|
26
31
|
log_endpoint_catalog(env)
|
27
32
|
end
|
28
33
|
@app.call(env) unless @app.nil?
|
@@ -30,45 +35,19 @@ module VagrantPlugins
|
|
30
35
|
|
31
36
|
private
|
32
37
|
|
33
|
-
def read_endpoint_catalog(env, catalog)
|
34
|
-
config = env[:machine].provider_config
|
35
|
-
client = env[:openstack_client]
|
36
|
-
@logger.info(I18n.t('vagrant_openstack.client.looking_for_available_endpoints'))
|
37
|
-
|
38
|
-
catalog.each do |service|
|
39
|
-
se = service['endpoints']
|
40
|
-
if se.size > 1
|
41
|
-
env[:ui].warn I18n.t('vagrant_openstack.client.multiple_endpoint', size: se.size, type: service['type'])
|
42
|
-
env[:ui].warn " => #{service['endpoints'][0]['publicURL']}"
|
43
|
-
end
|
44
|
-
url = se[0]['publicURL'].strip
|
45
|
-
client.session.endpoints[service['type'].to_sym] = url unless url.empty?
|
46
|
-
end
|
47
|
-
|
48
|
-
read_network_api_version(env) if config.openstack_network_url.nil? && !client.session.endpoints[:network].nil?
|
49
|
-
end
|
50
|
-
|
51
|
-
def read_network_api_version(env)
|
52
|
-
client = env[:openstack_client]
|
53
|
-
versions = client.neutron.get_api_version_list(env)
|
54
|
-
if versions.size > 1
|
55
|
-
version_list = ''
|
56
|
-
versions.each do |version|
|
57
|
-
links = version['links'].map { |l| l['href'] }
|
58
|
-
version_list << "#{version['id'].ljust(6)} #{version['status'].ljust(10)} #{links}\n"
|
59
|
-
end
|
60
|
-
fail Errors::MultipleApiVersion, api_name: 'Neutron', url_property: 'openstack_network_url', version_list: version_list
|
61
|
-
end
|
62
|
-
client.session.endpoints[:network] = versions.first['links'].first['href']
|
63
|
-
end
|
64
|
-
|
65
38
|
def override_endpoint_catalog_with_user_config(env)
|
66
39
|
client = env[:openstack_client]
|
67
40
|
config = env[:machine].provider_config
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
41
|
+
endpoints = client.session.endpoints
|
42
|
+
endpoints[:compute] = config.openstack_compute_url unless config.openstack_compute_url.nil?
|
43
|
+
endpoints[:network] = config.openstack_network_url unless config.openstack_network_url.nil?
|
44
|
+
endpoints[:volume] = config.openstack_volume_url unless config.openstack_volume_url.nil?
|
45
|
+
endpoints[:image] = config.openstack_image_url unless config.openstack_image_url.nil?
|
46
|
+
endpoints.delete_if { |_, value| value.nil? || value.empty? }
|
47
|
+
end
|
48
|
+
|
49
|
+
def check_configuration(env)
|
50
|
+
fail Errors::MissingNovaEndpoint unless env[:openstack_client].session.endpoints.key? :compute
|
72
51
|
end
|
73
52
|
|
74
53
|
def log_endpoint_catalog(env)
|
@@ -5,12 +5,13 @@ require 'sshkey'
|
|
5
5
|
|
6
6
|
require 'vagrant-openstack-provider/config_resolver'
|
7
7
|
require 'vagrant-openstack-provider/utils'
|
8
|
+
require 'vagrant-openstack-provider/action/abstract_action'
|
8
9
|
require 'vagrant/util/retryable'
|
9
10
|
|
10
11
|
module VagrantPlugins
|
11
12
|
module Openstack
|
12
13
|
module Action
|
13
|
-
class CreateServer
|
14
|
+
class CreateServer < AbstractAction
|
14
15
|
include Vagrant::Util::Retryable
|
15
16
|
|
16
17
|
def initialize(app, _env, resolver = ConfigResolver.new, utils = Utils.new)
|
@@ -20,7 +21,7 @@ module VagrantPlugins
|
|
20
21
|
@utils = utils
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
+
def execute(env)
|
24
25
|
@logger.info 'Start create server action'
|
25
26
|
|
26
27
|
config = env[:machine].provider_config
|
@@ -127,12 +128,15 @@ module VagrantPlugins
|
|
127
128
|
end
|
128
129
|
|
129
130
|
def waiting_for_server_to_be_built(env, server_id, retry_interval = 3, timeout = 200)
|
130
|
-
@logger.info
|
131
|
+
@logger.info "Waiting for the server with id #{server_id} to be built..."
|
131
132
|
env[:ui].info(I18n.t('vagrant_openstack.waiting_for_build'))
|
132
|
-
timeout(timeout) do
|
133
|
-
|
134
|
-
|
133
|
+
timeout(timeout, Errors::Timeout) do
|
134
|
+
server_status = 'WAITING'
|
135
|
+
until server_status == 'ACTIVE'
|
135
136
|
@logger.debug('Waiting for server to be ACTIVE')
|
137
|
+
server_status = env[:openstack_client].nova.get_server_details(env, server_id)['status']
|
138
|
+
fail Errors::ServerStatusError, server: server_id if server_status == 'ERROR'
|
139
|
+
sleep retry_interval
|
136
140
|
end
|
137
141
|
end
|
138
142
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'socket'
|
3
|
+
require 'timeout'
|
4
|
+
require 'sshkey'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
require 'vagrant-openstack-provider/config_resolver'
|
8
|
+
require 'vagrant-openstack-provider/utils'
|
9
|
+
require 'vagrant-openstack-provider/action/abstract_action'
|
10
|
+
require 'vagrant/util/retryable'
|
11
|
+
|
12
|
+
module VagrantPlugins
|
13
|
+
module Openstack
|
14
|
+
module Action
|
15
|
+
class CreateStack < AbstractAction
|
16
|
+
def initialize(app, _env)
|
17
|
+
@app = app
|
18
|
+
@logger = Log4r::Logger.new('vagrant_openstack::action::create_stack')
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute(env)
|
22
|
+
@logger.info 'Start create stacks action'
|
23
|
+
|
24
|
+
config = env[:machine].provider_config
|
25
|
+
|
26
|
+
heat = env[:openstack_client].heat
|
27
|
+
|
28
|
+
config.stacks.each do |stack|
|
29
|
+
env[:ui].info(I18n.t('vagrant_openstack.create_stack'))
|
30
|
+
env[:ui].info(" -- Stack Name : #{stack[:name]}")
|
31
|
+
env[:ui].info(" -- Template : #{stack[:template]}")
|
32
|
+
|
33
|
+
create_opts = {
|
34
|
+
name: stack[:name],
|
35
|
+
template: YAML.load_file(stack[:template])
|
36
|
+
}
|
37
|
+
|
38
|
+
stack_id = heat.create_stack(env, create_opts)
|
39
|
+
|
40
|
+
file_path = "#{env[:machine].data_dir}/stack_#{stack[:name]}_id"
|
41
|
+
File.write(file_path, stack_id)
|
42
|
+
|
43
|
+
waiting_for_stack_to_be_created(env, stack[:name], stack_id)
|
44
|
+
end unless config.stacks.nil?
|
45
|
+
|
46
|
+
@app.call(env)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def waiting_for_stack_to_be_created(env, stack_name, stack_id, retry_interval = 3, timeout = 200)
|
52
|
+
@logger.info "Waiting for the stack with id #{stack_id} to be built..."
|
53
|
+
env[:ui].info(I18n.t('vagrant_openstack.waiting_for_stack'))
|
54
|
+
timeout(timeout, Errors::Timeout) do
|
55
|
+
stack_status = 'CREATE_IN_PROGRESS'
|
56
|
+
until stack_status == 'CREATE_COMPLETE'
|
57
|
+
@logger.debug('Waiting for stack to be CREATED')
|
58
|
+
stack_status = env[:openstack_client].heat.get_stack_details(env, stack_name, stack_id)['stack_status']
|
59
|
+
fail Errors::StackStatusError, stack: stack_id if stack_status == 'CREATE_FAILED'
|
60
|
+
sleep retry_interval
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,26 +1,51 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-openstack-provider/action/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Openstack
|
5
7
|
module Action
|
6
8
|
# This deletes the running server, if there is one.
|
7
|
-
class DeleteServer
|
9
|
+
class DeleteServer < AbstractAction
|
8
10
|
def initialize(app, _env)
|
9
11
|
@app = app
|
10
12
|
@logger = Log4r::Logger.new('vagrant_openstack::action::delete_server')
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def execute(env)
|
14
16
|
if env[:machine].id
|
15
17
|
@logger.info "Deleting server #{env[:machine].id}..."
|
16
18
|
env[:ui].info(I18n.t('vagrant_openstack.deleting_server'))
|
17
19
|
env[:openstack_client].nova.delete_server(env, env[:machine].id)
|
18
20
|
env[:openstack_client].nova.delete_keypair_if_vagrant(env, env[:machine].id)
|
19
|
-
|
21
|
+
|
22
|
+
waiting_for_instance_to_be_deleted(env, env[:machine].id)
|
23
|
+
|
20
24
|
end
|
21
25
|
|
22
26
|
@app.call(env)
|
23
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def waiting_for_instance_to_be_deleted(env, instance_id, retry_interval = 3, timeout = 200)
|
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
|
+
timeout(timeout, Errors::Timeout) do
|
35
|
+
delete_ok = false
|
36
|
+
until delete_ok
|
37
|
+
begin
|
38
|
+
@logger.debug('Waiting for instance to be DELETED')
|
39
|
+
server_status = env[:openstack_client].nova.get_server_details(env, instance_id)['status']
|
40
|
+
fail Errors::ServerStatusError, server: instance_id if server_status == 'ERROR'
|
41
|
+
break if server_status == 'DELETED'
|
42
|
+
sleep retry_interval
|
43
|
+
rescue Errors::InstanceNotFound
|
44
|
+
delete_ok = true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
24
49
|
end
|
25
50
|
end
|
26
51
|
end
|