Class: VagrantPlugins::Cloudstack::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Cloudstack::Config
- Defined in:
- lib/vagrant-cloudstack/config.rb
Constant Summary collapse
- INSTANCE_VAR_DEFAULT_NIL =
%w(host name path port domain_id network_id network_name project_id service_offering_id service_offering_name template_id template_name zone_id zone_name keypair pf_ip_address_id pf_ip_address pf_public_port pf_public_rdp_port pf_private_port pf_trusted_networks display_name group user_data ssh_key ssh_user ssh_network_id ssh_network_name vm_user vm_password private_ip_address).freeze
- INSTANCE_VAR_DEFAULT_EMPTY_ARRAY =
%w(static_nat port_forwarding_rules firewall_rules security_group_ids security_group_names security_groups).freeze
Instance Attribute Summary collapse
-
#api_key ⇒ String
The API key for accessing Cloudstack.
-
#disk_offering_id ⇒ String
Disk offering uuid to use for the instance.
-
#disk_offering_name ⇒ String
Disk offering name to use for the instance.
-
#display_name ⇒ String
display name for the instance.
-
#domain_id ⇒ String
Domain id to launch the instance into.
-
#expunge_on_destroy ⇒ Boolean
flag to enable/disable expunge vm on destroy.
-
#firewall_rules ⇒ Array
comma separated list of firewall rules (hash with rule parameters).
-
#group ⇒ String
group for the instance.
-
#host ⇒ String
Cloudstack api host.
-
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
-
#keypair ⇒ String
The name of the keypair to use.
-
#name ⇒ String
Hostname for the machine instance This will be passed through to the api.
-
#network_id ⇒ String, Array
Network uuid(s) that the instance should use.
-
#network_name ⇒ String, Array
Network name(s) that the instance should use.
-
#network_type ⇒ String
Network Type.
-
#path ⇒ String
Cloudstack api path.
-
#pf_ip_address ⇒ String
IP address to use for port forwarding rule.
-
#pf_ip_address_id ⇒ String
IP address id to use for port forwarding rule.
-
#pf_open_firewall ⇒ Boolean
flag to enable/disable automatic open firewall rule.
-
#pf_private_port ⇒ String
private port to use for port forwarding rule.
-
#pf_private_rdp_port ⇒ String
private port to use for port forwarding rule.
-
#pf_public_port ⇒ String
public port to use for port forwarding rule.
-
#pf_public_port_randomrange ⇒ Range
public port to use for port forwarding rule.
-
#pf_public_rdp_port ⇒ String
public port to use for port forwarding rule.
-
#pf_trusted_networks ⇒ String
CIDR List string of trusted networks.
-
#port ⇒ String
Cloudstack api port.
-
#port_forwarding_rules ⇒ Array
comma separated list of port forwarding rules (hash with rule parameters).
-
#private_ip_address ⇒ String
Private ip for the instance.
-
#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.
-
#security_group_ids ⇒ Array
comma separated list of security groups id that going to be applied to the virtual machine.
-
#security_group_names ⇒ Array
comma separated list of security groups name that going to be applied to the virtual machine.
-
#security_groups ⇒ Array
comma separated list of security groups (hash with ingress/egress rules) to be applied to the virtual machine.
-
#service_offering_id ⇒ String
Service offering uuid to use for the instance.
-
#service_offering_name ⇒ String
Service offering name to use for the instance.
-
#ssh_key ⇒ String
The key to be used when loging in to the vm via ssh.
-
#ssh_network_id ⇒ String
The network_id to be used when loging in to the vm via ssh.
-
#ssh_network_name ⇒ String
The network_name to be used when loging in to the vm via ssh.
-
#ssh_user ⇒ String
The username to be used when loging in to the vm via ssh.
-
#static_nat ⇒ String
Paramters for Static NAT.
-
#template_id ⇒ String
Template uuid to use for the instance.
-
#template_name ⇒ String
Template name to use for the instance.
-
#user_data ⇒ String
The user data string.
-
#vm_password ⇒ String
The username to be used when loging in to the vm.
-
#vm_user ⇒ String
The username to be used when loging in to the vm.
-
#zone_id ⇒ String
Zone uuid to launch the instance into.
-
#zone_name ⇒ String
Zone name 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
Returns a new instance of Config.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/vagrant-cloudstack/config.rb', line 261 def initialize(domain_specific = false) # Initialize groups in bulk, re-use these groups to set defaults in bulk INSTANCE_VAR_DEFAULT_NIL.each do |instance_variable| instance_variable_set("@#{instance_variable}", UNSET_VALUE) end # Initialize groups in bulk, re-use these groups to set defaults in bulk INSTANCE_VAR_DEFAULT_EMPTY_ARRAY.each do |instance_variable| instance_variable_set("@#{instance_variable}", UNSET_VALUE) end @scheme = UNSET_VALUE @api_key = UNSET_VALUE @secret_key = UNSET_VALUE @instance_ready_timeout = UNSET_VALUE @network_type = UNSET_VALUE @pf_private_rdp_port = UNSET_VALUE @pf_public_port_randomrange = UNSET_VALUE @pf_open_firewall = UNSET_VALUE @expunge_on_destroy = 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.
41 42 43 |
# File 'lib/vagrant-cloudstack/config.rb', line 41 def api_key @api_key end |
#disk_offering_id ⇒ String
Disk offering uuid to use for the instance
91 92 93 |
# File 'lib/vagrant-cloudstack/config.rb', line 91 def disk_offering_id @disk_offering_id end |
#disk_offering_name ⇒ String
Disk offering name to use for the instance
96 97 98 |
# File 'lib/vagrant-cloudstack/config.rb', line 96 def disk_offering_name @disk_offering_name end |
#display_name ⇒ String
display name for the instance
209 210 211 |
# File 'lib/vagrant-cloudstack/config.rb', line 209 def display_name @display_name end |
#domain_id ⇒ String
Domain id to launch the instance into.
56 57 58 |
# File 'lib/vagrant-cloudstack/config.rb', line 56 def domain_id @domain_id end |
#expunge_on_destroy ⇒ Boolean
flag to enable/disable expunge vm on destroy
259 260 261 |
# File 'lib/vagrant-cloudstack/config.rb', line 259 def expunge_on_destroy @expunge_on_destroy end |
#firewall_rules ⇒ Array
comma separated list of firewall rules (hash with rule parameters)
185 186 187 |
# File 'lib/vagrant-cloudstack/config.rb', line 185 def firewall_rules @firewall_rules end |
#group ⇒ String
group for the instance
214 215 216 |
# File 'lib/vagrant-cloudstack/config.rb', line 214 def group @group end |
#host ⇒ String
Cloudstack api host.
15 16 17 |
# File 'lib/vagrant-cloudstack/config.rb', line 15 def host @host end |
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
51 52 53 |
# File 'lib/vagrant-cloudstack/config.rb', line 51 def instance_ready_timeout @instance_ready_timeout end |
#keypair ⇒ String
The name of the keypair to use.
123 124 125 |
# File 'lib/vagrant-cloudstack/config.rb', line 123 def keypair @keypair end |
#name ⇒ String
Hostname for the machine instance This will be passed through to the api.
21 22 23 |
# File 'lib/vagrant-cloudstack/config.rb', line 21 def name @name end |
#network_id ⇒ String, Array
Network uuid(s) that the instance should use
61 62 63 |
# File 'lib/vagrant-cloudstack/config.rb', line 61 def network_id @network_id end |
#network_name ⇒ String, Array
Network name(s) that the instance should use
66 67 68 |
# File 'lib/vagrant-cloudstack/config.rb', line 66 def network_name @network_name end |
#network_type ⇒ String
Network Type
71 72 73 |
# File 'lib/vagrant-cloudstack/config.rb', line 71 def network_type @network_type end |
#path ⇒ String
Cloudstack api path.
26 27 28 |
# File 'lib/vagrant-cloudstack/config.rb', line 26 def path @path end |
#pf_ip_address ⇒ String
IP address to use for port forwarding rule
138 139 140 |
# File 'lib/vagrant-cloudstack/config.rb', line 138 def pf_ip_address @pf_ip_address end |
#pf_ip_address_id ⇒ String
IP address id to use for port forwarding rule
133 134 135 |
# File 'lib/vagrant-cloudstack/config.rb', line 133 def pf_ip_address_id @pf_ip_address_id end |
#pf_open_firewall ⇒ Boolean
flag to enable/disable automatic open firewall rule
168 169 170 |
# File 'lib/vagrant-cloudstack/config.rb', line 168 def pf_open_firewall @pf_open_firewall end |
#pf_private_port ⇒ String
private port to use for port forwarding rule
163 164 165 |
# File 'lib/vagrant-cloudstack/config.rb', line 163 def pf_private_port @pf_private_port end |
#pf_private_rdp_port ⇒ String
private port to use for port forwarding rule
153 154 155 |
# File 'lib/vagrant-cloudstack/config.rb', line 153 def pf_private_rdp_port @pf_private_rdp_port end |
#pf_public_port ⇒ String
public port to use for port forwarding rule
143 144 145 |
# File 'lib/vagrant-cloudstack/config.rb', line 143 def pf_public_port @pf_public_port end |
#pf_public_port_randomrange ⇒ Range
public port to use for port forwarding rule
158 159 160 |
# File 'lib/vagrant-cloudstack/config.rb', line 158 def pf_public_port_randomrange @pf_public_port_randomrange end |
#pf_public_rdp_port ⇒ String
public port to use for port forwarding rule
148 149 150 |
# File 'lib/vagrant-cloudstack/config.rb', line 148 def pf_public_rdp_port @pf_public_rdp_port end |
#pf_trusted_networks ⇒ String
CIDR List string of trusted networks
173 174 175 |
# File 'lib/vagrant-cloudstack/config.rb', line 173 def pf_trusted_networks @pf_trusted_networks end |
#port ⇒ String
Cloudstack api port.
31 32 33 |
# File 'lib/vagrant-cloudstack/config.rb', line 31 def port @port end |
#port_forwarding_rules ⇒ Array
comma separated list of port forwarding rules (hash with rule parameters)
179 180 181 |
# File 'lib/vagrant-cloudstack/config.rb', line 179 def port_forwarding_rules @port_forwarding_rules end |
#private_ip_address ⇒ String
Private ip for the instance
254 255 256 |
# File 'lib/vagrant-cloudstack/config.rb', line 254 def private_ip_address @private_ip_address end |
#project_id ⇒ String
Project uuid that the instance should belong to
76 77 78 |
# File 'lib/vagrant-cloudstack/config.rb', line 76 def project_id @project_id end |
#scheme ⇒ String
Cloudstack api scheme
36 37 38 |
# File 'lib/vagrant-cloudstack/config.rb', line 36 def scheme @scheme end |
#secret_key ⇒ String
The secret key for accessing Cloudstack.
46 47 48 |
# File 'lib/vagrant-cloudstack/config.rb', line 46 def secret_key @secret_key end |
#security_group_ids ⇒ Array
comma separated list of security groups id that going to be applied to the virtual machine.
191 192 193 |
# File 'lib/vagrant-cloudstack/config.rb', line 191 def security_group_ids @security_group_ids end |
#security_group_names ⇒ Array
comma separated list of security groups name that going to be applied to the virtual machine.
197 198 199 |
# File 'lib/vagrant-cloudstack/config.rb', line 197 def security_group_names @security_group_names end |
#security_groups ⇒ Array
comma separated list of security groups (hash with ingress/egress rules) to be applied to the virtual machine.
204 205 206 |
# File 'lib/vagrant-cloudstack/config.rb', line 204 def security_groups @security_groups end |
#service_offering_id ⇒ String
Service offering uuid to use for the instance
81 82 83 |
# File 'lib/vagrant-cloudstack/config.rb', line 81 def service_offering_id @service_offering_id end |
#service_offering_name ⇒ String
Service offering name to use for the instance
86 87 88 |
# File 'lib/vagrant-cloudstack/config.rb', line 86 def service_offering_name @service_offering_name end |
#ssh_key ⇒ String
The key to be used when loging in to the vm via ssh
224 225 226 |
# File 'lib/vagrant-cloudstack/config.rb', line 224 def ssh_key @ssh_key end |
#ssh_network_id ⇒ String
The network_id to be used when loging in to the vm via ssh
234 235 236 |
# File 'lib/vagrant-cloudstack/config.rb', line 234 def ssh_network_id @ssh_network_id end |
#ssh_network_name ⇒ String
The network_name to be used when loging in to the vm via ssh
239 240 241 |
# File 'lib/vagrant-cloudstack/config.rb', line 239 def ssh_network_name @ssh_network_name end |
#ssh_user ⇒ String
The username to be used when loging in to the vm via ssh
229 230 231 |
# File 'lib/vagrant-cloudstack/config.rb', line 229 def ssh_user @ssh_user end |
#static_nat ⇒ String
Paramters for Static NAT
128 129 130 |
# File 'lib/vagrant-cloudstack/config.rb', line 128 def static_nat @static_nat end |
#template_id ⇒ String
Template uuid to use for the instance
101 102 103 |
# File 'lib/vagrant-cloudstack/config.rb', line 101 def template_id @template_id end |
#template_name ⇒ String
Template name to use for the instance
106 107 108 |
# File 'lib/vagrant-cloudstack/config.rb', line 106 def template_name @template_name end |
#user_data ⇒ String
The user data string
219 220 221 |
# File 'lib/vagrant-cloudstack/config.rb', line 219 def user_data @user_data end |
#vm_password ⇒ String
The username to be used when loging in to the vm
249 250 251 |
# File 'lib/vagrant-cloudstack/config.rb', line 249 def vm_password @vm_password end |
#vm_user ⇒ String
The username to be used when loging in to the vm
244 245 246 |
# File 'lib/vagrant-cloudstack/config.rb', line 244 def vm_user @vm_user end |
#zone_id ⇒ String
Zone uuid to launch the instance into. If nil, it will launch in default project.
112 113 114 |
# File 'lib/vagrant-cloudstack/config.rb', line 112 def zone_id @zone_id end |
#zone_name ⇒ String
Zone name to launch the instance into. If nil, it will launch in default project.
118 119 120 |
# File 'lib/vagrant-cloudstack/config.rb', line 118 def zone_name @zone_name 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
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/vagrant-cloudstack/config.rb', line 302 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
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/vagrant-cloudstack/config.rb', line 349 def finalize! INSTANCE_VAR_DEFAULT_NIL.each do |instance_variable| # ... must be nil, since we can't default that instance_variable_set("@#{instance_variable}", nil) if instance_variable_get("@#{instance_variable}") == UNSET_VALUE end INSTANCE_VAR_DEFAULT_EMPTY_ARRAY.each do |instance_variable| # ... must be empty array instance_variable_set("@#{instance_variable}", []) if instance_variable_get("@#{instance_variable}") == UNSET_VALUE end # We default the scheme to whatever the user has specifid in the .fog file # *OR* whatever is default for the provider in the fog library @scheme = nil if @scheme == UNSET_VALUE # Try to get access keys from environment variables, they will # default to nil if the environment variables are not present @api_key = ENV['CLOUDSTACK_API_KEY'] if @api_key == UNSET_VALUE @secret_key = ENV['CLOUDSTACK_SECRET_KEY'] 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 # NetworkType is 'Advanced' by default @network_type = "Advanced" if @network_type == UNSET_VALUE # Private rdp port defaults to 3389 @pf_private_rdp_port = 3389 if @pf_private_rdp_port == UNSET_VALUE # Public port random-range, default to rfc6335 'Dynamic Ports'; "(never assigned)" @pf_public_port_randomrange = {:start=>49152, :end=>65535} if @pf_public_port_randomrange == UNSET_VALUE # Open firewall is true by default (for backwards compatibility) @pf_open_firewall = true if @pf_open_firewall == UNSET_VALUE # expunge on destroy is nil by default @expunge_on_destroy = false if @expunge_on_destroy == UNSET_VALUE # Compile our domain specific configurations only within # NON-DOMAIN-SPECIFIC configurations. unless @__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.
433 434 435 436 437 438 |
# File 'lib/vagrant-cloudstack/config.rb', line 433 def get_domain_config(name) raise 'Configuration must be finalized before calling this method.' unless @__finalized # Return the compiled domain config @__compiled_domain_configs[name] || self end |
#merge(other) ⇒ Object
Internal methods.
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/vagrant-cloudstack/config.rb', line 324 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
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/vagrant-cloudstack/config.rb', line 413 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) unless 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 end {"Cloudstack Provider" => errors} end |