vagrant-profitbricks 1.0.0 → 4.0.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 +4 -4
- data/Gemfile +4 -4
- data/README.md +326 -174
- data/Rakefile +4 -2
- data/Vagrantfile +18 -13
- data/example_box/Vagrantfile +9 -0
- data/example_box/profitbricks.box +0 -0
- data/lib/vagrant-profitbricks.rb +12 -11
- data/lib/vagrant-profitbricks/action.rb +79 -40
- data/lib/vagrant-profitbricks/action/connect_profitbricks.rb +14 -12
- data/lib/vagrant-profitbricks/action/create_server.rb +74 -67
- data/lib/vagrant-profitbricks/action/delete_server.rb +33 -13
- data/lib/vagrant-profitbricks/action/is_created.rb +3 -1
- data/lib/vagrant-profitbricks/action/list_flavors.rb +5 -3
- data/lib/vagrant-profitbricks/action/list_images.rb +6 -4
- data/lib/vagrant-profitbricks/action/message_already_created.rb +4 -2
- data/lib/vagrant-profitbricks/action/message_not_created.rb +4 -2
- data/lib/vagrant-profitbricks/action/read_ssh_info.rb +10 -16
- data/lib/vagrant-profitbricks/action/read_state.rb +19 -12
- data/lib/vagrant-profitbricks/action/reboot_server.rb +45 -0
- data/lib/vagrant-profitbricks/action/run_init_script.rb +5 -3
- data/lib/vagrant-profitbricks/action/start_server.rb +50 -0
- data/lib/vagrant-profitbricks/action/stop_server.rb +51 -0
- data/lib/vagrant-profitbricks/command/datacenters.rb +34 -0
- data/lib/vagrant-profitbricks/command/flavors.rb +19 -6
- data/lib/vagrant-profitbricks/command/images.rb +21 -20
- data/lib/vagrant-profitbricks/command/locations.rb +34 -0
- data/lib/vagrant-profitbricks/command/root.rb +28 -23
- data/lib/vagrant-profitbricks/command/servers.rb +7 -4
- data/lib/vagrant-profitbricks/command/snapshots.rb +34 -0
- data/lib/vagrant-profitbricks/command/utils.rb +27 -0
- data/lib/vagrant-profitbricks/config.rb +44 -39
- data/lib/vagrant-profitbricks/errors.rb +14 -5
- data/lib/vagrant-profitbricks/plugin.rb +13 -11
- data/lib/vagrant-profitbricks/provider.rb +8 -6
- data/lib/vagrant-profitbricks/version.rb +3 -1
- data/locales/en.yml +28 -7
- data/spec/spec_helper.rb +4 -2
- data/spec/vagrant-profitbricks/config_spec.rb +65 -96
- data/vagrant-profitbricks.gemspec +17 -14
- metadata +42 -47
- data/Appraisals +0 -35
- data/CHANGELOG.md +0 -3
- data/RELEASE.md +0 -15
- data/bootstrap.cmd +0 -16
- data/features/provision.feature +0 -36
- data/features/steps/sdk_steps.rb +0 -13
- data/features/steps/server_steps.rb +0 -25
- data/features/support/env.rb +0 -35
- data/features/support/fog_mock.rb +0 -17
- data/features/vagrant-profitbricks.feature +0 -66
- data/lib/vagrant-profitbricks/action/create_image.rb +0 -53
- data/lib/vagrant-profitbricks/action/list_keypairs.rb +0 -20
- data/lib/vagrant-profitbricks/action/list_networks.rb +0 -20
- data/lib/vagrant-profitbricks/action/list_servers.rb +0 -21
- data/lib/vagrant-profitbricks/command/create_image.rb +0 -21
- data/lib/vagrant-profitbricks/command/keypairs.rb +0 -21
- data/lib/vagrant-profitbricks/command/list_images.rb +0 -21
- data/lib/vagrant-profitbricks/command/networks.rb +0 -21
- data/spec/vagrant-profitbricks/actions/list_flavors_spec.rb +0 -48
- data/spec/vagrant-profitbricks/actions/list_images_spec.rb +0 -48
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'bundler/setup'
|
3
5
|
require 'rspec/core/rake_task'
|
@@ -8,7 +10,7 @@ $stdout.sync = true
|
|
8
10
|
$stderr.sync = true
|
9
11
|
|
10
12
|
# Change to the directory of this file.
|
11
|
-
Dir.chdir(File.expand_path(
|
13
|
+
Dir.chdir(File.expand_path('../', __FILE__))
|
12
14
|
|
13
15
|
# This installs the tasks that help with gem creation and
|
14
16
|
# publishing.
|
@@ -18,4 +20,4 @@ Bundler::GemHelper.install_tasks
|
|
18
20
|
RSpec::Core::RakeTask.new
|
19
21
|
|
20
22
|
# Default task is to run the unit tests
|
21
|
-
task :
|
23
|
+
task default: 'spec'
|
data/Vagrantfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- mode: ruby -*-
|
2
4
|
# vi: set ft=ruby :
|
3
5
|
|
@@ -5,26 +7,29 @@
|
|
5
7
|
# configures the configuration version (we support older styles for
|
6
8
|
# backwards compatibility). Please don't change it unless you know what
|
7
9
|
# you're doing.
|
8
|
-
Vagrant.configure(
|
10
|
+
Vagrant.configure('2') do |config|
|
9
11
|
# The most common configuration options are documented and commented below.
|
10
12
|
# For a complete reference, please see the online documentation at
|
11
13
|
# https://docs.vagrantup.com.
|
12
14
|
|
13
15
|
# Every Vagrant development environment requires a box. You can search for
|
14
16
|
# boxes at https://atlas.hashicorp.com/search.
|
15
|
-
config.
|
17
|
+
config.ssh.private_key_path = '/path/to/.ssh/id_rsa'
|
18
|
+
|
16
19
|
config.vm.provider :profitbricks do |profitbricks|
|
17
|
-
profitbricks.username
|
18
|
-
profitbricks.password = '
|
19
|
-
profitbricks.profitbricks_url = 'https://api.profitbricks.com/cloudapi/
|
20
|
-
profitbricks.datacenter_id = '
|
20
|
+
profitbricks.username = ENV['PROFITBRICKS_USERNAME']
|
21
|
+
profitbricks.password = ENV['PROFITBRICKS_PASSWORD']
|
22
|
+
profitbricks.profitbricks_url = 'https://api.profitbricks.com/cloudapi/v4/'
|
23
|
+
profitbricks.datacenter_id = '19f5531c-4fb5-4657-9fee-ac6731131074'
|
21
24
|
profitbricks.location = 'de/fkb'
|
22
|
-
profitbricks.
|
23
|
-
profitbricks.
|
24
|
-
profitbricks.
|
25
|
-
profitbricks.
|
26
|
-
profitbricks.
|
27
|
-
|
25
|
+
profitbricks.image_alias = 'ubuntu:latest'
|
26
|
+
profitbricks.cores = '4'
|
27
|
+
profitbricks.ram = '4096'
|
28
|
+
profitbricks.image_password = 'test1234'
|
29
|
+
profitbricks.public_ssh_keys = [File.read('/path/to/.ssh/id_rsa.pub')]
|
30
|
+
end
|
31
|
+
|
32
|
+
config.vm.provision 'shell' do |s|
|
33
|
+
s.inline = 'apt-get update && apt-get install -y'
|
28
34
|
end
|
29
|
-
|
30
35
|
end
|
Binary file
|
data/lib/vagrant-profitbricks.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'vagrant-profitbricks/plugin'
|
3
5
|
|
4
6
|
module VagrantPlugins
|
5
7
|
module ProfitBricks
|
6
|
-
lib_path = Pathname.new(File.expand_path(
|
7
|
-
autoload :Action, lib_path.join(
|
8
|
-
autoload :Errors, lib_path.join(
|
8
|
+
lib_path = Pathname.new(File.expand_path('../vagrant-profitbricks', __FILE__))
|
9
|
+
autoload :Action, lib_path.join('action')
|
10
|
+
autoload :Errors, lib_path.join('errors')
|
9
11
|
|
10
12
|
# This returns the path to the source of this plugin.
|
11
13
|
#
|
12
14
|
# @return [Pathname]
|
13
15
|
def self.source_root
|
14
|
-
@source_root ||= Pathname.new(File.expand_path(
|
16
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
15
17
|
end
|
16
18
|
|
17
19
|
# This initializes the i18n load path so that the plugin-specific
|
18
20
|
# translations work.
|
19
21
|
def self.init_i18n
|
20
|
-
I18n.load_path << File.expand_path(
|
22
|
+
I18n.load_path << File.expand_path('locales/en.yml', source_root)
|
21
23
|
I18n.reload!
|
22
24
|
end
|
23
25
|
|
@@ -27,7 +29,7 @@ module VagrantPlugins
|
|
27
29
|
# Initialize logging
|
28
30
|
level = nil
|
29
31
|
begin
|
30
|
-
level = Log4r.const_get(ENV[
|
32
|
+
level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
|
31
33
|
rescue NameError
|
32
34
|
# This means that the logging constant wasn't found,
|
33
35
|
# which is fine. We just keep `level` as `nil`. But
|
@@ -38,15 +40,14 @@ module VagrantPlugins
|
|
38
40
|
# Some constants, such as "true" resolve to booleans, so the
|
39
41
|
# above error checking doesn't catch it. This will check to make
|
40
42
|
# sure that the log level is an integer, as Log4r requires.
|
41
|
-
level = nil
|
43
|
+
level = nil unless level.is_a?(Integer)
|
42
44
|
|
43
45
|
# Set the logging level on all "vagrant" namespaced
|
44
46
|
# logs as long as we have a valid level.
|
45
47
|
if level
|
46
|
-
logger = Log4r::Logger.new(
|
48
|
+
logger = Log4r::Logger.new('vagrant_profitbricks')
|
47
49
|
logger.outputters = Log4r::Outputter.stderr
|
48
50
|
logger.level = level
|
49
|
-
logger = nil
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
require 'vagrant/action/builder'
|
4
6
|
|
5
7
|
module VagrantPlugins
|
6
8
|
module ProfitBricks
|
@@ -9,28 +11,30 @@ module VagrantPlugins
|
|
9
11
|
include Vagrant::Action::Builtin
|
10
12
|
|
11
13
|
# The autoload farm
|
12
|
-
action_root = Pathname.new(File.expand_path(
|
13
|
-
autoload :ConnectProfitBricks, action_root.join(
|
14
|
-
autoload :CreateServer, action_root.join(
|
15
|
-
autoload :DeleteServer, action_root.join(
|
16
|
-
autoload :IsCreated, action_root.join(
|
17
|
-
autoload :MessageAlreadyCreated, action_root.join(
|
18
|
-
autoload :MessageNotCreated, action_root.join(
|
19
|
-
autoload :ReadSSHInfo, action_root.join(
|
20
|
-
autoload :ReadState, action_root.join(
|
21
|
-
autoload :RunInitScript, action_root.join(
|
22
|
-
autoload :CreateImage, action_root.join(
|
23
|
-
autoload :
|
24
|
-
autoload :ListFlavors, action_root.join(
|
25
|
-
autoload :
|
26
|
-
autoload :ListServers, action_root.join(
|
14
|
+
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
15
|
+
autoload :ConnectProfitBricks, action_root.join('connect_profitbricks')
|
16
|
+
autoload :CreateServer, action_root.join('create_server')
|
17
|
+
autoload :DeleteServer, action_root.join('delete_server')
|
18
|
+
autoload :IsCreated, action_root.join('is_created')
|
19
|
+
autoload :MessageAlreadyCreated, action_root.join('message_already_created')
|
20
|
+
autoload :MessageNotCreated, action_root.join('message_not_created')
|
21
|
+
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
|
22
|
+
autoload :ReadState, action_root.join('read_state')
|
23
|
+
autoload :RunInitScript, action_root.join('run_init_script')
|
24
|
+
autoload :CreateImage, action_root.join('create_image')
|
25
|
+
autoload :Stop, action_root.join('stop_server')
|
26
|
+
autoload :ListFlavors, action_root.join('list_flavors')
|
27
|
+
autoload :Start, action_root.join('start_server')
|
28
|
+
autoload :ListServers, action_root.join('list_servers')
|
29
|
+
autoload :Reboot, action_root.join('reboot_server')
|
30
|
+
autoload :ListImages, action_root.join('list_images')
|
27
31
|
|
28
32
|
# This action is called to destroy the remote machine.
|
29
33
|
def self.action_destroy
|
30
34
|
Vagrant::Action::Builder.new.tap do |b|
|
31
35
|
b.use ConfigValidate
|
32
36
|
b.use Call, IsCreated do |env, b1|
|
33
|
-
|
37
|
+
unless env[:result]
|
34
38
|
b1.use MessageNotCreated
|
35
39
|
next
|
36
40
|
end
|
@@ -41,7 +45,7 @@ module VagrantPlugins
|
|
41
45
|
b2.use DeleteServer
|
42
46
|
b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
|
43
47
|
else
|
44
|
-
b2.use Message, I18n.t(
|
48
|
+
b2.use Message, I18n.t('vagrant_profitbricks.will_not_destroy')
|
45
49
|
next
|
46
50
|
end
|
47
51
|
end
|
@@ -49,18 +53,35 @@ module VagrantPlugins
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
56
|
+
def self.action_reload
|
57
|
+
Vagrant::Action::Builder.new.tap do |b|
|
58
|
+
b.use ConfigValidate
|
59
|
+
b.use ConnectProfitBricks
|
60
|
+
b.use Call, GetState do |env, b1|
|
61
|
+
case env[:machine_state]
|
62
|
+
when :active
|
63
|
+
b1.use Reload
|
64
|
+
b1.use Provision
|
65
|
+
when :off
|
66
|
+
env[:ui].info I18n.t('vagrant_profitbricks.states.long_off')
|
67
|
+
when :not_created
|
68
|
+
env[:ui].info I18n.t('vagrant_profitbricks.not_created')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
52
74
|
# This action is called when `vagrant provision` is called.
|
53
75
|
def self.action_provision
|
54
76
|
Vagrant::Action::Builder.new.tap do |b|
|
55
77
|
b.use ConfigValidate
|
56
78
|
b.use Call, IsCreated do |env, b2|
|
57
|
-
|
79
|
+
unless env[:result]
|
58
80
|
b2.use MessageNotCreated
|
59
81
|
next
|
60
82
|
end
|
61
83
|
|
62
84
|
b2.use Provision
|
63
|
-
b2.use SyncedFolders
|
64
85
|
end
|
65
86
|
end
|
66
87
|
end
|
@@ -91,7 +112,7 @@ module VagrantPlugins
|
|
91
112
|
Vagrant::Action::Builder.new.tap do |b|
|
92
113
|
b.use ConfigValidate
|
93
114
|
b.use Call, IsCreated do |env, b2|
|
94
|
-
|
115
|
+
unless env[:result]
|
95
116
|
b2.use MessageNotCreated
|
96
117
|
next
|
97
118
|
end
|
@@ -105,7 +126,7 @@ module VagrantPlugins
|
|
105
126
|
Vagrant::Action::Builder.new.tap do |b|
|
106
127
|
b.use ConfigValidate
|
107
128
|
b.use Call, IsCreated do |env, b2|
|
108
|
-
|
129
|
+
unless env[:result]
|
109
130
|
b2.use MessageNotCreated
|
110
131
|
next
|
111
132
|
end
|
@@ -119,46 +140,64 @@ module VagrantPlugins
|
|
119
140
|
Vagrant::Action::Builder.new.tap do |b|
|
120
141
|
b.use ConfigValidate
|
121
142
|
b.use ConnectProfitBricks
|
122
|
-
b.use Call,
|
143
|
+
b.use Call, ReadState do |env, b2|
|
123
144
|
if env[:result]
|
124
145
|
b2.use MessageAlreadyCreated
|
125
146
|
next
|
126
147
|
end
|
127
|
-
|
128
|
-
|
129
|
-
|
148
|
+
case env[:machine_state_id]
|
149
|
+
when :not_created
|
150
|
+
b2.use CreateServer
|
151
|
+
b2.use Provision
|
152
|
+
when :off
|
153
|
+
b2.use Start
|
154
|
+
b2.use Provision
|
155
|
+
end
|
130
156
|
end
|
131
157
|
end
|
132
158
|
end
|
133
159
|
|
134
|
-
|
135
|
-
def self.action_list_images
|
160
|
+
def self.action_halt
|
136
161
|
Vagrant::Action::Builder.new.tap do |b|
|
137
|
-
|
138
|
-
|
139
|
-
|
162
|
+
b.use Call, IsCreated do |env, b1|
|
163
|
+
unless env[:result]
|
164
|
+
b1.use MessageNotCreated
|
165
|
+
next
|
166
|
+
end
|
167
|
+
|
168
|
+
b1.use ConfigValidate
|
169
|
+
b1.use ConnectProfitBricks
|
170
|
+
b1.use Stop
|
171
|
+
end
|
140
172
|
end
|
141
173
|
end
|
142
174
|
|
143
|
-
def self.
|
175
|
+
def self.action_reload
|
144
176
|
Vagrant::Action::Builder.new.tap do |b|
|
145
|
-
|
146
|
-
|
147
|
-
|
177
|
+
b.use Call, IsCreated do |env, b1|
|
178
|
+
unless env[:result]
|
179
|
+
b1.use MessageNotCreated
|
180
|
+
next
|
181
|
+
end
|
182
|
+
b1.use ConfigValidate
|
183
|
+
b1.use ConnectProfitBricks
|
184
|
+
b1.use Reboot
|
185
|
+
end
|
148
186
|
end
|
149
187
|
end
|
150
188
|
|
151
|
-
def self.
|
189
|
+
def self.action_list_flavors
|
152
190
|
Vagrant::Action::Builder.new.tap do |b|
|
191
|
+
b.use ConfigValidate
|
153
192
|
b.use ConnectProfitBricks
|
154
|
-
b.use
|
193
|
+
b.use ListFlavors
|
155
194
|
end
|
156
195
|
end
|
157
196
|
|
158
|
-
def self.
|
197
|
+
def self.action_list_images
|
159
198
|
Vagrant::Action::Builder.new.tap do |b|
|
160
199
|
b.use ConnectProfitBricks
|
161
|
-
b.use
|
200
|
+
b.use ListImages
|
162
201
|
end
|
163
202
|
end
|
164
203
|
end
|
@@ -1,35 +1,37 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fog/profitbricks'
|
4
|
+
require 'log4r'
|
3
5
|
|
4
6
|
module VagrantPlugins
|
5
7
|
module ProfitBricks
|
6
8
|
module Action
|
7
9
|
# This action connects to ProfitBricks and verifies that the credentials work
|
8
10
|
class ConnectProfitBricks
|
9
|
-
def initialize(app,
|
11
|
+
def initialize(app, _env)
|
10
12
|
@app = app
|
11
|
-
@logger = Log4r::Logger.new(
|
13
|
+
@logger = Log4r::Logger.new('vagrant_profitbricks::action::connect_profitbricks')
|
12
14
|
end
|
13
15
|
|
14
16
|
def call(env)
|
15
17
|
# Get the configs
|
16
|
-
config
|
17
|
-
password
|
18
|
+
config = env[:machine].provider_config
|
19
|
+
password = config.password
|
18
20
|
username = config.username
|
19
|
-
|
20
21
|
params = {
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
22
|
+
provider: 'ProfitBricks',
|
23
|
+
profitbricks_password: password,
|
24
|
+
profitbricks_username: username,
|
25
|
+
profitbricks_user_agent: I18n.t('vagrant_profitbricks.version')
|
24
26
|
}
|
25
27
|
|
26
28
|
if config.profitbricks_url
|
27
|
-
@logger.info(
|
29
|
+
@logger.info('Connecting to ProfitBricks Cloud API...')
|
28
30
|
params[:profitbricks_url] = config.profitbricks_url
|
29
31
|
end
|
30
32
|
|
31
33
|
env[:profitbricks_compute] = Fog::Compute.new params
|
32
|
-
@logger.info(
|
34
|
+
@logger.info('env[:profitbricks_compute]: ' + env[:profitbricks_compute].to_s)
|
33
35
|
|
34
36
|
@app.call(env)
|
35
37
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fog/profitbricks'
|
4
|
+
require 'log4r'
|
3
5
|
|
4
6
|
require 'vagrant/util/retryable'
|
5
7
|
|
@@ -13,10 +15,11 @@ module VagrantPlugins
|
|
13
15
|
def initialize(app, env)
|
14
16
|
@app = app
|
15
17
|
@compute = env[:profitbricks_compute]
|
16
|
-
@logger = Log4r::Logger.new(
|
18
|
+
@logger = Log4r::Logger.new('vagrant_profitbricks::action::create_server')
|
17
19
|
end
|
18
20
|
|
19
21
|
def call(env)
|
22
|
+
uuid_regex = /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/
|
20
23
|
# Get the ProfitBricks configs
|
21
24
|
config = env[:machine].provider_config
|
22
25
|
machine_config = env[:machine].config
|
@@ -27,52 +30,53 @@ module VagrantPlugins
|
|
27
30
|
end
|
28
31
|
|
29
32
|
# Figure out the Data Center ID,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
env[:ui].info(I18n.t("vagrant_profitbricks.creating_datacenter", :name => config.datacenter_id, :location => config.location))
|
35
|
-
datacenter = @compute.datacenters.create(:name => config.datacenter_id, :location => config.location)
|
36
|
-
|
33
|
+
if config.datacenter_id.match uuid_regex
|
34
|
+
datacenter = find_matching(@compute.datacenters, config.datacenter_id)
|
35
|
+
else
|
36
|
+
raise Errors::NoDatacenterID
|
37
37
|
end
|
38
|
-
raise Errors::NoMatchingDatacenter if !datacenter
|
39
38
|
|
40
39
|
# Find the flavor
|
41
40
|
if config.flavor
|
42
|
-
env[:ui].info(I18n.t(
|
41
|
+
env[:ui].info(I18n.t('vagrant_profitbricks.finding_flavor'))
|
43
42
|
flavor = find_matching(@compute.flavors, config.flavor)
|
44
|
-
raise Errors::NoMatchingFlavor
|
43
|
+
raise Errors::NoMatchingFlavor unless flavor
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
env[:ui].info(I18n.t("datacenter.location: #{datacenter.location}"))
|
51
|
-
images = @compute.images.all
|
52
|
-
image = find_matching_image(images, config.image, datacenter.location)
|
46
|
+
if !config.image && !config.image_alias
|
47
|
+
raise Errors::ImageOrLicenceTypeMustBeProvided
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
|
50
|
+
if config.image
|
51
|
+
images = @compute.images.all
|
52
|
+
image = find_matching_image(images, config.image, datacenter.location)
|
53
|
+
end
|
56
54
|
|
55
|
+
if config.image_alias
|
56
|
+
# Figure out the name for the server
|
57
|
+
server_name = config.server_name || env[:machine].name
|
58
|
+
end
|
57
59
|
# Prepare volume values
|
58
|
-
vol_name = server_name.to_s +
|
59
|
-
|
60
|
-
|
60
|
+
vol_name = server_name.to_s + '_volume' if server_name
|
61
|
+
|
62
|
+
vol_size = config.volume_size ? config.volume_size : 5
|
61
63
|
vol_type = config.volume_type
|
62
64
|
vol_licence_type = config.volume_licence_type if config.volume_licence_type
|
63
|
-
vol_ssh_keys = config.
|
65
|
+
vol_ssh_keys = config.public_ssh_keys if config.public_ssh_keys
|
64
66
|
vol_availability_zone = config.volume_availability_zone
|
65
67
|
vol_image_password = config.image_password if config.image_password
|
66
68
|
|
67
69
|
volume = {
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
70
|
+
name: vol_name,
|
71
|
+
size: vol_size,
|
72
|
+
type: vol_type,
|
73
|
+
availability_zone: vol_availability_zone
|
72
74
|
}
|
73
75
|
|
74
|
-
if
|
75
|
-
volume[:image] =
|
76
|
+
if image
|
77
|
+
volume[:image] = image.id
|
78
|
+
elsif config.image_alias
|
79
|
+
volume[:image_alias] = config.image_alias
|
76
80
|
elsif vol_licence_type
|
77
81
|
volume[:licence_type] = vol_licence_type
|
78
82
|
else
|
@@ -87,32 +91,36 @@ module VagrantPlugins
|
|
87
91
|
raise Errors::ImageOrLicenceTypeMustBeProvided
|
88
92
|
end
|
89
93
|
|
90
|
-
|
91
|
-
|
92
94
|
# create LAN if it does not exist, and create a NIC on that LAN
|
93
95
|
lan_id = config.lan_id
|
94
|
-
|
96
|
+
begin
|
97
|
+
lan = @compute.lans.get(datacenter.id, config.lan_id)
|
98
|
+
rescue Excon::Error::NotFound
|
99
|
+
raise Errors::NoLan
|
100
|
+
end
|
95
101
|
|
96
102
|
if !lan || lan.id.end_with?('/lans')
|
97
|
-
lan_name = server_name.to_s +
|
98
|
-
lan = @compute.lans.create(:
|
103
|
+
lan_name = server_name.to_s + '_lan' if server_name
|
104
|
+
lan = @compute.lans.create(datacenter_id: datacenter.id, name: lan_name, public: true)
|
99
105
|
lan_id = lan.id
|
100
106
|
end
|
101
107
|
|
102
|
-
nic_name = server_name.to_s +
|
108
|
+
nic_name = server_name.to_s + '_nic' if server_name
|
103
109
|
nic = {
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
110
|
+
name: nic_name,
|
111
|
+
lan: lan_id,
|
112
|
+
dhcp: true,
|
113
|
+
nat: config.nat
|
108
114
|
}
|
109
115
|
|
110
116
|
# Output the settings we're going to use to the user
|
111
|
-
env[:ui].info(I18n.t(
|
117
|
+
env[:ui].info(I18n.t('vagrant_profitbricks.launching_server'))
|
112
118
|
env[:ui].info(" -- Data Center ID: #{datacenter.id}")
|
119
|
+
env[:ui].info(" -- Location: #{datacenter.location}")
|
113
120
|
env[:ui].info(" -- Name: #{server_name}")
|
114
121
|
env[:ui].info(" -- Volume Name: #{vol_name}")
|
115
122
|
env[:ui].info(" -- Image: #{image.name}") if image
|
123
|
+
env[:ui].info(" -- Image: #{config.image_alias}") if config.image_alias
|
116
124
|
|
117
125
|
server_cores = nil
|
118
126
|
server_ram = nil
|
@@ -121,31 +129,30 @@ module VagrantPlugins
|
|
121
129
|
env[:ui].info(" -- Flavor: #{flavor.name}")
|
122
130
|
server_cores = flavor.cores
|
123
131
|
server_ram = flavor.ram
|
124
|
-
elsif config.
|
125
|
-
env[:ui].info(" -- Server cores: #{config.
|
126
|
-
env[:ui].info(" -- Server ram: #{config.
|
127
|
-
server_cores = config.
|
128
|
-
server_ram = config.
|
132
|
+
elsif config.ram && config.cores
|
133
|
+
env[:ui].info(" -- Server cores: #{config.cores}")
|
134
|
+
env[:ui].info(" -- Server ram: #{config.ram} MB")
|
135
|
+
server_cores = config.cores
|
136
|
+
server_ram = config.ram
|
129
137
|
else
|
130
138
|
raise Errors::NoMatchingFlavor
|
131
139
|
end
|
132
140
|
|
133
141
|
# Create the server
|
134
|
-
env[:ui].info(I18n.t(
|
135
|
-
server = @compute.servers.create(:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
)
|
142
|
+
env[:ui].info(I18n.t('vagrant_profitbricks.creating_server'))
|
143
|
+
server = @compute.servers.create(datacenter_id: datacenter.id,
|
144
|
+
name: server_name,
|
145
|
+
cores: server_cores,
|
146
|
+
ram: server_ram,
|
147
|
+
cpu_family: config.cpu_family,
|
148
|
+
volumes: [volume],
|
149
|
+
nics: [nic])
|
143
150
|
server.wait_for { ready? }
|
144
151
|
|
145
152
|
# Store the ID right away so we can track it
|
146
153
|
env[:machine].id = server.id
|
147
154
|
|
148
|
-
env[:ui].info(I18n.t(
|
155
|
+
env[:ui].info(I18n.t('vagrant_profitbricks.ready'))
|
149
156
|
@app.call(env)
|
150
157
|
end
|
151
158
|
|
@@ -158,8 +165,8 @@ module VagrantPlugins
|
|
158
165
|
def find_matching(collection, name)
|
159
166
|
item = collection.find do |single|
|
160
167
|
single.id == name ||
|
161
|
-
|
162
|
-
|
168
|
+
single.name == name ||
|
169
|
+
(name.is_a?(Regexp) && name =~ single.name)
|
163
170
|
end
|
164
171
|
|
165
172
|
item
|
@@ -170,21 +177,21 @@ module VagrantPlugins
|
|
170
177
|
# `name`. Or, if `name` is a regexp, a partial match is chosen
|
171
178
|
# as well.
|
172
179
|
def find_matching_image(collection, name, location)
|
173
|
-
location
|
174
|
-
item = collection.find
|
175
|
-
image.location
|
176
|
-
|
177
|
-
|
178
|
-
|
180
|
+
location ||= 'us/las'
|
181
|
+
item = collection.find do |image|
|
182
|
+
image.location == location &&
|
183
|
+
image.image_type == 'HDD' &&
|
184
|
+
(image.name == name || image.id == name ||
|
185
|
+
(name.is_a?(Regexp) && image.name =~ name))
|
179
186
|
end
|
180
|
-
|
187
|
+
|
181
188
|
item
|
182
189
|
end
|
183
190
|
|
184
191
|
# Ported from Vagrant::UI, but scoped to the machine's UI
|
185
192
|
def report_server_progress(machine, progress)
|
186
193
|
machine.ui.clear_line
|
187
|
-
line
|
194
|
+
line = "Progress: #{progress}"
|
188
195
|
|
189
196
|
machine.ui.info(line, new_line: false)
|
190
197
|
end
|