Class: VagrantPlugins::ProviderVeertu::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant-veertu/config.rb', line 68

def initialize
  @auto_nat_dns_proxy = UNSET_VALUE
  @check_guest_additions = UNSET_VALUE
  @customizations   = []
  @destroy_unused_network_interfaces = UNSET_VALUE
  @functional_veertusf = false
  @name             = UNSET_VALUE
  @network_adapters = {}
  @gui              = UNSET_VALUE
  @linked_clone = UNSET_VALUE
  @linked_clone_snapshot = UNSET_VALUE

  # We require that network adapter 1 is a NAT device.
  network_adapter(1, :nat)
end

Instance Attribute Details

#auto_nat_dns_proxyBoolean

Vagrant by default will make “smart” decisions to enable/disable the NAT DNS proxy. If this is set to ‘true`, then the DNS proxy will not be enabled, and it is up to the end user to do it.

Returns:

  • (Boolean)


10
11
12
# File 'lib/vagrant-veertu/config.rb', line 10

def auto_nat_dns_proxy
  @auto_nat_dns_proxy
end

#check_guest_additionsBoolean

If true, will check if guest additions are installed and up to date. By default, this is true.

Returns:

  • (Boolean)


16
17
18
# File 'lib/vagrant-veertu/config.rb', line 16

def check_guest_additions
  @check_guest_additions
end

#customizationsArray (readonly)

An array of customizations to make on the VM prior to booting it.

Returns:

  • (Array)


21
22
23
# File 'lib/vagrant-veertu/config.rb', line 21

def customizations
  @customizations
end

#destroy_unused_network_interfacesBoolean

If true, unused network interfaces will automatically be deleted. This defaults to false because the detection does not work across multiple users, and because on Windows this operation requires administrative privileges.

Returns:

  • (Boolean)


29
30
31
# File 'lib/vagrant-veertu/config.rb', line 29

def destroy_unused_network_interfaces
  @destroy_unused_network_interfaces
end

#functional_veertusfBoolean

Whether or not this VM has a functional veertusf filesystem module. This defaults to true. If you set this to false, then the “veertu” synced folder type won’t be valid.

Returns:

  • (Boolean)


61
62
63
# File 'lib/vagrant-veertu/config.rb', line 61

def functional_veertusf
  @functional_veertusf
end

#guiBoolean

If set to ‘true`, then Veertu will be launched with a GUI.

Returns:

  • (Boolean)


34
35
36
# File 'lib/vagrant-veertu/config.rb', line 34

def gui
  @gui
end

#linked_cloneBoolean

If set to ‘true`, then a linked clone is created from a master VM generated from the specified box.

Returns:

  • (Boolean)


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

def linked_clone
  @linked_clone
end

#linked_clone_snapshotString

The snapshot to base the linked clone from. If this isn’t set a snapshot will be made with the name of “base” which will be used.

If this is set, then the snapshot must already exist.

Returns:

  • (String)


48
49
50
# File 'lib/vagrant-veertu/config.rb', line 48

def linked_clone_snapshot
  @linked_clone_snapshot
end

#nameString

This should be set to the name of the machine in the Veertu GUI.

Returns:

  • (String)


54
55
56
# File 'lib/vagrant-veertu/config.rb', line 54

def name
  @name
end

#network_adaptersHash (readonly)

The defined network adapters.

Returns:

  • (Hash)


66
67
68
# File 'lib/vagrant-veertu/config.rb', line 66

def network_adapters
  @network_adapters
end

Instance Method Details

#cpus=(count) ⇒ Object

Shortcut for setting CPU count for the virtual machine. Calls #customize internally.

Parameters:

  • count (Integer, String)

    the count of CPUs



123
124
125
# File 'lib/vagrant-veertu/config.rb', line 123

def cpus=(count)
  customize("pre-boot", ["modify", :id, "set", "--cpu", count.to_i])
end

#customize(*command) ⇒ Object

Customize the VM by calling ‘VeertuManage` with the given arguments.

When called multiple times, the customizations will be applied in the order given.

The special ‘:name` parameter in the command will be replaced with the unique ID or name of the virtual machine. This is useful for parameters to `modifyvm` and the like.

VeertuManage.

Parameters:

  • command (Array)

    An array of arguments to pass to



96
97
98
99
100
# File 'lib/vagrant-veertu/config.rb', line 96

def customize(*command)
  event   = command.first.is_a?(String) ? command.shift : "pre-boot"
  command = command[0]
  @customizations << [event, command]
end

#finalize!Object

This is the hook that is called to finalize the object before it is put into use.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/vagrant-veertu/config.rb', line 137

def finalize!
  # Default is to auto the DNS proxy
  @auto_nat_dns_proxy = true if @auto_nat_dns_proxy == UNSET_VALUE

  if @check_guest_additions == UNSET_VALUE
    @check_guest_additions = true
  end

  if @destroy_unused_network_interfaces == UNSET_VALUE
    @destroy_unused_network_interfaces = false
  end

  if @functional_veertusf == UNSET_VALUE
    @functional_veertusf = true
  end

  # Default is to not show a GUI
  @gui = false if @gui == UNSET_VALUE

  # Do not create linked clone by default
  @linked_clone = false if @linked_clone == UNSET_VALUE
  @linked_clone_snapshot = nil if @linked_clone_snapshot == UNSET_VALUE

  # The default name is just nothing, and we default it
  @name = nil if @name == UNSET_VALUE
end

#memory=(size) ⇒ Object

Shortcut for setting memory size for the virtual machine. Calls #customize internally.

Parameters:

  • size (Integer, String)

    the memory size in MB



115
116
117
# File 'lib/vagrant-veertu/config.rb', line 115

def memory=(size)
  customize("pre-boot", ["modify", :id, "set", "--ram", size.to_s + "MB"])
end

#merge(other) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/vagrant-veertu/config.rb', line 127

def merge(other)
  super.tap do |result|
    c = customizations.dup
    c += other.customizations
    result.instance_variable_set(:@customizations, c)
  end
end

#network_adapter(slot, type, **opts) ⇒ Object

This defines a network adapter that will be added to the Veertu virtual machine in the given slot.

Parameters:

  • slot (Integer)

    The slot for this network adapter.

  • type (Symbol)

    The type of adapter.



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

def network_adapter(slot, type, **opts)
  @network_adapters[slot] = [type, opts]
end

#to_sObject



194
195
196
# File 'lib/vagrant-veertu/config.rb', line 194

def to_s
  "Veertu"
end

#validate(machine) ⇒ Object



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
# File 'lib/vagrant-veertu/config.rb', line 164

def validate(machine)
  errors = _detected_errors

  valid_events = ["pre-import", "pre-boot", "post-boot", "post-comm"]
  @customizations.each do |event, _|
    if !valid_events.include?(event)
      errors << I18n.t(
        "vagrant.veertu.config.invalid_event",
        event: event.to_s,
        valid_events: valid_events.join(", "))
    end
  end

  @customizations.each do |event, command|
    if event == "pre-import" && command.index(:id)
      errors << I18n.t("vagrant.veertu.config.id_in_pre_import")
    end
  end

  # Verify that internal networks are only on private networks.
  machine.config.vm.networks.each do |type, data|
    if data[:veertu__intnet] && type != :private_network
      errors << I18n.t("vagrant.veertu.config.intnet_on_bad_type")
      break
    end
  end

  { "Veertu Provider" => errors }
end