Class: VagrantPlugins::Cloudstack::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Cloudstack::Config
- Defined in:
- lib/vagrant-cloudstack/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ String
The API key for accessing Cloudstack.
-
#domain_id ⇒ String
Domain id to launch the instance into.
-
#host ⇒ String
Cloudstack api host.
-
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
-
#network_id ⇒ String
Network uuid that the instance should use.
-
#path ⇒ String
Cloudstack api path.
-
#port ⇒ String
Cloudstack api port.
-
#project_id ⇒ String
Project uuid that the instance should belong to.
-
#scheme ⇒ String
Cloudstack api scheme.
-
#secret_key ⇒ String
The secret key for accessing Cloudstack.
-
#service_offering_id ⇒ String
Service offering uuid to use for the instance.
-
#template_id ⇒ String
Template uuid to use for the instance.
-
#zone_id ⇒ String
Zone uuid to launch the instance into.
Instance Method Summary collapse
-
#domain_config(domain, attributes = nil) {|config| ... } ⇒ Object
Allows domain-specific overrides of any of the settings on this configuration object.
- #finalize! ⇒ Object
-
#get_domain_config(name) ⇒ Object
This gets the configuration for a specific domain.
-
#initialize(domain_specific = false) ⇒ Config
constructor
A new instance of Config.
-
#merge(other) ⇒ Object
——————————————————————- Internal methods.
- #validate(machine) ⇒ Object
Constructor Details
#initialize(domain_specific = false) ⇒ Config
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vagrant-cloudstack/config.rb', line 72 def initialize(domain_specific=false) @host = UNSET_VALUE @path = UNSET_VALUE @port = UNSET_VALUE @scheme = UNSET_VALUE @api_key = UNSET_VALUE @secret_key = UNSET_VALUE @instance_ready_timeout = UNSET_VALUE @domain_id = UNSET_VALUE @network_id = UNSET_VALUE @project_id = UNSET_VALUE @service_offering_id = UNSET_VALUE @template_id = UNSET_VALUE @zone_id = UNSET_VALUE # Internal state (prefix with __ so they aren't automatically # merged) @__compiled_domain_configs = {} @__finalized = false @__domain_config = {} @__domain_specific = domain_specific end |
Instance Attribute Details
#api_key ⇒ String
The API key for accessing Cloudstack.
29 30 31 |
# File 'lib/vagrant-cloudstack/config.rb', line 29 def api_key @api_key end |
#domain_id ⇒ String
Domain id to launch the instance into.
44 45 46 |
# File 'lib/vagrant-cloudstack/config.rb', line 44 def domain_id @domain_id end |
#host ⇒ String
Cloudstack api host.
9 10 11 |
# File 'lib/vagrant-cloudstack/config.rb', line 9 def host @host end |
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
39 40 41 |
# File 'lib/vagrant-cloudstack/config.rb', line 39 def instance_ready_timeout @instance_ready_timeout end |
#network_id ⇒ String
Network uuid that the instance should use
49 50 51 |
# File 'lib/vagrant-cloudstack/config.rb', line 49 def network_id @network_id end |
#path ⇒ String
Cloudstack api path.
14 15 16 |
# File 'lib/vagrant-cloudstack/config.rb', line 14 def path @path end |
#port ⇒ String
Cloudstack api port.
19 20 21 |
# File 'lib/vagrant-cloudstack/config.rb', line 19 def port @port end |
#project_id ⇒ String
Project uuid that the instance should belong to
54 55 56 |
# File 'lib/vagrant-cloudstack/config.rb', line 54 def project_id @project_id end |
#scheme ⇒ String
Cloudstack api scheme
24 25 26 |
# File 'lib/vagrant-cloudstack/config.rb', line 24 def scheme @scheme end |
#secret_key ⇒ String
The secret key for accessing Cloudstack.
34 35 36 |
# File 'lib/vagrant-cloudstack/config.rb', line 34 def secret_key @secret_key end |
#service_offering_id ⇒ String
Service offering uuid to use for the instance
59 60 61 |
# File 'lib/vagrant-cloudstack/config.rb', line 59 def service_offering_id @service_offering_id end |
#template_id ⇒ String
Template uuid to use for the instance
64 65 66 |
# File 'lib/vagrant-cloudstack/config.rb', line 64 def template_id @template_id end |
#zone_id ⇒ String
Zone uuid to launch the instance into. If nil, it will launch in default project.
70 71 72 |
# File 'lib/vagrant-cloudstack/config.rb', line 70 def zone_id @zone_id end |
Instance Method Details
#domain_config(domain, attributes = nil) {|config| ... } ⇒ Object
Allows domain-specific overrides of any of the settings on this configuration object. This allows the user to override things like template and keypair name for domains. Example:
cloudstack.domain_config "abcd-ef01-2345-6789" do |domain|
domain.template_id = "1234-5678-90ab-cdef"
domain.keypair_name = "company-east"
end
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/vagrant-cloudstack/config.rb', line 108 def domain_config(domain, attributes=nil, &block) # Append the block to the list of domain configs for that domain. # We'll evaluate these upon finalization. @__domain_config[domain] ||= [] # Append a block that sets attributes if we got one if attributes attr_block = lambda do |config| config.(attributes) end @__domain_config[domain] << attr_block end # Append a block if we got one @__domain_config[domain] << block if block_given? end |
#finalize! ⇒ Object
155 156 157 158 159 160 161 162 163 164 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 215 216 217 218 |
# File 'lib/vagrant-cloudstack/config.rb', line 155 def finalize! # Domain_id must be nil, since we can't default that @host = nil if @host == UNSET_VALUE # Path must be nil, since we can't default that @path = nil if @path == UNSET_VALUE # Port must be nil, since we can't default that @port = nil if @port == UNSET_VALUE # Scheme is 'http' by default @scheme = "http" if @scheme == UNSET_VALUE # Api key must be nil, since we can't default that @api_key = nil if @api_key == UNSET_VALUE # Secret key must be nil, since we can't default that @secret_key = nil if @secret_key == UNSET_VALUE # Set the default timeout for waiting for an instance to be ready @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE # Domain id must be nil, since we can't default that @domain_id = nil if @domain_id == UNSET_VALUE # Network uuid must be nil, since we can't default that @network_id = nil if @network_id == UNSET_VALUE # Project uuid must be nil, since we can't default that @project_id = nil if @project_id == UNSET_VALUE # Service offering uuid must be nil, since we can't default that @service_offering_id = nil if @service_offering_id == UNSET_VALUE # Template uuid must be nil, since we can't default that @template_id = nil if @template_id == UNSET_VALUE # Zone uuid must be nil, since we can't default that @zone_id = nil if @zone_id == UNSET_VALUE # Compile our domain specific configurations only within # NON-DOMAIN-SPECIFIC configurations. if !@__domain_specific @__domain_config.each do |domain, blocks| config = self.class.new(true).merge(self) # Execute the configuration for each block blocks.each { |b| b.call(config) } # The domain name of the configuration always equals the # domain config name: config.domain = domain # Finalize the configuration config.finalize! # Store it for retrieval @__compiled_domain_configs[domain] = config end end # Mark that we finalized @__finalized = true end |
#get_domain_config(name) ⇒ Object
This gets the configuration for a specific domain. It shouldn’t be called by the general public and is only used internally.
243 244 245 246 247 248 249 250 |
# File 'lib/vagrant-cloudstack/config.rb', line 243 def get_domain_config(name) if !@__finalized raise "Configuration must be finalized before calling this method." end # Return the compiled domain config @__compiled_domain_configs[name] || self end |
#merge(other) ⇒ Object
Internal methods.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vagrant-cloudstack/config.rb', line 130 def merge(other) super.tap do |result| # Copy over the domain specific flag. "True" is retained if either # has it. new_domain_specific = other.instance_variable_get(:@__domain_specific) result.instance_variable_set( :@__domain_specific, new_domain_specific || @__domain_specific) # Go through all the domain configs and prepend ours onto # theirs. new_domain_config = other.instance_variable_get(:@__domain_config) @__domain_config.each do |key, value| new_domain_config[key] ||= [] new_domain_config[key] = value + new_domain_config[key] end # Set it result.instance_variable_set(:@__domain_config, new_domain_config) # Merge in the tags result..merge!(self.) result..merge!(other.) end end |
#validate(machine) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/vagrant-cloudstack/config.rb', line 220 def validate(machine) errors = [] if @domain # Get the configuration for the domain we're using and validate only # that domain. config = get_domain_config(@domain) if !config.use_fog_profile errors << I18n.t("vagrant_cloudstack.config.api_key_required") if \ config.access_key_id.nil? errors << I18n.t("vagrant_cloudstack.config.secret_key_required") if \ config.secret_access_key.nil? end errors << I18n.t("vagrant_cloudstack.config.ami_required") if config.ami.nil? end { "Cloudstack Provider" => errors } end |