vagrant-hp 0.1.2 → 0.1.3
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/.coveragerc +4 -0
- data/.rubocop.yml +885 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +4 -0
- data/CHANGELOG.md_ +13 -0
- data/Gemfile +3 -2
- data/README.md +7 -3
- data/Rakefile +3 -0
- data/Vagrantfile +28 -0
- data/lib/vagrant-hp.rb +6 -7
- data/lib/vagrant-hp/action.rb +18 -17
- data/lib/vagrant-hp/action/connect_hp.rb +15 -16
- data/lib/vagrant-hp/action/create_server.rb +28 -24
- data/lib/vagrant-hp/action/delete_server.rb +6 -3
- data/lib/vagrant-hp/action/halt_server.rb +3 -3
- data/lib/vagrant-hp/action/message_already_created.rb +1 -1
- data/lib/vagrant-hp/action/message_not_created.rb +1 -1
- data/lib/vagrant-hp/action/read_ssh_info.rb +10 -9
- data/lib/vagrant-hp/action/read_state.rb +6 -4
- data/lib/vagrant-hp/action/sync_folders.rb +17 -14
- data/lib/vagrant-hp/action/test.rb +22 -0
- data/lib/vagrant-hp/action/timed_provision.rb +4 -4
- data/lib/vagrant-hp/action/warn_networks.rb +1 -1
- data/lib/vagrant-hp/config.rb +19 -19
- data/lib/vagrant-hp/errors.rb +2 -2
- data/lib/vagrant-hp/plugin.rb +13 -13
- data/lib/vagrant-hp/provider.rb +6 -6
- data/lib/vagrant-hp/version.rb +1 -1
- data/locales/en.yml +4 -0
- data/spec/vagrant-hp/config_spec.rb +20 -18
- data/test.rb +49 -0
- data/test_address.rb +38 -0
- data/test_key.pem +27 -0
- data/vagrant-hp.gemspec +5 -4
- metadata +68 -62
@@ -3,7 +3,7 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'log4r'
|
7
7
|
|
8
8
|
module VagrantPlugins
|
9
9
|
module HP
|
@@ -13,12 +13,12 @@ module VagrantPlugins
|
|
13
13
|
class ReadSSHInfo
|
14
14
|
def initialize(app, env)
|
15
15
|
@app = app
|
16
|
-
@logger = Log4r::Logger.new(
|
16
|
+
@logger = Log4r::Logger.new('vagrant_hp::action::read_ssh_info')
|
17
17
|
end
|
18
18
|
|
19
19
|
def call(env)
|
20
|
-
env[:machine_ssh_info] = read_ssh_info(env[:hp_compute],
|
21
|
-
|
20
|
+
env[:machine_ssh_info] = read_ssh_info(env[:hp_compute],
|
21
|
+
env[:machine])
|
22
22
|
@app.call(env)
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,8 @@ module VagrantPlugins
|
|
29
29
|
server = hp.servers.get(machine.id)
|
30
30
|
if server.nil?
|
31
31
|
# The machine can't be found
|
32
|
-
@logger.info(
|
32
|
+
@logger.info('Machine couldn''t be found,
|
33
|
+
assuming it got destroyed.')
|
33
34
|
machine.id = nil
|
34
35
|
return nil
|
35
36
|
end
|
@@ -39,10 +40,10 @@ module VagrantPlugins
|
|
39
40
|
# Read the DNS info
|
40
41
|
return {
|
41
42
|
# Usually there should only be one public IP
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
43
|
+
host: server.public_ip_address,
|
44
|
+
port: 22,
|
45
|
+
username: config.ssh_username,
|
46
|
+
private_key_path: config.ssh_private_key_path,
|
46
47
|
}
|
47
48
|
end
|
48
49
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'log4r'
|
7
7
|
|
8
8
|
module VagrantPlugins
|
9
9
|
module HP
|
@@ -13,7 +13,7 @@ module VagrantPlugins
|
|
13
13
|
class ReadState
|
14
14
|
def initialize(app, env)
|
15
15
|
@app = app
|
16
|
-
@logger = Log4r::Logger.new(
|
16
|
+
@logger = Log4r::Logger.new('vagrant_hp::action::read_state')
|
17
17
|
end
|
18
18
|
|
19
19
|
def call(env)
|
@@ -27,9 +27,11 @@ module VagrantPlugins
|
|
27
27
|
|
28
28
|
# Find the machine
|
29
29
|
server = hp.servers.get(machine.id)
|
30
|
-
if server.nil? ||
|
30
|
+
if server.nil? ||
|
31
|
+
[:"shutting-down", :terminated].include?(server.state.to_sym)
|
31
32
|
# The machine can't be found
|
32
|
-
@logger.info(
|
33
|
+
@logger.info(
|
34
|
+
'Machine not found or terminated, assuming it got destroyed.')
|
33
35
|
machine.id = nil
|
34
36
|
return :not_created
|
35
37
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'log4r'
|
7
7
|
|
8
|
-
require
|
8
|
+
require 'vagrant/util/subprocess'
|
9
9
|
|
10
10
|
module VagrantPlugins
|
11
11
|
module HP
|
@@ -15,7 +15,11 @@ module VagrantPlugins
|
|
15
15
|
class SyncFolders
|
16
16
|
def initialize(app, env)
|
17
17
|
@app = app
|
18
|
-
@logger = Log4r::Logger.new(
|
18
|
+
@logger = Log4r::Logger.new('vagrant_hp::action::sync_folders')
|
19
|
+
end
|
20
|
+
|
21
|
+
def ssh_key_options(ssh_info)
|
22
|
+
Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
|
19
23
|
end
|
20
24
|
|
21
25
|
def call(env)
|
@@ -24,7 +28,7 @@ module VagrantPlugins
|
|
24
28
|
ssh_info = env[:machine].ssh_info
|
25
29
|
|
26
30
|
env[:machine].config.vm.synced_folders.each do |id, data|
|
27
|
-
next if data[:hostpath] ==
|
31
|
+
next if data[:hostpath] == '.'
|
28
32
|
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
29
33
|
guestpath = data[:guestpath]
|
30
34
|
|
@@ -32,9 +36,9 @@ module VagrantPlugins
|
|
32
36
|
# avoid creating an additional directory with rsync
|
33
37
|
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
34
38
|
|
35
|
-
env[:ui].info(I18n.t(
|
36
|
-
:
|
37
|
-
:
|
39
|
+
env[:ui].info(I18n.t('vagrant_hp.rsync_folder',
|
40
|
+
hostpath: hostpath,
|
41
|
+
guestpath: guestpath))
|
38
42
|
|
39
43
|
# Create the guest path
|
40
44
|
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
@@ -43,17 +47,16 @@ module VagrantPlugins
|
|
43
47
|
|
44
48
|
# Rsync over to the guest path using the SSH info
|
45
49
|
command = [
|
46
|
-
|
47
|
-
|
48
|
-
hostpath,
|
49
|
-
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
50
|
+
'rsync', '--verbose', '--archive', '-z',
|
51
|
+
'-e', "ssh -o StrictHostKeyChecking=no -p #{ssh_info[:port]} #{ssh_key_options(ssh_info)}",
|
52
|
+
hostpath, "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
50
53
|
|
51
54
|
r = Vagrant::Util::Subprocess.execute(*command)
|
52
55
|
if r.exit_code != 0
|
53
56
|
raise Errors::RsyncError,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
guestpath: guestpath,
|
58
|
+
hostpath: hostpath,
|
59
|
+
stderr: r.stderr
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fog'
|
3
|
+
|
4
|
+
hp_access_key = "Y5SKH1MU6HZ2PEM9ZNZL"
|
5
|
+
hp_secret_key = "YA2BJr98R3hDK7IwpIkHXlDCDo9GG+GIuqhflPqQ"
|
6
|
+
hp_tenant_id = "87309806546461"
|
7
|
+
|
8
|
+
|
9
|
+
connection = Fog::Compute.new(
|
10
|
+
provider: :hp,
|
11
|
+
version: 'v2',
|
12
|
+
hp_access_key: hp_access_key,
|
13
|
+
hp_secret_key: hp_secret_key,
|
14
|
+
hp_tenant_id: hp_tenant_id,
|
15
|
+
hp_avl_zone: 'az-1.region-a.geo-1'
|
16
|
+
)
|
17
|
+
|
18
|
+
puts "++++++++++++++++++++++++++"
|
19
|
+
puts "hp_avl_zone: #{connection.inspect}"
|
20
|
+
puts "++++++++++++++++++++++++++"
|
21
|
+
puts "key_pairs: #{connection.key_pairs}"
|
22
|
+
puts "++++++++++++++++++++++++++"
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'vagrant-hp/util/timer'
|
7
7
|
|
8
8
|
module VagrantPlugins
|
9
9
|
module HP
|
@@ -12,14 +12,14 @@ module VagrantPlugins
|
|
12
12
|
# provisioner runs.
|
13
13
|
class TimedProvision < Vagrant::Action::Builtin::Provision
|
14
14
|
def run_provisioner(env, p)
|
15
|
-
env[:ui].info(
|
15
|
+
env[:ui].info('Inside TimedProvision')
|
16
16
|
timer = Util::Timer.time do
|
17
17
|
super
|
18
18
|
end
|
19
19
|
|
20
20
|
env[:metrics] ||= {}
|
21
|
-
env[:metrics][
|
22
|
-
env[:metrics][
|
21
|
+
env[:metrics]['provisioner_times'] ||= []
|
22
|
+
env[:metrics]['provisioner_times'] << [p.class.to_s, timer]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/vagrant-hp/config.rb
CHANGED
@@ -3,12 +3,11 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'vagrant'
|
7
7
|
|
8
8
|
module VagrantPlugins
|
9
9
|
module HP
|
10
|
-
class Config < Vagrant.plugin(
|
11
|
-
|
10
|
+
class Config < Vagrant.plugin('2', :config)
|
12
11
|
attr_accessor :access_key
|
13
12
|
|
14
13
|
attr_accessor :secret_key
|
@@ -31,9 +30,9 @@ module VagrantPlugins
|
|
31
30
|
|
32
31
|
attr_accessor :security_groups
|
33
32
|
|
34
|
-
def initialize(region_specific=false)
|
33
|
+
def initialize(region_specific = false)
|
35
34
|
@access_key = UNSET_VALUE
|
36
|
-
@secret_key= UNSET_VALUE
|
35
|
+
@secret_key = UNSET_VALUE
|
37
36
|
@server_name = UNSET_VALUE
|
38
37
|
@private_ip_address = UNSET_VALUE
|
39
38
|
@keypair_name = UNSET_VALUE
|
@@ -58,7 +57,8 @@ module VagrantPlugins
|
|
58
57
|
super.tap do |result|
|
59
58
|
# Copy over the region specific flag. "True" is retained if either
|
60
59
|
# has it.
|
61
|
-
new_region_specific = other.instance_variable_get(
|
60
|
+
new_region_specific = other.instance_variable_get(
|
61
|
+
:@__region_specific)
|
62
62
|
result.instance_variable_set(
|
63
63
|
:@__region_specific, new_region_specific || @__region_specific)
|
64
64
|
|
@@ -91,7 +91,7 @@ module VagrantPlugins
|
|
91
91
|
@image = nil if @image == UNSET_VALUE
|
92
92
|
|
93
93
|
# Default instance type is an standard.small
|
94
|
-
@flavor =
|
94
|
+
@flavor = 'standard.small' if @flavor == UNSET_VALUE
|
95
95
|
|
96
96
|
# Keypair defaults to nil
|
97
97
|
@keypair_name = nil if @keypair_name == UNSET_VALUE
|
@@ -101,7 +101,7 @@ module VagrantPlugins
|
|
101
101
|
|
102
102
|
# Default availability-zone is az1. This is sensible because HP Cloud
|
103
103
|
# generally defaults to this as well.
|
104
|
-
@availability_zone =
|
104
|
+
@availability_zone = 'az1' if @availability_zone == UNSET_VALUE
|
105
105
|
|
106
106
|
# The SSH values by default are nil, and the top-level config
|
107
107
|
# `config.ssh` values are used.
|
@@ -116,39 +116,39 @@ module VagrantPlugins
|
|
116
116
|
errors = []
|
117
117
|
warnings = []
|
118
118
|
messages = []
|
119
|
-
|
120
|
-
# access_key: required
|
121
|
-
errors << I18n.t(
|
119
|
+
|
120
|
+
# access_key: required
|
121
|
+
errors << I18n.t('vagrant_hp.config.access_key_required') \
|
122
122
|
if @access_key.nil?
|
123
123
|
|
124
124
|
# secret_key: required
|
125
|
-
errors << I18n.t(
|
125
|
+
errors << I18n.t('vagrant_hp.config.secret_key_required') \
|
126
126
|
if @secret_key.nil?
|
127
127
|
|
128
128
|
# tenant_id: required
|
129
|
-
errors << I18n.t(
|
129
|
+
errors << I18n.t('vagrant_hp.config.tenant_id_required') \
|
130
130
|
if @tenant_id.nil?
|
131
131
|
|
132
132
|
# keypair_name: required
|
133
|
-
errors << I18n.t(
|
133
|
+
errors << I18n.t('vagrant_hp.config.keypair_name_required') \
|
134
134
|
if @keypair_name.nil?
|
135
135
|
|
136
136
|
# image: required
|
137
|
-
errors << I18n.t(
|
137
|
+
errors << I18n.t('vagrant_hp.config.image_required') \
|
138
138
|
if @image.nil?
|
139
139
|
|
140
140
|
# ssh_private_key_path: required
|
141
|
-
errors << I18n.t(
|
141
|
+
errors << I18n.t('vagrant_hp.config.ssh_private_key_path') \
|
142
142
|
if @ssh_private_key_path.nil?
|
143
143
|
|
144
|
-
{
|
144
|
+
{ 'HP Provider' => errors }
|
145
145
|
end
|
146
146
|
|
147
147
|
# This gets the configuration for a specific region. It shouldn't
|
148
148
|
# be called by the general public and is only used internally.
|
149
149
|
def get_region_config(name)
|
150
|
-
|
151
|
-
raise
|
150
|
+
unless @__finalized
|
151
|
+
raise 'Configuration must be finalized before calling this method.'
|
152
152
|
end
|
153
153
|
|
154
154
|
# Return the compiled region config
|
data/lib/vagrant-hp/errors.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'vagrant'
|
7
7
|
|
8
8
|
module VagrantPlugins
|
9
9
|
module HP
|
10
10
|
module Errors
|
11
11
|
class VagrantHPError < Vagrant::Errors::VagrantError
|
12
|
-
error_namespace(
|
12
|
+
error_namespace('vagrant_hp.errors')
|
13
13
|
end
|
14
14
|
|
15
15
|
class FogError < VagrantHPError
|
data/lib/vagrant-hp/plugin.rb
CHANGED
@@ -4,28 +4,28 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
begin
|
7
|
-
require
|
7
|
+
require 'vagrant'
|
8
8
|
rescue LoadError
|
9
|
-
raise
|
9
|
+
raise 'The Vagrant HP plugin must be run within Vagrant.'
|
10
10
|
end
|
11
11
|
|
12
12
|
# This is a sanity check to make sure no one is attempting to install
|
13
13
|
# this into an early Vagrant version.
|
14
|
-
if Vagrant::VERSION <
|
15
|
-
raise
|
14
|
+
if Vagrant::VERSION < '1.1.0'
|
15
|
+
raise 'The Vagrant HP plugin is only compatible with Vagrant 1.1+'
|
16
16
|
end
|
17
17
|
|
18
18
|
module VagrantPlugins
|
19
19
|
module HP
|
20
|
-
class Plugin < Vagrant.plugin(
|
21
|
-
name
|
20
|
+
class Plugin < Vagrant.plugin('2')
|
21
|
+
name 'HP'
|
22
22
|
description <<-DESC
|
23
23
|
This plugin installs a provider that allows Vagrant to manage
|
24
24
|
machines in HP Cloud.
|
25
25
|
DESC
|
26
26
|
|
27
27
|
config(:hp, :provider) do
|
28
|
-
require_relative
|
28
|
+
require_relative 'config'
|
29
29
|
Config
|
30
30
|
end
|
31
31
|
|
@@ -35,23 +35,23 @@ module VagrantPlugins
|
|
35
35
|
setup_i18n
|
36
36
|
|
37
37
|
# Return the provider
|
38
|
-
require_relative
|
38
|
+
require_relative 'provider'
|
39
39
|
Provider
|
40
40
|
end
|
41
41
|
|
42
42
|
# This initializes the internationalization strings.
|
43
43
|
def self.setup_i18n
|
44
|
-
I18n.load_path << File.expand_path(
|
44
|
+
I18n.load_path << File.expand_path('locales/en.yml', HP.source_root)
|
45
45
|
I18n.reload!
|
46
46
|
end
|
47
47
|
|
48
48
|
# This sets up our log level to be whatever VAGRANT_LOG is.
|
49
49
|
def self.setup_logging
|
50
|
-
require
|
50
|
+
require 'log4r'
|
51
51
|
|
52
52
|
level = nil
|
53
53
|
begin
|
54
|
-
level = Log4r.const_get(ENV[
|
54
|
+
level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
|
55
55
|
rescue NameError
|
56
56
|
# This means that the logging constant wasn't found,
|
57
57
|
# which is fine. We just keep `level` as `nil`. But
|
@@ -62,12 +62,12 @@ module VagrantPlugins
|
|
62
62
|
# Some constants, such as "true" resolve to booleans, so the
|
63
63
|
# above error checking doesn't catch it. This will check to make
|
64
64
|
# sure that the log level is an integer, as Log4r requires.
|
65
|
-
level = nil
|
65
|
+
level = nil unless level.is_a?(Integer)
|
66
66
|
|
67
67
|
# Set the logging level on all "vagrant" namespaced
|
68
68
|
# logs as long as we have a valid level.
|
69
69
|
if level
|
70
|
-
logger = Log4r::Logger.new(
|
70
|
+
logger = Log4r::Logger.new('vagrant_hp')
|
71
71
|
logger.outputters = Log4r::Outputter.stderr
|
72
72
|
logger.level = level
|
73
73
|
logger = nil
|
data/lib/vagrant-hp/provider.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require 'log4r'
|
7
|
+
require 'vagrant'
|
8
8
|
|
9
9
|
module VagrantPlugins
|
10
10
|
module HP
|
11
|
-
class Provider < Vagrant.plugin(
|
11
|
+
class Provider < Vagrant.plugin('2', :provider)
|
12
12
|
def initialize(machine)
|
13
13
|
@machine = machine
|
14
14
|
end
|
@@ -26,7 +26,7 @@ module VagrantPlugins
|
|
26
26
|
# Run a custom action called "read_ssh_info" which does what it
|
27
27
|
# says and puts the resulting SSH info into the `:machine_ssh_info`
|
28
28
|
# key in the environment.
|
29
|
-
env = @machine.action(
|
29
|
+
env = @machine.action('read_ssh_info')
|
30
30
|
env[:machine_ssh_info]
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ module VagrantPlugins
|
|
34
34
|
# Run a custom action we define called "read_state" which does
|
35
35
|
# what it says. It puts the state in the `:machine_state_id`
|
36
36
|
# key in the environment.
|
37
|
-
env = @machine.action(
|
37
|
+
env = @machine.action('read_state')
|
38
38
|
|
39
39
|
state_id = env[:machine_state_id]
|
40
40
|
|
@@ -47,7 +47,7 @@ module VagrantPlugins
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def to_s
|
50
|
-
id = @machine.id.nil? ?
|
50
|
+
id = @machine.id.nil? ? 'new' : @machine.id
|
51
51
|
"HP (#{id})"
|
52
52
|
end
|
53
53
|
end
|