Class: VagrantPlugins::Cloudstack::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-cloudstack/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain_specific = false) ⇒ Config

Returns a new instance of Config.



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/vagrant-cloudstack/config.rb', line 196

def initialize(domain_specific=false)
  @host                      = UNSET_VALUE
  @name                      = 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
  @network_name              = UNSET_VALUE
  @network_type              = UNSET_VALUE
  @project_id                = UNSET_VALUE
  @service_offering_id       = UNSET_VALUE
  @service_offering_name     = UNSET_VALUE
  @template_id               = UNSET_VALUE
  @template_name             = UNSET_VALUE
  @zone_id                   = UNSET_VALUE
  @zone_name                 = UNSET_VALUE
  @keypair                   = UNSET_VALUE
  @static_nat                = UNSET_VALUE
  @pf_ip_address_id          = UNSET_VALUE
  @pf_ip_address             = UNSET_VALUE
  @pf_public_port            = UNSET_VALUE
  @pf_private_port           = UNSET_VALUE
  @pf_open_firewall          = UNSET_VALUE
  @port_forwarding_rules     = UNSET_VALUE
  @firewall_rules            = UNSET_VALUE
  @security_group_ids        = UNSET_VALUE
  @display_name              = UNSET_VALUE
  @group                     = UNSET_VALUE
  @security_group_names      = UNSET_VALUE
  @security_groups           = UNSET_VALUE
  @user_data                 = UNSET_VALUE
  @ssh_key                   = UNSET_VALUE
  @ssh_user                  = 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_keyString

The API key for accessing Cloudstack.

Returns:

  • (String)


35
36
37
# File 'lib/vagrant-cloudstack/config.rb', line 35

def api_key
  @api_key
end

#display_nameString

display name for the instance

Returns:

  • (String)


173
174
175
# File 'lib/vagrant-cloudstack/config.rb', line 173

def display_name
  @display_name
end

#domain_idString

Domain id to launch the instance into.

Returns:

  • (String)


50
51
52
# File 'lib/vagrant-cloudstack/config.rb', line 50

def domain_id
  @domain_id
end

#firewall_rulesArray

comma separated list of firewall rules (hash with rule parameters)

Returns:

  • (Array)


149
150
151
# File 'lib/vagrant-cloudstack/config.rb', line 149

def firewall_rules
  @firewall_rules
end

#groupString

group for the instance

Returns:

  • (String)


178
179
180
# File 'lib/vagrant-cloudstack/config.rb', line 178

def group
  @group
end

#hostString

Cloudstack api host.

Returns:

  • (String)


9
10
11
# File 'lib/vagrant-cloudstack/config.rb', line 9

def host
  @host
end

#instance_ready_timeoutFixnum

The timeout to wait for an instance to become ready.

Returns:

  • (Fixnum)


45
46
47
# File 'lib/vagrant-cloudstack/config.rb', line 45

def instance_ready_timeout
  @instance_ready_timeout
end

#keypairString

The name of the keypair to use.

Returns:

  • (String)


107
108
109
# File 'lib/vagrant-cloudstack/config.rb', line 107

def keypair
  @keypair
end

#nameString

Hostname for the machine instance This will be passed through to the api.

Returns:

  • (String)


15
16
17
# File 'lib/vagrant-cloudstack/config.rb', line 15

def name
  @name
end

#network_idString

Network uuid that the instance should use

Returns:

  • (String)


55
56
57
# File 'lib/vagrant-cloudstack/config.rb', line 55

def network_id
  @network_id
end

#network_nameString

Network name that the instance should use

Returns:

  • (String)


60
61
62
# File 'lib/vagrant-cloudstack/config.rb', line 60

def network_name
  @network_name
end

#network_typeString

Network Type

Returns:

  • (String)


65
66
67
# File 'lib/vagrant-cloudstack/config.rb', line 65

def network_type
  @network_type
end

#pathString

Cloudstack api path.

Returns:

  • (String)


20
21
22
# File 'lib/vagrant-cloudstack/config.rb', line 20

def path
  @path
end

#pf_ip_addressString

IP address to use for port forwarding rule

Returns:

  • (String)


122
123
124
# File 'lib/vagrant-cloudstack/config.rb', line 122

def pf_ip_address
  @pf_ip_address
end

#pf_ip_address_idString

IP address id to use for port forwarding rule

Returns:

  • (String)


117
118
119
# File 'lib/vagrant-cloudstack/config.rb', line 117

def pf_ip_address_id
  @pf_ip_address_id
end

#pf_open_firewallBoolean

flag to enable/disable automatic open firewall rule

Returns:

  • (Boolean)


137
138
139
# File 'lib/vagrant-cloudstack/config.rb', line 137

def pf_open_firewall
  @pf_open_firewall
end

#pf_private_portString

private port to use for port forwarding rule

Returns:

  • (String)


132
133
134
# File 'lib/vagrant-cloudstack/config.rb', line 132

def pf_private_port
  @pf_private_port
end

#pf_public_portString

public port to use for port forwarding rule

Returns:

  • (String)


127
128
129
# File 'lib/vagrant-cloudstack/config.rb', line 127

def pf_public_port
  @pf_public_port
end

#portString

Cloudstack api port.

Returns:

  • (String)


25
26
27
# File 'lib/vagrant-cloudstack/config.rb', line 25

def port
  @port
end

#port_forwarding_rulesArray

comma separated list of port forwarding rules (hash with rule parameters)

Returns:

  • (Array)


143
144
145
# File 'lib/vagrant-cloudstack/config.rb', line 143

def port_forwarding_rules
  @port_forwarding_rules
end

#project_idString

Project uuid that the instance should belong to

Returns:

  • (String)


70
71
72
# File 'lib/vagrant-cloudstack/config.rb', line 70

def project_id
  @project_id
end

#schemeString

Cloudstack api scheme

Returns:

  • (String)


30
31
32
# File 'lib/vagrant-cloudstack/config.rb', line 30

def scheme
  @scheme
end

#secret_keyString

The secret key for accessing Cloudstack.

Returns:

  • (String)


40
41
42
# File 'lib/vagrant-cloudstack/config.rb', line 40

def secret_key
  @secret_key
end

#security_group_idsArray

comma separated list of security groups id that going to be applied to the virtual machine.

Returns:

  • (Array)


155
156
157
# File 'lib/vagrant-cloudstack/config.rb', line 155

def security_group_ids
  @security_group_ids
end

#security_group_namesArray

comma separated list of security groups name that going to be applied to the virtual machine.

Returns:

  • (Array)


161
162
163
# File 'lib/vagrant-cloudstack/config.rb', line 161

def security_group_names
  @security_group_names
end

#security_groupsArray

comma separated list of security groups (hash with ingress/egress rules) to be applied to the virtual machine.

Returns:

  • (Array)


168
169
170
# File 'lib/vagrant-cloudstack/config.rb', line 168

def security_groups
  @security_groups
end

#service_offering_idString

Service offering uuid to use for the instance

Returns:

  • (String)


75
76
77
# File 'lib/vagrant-cloudstack/config.rb', line 75

def service_offering_id
  @service_offering_id
end

#service_offering_nameString

Service offering name to use for the instance

Returns:

  • (String)


80
81
82
# File 'lib/vagrant-cloudstack/config.rb', line 80

def service_offering_name
  @service_offering_name
end

#ssh_keyString

The key to be used when loging in to the vm via ssh

Returns:

  • (String)


188
189
190
# File 'lib/vagrant-cloudstack/config.rb', line 188

def ssh_key
  @ssh_key
end

#ssh_userString

The username to be used when loging in to the vm via ssh

Returns:

  • (String)


193
194
195
# File 'lib/vagrant-cloudstack/config.rb', line 193

def ssh_user
  @ssh_user
end

#static_natString

Paramters for Static NAT

Returns:

  • (String)


112
113
114
# File 'lib/vagrant-cloudstack/config.rb', line 112

def static_nat
  @static_nat
end

#template_idString

Template uuid to use for the instance

Returns:

  • (String)


85
86
87
# File 'lib/vagrant-cloudstack/config.rb', line 85

def template_id
  @template_id
end

#template_nameString

Template name to use for the instance

Returns:

  • (String)


90
91
92
# File 'lib/vagrant-cloudstack/config.rb', line 90

def template_name
  @template_name
end

#user_dataString

The user data string

Returns:

  • (String)


183
184
185
# File 'lib/vagrant-cloudstack/config.rb', line 183

def user_data
  @user_data
end

#zone_idString

Zone uuid to launch the instance into. If nil, it will launch in default project.

Returns:

  • (String)


96
97
98
# File 'lib/vagrant-cloudstack/config.rb', line 96

def zone_id
  @zone_id
end

#zone_nameString

Zone name to launch the instance into. If nil, it will launch in default project.

Returns:

  • (String)


102
103
104
# File 'lib/vagrant-cloudstack/config.rb', line 102

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

Parameters:

  • domain (String)

    The Domain name to configure.

  • attributes (Hash) (defaults to: nil)

    Direct attributes to set on the configuration as a shortcut instead of specifying a full block.

Yields:

  • (config)

    Yields a new domain configuration.



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/vagrant-cloudstack/config.rb', line 255

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.set_options(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



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/vagrant-cloudstack/config.rb', line 302

def finalize!
  # Host must be nil, since we can't default that
  @host                   = nil if @host == UNSET_VALUE

  # Name must be nil, since we can't default that
  @name                   = nil if @name == 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

  # 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

  # 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

  # Network uuid must be nil, since we can't default that
  @network_name           = nil if @network_name == UNSET_VALUE

  # NetworkType is 'Advanced' by default
  @network_type           = "Advanced" if @network_type == 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

  # Service offering name must be nil, since we can't default that
  @service_offering_name  = nil if @service_offering_name == UNSET_VALUE

  # Template uuid must be nil, since we can't default that
  @template_id            = nil if @template_id == UNSET_VALUE

  # Template name must be nil, since we can't default that
  @template_name          = nil if @template_name == UNSET_VALUE

  # Zone uuid must be nil, since we can't default that
  @zone_id                = nil if @zone_id == UNSET_VALUE

  # Zone uuid must be nil, since we can't default that
  @zone_name              = nil if @zone_name == UNSET_VALUE

  # Keypair defaults to nil
  @keypair                = nil if @keypair == UNSET_VALUE

  # Static NAT must be empty array
  @static_nat             = [] if @static_nat == UNSET_VALUE

  # IP address id must be nil, since we can't default that
  @pf_ip_address_id       = nil if @pf_ip_address_id == UNSET_VALUE

  # IP address must be nil, since we can't default that
  @pf_ip_address          = nil if @pf_ip_address == UNSET_VALUE

  # Public port must be nil, since we can't default that
  @pf_public_port         = nil if @pf_public_port == UNSET_VALUE

  # Private port must be nil, since we can't default that
  @pf_private_port        = nil if @pf_private_port == UNSET_VALUE

  # Open firewall is true by default (for backwards compatibility)
  @pf_open_firewall       = true if @pf_open_firewall == UNSET_VALUE

  # Port forwarding rules  must be empty array
  @port_forwarding_rules  = [] if @port_forwarding_rules == UNSET_VALUE

  # Firewall rules  must be empty array
  @firewall_rules         = [] if @firewall_rules == UNSET_VALUE

  # Security Group IDs must be nil, since we can't default that
  @security_group_ids     = [] if @security_group_ids == UNSET_VALUE

  # Security Group Names must be nil, since we can't default that
  @security_group_names   = [] if @security_group_names == UNSET_VALUE

  # Security Groups must be nil, since we can't default that
  @security_groups        = [] if @security_groups == UNSET_VALUE

  # Display name must be nil, since we can't default that
  @display_name           = nil if @display_name == UNSET_VALUE

  # Group must be nil, since we can't default that
  @group                  = nil if @group == UNSET_VALUE

  # User Data is nil by default
  @user_data              = nil if @user_data == UNSET_VALUE

  # ssh key is nil by default
  @ssh_key                = nil if @ssh_key == UNSET_VALUE

  # ssh key is nil by default
  @ssh_user               = nil if @ssh_user == 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.



457
458
459
460
461
462
463
464
# File 'lib/vagrant-cloudstack/config.rb', line 457

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.




277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/vagrant-cloudstack/config.rb', line 277

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.tags.merge!(self.tags)
    result.tags.merge!(other.tags)
  end
end

#validate(machine) ⇒ Object



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/vagrant-cloudstack/config.rb', line 436

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
  end

  {"Cloudstack Provider" => errors}
end