vagrant-hp 0.1.0 → 0.1.1
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.
- data/.gitignore +59 -59
- data/CHANGELOG.md +6 -3
- data/Gemfile +10 -10
- data/LICENSE +9 -0
- data/README.md +172 -167
- data/Rakefile +21 -21
- data/example_box/README.md +13 -13
- data/example_box/Vagrantfile +7 -7
- data/example_box/metadata.json +3 -3
- data/lib/vagrant-hp.rb +18 -18
- data/lib/vagrant-hp/action.rb +110 -110
- data/lib/vagrant-hp/action/connect_hp.rb +54 -54
- data/lib/vagrant-hp/action/create_server.rb +124 -121
- data/lib/vagrant-hp/action/delete_server.rb +30 -30
- data/lib/vagrant-hp/action/halt_server.rb +30 -30
- data/lib/vagrant-hp/action/is_created.rb +23 -23
- data/lib/vagrant-hp/action/is_running.rb +23 -23
- data/lib/vagrant-hp/action/message_already_created.rb +21 -21
- data/lib/vagrant-hp/action/message_not_created.rb +21 -21
- data/lib/vagrant-hp/action/read_ssh_info.rb +51 -51
- data/lib/vagrant-hp/action/read_state.rb +43 -43
- data/lib/vagrant-hp/action/sync_folders.rb +63 -63
- data/lib/vagrant-hp/action/timed_provision.rb +27 -27
- data/lib/vagrant-hp/action/warn_networks.rb +24 -24
- data/lib/vagrant-hp/config.rb +159 -157
- data/lib/vagrant-hp/errors.rb +24 -24
- data/lib/vagrant-hp/plugin.rb +78 -78
- data/lib/vagrant-hp/provider.rb +55 -55
- data/lib/vagrant-hp/util/timer.rb +17 -17
- data/lib/vagrant-hp/version.rb +10 -10
- data/locales/en.yml +91 -91
- data/spec/vagrant-hp/config_spec.rb +42 -42
- data/vagrant-hp.gemspec +59 -59
- metadata +4 -3
@@ -1,24 +1,24 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
module VagrantPlugins
|
7
|
-
module HP
|
8
|
-
module Action
|
9
|
-
class WarnNetworks
|
10
|
-
def initialize(app, env)
|
11
|
-
@app = app
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
if env[:machine].config.vm.networks.length > 0
|
16
|
-
env[:ui].warn(I18n.t("vagrant_hp.warn_networks"))
|
17
|
-
end
|
18
|
-
|
19
|
-
@app.call(env)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module HP
|
8
|
+
module Action
|
9
|
+
class WarnNetworks
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env[:machine].config.vm.networks.length > 0
|
16
|
+
env[:ui].warn(I18n.t("vagrant_hp.warn_networks"))
|
17
|
+
end
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/vagrant-hp/config.rb
CHANGED
@@ -1,157 +1,159 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "vagrant"
|
7
|
-
|
8
|
-
module VagrantPlugins
|
9
|
-
module HP
|
10
|
-
class Config < Vagrant.plugin("2", :config)
|
11
|
-
|
12
|
-
attr_accessor :access_key
|
13
|
-
|
14
|
-
attr_accessor :secret_key
|
15
|
-
|
16
|
-
attr_accessor :tenant_id
|
17
|
-
|
18
|
-
attr_accessor :availability_zone
|
19
|
-
|
20
|
-
attr_accessor :flavor
|
21
|
-
|
22
|
-
attr_accessor :image
|
23
|
-
|
24
|
-
attr_accessor :server_name
|
25
|
-
|
26
|
-
attr_accessor :keypair_name
|
27
|
-
|
28
|
-
attr_accessor :ssh_private_key_path
|
29
|
-
|
30
|
-
attr_accessor :ssh_username
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
|
45
|
-
@
|
46
|
-
|
47
|
-
@
|
48
|
-
@
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#-------------------------------------------------------------------
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
@
|
85
|
-
|
86
|
-
@
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "vagrant"
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module HP
|
10
|
+
class Config < Vagrant.plugin("2", :config)
|
11
|
+
|
12
|
+
attr_accessor :access_key
|
13
|
+
|
14
|
+
attr_accessor :secret_key
|
15
|
+
|
16
|
+
attr_accessor :tenant_id
|
17
|
+
|
18
|
+
attr_accessor :availability_zone
|
19
|
+
|
20
|
+
attr_accessor :flavor
|
21
|
+
|
22
|
+
attr_accessor :image
|
23
|
+
|
24
|
+
attr_accessor :server_name
|
25
|
+
|
26
|
+
attr_accessor :keypair_name
|
27
|
+
|
28
|
+
attr_accessor :ssh_private_key_path
|
29
|
+
|
30
|
+
attr_accessor :ssh_username
|
31
|
+
|
32
|
+
attr_accessor :security_groups
|
33
|
+
|
34
|
+
def initialize(region_specific=false)
|
35
|
+
@access_key = UNSET_VALUE
|
36
|
+
@secret_key= UNSET_VALUE
|
37
|
+
@server_name = UNSET_VALUE
|
38
|
+
@private_ip_address = UNSET_VALUE
|
39
|
+
@keypair_name = UNSET_VALUE
|
40
|
+
@tenant_id = UNSET_VALUE
|
41
|
+
@availability_zone = UNSET_VALUE
|
42
|
+
@image = UNSET_VALUE
|
43
|
+
@ssh_private_key_path = UNSET_VALUE
|
44
|
+
@ssh_username = UNSET_VALUE
|
45
|
+
@flavor = UNSET_VALUE
|
46
|
+
|
47
|
+
@__compiled_region_configs = {}
|
48
|
+
@__finalized = false
|
49
|
+
@__region_config = {}
|
50
|
+
@__region_specific = region_specific
|
51
|
+
end
|
52
|
+
|
53
|
+
#-------------------------------------------------------------------
|
54
|
+
# Internal methods.
|
55
|
+
#-------------------------------------------------------------------
|
56
|
+
|
57
|
+
def merge(other)
|
58
|
+
super.tap do |result|
|
59
|
+
# Copy over the region specific flag. "True" is retained if either
|
60
|
+
# has it.
|
61
|
+
new_region_specific = other.instance_variable_get(:@__region_specific)
|
62
|
+
result.instance_variable_set(
|
63
|
+
:@__region_specific, new_region_specific || @__region_specific)
|
64
|
+
|
65
|
+
# Go through all the region configs and prepend ours onto
|
66
|
+
# theirs.
|
67
|
+
new_region_config = other.instance_variable_get(:@__region_config)
|
68
|
+
@__region_config.each do |key, value|
|
69
|
+
new_region_config[key] ||= []
|
70
|
+
new_region_config[key] = value + new_region_config[key]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Set it
|
74
|
+
result.instance_variable_set(:@__region_config, new_region_config)
|
75
|
+
|
76
|
+
# Merge in the tags
|
77
|
+
result.tags.merge!(self.tags)
|
78
|
+
result.tags.merge!(other.tags)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def finalize!
|
83
|
+
# The access keys default to nil
|
84
|
+
@access_key = nil if @access_key == UNSET_VALUE
|
85
|
+
@secret_key = nil if @secret_key == UNSET_VALUE
|
86
|
+
@tenant_id = nil if @tenant_id == UNSET_VALUE
|
87
|
+
|
88
|
+
@server_name = nil if @server_name == UNSET_VALUE
|
89
|
+
|
90
|
+
# AMI must be nil, since we can't default that
|
91
|
+
@image = nil if @image == UNSET_VALUE
|
92
|
+
|
93
|
+
# Default instance type is an standard.small
|
94
|
+
@flavor = "standard.small" if @flavor == UNSET_VALUE
|
95
|
+
|
96
|
+
# Keypair defaults to nil
|
97
|
+
@keypair_name = nil if @keypair_name == UNSET_VALUE
|
98
|
+
|
99
|
+
# Default the private IP to nil since VPC is not default
|
100
|
+
@private_ip_address = nil if @private_ip_address == UNSET_VALUE
|
101
|
+
|
102
|
+
# Default availability-zone is az1. This is sensible because HP Cloud
|
103
|
+
# generally defaults to this as well.
|
104
|
+
@availability_zone = "az1" if @availability_zone == UNSET_VALUE
|
105
|
+
|
106
|
+
# The SSH values by default are nil, and the top-level config
|
107
|
+
# `config.ssh` values are used.
|
108
|
+
@ssh_private_key_path = nil if @ssh_private_key_path == UNSET_VALUE
|
109
|
+
@ssh_username = nil if @ssh_username == UNSET_VALUE
|
110
|
+
|
111
|
+
# Mark that we finalized
|
112
|
+
@__finalized = true
|
113
|
+
end
|
114
|
+
|
115
|
+
def validate(machine)
|
116
|
+
errors = []
|
117
|
+
warnings = []
|
118
|
+
messages = []
|
119
|
+
|
120
|
+
# access_key: required
|
121
|
+
errors << I18n.t("vagrant_hp.config.access_key_required") \
|
122
|
+
if @access_key.nil?
|
123
|
+
|
124
|
+
# secret_key: required
|
125
|
+
errors << I18n.t("vagrant_hp.config.secret_key_required") \
|
126
|
+
if @secret_key.nil?
|
127
|
+
|
128
|
+
# tenant_id: required
|
129
|
+
errors << I18n.t("vagrant_hp.config.tenant_id_required") \
|
130
|
+
if @tenant_id.nil?
|
131
|
+
|
132
|
+
# keypair_name: required
|
133
|
+
errors << I18n.t("vagrant_hp.config.keypair_name_required") \
|
134
|
+
if @keypair_name.nil?
|
135
|
+
|
136
|
+
# image: required
|
137
|
+
errors << I18n.t("vagrant_hp.config.image_required") \
|
138
|
+
if @image.nil?
|
139
|
+
|
140
|
+
# ssh_private_key_path: required
|
141
|
+
errors << I18n.t("vagrant_hp.config.ssh_private_key_path") \
|
142
|
+
if @ssh_private_key_path.nil?
|
143
|
+
|
144
|
+
{ "HP Provider" => errors }
|
145
|
+
end
|
146
|
+
|
147
|
+
# This gets the configuration for a specific region. It shouldn't
|
148
|
+
# be called by the general public and is only used internally.
|
149
|
+
def get_region_config(name)
|
150
|
+
if !@__finalized
|
151
|
+
raise "Configuration must be finalized before calling this method."
|
152
|
+
end
|
153
|
+
|
154
|
+
# Return the compiled region config
|
155
|
+
@__compiled_region_configs[name] || self
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/vagrant-hp/errors.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "vagrant"
|
7
|
-
|
8
|
-
module VagrantPlugins
|
9
|
-
module HP
|
10
|
-
module Errors
|
11
|
-
class VagrantHPError < Vagrant::Errors::VagrantError
|
12
|
-
error_namespace("vagrant_hp.errors")
|
13
|
-
end
|
14
|
-
|
15
|
-
class FogError < VagrantHPError
|
16
|
-
error_key(:fog_error)
|
17
|
-
end
|
18
|
-
|
19
|
-
class RsyncError < VagrantHPError
|
20
|
-
error_key(:rsync_error)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "vagrant"
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module HP
|
10
|
+
module Errors
|
11
|
+
class VagrantHPError < Vagrant::Errors::VagrantError
|
12
|
+
error_namespace("vagrant_hp.errors")
|
13
|
+
end
|
14
|
+
|
15
|
+
class FogError < VagrantHPError
|
16
|
+
error_key(:fog_error)
|
17
|
+
end
|
18
|
+
|
19
|
+
class RsyncError < VagrantHPError
|
20
|
+
error_key(:rsync_error)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/vagrant-hp/plugin.rb
CHANGED
@@ -1,78 +1,78 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
begin
|
7
|
-
require "vagrant"
|
8
|
-
rescue LoadError
|
9
|
-
raise "The Vagrant HP plugin must be run within Vagrant."
|
10
|
-
end
|
11
|
-
|
12
|
-
# This is a sanity check to make sure no one is attempting to install
|
13
|
-
# this into an early Vagrant version.
|
14
|
-
if Vagrant::VERSION < "1.1.0"
|
15
|
-
raise "The Vagrant HP plugin is only compatible with Vagrant 1.1+"
|
16
|
-
end
|
17
|
-
|
18
|
-
module VagrantPlugins
|
19
|
-
module HP
|
20
|
-
class Plugin < Vagrant.plugin("2")
|
21
|
-
name "HP"
|
22
|
-
description <<-DESC
|
23
|
-
This plugin installs a provider that allows Vagrant to manage
|
24
|
-
machines in HP Cloud.
|
25
|
-
DESC
|
26
|
-
|
27
|
-
config(:hp, :provider) do
|
28
|
-
require_relative "config"
|
29
|
-
Config
|
30
|
-
end
|
31
|
-
|
32
|
-
provider(:hp) do
|
33
|
-
# Setup logging and i18n
|
34
|
-
setup_logging
|
35
|
-
setup_i18n
|
36
|
-
|
37
|
-
# Return the provider
|
38
|
-
require_relative "provider"
|
39
|
-
Provider
|
40
|
-
end
|
41
|
-
|
42
|
-
# This initializes the internationalization strings.
|
43
|
-
def self.setup_i18n
|
44
|
-
I18n.load_path << File.expand_path("locales/en.yml", HP.source_root)
|
45
|
-
I18n.reload!
|
46
|
-
end
|
47
|
-
|
48
|
-
# This sets up our log level to be whatever VAGRANT_LOG is.
|
49
|
-
def self.setup_logging
|
50
|
-
require "log4r"
|
51
|
-
|
52
|
-
level = nil
|
53
|
-
begin
|
54
|
-
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
55
|
-
rescue NameError
|
56
|
-
# This means that the logging constant wasn't found,
|
57
|
-
# which is fine. We just keep `level` as `nil`. But
|
58
|
-
# we tell the user.
|
59
|
-
level = nil
|
60
|
-
end
|
61
|
-
|
62
|
-
# Some constants, such as "true" resolve to booleans, so the
|
63
|
-
# above error checking doesn't catch it. This will check to make
|
64
|
-
# sure that the log level is an integer, as Log4r requires.
|
65
|
-
level = nil if !level.is_a?(Integer)
|
66
|
-
|
67
|
-
# Set the logging level on all "vagrant" namespaced
|
68
|
-
# logs as long as we have a valid level.
|
69
|
-
if level
|
70
|
-
logger = Log4r::Logger.new("vagrant_hp")
|
71
|
-
logger.outputters = Log4r::Outputter.stderr
|
72
|
-
logger.level = level
|
73
|
-
logger = nil
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "vagrant"
|
8
|
+
rescue LoadError
|
9
|
+
raise "The Vagrant HP plugin must be run within Vagrant."
|
10
|
+
end
|
11
|
+
|
12
|
+
# This is a sanity check to make sure no one is attempting to install
|
13
|
+
# this into an early Vagrant version.
|
14
|
+
if Vagrant::VERSION < "1.1.0"
|
15
|
+
raise "The Vagrant HP plugin is only compatible with Vagrant 1.1+"
|
16
|
+
end
|
17
|
+
|
18
|
+
module VagrantPlugins
|
19
|
+
module HP
|
20
|
+
class Plugin < Vagrant.plugin("2")
|
21
|
+
name "HP"
|
22
|
+
description <<-DESC
|
23
|
+
This plugin installs a provider that allows Vagrant to manage
|
24
|
+
machines in HP Cloud.
|
25
|
+
DESC
|
26
|
+
|
27
|
+
config(:hp, :provider) do
|
28
|
+
require_relative "config"
|
29
|
+
Config
|
30
|
+
end
|
31
|
+
|
32
|
+
provider(:hp) do
|
33
|
+
# Setup logging and i18n
|
34
|
+
setup_logging
|
35
|
+
setup_i18n
|
36
|
+
|
37
|
+
# Return the provider
|
38
|
+
require_relative "provider"
|
39
|
+
Provider
|
40
|
+
end
|
41
|
+
|
42
|
+
# This initializes the internationalization strings.
|
43
|
+
def self.setup_i18n
|
44
|
+
I18n.load_path << File.expand_path("locales/en.yml", HP.source_root)
|
45
|
+
I18n.reload!
|
46
|
+
end
|
47
|
+
|
48
|
+
# This sets up our log level to be whatever VAGRANT_LOG is.
|
49
|
+
def self.setup_logging
|
50
|
+
require "log4r"
|
51
|
+
|
52
|
+
level = nil
|
53
|
+
begin
|
54
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
55
|
+
rescue NameError
|
56
|
+
# This means that the logging constant wasn't found,
|
57
|
+
# which is fine. We just keep `level` as `nil`. But
|
58
|
+
# we tell the user.
|
59
|
+
level = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# Some constants, such as "true" resolve to booleans, so the
|
63
|
+
# above error checking doesn't catch it. This will check to make
|
64
|
+
# sure that the log level is an integer, as Log4r requires.
|
65
|
+
level = nil if !level.is_a?(Integer)
|
66
|
+
|
67
|
+
# Set the logging level on all "vagrant" namespaced
|
68
|
+
# logs as long as we have a valid level.
|
69
|
+
if level
|
70
|
+
logger = Log4r::Logger.new("vagrant_hp")
|
71
|
+
logger.outputters = Log4r::Outputter.stderr
|
72
|
+
logger.level = level
|
73
|
+
logger = nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|