Class: VagrantPlugins::HP::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::HP::Config
- Defined in:
- lib/vagrant-hp/config.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
-
#flavor ⇒ Object
Returns the value of attribute flavor.
-
#image ⇒ Object
Returns the value of attribute image.
-
#keypair_name ⇒ Object
Returns the value of attribute keypair_name.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#server_name ⇒ Object
Returns the value of attribute server_name.
-
#ssh_private_key_path ⇒ Object
Returns the value of attribute ssh_private_key_path.
-
#ssh_username ⇒ Object
Returns the value of attribute ssh_username.
-
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#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.
- #validate(machine) ⇒ Object
Constructor Details
#initialize(region_specific = false) ⇒ Config
Returns a new instance of Config.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vagrant-hp/config.rb', line 32 def initialize(region_specific=false) @access_key = UNSET_VALUE @secret_key= UNSET_VALUE @server_name = UNSET_VALUE @private_ip_address = UNSET_VALUE @keypair_name = UNSET_VALUE @tenant_id = UNSET_VALUE @availability_zone = UNSET_VALUE @image = UNSET_VALUE @ssh_private_key_path = UNSET_VALUE @ssh_username = UNSET_VALUE @flavor = UNSET_VALUE @__compiled_region_configs = {} @__finalized = false @__region_config = {} @__region_specific = region_specific end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
12 13 14 |
# File 'lib/vagrant-hp/config.rb', line 12 def access_key @access_key end |
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
18 19 20 |
# File 'lib/vagrant-hp/config.rb', line 18 def availability_zone @availability_zone end |
#flavor ⇒ Object
Returns the value of attribute flavor.
20 21 22 |
# File 'lib/vagrant-hp/config.rb', line 20 def flavor @flavor end |
#image ⇒ Object
Returns the value of attribute image.
22 23 24 |
# File 'lib/vagrant-hp/config.rb', line 22 def image @image end |
#keypair_name ⇒ Object
Returns the value of attribute keypair_name.
26 27 28 |
# File 'lib/vagrant-hp/config.rb', line 26 def keypair_name @keypair_name end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
14 15 16 |
# File 'lib/vagrant-hp/config.rb', line 14 def secret_key @secret_key end |
#server_name ⇒ Object
Returns the value of attribute server_name.
24 25 26 |
# File 'lib/vagrant-hp/config.rb', line 24 def server_name @server_name end |
#ssh_private_key_path ⇒ Object
Returns the value of attribute ssh_private_key_path.
28 29 30 |
# File 'lib/vagrant-hp/config.rb', line 28 def ssh_private_key_path @ssh_private_key_path end |
#ssh_username ⇒ Object
Returns the value of attribute ssh_username.
30 31 32 |
# File 'lib/vagrant-hp/config.rb', line 30 def ssh_username @ssh_username end |
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
16 17 18 |
# File 'lib/vagrant-hp/config.rb', line 16 def tenant_id @tenant_id end |
Instance Method Details
#finalize! ⇒ Object
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 |
# File 'lib/vagrant-hp/config.rb', line 80 def finalize! # The access keys default to nil @access_key = nil if @access_key == UNSET_VALUE @secret_key = nil if @secret_key == UNSET_VALUE @tenant_id = nil if @tenant_id == UNSET_VALUE @server_name = nil if @server_name == UNSET_VALUE # AMI must be nil, since we can't default that @image = nil if @image == UNSET_VALUE # Default instance type is an standard.small @flavor = "standard.small" if @flavor == UNSET_VALUE # Keypair defaults to nil @keypair_name = nil if @keypair_name == UNSET_VALUE # Default the private IP to nil since VPC is not default @private_ip_address = nil if @private_ip_address == UNSET_VALUE # Default availability-zone is az1. This is sensible because HP Cloud # generally defaults to this as well. @availability_zone = "az1" if @availability_zone == UNSET_VALUE # The SSH values by default are nil, and the top-level config # `config.ssh` values are used. @ssh_private_key_path = nil if @ssh_private_key_path == UNSET_VALUE @ssh_username = nil if @ssh_username == UNSET_VALUE # Mark that we finalized @__finalized = true 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.
147 148 149 150 151 152 153 154 |
# File 'lib/vagrant-hp/config.rb', line 147 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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vagrant-hp/config.rb', line 55 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) # Merge in the tags result..merge!(self.) result..merge!(other.) end end |
#validate(machine) ⇒ Object
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 |
# File 'lib/vagrant-hp/config.rb', line 113 def validate(machine) errors = [] warnings = [] = [] # access_key: required errors << I18n.t("vagrant_hp.config.access_key_required") \ if @access_key.nil? # secret_key: required errors << I18n.t("vagrant_hp.config.secret_key_required") \ if @secret_key.nil? # tenant_id: required errors << I18n.t("vagrant_hp.config.tenant_id_required") \ if @tenant_id.nil? # keypair_name: required errors << I18n.t("vagrant_hp.config.keypair_name_required") \ if @keypair_name.nil? # image: required errors << I18n.t("vagrant_hp.config.image_required") \ if @image.nil? # ssh_private_key_path: required errors << I18n.t("vagrant_hp.config.ssh_private_key_path") \ if @ssh_private_key_path.nil? { "HP Provider" => errors } end |