Example #1
0
    def guest_from_installer(self):
        """
        Return a L{Guest} instance wrapping the current installer.

        If all the appropriate values are present in the installer
        (conn, type, os_type, arch), we have everything we need to determine
        what L{Guest} class is expected and what default values to pass
        it. This is a convenience method to save the API user from having
        to enter all these known details twice.
        """

        if not self.conn:
            raise ValueError(_("A connection must be specified."))

        guest, domain = CapabilitiesParser.guest_lookup(conn=self.conn,
                                                        caps=self._caps,
                                                        os_type=self.os_type,
                                                        type=self.type,
                                                        arch=self.arch)

        if self.os_type == "xen":
            gobj = virtinst.ParaVirtGuest(installer=self, connection=self.conn)
            gobj.arch = guest.arch
        elif self.os_type == "hvm":
            gobj = virtinst.FullVirtGuest(installer=self,
                                          connection=self.conn,
                                          emulator=domain.emulator,
                                          arch=guest.arch)
            gobj.loader = domain.loader
        if self.type == "openvz":
            gobj = virtinst.FullVirtGuest(installer=self,
                                          connection=self.conn,
                                          emulator=domain.emulator,
                                          arch=guest.arch)
            gobj.loader = domain.loader
        else:
            raise ValueError(
                _("No 'Guest' class for virtualization type '%s'" % self.type))

        return gobj
Example #2
0
def get_basic_fullyvirt_guest(typ="xen", installer=None):
    g = virtinst.FullVirtGuest(conn=_conn, type=typ,
                               emulator="/usr/lib/xen/bin/qemu-dm",
                               arch="i686")
    g.name = "TestGuest"
    g.memory = int(200)
    g.maxmemory = int(400)
    g.uuid = "12345678-1234-1234-1234-123456789012"
    g.cdrom = "/dev/loop0"
    g.graphics = (True, "sdl")
    g.features['pae'] = 0
    g.vcpus = 5
    if installer:
        g.installer = installer

    g.installer._scratchdir = scratch
    return g
def start_install(name=None,
                  ram=None,
                  disks=None,
                  uuid=None,
                  extra=None,
                  vcpus=None,
                  profile_data=None,
                  arch=None,
                  no_gfx=False,
                  fullvirt=False,
                  bridge=None,
                  virt_type=None,
                  virt_auto_boot=None):

    #FIXME how to do a non-default connection
    #Can we drive off of virt-type?
    connection = None

    if (virt_type is None) or (virt_type == "auto"):
        connection = virtinst.util.default_connection()
    elif virt_type.lower()[0:3] == "xen":
        connection = "xen"
    else:
        connection = "qemu:///system"

    connection = libvirt.open(connection)
    capabilities = virtinst.CapabilitiesParser.parse(
        connection.getCapabilities())
    image_arch = transform_arch(arch)

    image = ImageParser.Image()
    #dev api
    #image = ImageParser.Image(filename="") #FIXME, ImageParser should take in None
    image.name = name

    domain = ImageParser.Domain()
    domain.vcpu = vcpus
    domain.memory = ram
    image.domain = domain

    boot = ImageParser.Boot()
    boot.type = "hvm"  #FIXME HARDCODED
    boot.loader = "hd"  #FIXME HARDCODED
    boot.arch = image_arch
    domain.boots.append(boot)

    #FIXME Several issues. Single Disk, type is hardcoded
    #And there is no way to provision with access to "file"
    process_disk(image, boot, profile_data["file"], disks[0][0], "hda")

    #FIXME boot_index??
    installer = virtinst.ImageInstaller(boot_index=0,
                                        image=image,
                                        capabilities=capabilities)
    guest = virtinst.FullVirtGuest(connection=connection,
                                   installer=installer,
                                   arch=image_arch)

    extra = extra.replace("&", "&")

    guest.extraargs = extra
    guest.set_name(name)
    guest.set_memory(ram)
    guest.set_vcpus(vcpus)

    if not no_gfx:
        guest.set_graphics("vnc")
    else:
        guest.set_graphics(False)

    if uuid is not None:
        guest.set_uuid(uuid)

    process_networks(domain, guest, profile_data, bridge)

    guest.start_install()

    return "use virt-manager or reconnect with virsh console %s" % name
 def testFVGuestValidation(self):
     FVGuest = virtinst.FullVirtGuest(connection=testconn, type="xen")
     self._testArgs(FVGuest, virtinst.FullVirtGuest, 'fvguest')
Example #5
0
    "mandriva-2009.1": {
        "noxen": True,
        'i386': MANDRIVA_BASEURL % ("2009.1", "i586"),
        'x86_64': MANDRIVA_BASEURL % ("2009.1", "x86_64"),
        'distro': ("linux", None)
    },
    "mandriva-2010.2": {
        "noxen": True,
        'i386': MANDRIVA_BASEURL % ("2010.2", "i586"),
        'x86_64': MANDRIVA_BASEURL % ("2010.2", "x86_64"),
        'distro': ("linux", None)
    },
}

testconn = libvirt.open("test:///default")
testguest = virtinst.FullVirtGuest(conn=testconn,
                                   installer=virtinst.DistroInstaller())


class TestURLFetch(unittest.TestCase):
    def setUp(self):
        self.meter = urlgrabber.progress.BaseMeter()
        if utils.get_debug():
            self.meter = urlgrabber.progress.TextMeter(fo=sys.stdout)

    def _fetchLocalMedia(self, mediapath):
        arch = platform.machine()

        fetcher = OSDistro._fetcherForURI(mediapath, "/tmp")

        try:
            fetcher.prepareLocation()
Example #6
0
def start_install(name=None, 
                  ram=None, 
                  disks=None,
                  uuid=None,  
                  extra=None, 
                  vcpus=None,  
                  profile_data=None, 
                  arch=None, 
                  no_gfx=False, 
                  fullvirt=False, 
                  bridge=None, 
                  virt_type=None,
                  virt_auto_boot=False,
                  qemu_driver_type=None):

    if profile_data.has_key("file"):
        raise koan.InfoException("Xen does not work with --image yet")

    if fullvirt:
        # FIXME: add error handling here to explain when it's not supported
        guest = virtinst.FullVirtGuest(installer=DistroManager.PXEInstaller())
    else:
        guest = virtinst.ParaVirtGuest()

    extra = extra.replace("&","&")

    if not fullvirt:
        guest.set_boot((profile_data["kernel_local"], profile_data["initrd_local"]))
        # fullvirt OS's will get this from the PXE config (managed by Cobbler)
        guest.extraargs = extra
    else:
        print "- fullvirt mode"
        if profile_data.has_key("breed"):
            breed = profile_data["breed"]
            if breed != "other" and breed != "":
                if breed in [ "debian", "suse", "redhat" ]:
                    guest.set_os_type("linux")
                elif breed in [ "windows" ]:
                    guest.set_os_type("windows")
                else:
                    guest.set_os_type("unix")
                if profile_data.has_key("os_version"):
                    # FIXME: when os_version is not defined and it's linux, do we use generic24/generic26 ?
                    version = profile_data["os_version"]
                    if version != "other" and version != "":
                        try:
                            guest.set_os_variant(version)
                        except:
                            print "- virtinst library does not understand variant %s, treating as generic" % version
                            pass


    guest.set_name(name)
    guest.set_memory(ram)
    guest.set_vcpus(vcpus)

    if not no_gfx:
        guest.set_graphics("vnc")
    else:
        guest.set_graphics(False)

    if uuid is not None:
        guest.set_uuid(uuid)

    for d in disks:
        if d[1] != 0 or d[0].startswith("/dev"):
            guest.disks.append(virtinst.XenDisk(d[0], size=d[1]))
        else:
            raise koan.InfoException("this virtualization type does not work without a disk image, set virt-size in Cobbler to non-zero")

    counter = 0

    if profile_data.has_key("interfaces"):

        interfaces = profile_data["interfaces"].keys()
        interfaces.sort()
        counter = -1
        vlanpattern = re.compile("[a-zA-Z0-9]+\.[0-9]+")

        for iname in interfaces:
            counter = counter + 1
            intf = profile_data["interfaces"][iname]

            if intf["bonding"] == "master" or vlanpattern.match(iname) or iname.find(":") != -1: 
                continue

            mac = intf["mac_address"]
            if mac == "":
                mac = random_mac()

            if not bridge:
                profile_bridge = profile_data["virt_bridge"]

                intf_bridge = intf["virt_bridge"]
                if intf_bridge == "":
                    if profile_bridge == "":
                        raise koan.InfoException("virt-bridge setting is not defined in cobbler")
                    intf_bridge = profile_bridge

            else:
                if bridge.find(",") == -1:
                    intf_bridge = bridge
                else:
                    bridges = bridge.split(",")
                    intf_bridge = bridges[counter]


            nic_obj = virtinst.XenNetworkInterface(macaddr=mac, bridge=intf_bridge)
            guest.nics.append(nic_obj)
            counter = counter + 1
   
    else:
            # for --profile you just get one NIC, go define a system if you want more.
            # FIXME: can mac still be sent on command line in this case?

            if bridge is None:
                profile_bridge = profile_data["virt_bridge"]
            else:
                profile_bridge = bridge

            if profile_bridge == "":
                raise koan.InfoException("virt-bridge setting is not defined in cobbler")

            nic_obj = virtinst.XenNetworkInterface(macaddr=random_mac(), bridge=profile_bridge)
            guest.nics.append(nic_obj)
            
        


    guest.start_install()
    
    return "use virt-manager or reconnect with virsh console %s" % name 
     
Example #7
0
def start_install(name=None,
                  ram=None,
                  disks=None,
                  mac=None,
                  uuid=None,
                  extra=None,
                  vcpus=None,
                  profile_data=None,
                  arch=None,
                  no_gfx=False,
                  fullvirt=True,
                  bridge=None,
                  virt_type=None,
                  virt_auto_boot=False,
                  qemu_driver_type=None,
                  qemu_net_type=None):

    vtype = "qemu"
    if virtinst.util.is_kvm_capable():
        vtype = "kvm"
        arch = None  # let virtinst.FullVirtGuest() default to the host arch
    elif virtinst.util.is_kqemu_capable():
        vtype = "kqemu"
    print "- using qemu hypervisor, type=%s" % vtype

    if arch is not None and arch.lower() in ["x86", "i386"]:
        arch = "i686"

    guest = virtinst.FullVirtGuest(hypervisorURI="qemu:///system",
                                   type=vtype,
                                   arch=arch)

    if not profile_data.has_key("file"):
        # images don't need to source this
        if not profile_data.has_key("install_tree"):
            raise koan.InfoException(
                "Cannot find install source in kickstart file, aborting.")

        if not profile_data["install_tree"].endswith("/"):
            profile_data["install_tree"] = profile_data["install_tree"] + "/"

        # virt manager doesn't like nfs:// and just wants nfs:
        # (which cobbler should fix anyway)
        profile_data["install_tree"] = profile_data["install_tree"].replace(
            "nfs://", "nfs:")

    if profile_data.has_key("file"):
        # this is an image based installation
        input_path = profile_data["file"]
        print "- using image location %s" % input_path
        if input_path.find(":") == -1:
            # this is not an NFS path
            guest.cdrom = input_path
        else:
            (tempdir, filename) = utils.nfsmount(input_path)
            guest.cdrom = os.path.join(tempdir, filename)

        kickstart = profile_data.get("kickstart", "")
        if kickstart != "":
            # we have a (windows?) answer file we have to provide
            # to the ISO.
            print "I want to make a floppy for %s" % kickstart
            floppy_path = utils.make_floppy(kickstart)
            guest.disks.append(
                virtinst.VirtualDisk(device=virtinst.VirtualDisk.DEVICE_FLOPPY,
                                     path=floppy_path))

    else:
        guest.location = profile_data["install_tree"]

    extra = extra.replace("&", "&")
    guest.extraargs = extra

    if profile_data.has_key("breed"):
        breed = profile_data["breed"]
        if breed != "other" and breed != "":
            if breed in ["ubuntu", "debian", "redhat"]:
                guest.set_os_type("linux")
            elif breed == "suse":
                guest.set_os_type("linux")
                # SUSE requires the correct arch to find
                # kernel+initrd on the inst-source /boot/<arch>/loader/...
                guest.arch = profile_data["arch"]
                if guest.arch in ["i386", "i486", "i586"]:
                    guest.arch = "i686"
            elif breed in ["windows"]:
                guest.set_os_type("windows")
            else:
                guest.set_os_type("unix")
            if profile_data.has_key("os_version"):
                # FIXME: when os_version is not defined and it's linux, do we use generic24/generic26 ?
                if breed == "ubuntu":
                    # If breed is Ubuntu, need to set the version to the type of "ubuntu<version>"
                    # as defined by virtinst. (i.e. ubuntunatty)
                    version = "ubuntu%s" % profile_data["os_version"]
                else:
                    version = profile_data["os_version"]
                if version != "other" and version != "":
                    try:
                        guest.set_os_variant(version)
                    except:
                        print "- virtinst library does not understand variant %s, treating as generic" % version
                        pass

    guest.set_name(name)
    guest.set_memory(ram)
    guest.set_vcpus(vcpus)
    guest.set_autostart(virt_auto_boot)
    # for KVM, we actually can't disable this, since it's the only
    # console it has other than SDL
    guest.set_graphics("vnc")

    if uuid is not None:
        guest.set_uuid(uuid)

    for d in disks:
        print "- adding disk: %s of size %s (driver type=%s)" % (d[0], d[1],
                                                                 d[2])
        if d[1] != 0 or d[0].startswith("/dev"):
            vdisk = virtinst.VirtualDisk(d[0], size=d[1], bus=qemu_driver_type)
            try:
                vdisk.set_driver_type(d[2])
            except:
                print "- virtinst failed to create the VirtualDisk with the specified driver type (%s), using whatever it defaults to instead" % d[
                    2]
            guest.disks.append(vdisk)
        else:
            raise koan.InfoException(
                "this virtualization type does not work without a disk image, set virt-size in Cobbler to non-zero"
            )

    if profile_data.has_key("interfaces"):

        counter = 0
        interfaces = profile_data["interfaces"].keys()
        interfaces.sort()
        vlanpattern = re.compile("[a-zA-Z0-9]+\.[0-9]+")
        for iname in interfaces:
            intf = profile_data["interfaces"][iname]

            if intf["interface_type"] in ("master", "bond",
                                          "bridge") or vlanpattern.match(
                                              iname) or iname.find(":") != -1:
                continue

            mac = intf["mac_address"]
            if mac == "":
                mac = random_mac()

            if bridge is None:
                profile_bridge = profile_data["virt_bridge"]

                intf_bridge = intf["virt_bridge"]
                if intf_bridge == "":
                    if profile_bridge == "":
                        raise koan.InfoException(
                            "virt-bridge setting is not defined in cobbler")
                    intf_bridge = profile_bridge
            else:
                if bridge.find(",") == -1:
                    intf_bridge = bridge
                else:
                    bridges = bridge.split(",")
                    intf_bridge = bridges[counter]
            nic_obj = virtinst.VirtualNetworkInterface(macaddr=mac,
                                                       bridge=intf_bridge,
                                                       model=qemu_net_type)
            guest.nics.append(nic_obj)
            counter = counter + 1

    else:

        if bridge is not None:
            profile_bridge = bridge
        else:
            profile_bridge = profile_data["virt_bridge"]

        if profile_bridge == "":
            raise koan.InfoException(
                "virt-bridge setting is not defined in cobbler")

        nic_obj = virtinst.VirtualNetworkInterface(macaddr=random_mac(),
                                                   bridge=profile_bridge,
                                                   model=qemu_net_type)
        guest.nics.append(nic_obj)

    guest.start_install()

    return "use virt-manager and connect to qemu to manage guest: %s" % name