Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to LXC (proxmox4) #26

Merged
merged 5 commits into from
Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/vagrant-proxmox/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def self.action_up
b2.use MessageUploadServerError
end
end
elsif env1[:machine].provider_config.vm_type == :lxc
b1.use Call, UploadTemplateFile do |env2, b2|
if env2[:result] == :ok
b2.use CreateVm
b2.use StartVm
b2.use SyncFolders
elsif env2[:result] == :file_not_found
b2.use MessageFileNotFound
elsif env2[:result] == :server_upload_error
b2.use MessageUploadServerError
end
end
elsif env1[:machine].provider_config.vm_type == :qemu
b1.use Call, UploadIsoFile do |env2, b2|
if env2[:result] == :ok
Expand Down
15 changes: 15 additions & 0 deletions lib/vagrant-proxmox/action/create_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def call env
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)
Expand Down Expand Up @@ -62,6 +63,20 @@ def create_params_openvz(config, env, vm_id)
params[:ip_address] = get_machine_ip_address(env) if get_machine_ip_address(env)
end
end

private
def create_params_lxc(config, env, vm_id)
{vmid: vm_id,
ostemplate: config.openvz_os_template,
hostname: env[:machine].config.vm.hostname || env[:machine].name.to_s,
password: 'vagrant',
storage: "#{config.vm_storage}:#{config.vm_disk_size}",
memory: config.vm_memory,
description: "#{config.vm_name_prefix}#{env[:machine].name}"}
.tap do |params|
params[:net0] = "name=#{get_machine_interface_name(env)},ip=#{get_machine_ip_address(env)}/24,gw=#{get_machine_gw_ip(env)},bridge=#{get_machine_bridge_name(env)}" if get_machine_ip_address(env)
end
end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/vagrant-proxmox/action/proxmox_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ def next_action env
def get_machine_ip_address env
env[:machine].config.vm.networks.select { |type, _| type == :public_network }.first[1][:ip] rescue nil
end

protected
def get_machine_interface_name env
env[:machine].config.vm.networks.select { |type, _| type == :public_network }.first[1][:interface] rescue nil
end

protected
def get_machine_bridge_name env
env[:machine].config.vm.networks.select { |type, _| type == :public_network }.first[1][:bridge] rescue nil
end

protected
def get_machine_gw_ip env
env[:machine].config.vm.networks.select { |type, _| type == :public_network }.first[1][:gw] rescue nil
end

protected
def get_machine_macaddress env
Expand Down
16 changes: 15 additions & 1 deletion lib/vagrant-proxmox/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Config < Vagrant.plugin('2', :config)
# @return [String]
attr_accessor :password

# The virtual machine type, e.g. :openvz or :qemu
# The virtual machine type, e.g. :openvz or :qemu or :lxc
#
# @return [Symbol]
attr_accessor :vm_type
Expand Down Expand Up @@ -57,6 +57,17 @@ class Config < Vagrant.plugin('2', :config)
# @return [Integer]
attr_accessor :vm_memory

# The vm disk size to use for the virtual machine, e.g. '30G'
#
# @return [String]
attr_accessor :vm_disk_size

# The vm storage to use for the virtual machine, e.g. 'local', 'raid', 'cephstore'
# defaults to 'raid' for backwards compatability
#
# @return [String]
attr_accessor :vm_storage

# The maximum timeout for a proxmox server task (in seconds)
#
# @return [Integer]
Expand Down Expand Up @@ -147,6 +158,8 @@ def initialize
@vm_id_range = 900..999
@vm_name_prefix = 'vagrant_'
@vm_memory = 512
@vm_disk_size = '20G'
@vm_storage = 'local'
@task_timeout = 60
@task_status_check_interval = 2
@ssh_timeout = 60
Expand Down Expand Up @@ -180,6 +193,7 @@ def finalize!
@qemu_iso = nil if @qemu_iso == UNSET_VALUE
@qemu_disk_size = nil if @qemu_disk_size == UNSET_VALUE
@qemu_disk_size = convert_disk_size_to_gigabyte @qemu_disk_size if @qemu_disk_size
@vm_disk_size = convert_disk_size_to_gigabyte @vm_disk_size if @vm_disk_size
end

def validate machine
Expand Down