Class: VagrantPlugins::Proxmox::Action::ConfigClone

Inherits:
ProxmoxAction
  • Object
show all
Defined in:
lib/vagrant-proxmox/action/config_clone.rb

Overview

This action modifies the configuration of a cloned vm Basically it creates a user network interface with hostfwd for the provisioning and an interface for every public or private interface defined in the Vagrantfile

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ConfigClone

Returns a new instance of ConfigClone.



10
11
12
13
14
15
# File 'lib/vagrant-proxmox/action/config_clone.rb', line 10

def initialize app, env
	@app = app
	@logger = Log4r::Logger.new 'vagrant_proxmox::action::config_clone'
	@node_ip = nil
	@guest_port = nil
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant-proxmox/action/config_clone.rb', line 17

def call env
	env[:ui].info I18n.t('vagrant_proxmox.configuring_vm')
	config = env[:machine].provider_config
	node = env[:proxmox_selected_node]
	vm_id = nil

	begin
		vm_id = env[:machine].id.split("/").last
		@node_ip = connection(env).get_node_ip(node, 'vmbr0') if config.vm_type == :qemu
		@guest_port = sprintf("22%03d", vm_id.to_i).to_s
	rescue StandardError => e
		raise VagrantPlugins::Proxmox::Errors::VMConfigError, proxmox_exit_status: e.message
	end

	begin
		template_config = connection(env).get_vm_config node: node, vm_id: vm_id, vm_type: config.vm_type
		params = create_params_qemu(config, env, vm_id, template_config)
		exit_status = connection(env).config_clone node: node, vm_type: config.vm_type, params: params
		exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
	rescue StandardError => e
		raise VagrantPlugins::Proxmox::Errors::VMConfigError, proxmox_exit_status: e.message
	end

	env[:ui].info I18n.t('vagrant_proxmox.done')
	next_action env
end