Class: VagrantPlugins::Brightbox::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Brightbox::Config
- Defined in:
- lib/vagrant-brightbox/config.rb
Instance Attribute Summary collapse
-
#account ⇒ String
The account id of the account on which operations should be performed.
-
#api_url ⇒ String
The URL to use as the API endpoint.
-
#auth_url ⇒ String
The URL to use as the API authentication endpoint.
-
#client_id ⇒ String
The API Client ID for accessing Brightbox.
-
#image_id ⇒ String
The ID of the Image to use.
-
#password ⇒ String
Password for user based authentication.
-
#region ⇒ String
The name of the Brightbox region in which to create the server.
-
#secret ⇒ String
The secret access key for accessing Brightbox.
-
#server_build_timeout ⇒ Fixnum
The timeout to wait for a server to become ready.
-
#server_groups ⇒ Array<String>
The server groups to set on the server.
-
#server_name ⇒ Object
The name of the server.
-
#server_type ⇒ String
The type of server to launch, such as “nano”.
-
#user_data ⇒ String
The user data string.
-
#username ⇒ String
Email or user id for user based authentication.
-
#zone ⇒ String
The zone to launch the server into.
Instance Method Summary collapse
- #finalize! ⇒ Object
- #fog_config_file_exists? ⇒ Boolean
-
#get_region_config(name) ⇒ Object
This gets the configuration for a specific region.
-
#initialize(region_specific = false) ⇒ Config
constructor
A new instance of Config.
-
#merge(other) ⇒ Object
——————————————————————- Internal methods.
-
#region_config(region, attributes = nil) {|config| ... } ⇒ Object
Allows region-specific overrides of any of the settings on this configuration object.
- #valid_region? ⇒ Boolean
- #validate(machine) ⇒ Object
Constructor Details
#initialize(region_specific = false) ⇒ Config
Returns a new instance of Config.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/vagrant-brightbox/config.rb', line 84 def initialize(region_specific=false) @client_id = UNSET_VALUE @secret = UNSET_VALUE @api_url = UNSET_VALUE @auth_url = UNSET_VALUE @username = UNSET_VALUE @password = UNSET_VALUE @account = UNSET_VALUE @image_id = UNSET_VALUE @zone = UNSET_VALUE @server_build_timeout = UNSET_VALUE @server_type = UNSET_VALUE @server_name = UNSET_VALUE @region = UNSET_VALUE @server_groups = UNSET_VALUE @user_data = UNSET_VALUE # Internal state (prefix with __ so they aren't automatically # merged) @__compiled_region_configs = {} @__finalized = false @__region_config = {} @__region_specific = region_specific end |
Instance Attribute Details
#account ⇒ String
The account id of the account on which operations should be performed
39 40 41 |
# File 'lib/vagrant-brightbox/config.rb', line 39 def account @account end |
#api_url ⇒ String
The URL to use as the API endpoint
19 20 21 |
# File 'lib/vagrant-brightbox/config.rb', line 19 def api_url @api_url end |
#auth_url ⇒ String
The URL to use as the API authentication endpoint
24 25 26 |
# File 'lib/vagrant-brightbox/config.rb', line 24 def auth_url @auth_url end |
#client_id ⇒ String
The API Client ID for accessing Brightbox.
9 10 11 |
# File 'lib/vagrant-brightbox/config.rb', line 9 def client_id @client_id end |
#image_id ⇒ String
The ID of the Image to use.
45 46 47 |
# File 'lib/vagrant-brightbox/config.rb', line 45 def image_id @image_id end |
#password ⇒ String
Password for user based authentication
34 35 36 |
# File 'lib/vagrant-brightbox/config.rb', line 34 def password @password end |
#region ⇒ String
The name of the Brightbox region in which to create the server.
71 72 73 |
# File 'lib/vagrant-brightbox/config.rb', line 71 def region @region end |
#secret ⇒ String
The secret access key for accessing Brightbox.
14 15 16 |
# File 'lib/vagrant-brightbox/config.rb', line 14 def secret @secret end |
#server_build_timeout ⇒ Fixnum
The timeout to wait for a server to become ready
56 57 58 |
# File 'lib/vagrant-brightbox/config.rb', line 56 def server_build_timeout @server_build_timeout end |
#server_groups ⇒ Array<String>
The server groups to set on the server. This must be a list of group IDs.
77 78 79 |
# File 'lib/vagrant-brightbox/config.rb', line 77 def server_groups @server_groups end |
#server_name ⇒ Object
The name of the server. This defaults to the name of the machine defined by Vagrant (via ‘config.vm.define`), but can be overriden here.
66 67 68 |
# File 'lib/vagrant-brightbox/config.rb', line 66 def server_name @server_name end |
#server_type ⇒ String
The type of server to launch, such as “nano”
61 62 63 |
# File 'lib/vagrant-brightbox/config.rb', line 61 def server_type @server_type end |
#user_data ⇒ String
The user data string
82 83 84 |
# File 'lib/vagrant-brightbox/config.rb', line 82 def user_data @user_data end |
#username ⇒ String
Email or user id for user based authentication
29 30 31 |
# File 'lib/vagrant-brightbox/config.rb', line 29 def username @username end |
#zone ⇒ String
The zone to launch the server into. If nil, it will use the default for your account.
51 52 53 |
# File 'lib/vagrant-brightbox/config.rb', line 51 def zone @zone end |
Instance Method Details
#finalize! ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/vagrant-brightbox/config.rb', line 165 def finalize! # Default region is UK gb1. Because that's all there is at the moment! @region = "gb1" if @region == UNSET_VALUE # The server groups are empty by default. @server_groups = [] if @server_groups == UNSET_VALUE # Everything defaults to nil @client_id = nil if @client_id == UNSET_VALUE @secret = nil if @secret == UNSET_VALUE @auth_url = nil if @auth_url == UNSET_VALUE @api_url = nil if @api_url == UNSET_VALUE @username = nil if @username == UNSET_VALUE @password = nil if @password == UNSET_VALUE @account = nil if @account == UNSET_VALUE @image_id = nil if @image_id == UNSET_VALUE @server_type = nil if @server_type == UNSET_VALUE @server_name = nil if @server_name == UNSET_VALUE @zone = nil if @zone == UNSET_VALUE # User data is nil by default @user_data = nil if @user_data == UNSET_VALUE # The default timeout is 120 seconds @server_build_timeout = 120 if @server_build_timeout == UNSET_VALUE # Compile our region specific configurations only within # NON-REGION-SPECIFIC configurations. if !@__region_specific @__region_config.each do |region, blocks| config = self.class.new(true).merge(self) # Execute the configuration for each block blocks.each { |b| b.call(config) } # The region name of the configuration always equals the # region config name: config.region = region # Finalize the configuration config.finalize! # Store it for retrieval @__compiled_region_configs[region] = config end end # Mark that we finalized @__finalized = true end |
#fog_config_file_exists? ⇒ Boolean
241 242 243 |
# File 'lib/vagrant-brightbox/config.rb', line 241 def fog_config_file_exists? File.file?(File.join(ENV['HOME'], '.fog')) end |
#get_region_config(name) ⇒ Object
This gets the configuration for a specific region. It shouldn’t be called by the general public and is only used internally.
252 253 254 255 256 257 258 259 |
# File 'lib/vagrant-brightbox/config.rb', line 252 def get_region_config(name) if !@__finalized raise "Configuration must be finalized before calling this method." end # Return the compiled region config @__compiled_region_configs[name] || self end |
#merge(other) ⇒ Object
Internal methods.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/vagrant-brightbox/config.rb', line 143 def merge(other) super.tap do |result| # Copy over the region specific flag. "True" is retained if either # has it. new_region_specific = other.instance_variable_get(:@__region_specific) result.instance_variable_set( :@__region_specific, new_region_specific || @__region_specific) # Go through all the region configs and prepend ours onto # theirs. new_region_config = other.instance_variable_get(:@__region_config) @__region_config.each do |key, value| new_region_config[key] ||= [] new_region_config[key] = value + new_region_config[key] end # Set it result.instance_variable_set(:@__region_config, new_region_config) end end |
#region_config(region, attributes = nil) {|config| ... } ⇒ Object
Allows region-specific overrides of any of the settings on this configuration object. This allows the user to override things like Image and keypair name for regions. Example:
brightbox.region_config "gb1" do |region|
region.image_id = "img-umqoe"
end
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/vagrant-brightbox/config.rb', line 121 def region_config(region, attributes=nil, &block) # Append the block to the list of region configs for that region. # We'll evaluate these upon finalization. @__region_config[region] ||= [] # Append a block that sets attributes if we got one if attributes attr_block = lambda do |config| config.(attributes) end @__region_config[region] << attr_block end # Append a block if we got one @__region_config[region] << block if block_given? end |
#valid_region? ⇒ Boolean
245 246 247 248 |
# File 'lib/vagrant-brightbox/config.rb', line 245 def valid_region? return false unless @region =~ /gb1/ @region == 'gb1' || !(@auth_url.nil? || @api_url.nil?) end |
#validate(machine) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/vagrant-brightbox/config.rb', line 216 def validate(machine) errors = _detected_errors errors << I18n.t("vagrant_brightbox.config.region_required") if @region.nil? errors << I18n.t("vagrant_brightbox.config.region_invalid") unless valid_region? if @region && valid_region? # Get the configuration for the region we're using and validate only # that region. config = get_region_config(@region) # Secret could be in fog config file. unless fog_config_file_exists? errors << I18n.t("vagrant_brightbox.config.client_id_required") if \ config.client_id.nil? errors << I18n.t("vagrant_brightbox.config.secret_required") if \ config.secret.nil? end end { "Brightbox Provider" => errors } end |