Unified Xen DomU configuration file

Previously, we create a configuration file for each DomU virtual machines in our cluster. Most of the content in these configuration files is the same. The differences are only the name, memory size and image file address. There are several disadvantages of this method: We must create and configure a new configuration file when creating a new virtual machines; We must change every configuration files when we want to change the parameters of the virtual machines such as change the raw image file driver from loopback to tap. So we change to using a unified Xen DomU configuration file. We creating DomUs, just use this unified Xen DomU configuration file and add some parameters to it.


For VM with id *vmid*: Name is: vm*vmid* Raw image file address is: /lhome/xen/vm*vmid*/vmdisk*vmid* The parameter for *vmid *is *vmid*. The parameter for memory size is *vmmem*. We force the memory size of the virtual machines to be at least 1G. We assume the virtual cpu number is 2 for all virtual machines. If the cpu number should be different from virtual machines, we can also add a parameter for it.

The configuration file vm.run

This is the unified configuration file /lhome/xen/vm.run:

    # Called automatically by 'xm create'.
    # Checks that 'vmid' has been given a valid value.
    def vmid_check(var, val):
        val = int(val)
        if val <= 0:
             raise ValueError
        return val
    # Checks that 'vmmem' has been given a valid value
    # Make sure the vmmem is >= 1024
    def vmmem_check(var, val):
        val = int(val)
        if val <= 1024:
            return 1024
        return val
    # Define the 'vmid' variable so that 'xm create' knows about it.
                use="Virtual machine id. Integer greater than 0.",
    # Define the 'vmmem' variable
                use="Virtual machine memory. Integer greater thatn 1024.",
    # Check the defined variables have valid values..
    # --------------------------------------------------------------
    name="vm%d" % vmid
    memory="%d" % vmmem
    disk=["tap:aio:/lhome/xen/vm%d/vmdisk%d,xvda,w" % (vmid,vmid) ]

The meaning should be easy to understand with these comments.

How to use it

When we want to create vm*vmid* with *vmmem* kb memory, just follow these steps:

    # cd /lhome/xen
    # xm create vm.run vmid=<em>vmid</em> vmmem=<em>vmmem</em>
Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *