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.
-
#security_groups ⇒ Object
Returns the value of attribute security_groups.
-
#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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vagrant-hp/config.rb', line 33 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.
11 12 13 |
# File 'lib/vagrant-hp/config.rb', line 11 def access_key @access_key end |
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
17 18 19 |
# File 'lib/vagrant-hp/config.rb', line 17 def availability_zone @availability_zone end |
#flavor ⇒ Object
Returns the value of attribute flavor.
19 20 21 |
# File 'lib/vagrant-hp/config.rb', line 19 def flavor @flavor end |
#image ⇒ Object
Returns the value of attribute image.
21 22 23 |
# File 'lib/vagrant-hp/config.rb', line 21 def image @image end |
#keypair_name ⇒ Object
Returns the value of attribute keypair_name.
25 26 27 |
# File 'lib/vagrant-hp/config.rb', line 25 def keypair_name @keypair_name end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
13 14 15 |
# File 'lib/vagrant-hp/config.rb', line 13 def secret_key @secret_key end |
#security_groups ⇒ Object
Returns the value of attribute security_groups.
31 32 33 |
# File 'lib/vagrant-hp/config.rb', line 31 def security_groups @security_groups end |
#server_name ⇒ Object
Returns the value of attribute server_name.
23 24 25 |
# File 'lib/vagrant-hp/config.rb', line 23 def server_name @server_name end |
#ssh_private_key_path ⇒ Object
Returns the value of attribute ssh_private_key_path.
27 28 29 |
# File 'lib/vagrant-hp/config.rb', line 27 def ssh_private_key_path @ssh_private_key_path end |
#ssh_username ⇒ Object
Returns the value of attribute ssh_username.
29 30 31 |
# File 'lib/vagrant-hp/config.rb', line 29 def ssh_username @ssh_username end |
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
15 16 17 |
# File 'lib/vagrant-hp/config.rb', line 15 def tenant_id @tenant_id end |
Instance Method Details
#finalize! ⇒ Object
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 |
# File 'lib/vagrant-hp/config.rb', line 82 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.
149 150 151 152 153 154 155 156 |
# File 'lib/vagrant-hp/config.rb', line 149 def get_region_config(name) unless @__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.
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 |
# File 'lib/vagrant-hp/config.rb', line 56 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
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 |
# File 'lib/vagrant-hp/config.rb', line 115 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 |