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

Customising libvirt settings can only be done when creating a box #418

Closed
Dreamsorcerer opened this Issue Jul 14, 2015 · 14 comments

Comments

Projects
None yet
5 participants
@Dreamsorcerer
Copy link

Dreamsorcerer commented Jul 14, 2015

Adding the below code to the vagrantfile does not have any effect after a 'vagrant reload', the box must be destroyed and recreated. This works fine with virtualbox, so must be a limitation with the libvirt plugin.

config.vm.provider :libvirt do |libvirt|
libvirt.memory = 2048
libvirt.cpus = 4
end

@skamithi

This comment has been minimized.

Copy link
Contributor

skamithi commented Jul 21, 2015

I can change it just fine. Here is a vagrant file I'm currently working with. Got multiple devices each with different memory requirements. All servers except one use 256MB. One has a 4GB RAM 2 CPU requirement.

 config.vm.provider :libvirt do |domain|
    domain.memory = 256
    domain.nested = true
  end

  # deployment server Uses 256MB RAM
  config.vm.define :deployserver do |node|
    node.vm.hostname = 'deployosad'
    node.vm.box = 'trusty64_2'
      .........
     ........
    end
  end

  # LoadBalancing VM Uses default 256MB RAM
  config.vm.define :haproxy do |node|
    node.vm.hostname = 'haproxy'
    node.vm.box = 'trusty64_2'
    node.vm.synced_folder '.', '/vagrant', :disabled => true
   ....
   ......
  end

  # Requires 4G of RAM and 2 CPUS
  config.vm.define :stackserver do |node|
    node.vm.provider :libvirt do |domain|
      domain.memory = 4096
      domain.cpus = 2
    end
    node.vm.hostname = 'stackserver'
    node.vm.box = 'trusty64_2'
    node.vm.synced_folder '.', '/vagrant', :disabled => true
   ...
   .....
  end

@Dreamsorcerer

This comment has been minimized.

Copy link

Dreamsorcerer commented Jul 21, 2015

This is my complete vagrantfile (minus the provisioning code), which always gives me 512MB memory and 1 CPU.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "naelyn/ubuntu-trusty64-libvirt"
  config.vm.box_check_update = false
  config.vm.provision :shell, path: "http://path.to/provision-script.sh"
  config.vm.network "private_network", ip: "10.0.86.41"
  config.vm.synced_folder ".", "/vagrant", type: "nfs", nfs_udp: false, nfs_version: 4
  config.vm.provider :libvirt do |domain|
    domain.memory = 2048
    domain.cpus = 2
  end
  config.vm.provision "shell", run: "always",
    inline: "echo 'Updating...'
        # Some bash code to update tools"
end
@skamithi

This comment has been minimized.

Copy link
Contributor

skamithi commented Jul 21, 2015

Nothing obvious for me from config standpoint. I guess you need to debug the plugin and see what is breaking for you. First step is run vagrant with debug option. If that doesn't work I have a blog post on how to run the ruby debugger in the plugin to see what its doing.

@Dreamsorcerer

This comment has been minimized.

Copy link

Dreamsorcerer commented Jul 21, 2015

Is this of any help (the --debug output)? Not sure what I'm looking for.

@Dreamsorcerer

This comment has been minimized.

Copy link

Dreamsorcerer commented Jul 21, 2015

@skamithi

This comment has been minimized.

Copy link
Contributor

skamithi commented Jul 21, 2015

your machine is already provisioned. If you want the VM to get the memory setting changes, either edit it using virt-manager (gui) /virsh edit <domain>(cli). Or destroy the VM (vagrant destroy) and recreate it (vagrant up). vagrant does not change memory settings after starting up the VM for the first time.

@Dreamsorcerer

This comment has been minimized.

Copy link

Dreamsorcerer commented Jul 22, 2015

That's not vagrant. I've changed the settings in the vagrantfile before, and just tested it again, and a simple 'vagrant reload' is all that is needed to change these settings with virtualbox. So, this is a limitation with the libvirt plugin. Atleast I am able to fix it now by recreating the box, but this should still be fixed with the plugin.

@Dreamsorcerer Dreamsorcerer changed the title Can't change memory of vm Customising libvirt settings can only be done when creating a box Jul 22, 2015

@pronix

This comment has been minimized.

Copy link
Member

pronix commented Jul 22, 2015

I will happy accept your pr ;)
On 22 Jul 2015 11:03, "Sam Bull" notifications@github.com wrote:

That's not vagrant. I've changed the settings in the vagrantfile before,
and just tested it again, and a simple 'vagrant reload' is all that is
needed to change these settings with virtualbox. So, this is a limitation
with the libvirt plugin. Atleast I am able to fix it now by recreating the
box, but this should still be fixed with the plugin.


Reply to this email directly or view it on GitHub
#418 (comment)
.

@mkutsevol

This comment has been minimized.

Copy link
Contributor

mkutsevol commented Sep 26, 2015

I'm interested too.
Will make a PR soon. Hope even today :)

@infernix

This comment has been minimized.

Copy link
Member

infernix commented Oct 5, 2015

@mkutsevol the code in your PR is generating invalid XML. Take the following Vagrantfile:

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
 config.vm.box = "centos71libvirt.box"
 config.vm.box_url = "https://spirit.infernix.net/vagrant/centos71libvirt.box"
 config.vm.provider :libvirt do |v|
  v.storage_pool_name = "vagrant"
  v.storage :file, :size => '2G', :type => 'qcow2'
  v.storage :file, :size => '2G', :type => 'qcow2'
 end
end

This yields the following error on a vagrant up:

Call to virDomainCreateWithFlags failed: unsupported configuration: target must be 0 for ide controller

Generated XML:

<domain type='kvm'>
  <name>vgtest_default</name>
  <uuid>9762b1a5-00db-480c-a347-e09958dffeb7</uuid>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.3'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu mode='host-model'>
    <model fallback='allow'>qemu64</model>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/infernix/vagrant-libvirt/vgtest_default.img'/>
      <target dev='vda' bus='sata'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/infernix/vagrant-libvirt/vgtest_default-vdb.qcow2'/>
      <target dev='vdb' bus='sata'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/infernix/vagrant-libvirt/vgtest_default-vdc.qcow2'/>
      <target dev='vdc' bus='sata'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='sata' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:e1:b9:dd'/>
      <source network='vagrant-libvirt'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
  </devices>
</domain>

Observe the <address/> lines in the <drive/> definitions. The first two are OK, but the third one:

<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>

Merged in d11b0b9 I think, it is probably the disk_bus code but I'm not really sure why it is happening. Note that you may need to apply PR #476 to reproduce.

@mkutsevol

This comment has been minimized.

Copy link
Contributor

mkutsevol commented Oct 6, 2015

Hello!
Will look into it soon.

@mkutsevol

This comment has been minimized.

Copy link
Contributor

mkutsevol commented Oct 6, 2015

@infernix, found, will fix.

pronix added a commit that referenced this issue Oct 6, 2015

Merge pull request #477 from mkutsevol/master
Fix regression with additional disks + additional disk reload support #418
@mkutsevol

This comment has been minimized.

Copy link
Contributor

mkutsevol commented Oct 16, 2015

@Dreamsorcerer can you confirm that the latest 0.0.32 release is working as expected and close the issue if it does?
Thank you.

@Dreamsorcerer

This comment has been minimized.

Copy link

Dreamsorcerer commented Oct 16, 2015

Yep, 'vagrant plugin update' and it is working correctly. Great work!

ghjnut added a commit to sendgrid-ops/vagrant-libvirt that referenced this issue Oct 16, 2015

Merge remote-tracking branch 'upstream/master'
* upstream/master: (153 commits)
  typo
  Fix indentation from commit 2525be9
  Add 1GB to the size of virtual disk as defined in metadata.json.  Since teh awk int function truncates (not rounds) soemtimes the virtual disk was defined a bit too small causing sporadic boot failusres.
  0.0.32
  Customising libvirt settings can only be done when creating a box vagrant-libvirt#418
  Use env[:machine].config.vm.box variable, not .box
  Added comment to describe cahanges as requested
  No need to use both grep and awk here - just grep will do.
  If the disk size is specified as a decimil number the generated metadat.json file is invalid resulting in a broken vagrant box.  Wraped this in the awk int() function to only print the integer part of the disk size.
  suspend to disk? vagrant-libvirt#411
  suspend to disk? vagrant-libvirt#411
  Customising libvirt settings can only be done when creating a box vagrant-libvirt#418
  Customising libvirt settings can only be done when creating a box vagrant-libvirt#418
  0.0.31
  Add Table of Contents
  Improve decoration
  Issue with emulated CPU types.
  Accept both symbol and string for network type
  typo
  helps
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment