Class: VagrantPlugins::Proxmox::Action::CreateVm
- Inherits:
-
ProxmoxAction
- Object
- ProxmoxAction
- VagrantPlugins::Proxmox::Action::CreateVm
- Defined in:
- lib/vagrant-proxmox/action/create_vm.rb
Overview
This action creates a new virtual machine on the Proxmox server and stores its node and vm_id env.id
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ CreateVm
constructor
A new instance of CreateVm.
Constructor Details
#initialize(app, env) ⇒ CreateVm
Returns a new instance of CreateVm.
9 10 11 12 |
# File 'lib/vagrant-proxmox/action/create_vm.rb', line 9 def initialize app, env @app = app @logger = Log4r::Logger.new 'vagrant_proxmox::action::create_vm' end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vagrant-proxmox/action/create_vm.rb', line 14 def call env env[:ui].info I18n.t('vagrant_proxmox.creating_vm') config = env[:machine].provider_config node = env[:proxmox_selected_node] vm_id = nil begin vm_id = connection(env).get_free_vm_id params = create_params_openvz(config, env, vm_id) if config.vm_type == :openvz params = create_params_lxc(config, env, vm_id) if config.vm_type == :lxc params = create_params_qemu(config, env, vm_id) if config.vm_type == :qemu exit_status = connection(env).create_vm 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::VMCreateError, proxmox_exit_status: e. end env[:machine].id = "#{node}/#{vm_id}" env[:ui].info I18n.t('vagrant_proxmox.done') next_action env end |