vagrant-profitbricks 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Appraisals +35 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +18 -0
- data/LICENSE +202 -0
- data/README.md +268 -0
- data/RELEASE.md +15 -0
- data/Rakefile +21 -0
- data/Vagrantfile +30 -0
- data/bootstrap.cmd +16 -0
- data/dummy.box +36 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/features/provision.feature +36 -0
- data/features/steps/sdk_steps.rb +13 -0
- data/features/steps/server_steps.rb +25 -0
- data/features/support/env.rb +35 -0
- data/features/support/fog_mock.rb +17 -0
- data/features/vagrant-profitbricks.feature +66 -0
- data/lib/vagrant-profitbricks.rb +53 -0
- data/lib/vagrant-profitbricks/action.rb +166 -0
- data/lib/vagrant-profitbricks/action/connect_profitbricks.rb +39 -0
- data/lib/vagrant-profitbricks/action/create_image.rb +53 -0
- data/lib/vagrant-profitbricks/action/create_server.rb +194 -0
- data/lib/vagrant-profitbricks/action/delete_server.rb +43 -0
- data/lib/vagrant-profitbricks/action/is_created.rb +16 -0
- data/lib/vagrant-profitbricks/action/list_flavors.rb +20 -0
- data/lib/vagrant-profitbricks/action/list_images.rb +20 -0
- data/lib/vagrant-profitbricks/action/list_keypairs.rb +20 -0
- data/lib/vagrant-profitbricks/action/list_networks.rb +20 -0
- data/lib/vagrant-profitbricks/action/list_servers.rb +21 -0
- data/lib/vagrant-profitbricks/action/message_already_created.rb +16 -0
- data/lib/vagrant-profitbricks/action/message_not_created.rb +16 -0
- data/lib/vagrant-profitbricks/action/read_ssh_info.rb +49 -0
- data/lib/vagrant-profitbricks/action/read_state.rb +39 -0
- data/lib/vagrant-profitbricks/action/run_init_script.rb +28 -0
- data/lib/vagrant-profitbricks/command/create_image.rb +21 -0
- data/lib/vagrant-profitbricks/command/flavors.rb +21 -0
- data/lib/vagrant-profitbricks/command/images.rb +33 -0
- data/lib/vagrant-profitbricks/command/keypairs.rb +21 -0
- data/lib/vagrant-profitbricks/command/list_images.rb +21 -0
- data/lib/vagrant-profitbricks/command/networks.rb +21 -0
- data/lib/vagrant-profitbricks/command/root.rb +79 -0
- data/lib/vagrant-profitbricks/command/servers.rb +21 -0
- data/lib/vagrant-profitbricks/config.rb +152 -0
- data/lib/vagrant-profitbricks/errors.rb +39 -0
- data/lib/vagrant-profitbricks/plugin.rb +44 -0
- data/lib/vagrant-profitbricks/provider.rb +50 -0
- data/lib/vagrant-profitbricks/version.rb +5 -0
- data/locales/en.yml +124 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/vagrant-profitbricks/actions/list_flavors_spec.rb +48 -0
- data/spec/vagrant-profitbricks/actions/list_images_spec.rb +48 -0
- data/spec/vagrant-profitbricks/config_spec.rb +150 -0
- data/vagrant-profitbricks.gemspec +25 -0
- metadata +164 -0
data/RELEASE.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Release process
|
2
|
+
|
3
|
+
This is the current release process for 'vagrant-profitbricks'.
|
4
|
+
|
5
|
+
## Prepare the release
|
6
|
+
|
7
|
+
* Update the version in "lib/vagrant-profitbricks/version.rb"
|
8
|
+
* Update the version in CHANGELOG.md
|
9
|
+
* Use "rake release". This will make sure to tag that commit and push it to RubyGems.
|
10
|
+
* Create new [github release](https://github.com/profitbricks/vagrant-profitbricks/releases)
|
11
|
+
* Update the version again in both files to a dev version for working again.
|
12
|
+
|
13
|
+
The CHANGELOG.md should be maintained in a similar format to Vagrant:
|
14
|
+
|
15
|
+
https://github.com/mitchellh/vagrant/blob/master/CHANGELOG.md
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
# Immediately sync all stdout so that tools like buildbot can
|
6
|
+
# immediately load in the output.
|
7
|
+
$stdout.sync = true
|
8
|
+
$stderr.sync = true
|
9
|
+
|
10
|
+
# Change to the directory of this file.
|
11
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
12
|
+
|
13
|
+
# This installs the tasks that help with gem creation and
|
14
|
+
# publishing.
|
15
|
+
Bundler::GemHelper.install_tasks
|
16
|
+
|
17
|
+
# Install the `spec` task so that we can run tests.
|
18
|
+
RSpec::Core::RakeTask.new
|
19
|
+
|
20
|
+
# Default task is to run the unit tests
|
21
|
+
task :default => "spec"
|
data/Vagrantfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
5
|
+
# configures the configuration version (we support older styles for
|
6
|
+
# backwards compatibility). Please don't change it unless you know what
|
7
|
+
# you're doing.
|
8
|
+
Vagrant.configure("2") do |config|
|
9
|
+
# The most common configuration options are documented and commented below.
|
10
|
+
# For a complete reference, please see the online documentation at
|
11
|
+
# https://docs.vagrantup.com.
|
12
|
+
|
13
|
+
# Every Vagrant development environment requires a box. You can search for
|
14
|
+
# boxes at https://atlas.hashicorp.com/search.
|
15
|
+
config.vm.box = 'profitbricks'
|
16
|
+
config.vm.provider :profitbricks do |profitbricks|
|
17
|
+
profitbricks.username = 'YOUR_PB_USERNAME'
|
18
|
+
profitbricks.password = 'YOUR_PB_PASSWORD'
|
19
|
+
profitbricks.profitbricks_url = 'https://api.profitbricks.com/cloudapi/v3/'
|
20
|
+
profitbricks.datacenter_id = 'pb vagrant test'
|
21
|
+
profitbricks.location = 'de/fkb'
|
22
|
+
profitbricks.image = 'openSUSE-13.2-server-2016-11-01'
|
23
|
+
profitbricks.volume_licence_type = 'LINUX'
|
24
|
+
profitbricks.profitbricks_cores = '1'
|
25
|
+
profitbricks.profitbricks_ram = '2048'
|
26
|
+
profitbricks.image_password = 'PASSWORD'
|
27
|
+
# profitbricks.volume_ssh_keys = ['YOUR_PUBLIC_SSH_KEY'] # if you want to enable SSH (Works with ProfitBricks supplied Linux images)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/bootstrap.cmd
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Function SetupWinRM
|
2
|
+
{
|
3
|
+
Param(
|
4
|
+
[String]$hostname,
|
5
|
+
[String]$thumbprint
|
6
|
+
)
|
7
|
+
netsh advfirewall firewall set rule group="remote administration" new enable=yes
|
8
|
+
netsh advfirewall firewall add rule name="WinRM HTTP" dir=in action=allow protocol=TCP localport=5985
|
9
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" dir=in action=allow protocol=TCP localport=5986
|
10
|
+
winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"${hostname}`"; CertificateThumbprint=`"${thumbprint}`"}"
|
11
|
+
}
|
12
|
+
|
13
|
+
$hostname = $env:COMPUTERNAME
|
14
|
+
$cert = New-SelfSignedCertificate -CertStoreLocation cert:\LocalMachine\My -DnsName $hostname
|
15
|
+
$thumbprint = $cert.Thumbprint
|
16
|
+
SetupWinRM -hostname $hostname -thumbprint $thumbprint
|
data/dummy.box
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
1f8b 0800 f4d2 3351 0003 ed95 5d6f 9b30
|
2
|
+
1486 7bed 5f71 4426 ad9d 140a 2909 12d2
|
3
|
+
2ef6 91cb dd74 d5ae e3c2 21b8 059c d986
|
4
|
+
b45b f7df 7780 0465 93b6 5ca5 53b5 f348
|
5
|
+
91b1 395f 3ef6 4bfc cbeb e5bb 8f9f 967e
|
6
|
+
959d 9d8a 2008 1651 04dd 182f e6fd 18cc
|
7
|
+
8679 4f1c 0510 cec2 308a 67d1 fc2a 8620
|
8
|
+
bc5a 84f3 3308 4e56 d101 8d75 d250 2995
|
9
|
+
7269 8165 59fc c18e ccf2 fc2f 7186 adc0
|
10
|
+
38be 1026 f045 ae8d ac1d 5ccb f4fe f346
|
11
|
+
a608 1f4a dd64 b07c 90d5 a644 78af 1f84
|
12
|
+
d81b 6d8c 6e55 86c6 02ca b400 835f 1b65
|
13
|
+
1024 a4d4 475d 8def a776 83a9 ca55 0ab7
|
14
|
+
fa01 726d 2ae9 7c71 5328 4b93 920c c016
|
15
|
+
7a6b c115 08b8 4b94 eada 61ed 2ce8 9c02
|
16
|
+
eefc 7a8b 95a1 da6c 57db 6acc 40d1 34b8
|
17
|
+
c6d4 6441 5155 edf4 e095 08b1 5aad c42b
|
18
|
+
a073 85b4 fd96 c3e8 ed77 41fd cb0a 9dcc
|
19
|
+
a493 fe9d d535 cd77 9bcb 5589 bdeb 5067
|
20
|
+
67bb d5e6 9e9e 1ea1 b1aa 5eef 5bf5 9a96
|
21
|
+
1a55 baa9 aae1 c017 2a34 ebce 8c2a b1e8
|
22
|
+
9a8d c830 974d e96c bf91 b1bf 3edc 1468
|
23
|
+
11c6 b7a9 aca9 9d56 958f 708b a05b 345b
|
24
|
+
a31c f5a2 cb5c a875 41fd 2cb1 c552 1c64
|
25
|
+
b370 6e1b 3a02 69bb 96dc 61ea c068 ed0e
|
26
|
+
0bb2 17be 3876 febf ecfe 4477 ec98 fec3
|
27
|
+
381e f5bf 20ed 0461 340f 17ac ffe7 6002
|
28
|
+
d337 53a8 7486 0998 86ee 1b4d c504 5a95
|
29
|
+
7477 1872 f7b6 5f4d c64f 804f 32cd d5ba
|
30
|
+
3178 eecd bc0b c834 3c0d 4b4f 0260 78f2
|
31
|
+
dbca dfeb 1492 517e bdad b19d 1dd6 99e8
|
32
|
+
7eff 7afb ff3d bf7d 0d4f 92e3 98fe 83c3
|
33
|
+
ffff f9ac d37f 1cc7 acff e7e0 3b89 11c0
|
34
|
+
dbab d54b c01b f5ea 891f 2c50 8661 1886
|
35
|
+
6118 8661 1886 6118 8661 1886 6118 8661
|
36
|
+
9817 c24f 55d9 a1bd 0028 0000
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Vagrant ProfitBricks Cloud Example Box
|
2
|
+
|
3
|
+
Vagrant providers each require a custom provider-specific box format.
|
4
|
+
This folder shows the example contents of a box for the `profitbricks` provider.
|
5
|
+
To turn this into a box:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ tar cvzf profitbricks.box ./metadata.json ./Vagrantfile
|
9
|
+
```
|
10
|
+
|
11
|
+
This box works by using Vagrant's built-in Vagrantfile merging to setup
|
12
|
+
defaults for ProfitBricks. These defaults can easily be overwritten by higher-level
|
13
|
+
Vagrantfiles (such as project root Vagrantfiles).
|
@@ -0,0 +1,36 @@
|
|
1
|
+
@announce
|
2
|
+
@vagrant-profitbricks
|
3
|
+
Feature: vagrant-profitbricks fog tests
|
4
|
+
|
5
|
+
Background:
|
6
|
+
Given I have ProfitBricks credentials available
|
7
|
+
And I have a "fog_mock.rb" file
|
8
|
+
|
9
|
+
Scenario: Create a single server (with provisioning)
|
10
|
+
Given a file named "Vagrantfile" with:
|
11
|
+
"""
|
12
|
+
Vagrant.configure("2") do |config|
|
13
|
+
Vagrant.require_plugin "vagrant-profitbricks"
|
14
|
+
|
15
|
+
config.vm.box = "dummy"
|
16
|
+
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
17
|
+
|
18
|
+
|
19
|
+
config.vm.provider :profitbricks do |rs|
|
20
|
+
rs.server_name = 'vagrant-provisioned-server'
|
21
|
+
rs.username = ENV['PB_USERNAME']
|
22
|
+
rs.password = ENV['PB_PASSWORD']
|
23
|
+
rs.flavor = "Micro"
|
24
|
+
rs.image = /Ubuntu/
|
25
|
+
rs.admin_password = 'Vagrant123'
|
26
|
+
rs.data_center_id = /My/ #'d7c69d5e-59e2-4133-a982-788fe4bb7599'
|
27
|
+
rs.profitbricks_volume_size = 8
|
28
|
+
end
|
29
|
+
|
30
|
+
config.vm.provision :shell, :inline => "echo Hello, World"
|
31
|
+
end
|
32
|
+
"""
|
33
|
+
When I successfully run `bundle exec vagrant up --provider profitbricks`
|
34
|
+
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
|
35
|
+
# And I get the server from "Instance ID:"
|
36
|
+
Then the server "vagrant-provisioned-server" should be active
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Given(/^I have ProfitBricks credentials available$/) do
|
2
|
+
fail unless ENV['PB_USERNAME'] && ENV['PB_API_PASSWORD']
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^I have a "fog_mock.rb" file$/) do
|
6
|
+
script = File.open("features/support/fog_mock.rb").read
|
7
|
+
steps %Q{
|
8
|
+
Given a file named "fog_mock.rb" with:
|
9
|
+
"""
|
10
|
+
#{script}
|
11
|
+
"""
|
12
|
+
}
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
When(/^I get the server from "(.*?)"$/) do |label|
|
2
|
+
@server_id = all_output.match(/#{label}\s([\w-]*)/)[1]
|
3
|
+
puts "Server: #{@server_id}"
|
4
|
+
end
|
5
|
+
|
6
|
+
When(/^I load the server$/) do
|
7
|
+
@server_id = all_output.strip.lines.to_a.last
|
8
|
+
puts "Server: #{@server_id}"
|
9
|
+
end
|
10
|
+
|
11
|
+
Then(/^the server should be active$/) do
|
12
|
+
unless Fog.mock? # unfortunately we can't assert this with Fog.mock!, since mocked objects do not persist from the subprocess
|
13
|
+
assert_active @server_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Then(/^the server "(.+)" should be active$/) do |server_name|
|
18
|
+
server = @compute.servers.all.find{|s| s.name == server_name}
|
19
|
+
assert_active server.id
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_active server_id
|
23
|
+
server = @compute.servers.get server_id
|
24
|
+
server.state.should == 'available'
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fog'
|
2
|
+
require 'aruba/cucumber'
|
3
|
+
|
4
|
+
Fog.mock! if ENV['PB_MOCK'] == 'true'
|
5
|
+
|
6
|
+
Before do | scenario |
|
7
|
+
@aruba_timeout_seconds = 600
|
8
|
+
@scenario = File.basename(scenario.file)
|
9
|
+
ENV['CASSETTE'] = @scenario
|
10
|
+
|
11
|
+
# proxy_options = {
|
12
|
+
# :connection_options => {
|
13
|
+
# :proxy => ENV['https_proxy'],
|
14
|
+
# :ssl_verify_peer => false
|
15
|
+
# }
|
16
|
+
# }
|
17
|
+
|
18
|
+
connect_options = {
|
19
|
+
:provider => 'profitbricks',
|
20
|
+
:profitbricks_username => ENV['PB_USERNAME'],
|
21
|
+
:profitbricks_password => ENV['PB_API_PASSWORD'],
|
22
|
+
}
|
23
|
+
#connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
|
24
|
+
@compute = Fog::Compute.new(connect_options)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Around do | scenario, block |
|
28
|
+
# Bundler.with_clean_env do
|
29
|
+
# block.call
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
After('@creates_server') do
|
34
|
+
@compute.servers.delete @server_id
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fog'
|
2
|
+
if ENV['PB_MOCK'] == 'true'
|
3
|
+
Fog.mock!
|
4
|
+
# Fog::ProfitBricks::MockData.configure do |c|
|
5
|
+
# c[:image_name_generator] = Proc.new { "Ubuntu" }
|
6
|
+
# c[:ipv4_generator] = Proc.new { "10.11.12.2"}
|
7
|
+
# end
|
8
|
+
connect_options = {
|
9
|
+
:provider => 'profitbricks',
|
10
|
+
:profitbricks_username => ENV['PB_USERNAME'],
|
11
|
+
:profitbricks_password => ENV['PB_API_PASSWORD']
|
12
|
+
}
|
13
|
+
connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
|
14
|
+
compute = Fog::Compute.new(connect_options)
|
15
|
+
# Force creation of Ubuntu image so it will show up in compute.images.list
|
16
|
+
compute.images.get(0)
|
17
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
@announce
|
2
|
+
@vagrant-profitbricks
|
3
|
+
Feature: vagrant-profitbricks fog tests
|
4
|
+
As a Fog developer
|
5
|
+
I want to smoke (or "fog") test vagrant-profitbricks.
|
6
|
+
So I am confident my upstream changes did not create downstream problems.
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given I have ProfitBricks credentials available
|
10
|
+
And I have a "fog_mock.rb" file
|
11
|
+
|
12
|
+
Scenario: Create a single server
|
13
|
+
Given a file named "Vagrantfile" with:
|
14
|
+
"""
|
15
|
+
# Testing options
|
16
|
+
require File.expand_path '../fog_mock', __FILE__
|
17
|
+
|
18
|
+
Vagrant.configure("2") do |config|
|
19
|
+
# dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-profitbricks'
|
20
|
+
Vagrant.require_plugin "vagrant-profitbricks"
|
21
|
+
|
22
|
+
config.vm.box = "dummy"
|
23
|
+
config.ssh.username = "vagrant" if Fog.mock?
|
24
|
+
config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
|
25
|
+
|
26
|
+
config.vm.provider :profitbricks do |rs|
|
27
|
+
rs.server_name = 'vagrant-single-server'
|
28
|
+
rs.username = ENV['PB_USERNAME']
|
29
|
+
rs.password = ENV['PB_PASSWORD']
|
30
|
+
rs.flavor = /1 GB Performance/
|
31
|
+
rs.image = /Ubuntu/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
"""
|
35
|
+
When I successfully run `bundle exec vagrant up --provider profitbricks`
|
36
|
+
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
|
37
|
+
# And I get the server from "Instance ID:"
|
38
|
+
Then the server "vagrant-single-server" should be active
|
39
|
+
|
40
|
+
Scenario: Create a single server (profitbricks_compute_url)
|
41
|
+
Given a file named "Vagrantfile" with:
|
42
|
+
"""
|
43
|
+
# Testing options
|
44
|
+
require File.expand_path '../fog_mock', __FILE__
|
45
|
+
|
46
|
+
Vagrant.configure("2") do |config|
|
47
|
+
# dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-profitbricks'
|
48
|
+
Vagrant.require_plugin "vagrant-profitbricks"
|
49
|
+
|
50
|
+
config.vm.box = "dummy"
|
51
|
+
config.ssh.username = "vagrant" if Fog.mock?
|
52
|
+
config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
|
53
|
+
|
54
|
+
config.vm.provider :profitbricks do |rs|
|
55
|
+
rs.server_name = 'vagrant-single-server'
|
56
|
+
rs.username = ENV['PB_USERNAME']
|
57
|
+
rs.password = ENV['PB_PASSWORD']
|
58
|
+
rs.flavor = /1 GB Performance/
|
59
|
+
rs.image = /Ubuntu/
|
60
|
+
end
|
61
|
+
end
|
62
|
+
"""
|
63
|
+
When I successfully run `bundle exec vagrant up --provider profitbricks`
|
64
|
+
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
|
65
|
+
# And I get the server from "Instance ID:"
|
66
|
+
Then the server "vagrant-single-server" should be active
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "vagrant-profitbricks/plugin"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module ProfitBricks
|
6
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-profitbricks", __FILE__))
|
7
|
+
autoload :Action, lib_path.join("action")
|
8
|
+
autoload :Errors, lib_path.join("errors")
|
9
|
+
|
10
|
+
# This returns the path to the source of this plugin.
|
11
|
+
#
|
12
|
+
# @return [Pathname]
|
13
|
+
def self.source_root
|
14
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
# This initializes the i18n load path so that the plugin-specific
|
18
|
+
# translations work.
|
19
|
+
def self.init_i18n
|
20
|
+
I18n.load_path << File.expand_path("locales/en.yml", source_root)
|
21
|
+
I18n.reload!
|
22
|
+
end
|
23
|
+
|
24
|
+
# This initializes the logging so that our logs are outputted at
|
25
|
+
# the same level as Vagrant core logs.
|
26
|
+
def self.init_logging
|
27
|
+
# Initialize logging
|
28
|
+
level = nil
|
29
|
+
begin
|
30
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
31
|
+
rescue NameError
|
32
|
+
# This means that the logging constant wasn't found,
|
33
|
+
# which is fine. We just keep `level` as `nil`. But
|
34
|
+
# we tell the user.
|
35
|
+
level = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# Some constants, such as "true" resolve to booleans, so the
|
39
|
+
# above error checking doesn't catch it. This will check to make
|
40
|
+
# sure that the log level is an integer, as Log4r requires.
|
41
|
+
level = nil if !level.is_a?(Integer)
|
42
|
+
|
43
|
+
# Set the logging level on all "vagrant" namespaced
|
44
|
+
# logs as long as we have a valid level.
|
45
|
+
if level
|
46
|
+
logger = Log4r::Logger.new("vagrant_profitbricks")
|
47
|
+
logger.outputters = Log4r::Outputter.stderr
|
48
|
+
logger.level = level
|
49
|
+
logger = nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "vagrant/action/builder"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ProfitBricks
|
7
|
+
module Action
|
8
|
+
# Include the built-in modules so we can use them as top-level things.
|
9
|
+
include Vagrant::Action::Builtin
|
10
|
+
|
11
|
+
# The autoload farm
|
12
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
13
|
+
autoload :ConnectProfitBricks, action_root.join("connect_profitbricks")
|
14
|
+
autoload :CreateServer, action_root.join("create_server")
|
15
|
+
autoload :DeleteServer, action_root.join("delete_server")
|
16
|
+
autoload :IsCreated, action_root.join("is_created")
|
17
|
+
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
18
|
+
autoload :MessageNotCreated, action_root.join("message_not_created")
|
19
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
20
|
+
autoload :ReadState, action_root.join("read_state")
|
21
|
+
autoload :RunInitScript, action_root.join("run_init_script")
|
22
|
+
autoload :CreateImage, action_root.join("create_image")
|
23
|
+
autoload :ListImages, action_root.join("list_images")
|
24
|
+
autoload :ListFlavors, action_root.join("list_flavors")
|
25
|
+
autoload :ListInterfaces, action_root.join("list_networks")
|
26
|
+
autoload :ListServers, action_root.join("list_servers")
|
27
|
+
|
28
|
+
# This action is called to destroy the remote machine.
|
29
|
+
def self.action_destroy
|
30
|
+
Vagrant::Action::Builder.new.tap do |b|
|
31
|
+
b.use ConfigValidate
|
32
|
+
b.use Call, IsCreated do |env, b1|
|
33
|
+
if !env[:result]
|
34
|
+
b1.use MessageNotCreated
|
35
|
+
next
|
36
|
+
end
|
37
|
+
|
38
|
+
b1.use Call, DestroyConfirm do |env1, b2|
|
39
|
+
if env1[:result]
|
40
|
+
b2.use ConnectProfitBricks
|
41
|
+
b2.use DeleteServer
|
42
|
+
b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
|
43
|
+
else
|
44
|
+
b2.use Message, I18n.t("vagrant_profitbricks.will_not_destroy")
|
45
|
+
next
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# This action is called when `vagrant provision` is called.
|
53
|
+
def self.action_provision
|
54
|
+
Vagrant::Action::Builder.new.tap do |b|
|
55
|
+
b.use ConfigValidate
|
56
|
+
b.use Call, IsCreated do |env, b2|
|
57
|
+
if !env[:result]
|
58
|
+
b2.use MessageNotCreated
|
59
|
+
next
|
60
|
+
end
|
61
|
+
|
62
|
+
b2.use Provision
|
63
|
+
b2.use SyncedFolders
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# This action is called to read the SSH info of the machine. The
|
69
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
70
|
+
# key.
|
71
|
+
def self.action_read_ssh_info
|
72
|
+
Vagrant::Action::Builder.new.tap do |b|
|
73
|
+
b.use ConfigValidate
|
74
|
+
b.use ConnectProfitBricks
|
75
|
+
b.use ReadSSHInfo
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# This action is called to read the state of the machine. The
|
80
|
+
# resulting state is expected to be put into the `:machine_state_id`
|
81
|
+
# key.
|
82
|
+
def self.action_read_state
|
83
|
+
Vagrant::Action::Builder.new.tap do |b|
|
84
|
+
b.use ConfigValidate
|
85
|
+
b.use ConnectProfitBricks
|
86
|
+
b.use ReadState
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.action_ssh
|
91
|
+
Vagrant::Action::Builder.new.tap do |b|
|
92
|
+
b.use ConfigValidate
|
93
|
+
b.use Call, IsCreated do |env, b2|
|
94
|
+
if !env[:result]
|
95
|
+
b2.use MessageNotCreated
|
96
|
+
next
|
97
|
+
end
|
98
|
+
|
99
|
+
b2.use SSHExec
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.action_ssh_run
|
105
|
+
Vagrant::Action::Builder.new.tap do |b|
|
106
|
+
b.use ConfigValidate
|
107
|
+
b.use Call, IsCreated do |env, b2|
|
108
|
+
if !env[:result]
|
109
|
+
b2.use MessageNotCreated
|
110
|
+
next
|
111
|
+
end
|
112
|
+
|
113
|
+
b2.use SSHRun
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.action_up
|
119
|
+
Vagrant::Action::Builder.new.tap do |b|
|
120
|
+
b.use ConfigValidate
|
121
|
+
b.use ConnectProfitBricks
|
122
|
+
b.use Call, IsCreated do |env, b2|
|
123
|
+
if env[:result]
|
124
|
+
b2.use MessageAlreadyCreated
|
125
|
+
next
|
126
|
+
end
|
127
|
+
|
128
|
+
b2.use Provision
|
129
|
+
b2.use CreateServer
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Extended actions
|
135
|
+
def self.action_list_images
|
136
|
+
Vagrant::Action::Builder.new.tap do |b|
|
137
|
+
# b.use ConfigValidate # is this per machine?
|
138
|
+
b.use ConnectProfitBricks
|
139
|
+
b.use ListImages
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.action_list_flavors
|
144
|
+
Vagrant::Action::Builder.new.tap do |b|
|
145
|
+
# b.use ConfigValidate # is this per machine?
|
146
|
+
b.use ConnectProfitBricks
|
147
|
+
b.use ListFlavors
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.action_list_networks
|
152
|
+
Vagrant::Action::Builder.new.tap do |b|
|
153
|
+
b.use ConnectProfitBricks
|
154
|
+
b.use ListInterfaces
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.action_list_servers
|
159
|
+
Vagrant::Action::Builder.new.tap do |b|
|
160
|
+
b.use ConnectProfitBricks
|
161
|
+
b.use ListServers
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|