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

Support KVM or LXC containers instead of / in addition to OpenVZ ? #25

Open
madmas opened this issue Nov 2, 2015 · 10 comments
Open

Support KVM or LXC containers instead of / in addition to OpenVZ ? #25

madmas opened this issue Nov 2, 2015 · 10 comments

Comments

@madmas
Copy link

madmas commented Nov 2, 2015

Appearently, the support for OpenVZ will be removed in the next version of Proxmox (which is version 4).
Are there any plans to support other containers like KVM or LXC?

@mrjcleaver
Copy link

I was wondering the same!

@thomasbergmann
Copy link

Any updates on this, facing the same problem. I´ll try changing proxmox.vm_type = :openvz to proxmox.vm_type = :lxc. Maybe that works.

@devekko
Copy link

devekko commented Nov 8, 2015

sorry to pile-on, I want Proxmox 4 kvm and lxc too

let us know if there are areas needing patches etc

@antoinerrr
Copy link
Contributor

Hi,
It's easy to add. Go to your vagrant plugin directory and on the vagrant-proxmox-0.0.9/lib/vagrant-proxmox one.

action.rb file
add this after the line 47

                            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

/action/create_vm.rb file

module VagrantPlugins
    module Proxmox
        module Action

            # This action creates a new virtual machine on the Proxmox server and
            # stores its node and vm_id env[:machine].id
            class CreateVm < ProxmoxAction

                def initialize app, env
                    @app = app
                    @logger = Log4r::Logger.new 'vagrant_proxmox::action::create_vm'
                end

                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.message
                    end

                    env[:machine].id = "#{node}/#{vm_id}"

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

                private
                def create_params_qemu(config, env, vm_id)
                    network = "#{config.qemu_nic_model},bridge=#{config.qemu_bridge}"
                    network = "#{config.qemu_nic_model}=#{get_machine_macaddress(env)},bridge=#{config.qemu_bridge}" if get_machine_macaddress(env)
                    {vmid: vm_id,
                     name: env[:machine].config.vm.hostname || env[:machine].name.to_s,
                     ostype: config.qemu_os,
                     ide2: "#{config.qemu_iso},media=cdrom",
                     sata0: "#{config.qemu_storage}:#{config.qemu_disk_size},format=qcow2",
                     sockets: config.qemu_sockets,
                     cores: config.qemu_cores,
                     memory: config.vm_memory,
                     net0: network,
                     description: "#{config.vm_name_prefix}#{env[:machine].name}"}
                end

                private
                def create_params_openvz(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',
                     memory: config.vm_memory,
                     description: "#{config.vm_name_prefix}#{env[:machine].name}"}
                    .tap do |params|
                        params[:ip_address] = get_machine_ip_address(env) if get_machine_ip_address(env)
                    end
                end
                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',
                     memory: config.vm_memory,
                     description: "#{config.vm_name_prefix}#{env[:machine].name}"}
                    .tap do |params|
                        params[:net0] = "name=eth0,ip=#{get_machine_ip_address(env)}/24,gw=10.150.170.1,bridge=vmbr0" if get_machine_ip_address(env)
                    end
                end
            end
        end
    end
end

This is my setup just change the line with "params[:net0]" at the end to match your needs,
I do not remember if i have change something else (probably some change with the error handling), a pull request is coming on the next few day with everything

@devekko
Copy link

devekko commented Nov 24, 2015

thanks @antoiner77

@mrjcleaver
Copy link

Thanks!

@antoinerrr
Copy link
Contributor

Hi
#26
More complete fix

Bye

@kenorb
Copy link

kenorb commented Apr 15, 2016

Fixed in PR #26?

@jdkruzr
Copy link

jdkruzr commented Apr 24, 2016

Has this change been committed to master yet?

@kenorb
Copy link

kenorb commented Apr 26, 2016

It was merged into master on 22 Mar 2016.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants