Beispiel #1
0
def get_basic_paravirt_guest(installer=None):
    g = virtinst.ParaVirtGuest(conn=_conn, type="xen")
    g.name = "TestGuest"
    g.memory = int(200)
    g.maxmemory = int(400)
    g.uuid = "12345678-1234-1234-1234-123456789012"
    g.boot = ["/boot/vmlinuz", "/boot/initrd"]
    g.graphics = (True, "vnc", None, "ja")
    g.vcpus = 5

    if installer:
        g.installer = installer

    g.installer._scratchdir = scratch
    return g
Beispiel #2
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
 def testGuestValidation(self):
     PVGuest = virtinst.ParaVirtGuest(connection=testconn, type="xen")
     self._testArgs(PVGuest, virtinst.Guest, 'guest')
Beispiel #4
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