Esempio n. 1
0
    def parseDeviceModelArgs(self, imageConfig, deviceConfig):
        dmargs = [ 'cdrom', 'boot', 'fda', 'fdb', 'ne2000', 'audio',
                   'localtime', 'serial', 'stdvga', 'isa', 'vcpus']
        ret = []
        for a in dmargs:
            v = sxp.child_value(imageConfig, a)

            # python doesn't allow '-' in variable names
            if a == 'stdvga': a = 'std-vga'
            if a == 'ne2000': a = 'nic-ne2000'
            if a == 'audio': a = 'enable-audio'

            # Handle booleans gracefully
            if a in ['localtime', 'std-vga', 'isa', 'nic-ne2000', 'enable-audio']:
                if v != None: v = int(v)
                if v: ret.append("-%s" % a)
            else:
                if v:
                    ret.append("-%s" % a)
                    ret.append("%s" % v)
            log.debug("args: %s, val: %s" % (a,v))

        # Handle disk/network related options
        mac = None
        ret = ret + ["-domain-name", "%s" % self.vm.info['name']]
        nics = 0
        for (name, info) in deviceConfig:
            if name == 'vbd':
                uname = sxp.child_value(info, 'uname')
                typedev = sxp.child_value(info, 'dev')
                (_, vbdparam) = string.split(uname, ':', 1)

                if 'file:' in uname and not os.path.isfile(vbdparam):
                   raise VmError('Disk image does not exist: %s' % vbdparam)

                if 'ioemu:' in typedev:
                    (emtype, vbddev) = string.split(typedev, ':', 1)
                else:
                    emtype = 'vbd'
                    vbddev = typedev
                if emtype == 'vbd':
                    continue;
                vbddev_list = ['hda', 'hdb', 'hdc', 'hdd']
                if vbddev not in vbddev_list:
                    raise VmError("hvm: for qemu vbd type=file&dev=hda~hdd")
                ret.append("-%s" % vbddev)
                ret.append("%s" % vbdparam)
            if name == 'vif':
                type = sxp.child_value(info, 'type')
                if type != 'ioemu':
                    continue
                nics += 1
                if mac != None:
                    continue
                mac = sxp.child_value(info, 'mac')
                bridge = sxp.child_value(info, 'bridge')
                if mac == None:
                    mac = randomMAC()
                if bridge == None:
                    bridge = 'xenbr0'
                ret.append("-macaddr")
                ret.append("%s" % mac)
                ret.append("-bridge")
                ret.append("%s" % bridge)
            if name == 'vtpm':
                instance = sxp.child_value(info, 'pref_instance')
                ret.append("-instance")
                ret.append("%s" % instance)
        ret.append("-nics")
        ret.append("%d" % nics)
        return ret
Esempio n. 2
0
def gen_randomMAC():
    return randomMAC()