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.
@@ -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
@@ -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
- def initialize(region_specific=false)
33
- @access_key = UNSET_VALUE
34
- @secret_key= UNSET_VALUE
35
- @server_name = UNSET_VALUE
36
- @private_ip_address = UNSET_VALUE
37
- @keypair_name = UNSET_VALUE
38
- @tenant_id = UNSET_VALUE
39
- @availability_zone = UNSET_VALUE
40
- @image = UNSET_VALUE
41
- @ssh_private_key_path = UNSET_VALUE
42
- @ssh_username = UNSET_VALUE
43
- @flavor = UNSET_VALUE
44
-
45
- @__compiled_region_configs = {}
46
- @__finalized = false
47
- @__region_config = {}
48
- @__region_specific = region_specific
49
- end
50
-
51
- #-------------------------------------------------------------------
52
- # Internal methods.
53
- #-------------------------------------------------------------------
54
-
55
- def merge(other)
56
- super.tap do |result|
57
- # Copy over the region specific flag. "True" is retained if either
58
- # has it.
59
- new_region_specific = other.instance_variable_get(:@__region_specific)
60
- result.instance_variable_set(
61
- :@__region_specific, new_region_specific || @__region_specific)
62
-
63
- # Go through all the region configs and prepend ours onto
64
- # theirs.
65
- new_region_config = other.instance_variable_get(:@__region_config)
66
- @__region_config.each do |key, value|
67
- new_region_config[key] ||= []
68
- new_region_config[key] = value + new_region_config[key]
69
- end
70
-
71
- # Set it
72
- result.instance_variable_set(:@__region_config, new_region_config)
73
-
74
- # Merge in the tags
75
- result.tags.merge!(self.tags)
76
- result.tags.merge!(other.tags)
77
- end
78
- end
79
-
80
- def finalize!
81
- # The access keys default to nil
82
- @access_key = nil if @access_key == UNSET_VALUE
83
- @secret_key = nil if @secret_key == UNSET_VALUE
84
- @tenant_id = nil if @tenant_id == UNSET_VALUE
85
-
86
- @server_name = nil if @server_name == UNSET_VALUE
87
-
88
- # AMI must be nil, since we can't default that
89
- @image = nil if @image == UNSET_VALUE
90
-
91
- # Default instance type is an standard.small
92
- @flavor = "standard.small" if @flavor == UNSET_VALUE
93
-
94
- # Keypair defaults to nil
95
- @keypair_name = nil if @keypair_name == UNSET_VALUE
96
-
97
- # Default the private IP to nil since VPC is not default
98
- @private_ip_address = nil if @private_ip_address == UNSET_VALUE
99
-
100
- # Default availability-zone is az1. This is sensible because HP Cloud
101
- # generally defaults to this as well.
102
- @availability_zone = "az1" if @availability_zone == UNSET_VALUE
103
-
104
- # The SSH values by default are nil, and the top-level config
105
- # `config.ssh` values are used.
106
- @ssh_private_key_path = nil if @ssh_private_key_path == UNSET_VALUE
107
- @ssh_username = nil if @ssh_username == UNSET_VALUE
108
-
109
- # Mark that we finalized
110
- @__finalized = true
111
- end
112
-
113
- def validate(machine)
114
- errors = []
115
- warnings = []
116
- messages = []
117
-
118
- # access_key: required
119
- errors << I18n.t("vagrant_hp.config.access_key_required") \
120
- if @access_key.nil?
121
-
122
- # secret_key: required
123
- errors << I18n.t("vagrant_hp.config.secret_key_required") \
124
- if @secret_key.nil?
125
-
126
- # tenant_id: required
127
- errors << I18n.t("vagrant_hp.config.tenant_id_required") \
128
- if @tenant_id.nil?
129
-
130
- # keypair_name: required
131
- errors << I18n.t("vagrant_hp.config.keypair_name_required") \
132
- if @keypair_name.nil?
133
-
134
- # image: required
135
- errors << I18n.t("vagrant_hp.config.image_required") \
136
- if @image.nil?
137
-
138
- # ssh_private_key_path: required
139
- errors << I18n.t("vagrant_hp.config.ssh_private_key_path") \
140
- if @ssh_private_key_path.nil?
141
-
142
- { "HP Provider" => errors }
143
- end
144
-
145
- # This gets the configuration for a specific region. It shouldn't
146
- # be called by the general public and is only used internally.
147
- def get_region_config(name)
148
- if !@__finalized
149
- raise "Configuration must be finalized before calling this method."
150
- end
151
-
152
- # Return the compiled region config
153
- @__compiled_region_configs[name] || self
154
- end
155
- end
156
- end
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
@@ -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
@@ -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