Class: ConfigBuilder::Model::VM

Inherits:
Base
  • Object
show all
Includes:
ConfigBuilder::ModelDelegator
Defined in:
lib/config_builder/model/vm.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigBuilder::ModelDelegator

#eval_models, included, #model_delegators

Methods inherited from Base

#attrs=, #call, def_model_attribute, model_attributes, new_from_hash

Constructor Details

#initializeVM

Returns a new instance of VM.



81
82
83
84
85
86
87
88
# File 'lib/config_builder/model/vm.rb', line 81

def initialize
  @defaults = {
    :provisioners     => [],
    :forwarded_ports  => [],
    :private_networks => [],
    :synced_folders   => [],
  }
end

Instance Attribute Details

#boxString

Returns The name of the Vagrant box to instantiate for this VM.

Returns:

  • (String)

    The name of the Vagrant box to instantiate for this VM



67
# File 'lib/config_builder/model/vm.rb', line 67

def_model_attribute :box

#box_urlString

Returns The source URL for the Vagrant box associated with this VM.

Returns:

  • (String)

    The source URL for the Vagrant box associated with this VM



71
# File 'lib/config_builder/model/vm.rb', line 71

def_model_attribute :box

#forwarded_portsArray<Hash<Symbol, Object>>

Returns A collection of port mappings.

Examples:

>> vm.forwarded_ports
=> [
      {:guest => 80, :host  => 20080},
      {:guest => 443, :host => 20443},
   ]

Returns:

  • (Array<Hash<Symbol, Object>>)

    A collection of port mappings



41
# File 'lib/config_builder/model/vm.rb', line 41

def_model_delegator :forwarded_ports

#hostnameString

Returns The hostname the machine should have.

Returns:

  • (String)

    The hostname the machine should have.



79
# File 'lib/config_builder/model/vm.rb', line 79

def_model_attribute :hostname

#nameString

Returns The name of the instantiated box in this environment.

Returns:

  • (String)

    The name of the instantiated box in this environment



75
# File 'lib/config_builder/model/vm.rb', line 75

def_model_attribute :name

#private_networksArray<Hash<Symbol, Object>>

Returns A collection of IP address network settings.

Examples:

>> vm.private_networks
=> [
      {:ip => '10.20.4.1'},
      {:ip => '192.168.100.5', :netmask => '255.255.255.128'},
   ]

Returns:

  • (Array<Hash<Symbol, Object>>)

    A collection of IP address network settings.



52
# File 'lib/config_builder/model/vm.rb', line 52

def_model_delegator :private_networks

#providerHash<Symbol, Object>

Returns The provider configuration for this VM.

Examples:

>> vm.provider
=> {
      :type => 'virtualbox',
      :name => 'tiny-tina',
      :gui  => false,
   }

Returns:

  • (Hash<Symbol, Object>)

    The provider configuration for this VM



16
# File 'lib/config_builder/model/vm.rb', line 16

def_model_delegator :provider

#provisionersArray<Hash<Symbol, Object>>

Returns A collection of provisioner parameters in the order that they should be applied of provisioner types, and a list of provisioner instances for each type.

Examples:

>> vm.provisioners
=> [
      {:type => :shell, :path   => '/vagrant/bin/magic.sh'},
      {:type => :shell, :inline => '/bin/echo hello world'},

      {:type => :puppet, :manifest => 'foo.pp'},
      {:type => :puppet, :manifest => 'bar.pp', :modulepath => '/vagrant/modules'},
   ]

Returns:

  • (Array<Hash<Symbol, Object>>)

    A collection of provisioner parameters in the order that they should be applied of provisioner types, and a list of provisioner instances for each type



31
# File 'lib/config_builder/model/vm.rb', line 31

def_model_delegator :provisioners

#synced_foldersArray<Hash<Symbol, Object>>

Examples:

>> vm.synced_folders
=> [
      {:host_path => 'manifests/', :guest_path => '/root/manifests', :disabled => false},
      {:host_path => 'modules/', :guest_path => '/root/modules'},
   ]

Returns:

  • (Array<Hash<Symbol, Object>>)


63
# File 'lib/config_builder/model/vm.rb', line 63

def_model_delegator :synced_folders

Instance Method Details

#to_procObject



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/config_builder/model/vm.rb', line 90

def to_proc
  Proc.new do |global_config|
    global_config.vm.define(attr(:name)) do |config|
      vm_config = config.vm

      vm_config.box = attr(:box) if defined? attr(:box)
      vm_config.box_url = attr(:box_url) if defined? attr(:box_url)
      vm_config.hostname = attr(:hostname) if defined? attr(:hostname)

      eval_models(vm_config)
    end
  end
end