xenserver / packer-plugin-xenserver

A builder plugin for Packer.IO to support building Citrix Hypervisor images.
Mozilla Public License 2.0
101 stars 113 forks source link

Setting VM parameters? #24

Open kongslund opened 9 years ago

kongslund commented 9 years ago

I am currently experimenting with the 6.x-support branch. I've been able to create an Ubuntu 12.04 image (based on https://github.com/xenserver/packer-templates/blob/master/ubuntu-12.04-amd64.json) and now I am trying to add PV support.

Installing the guest utilities and linux-virtual is done in a provision script but I am unsure about setting VM parameters such as PV-bootloader and PV-args, and marking the first disk as bootable. Is that really supposed to happen in a provision script executed on the VM itself or are there any xenserver-iso configuration parameters I have missed?

kongslund commented 9 years ago

@rdobson I would like to assist in extending each builder so that additional VM params and disk params can be set. I have already played a bit with a prototype that can set the VM params name-description and is-a-template. It consists of an additional build step, StepSetVmParams, which takes place immediately before StepExport.

My immediate use case is that I would like to be able to enable PV for an Ubuntu ISO installation and convert it to a template solely by using Packer and the provisioning scripts declared in the Packer template. Also the first disk should be marked as bootable.

Before doing too much work I would like to discuss my ideas with you in order to ensure that the additions will be useful and in line with your thoughts about how the builders should evolve.

In the current Packer XenServer plugins the following VM properties can be already set in the configuration file:

VM Property Configuration Property
name-label vm_name (string)
memory-static-max vm_memory (integer)
memory-dynamic-max vm_memory (integer)
memory-dynamic-min vm_memory (integer)
memory-static-min vm_memory (integer)
platform platform_args (object of key/value strings)

I would like to add support for the following VM properties:

VM Property Proposed Configuration Property
HVM-boot-policy hvm.boot_policy (string, default "")
HVM-boot-params hvm.boot_params (string, default "")
HVM-shadow-multiplier hvm.shadow_multiplier (float, default 1.0)
PV-kernel pv.kernel (string, default "")
PV-ramdisk pv.ramdisk (string, default "")
PV-args pv.args (string, default "")
PV-legacy-args pv.legacy_args (string, default "")
PV-bootloader pv.bootloader (string, default "")
PV-bootloader-args pv.bootloader_args (string, default "")
name-description vm_description (string, default "")
is-a-template convert_to_template (bool, default false)

The HVM and PV settings will be defined in objects, e.g.:

"pv": {
  "bootloader": "pygrub",
  "args": "console=hvc0 xencons=hvc"
}

Adding a pv or hvm section is optional. Adding both is not allowed. When none is added none of the related VM params are changed before exporting the VM.

When adding a pv section, the pv.bootloader field must be non-empty. The HVM-boot-policy VM property will automatically be set to the empty string.

Likewise when adding a hvm section the hvm.boot_policy field must be non-empty. The PV-bootloader VM property will automatically be set to the empty string. The hvm.boot_policy field must only allow the value 'BIOS order'

The vm_description and convert_to_template properties should be straight forward. They will always result in the corresponding VM properties to be changed.

In addition to the above I would like to add support for the following VDI/VBD properties for the first disk (userdevice=0):

Disk Property Proposed Configuration Property
bootable disk_bootable (bool, default false)
name-label disk_name (string, default "" meaning unchanged)

Any remarks to this proposal?

rdobson commented 9 years ago

Thanks very much for taking the time to write this proposal @kongslund.

I think that adding name-description is fine, however I'm less convinced about exposing the HVM/PV parameters right now (happy to be persuaded though). Did you know that you can specify a template from which to copy these parameters? (i.e. make use of the official XenServer template for Ubuntu for example). You can do this with clone_template.

As for the VDI/VBD properties, could you help me understand a bit better what you're trying to do here? Setting the root disk to be bootable is probably something we want to do in all cases I would imagine (I'm surprised that's not the case).

As for the StepSetVmParams - I think it's cleaner to have all the VM parameters set at creation time. I think what you're really asking for is, rather than export the resulting VM, turn it into a template? (that would be the only operation that needs to happen after creation right?).

If that's the case, perhaps it would be better to just add a new format type of template - upon which Packer turns the resulting VM into a template and returns the ID?

What do you think?

kongslund commented 9 years ago

Thank you for your feedback @rdobson

I've tried setting clone_template to Ubuntu Precise Pangolin 12.04 (64-bit). It gave me some headaches.

As part of the provisioning I do the following

# Install XenServer tools
mount /dev/sr1 /mnt
dpkg -i /mnt/Linux/xe-guest-utilities_*_amd64.deb
umount /mnt

# Install kernel with virtual support and remove default kernel
apt-get install -f -y linux-virtual
dpkg -l | grep generic | grep linux | awk '{print $2}' | xargs apt-get remove -y

update-grub

# Setup hvc console (used by XenCenter) instead of tty
cat /etc/init/tty1.conf | sed 's/tty1/hvc0/g' > /etc/init/hvc0.conf

After Packer has finished the VM has the following parameters set:

HVM-boot-policy ( RW): BIOS order
HVM-boot-params (MRW): order: cd
PV-args ( RW): -- quiet console=hvc0
PV-bootloader ( RW): eliloader

According to the Citrix XenServer Management API Guide HVM-boot-policy takes priority over PV-bootloader so the VM boots up as HVM.

If I unset HVM-boot-policy then the VM will not start:

The bootloader for this VM returned an error -- did the VM installation succeed? UNSUPPORTED_INSTALL_METHOD other-config:install-repository was not set to an appropriate value, and this is required for the selected distribution type.

If I then set PV-bootloader=pygrub and start the VM it will boot from the CD which for some reason is still attached (FYI: I'm using 6.x-support on a XenServer 6.2.0).

If I eject the CD and start the VM it gives the following error:

  Internal error: there is no bootable device

If I then mark the first disk as bootable then it works and XenCenter shows me a nice hvc0 terminal.

I am probably doing something wrong here so please correct me if I am. My understanding of the bootloader concepts is still somewhat fuzzy and the XenServer 6.2 documentation does not contain anything about either eliloader or pygrub.

Btw: XenServer's own Ubuntu-12.04 template example does not use clone_template.

Regarding converting to a template: if a format type called template is introduced would it then mean that the VM will be converted to a template and then always exported as an XVA file? If so then it does not fit my use case. Currently I have format set to none and keep_vm set to on_success in order to keep the produced template on the XenServer host and avoid a time consuming export. The reason is that template needs to undergo additional automated testing and only after passing these tests do we consider to export it so our users can try it out on their systems. The duration of this build'n'test feedback loop needs to be short since we have a multiple of builds each day.

This actually brings me to another topic that I've wanted to bring up for discussion: xenserver-xva is a nice plugin but I would like to avoid the time consuming import step if I already have a VM or template on the XenServer host which I would like to use as the source. Does this call for a new plugin (xenserver-vm?) or do you think it would make sense to incorporate it in xenserver-xva, e.g. by adding a new property source_name which is mutually exclusive with source_path? I'd like to assist with this as well.