当前位置: 首页>>代码示例>>Python>>正文


Python virtinst._函数代码示例

本文整理汇总了Python中virtinst._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _replace_original_vm

    def _replace_original_vm(self, removeOld):
        """
        Remove the existing VM with the same name if requested, or error
        if there is a collision.
        """
        vm = None
        try:
            vm = self.conn.lookupByName(self.name)
        except libvirt.libvirtError:
            pass

        if vm is None:
            return

        if not removeOld:
            raise RuntimeError(_("Domain named %s already exists!") %
                               self.name)

        try:
            if vm.ID() != -1:
                logging.info("Destroying image %s" % self.name)
                vm.destroy()

            logging.info("Removing old definition for image %s" % self.name)
            vm.undefine()
        except libvirt.libvirtError, e:
            raise RuntimeError(_("Could not remove old vm '%s': %s") %
                               (self.name, str(e)))
开发者ID:paradox12,项目名称:python-virtinst,代码行数:28,代码来源:Guest.py

示例2: set_boot

    def set_boot(self, val):
        self.cdrom = False
        boot = {}
        if type(val) == tuple:
            if len(val) != 2:
                raise ValueError(_("Must pass both a kernel and initrd"))
            (k, i) = val
            boot = {"kernel": k, "initrd": i}

        elif type(val) == dict:
            if "kernel" not in val or "initrd" not in val:
                raise ValueError(_("Must pass both a kernel and initrd"))
            boot = val

        elif type(val) == list:
            if len(val) != 2:
                raise ValueError(_("Must pass both a kernel and initrd"))
            boot = {"kernel": val[0], "initrd": val[1]}

        else:
            raise ValueError(_("Kernel and initrd must be specified by "
                               "a list, dict, or tuple."))

        self._install_bootconfig.kernel = boot.get("kernel")
        self._install_bootconfig.initrd = boot.get("initrd")
开发者ID:tomlanyon,项目名称:python-virtinst,代码行数:25,代码来源:Installer.py

示例3: set_port

 def set_port(self, val):
     if val is None:
         val = -1
     elif type(val) is not int \
          or (val != -1 and (val < 5900 or val > 65535)):
         raise ValueError, _("VNC port must be a number between 5900 and 65535, or -1 for auto allocation")
     self._port = val
开发者ID:paradox12,项目名称:python-virtinst,代码行数:7,代码来源:VirtualGraphics.py

示例4: __init__

    def __init__(self, image, capabilities=None, boot_index=None, conn=None):
        Installer.Installer.__init__(self, conn=conn, caps=capabilities)

        self._arch = None
        self._image = image

        if not (self.conn or self._get_caps()):
            raise ValueError(_("'conn' or 'capabilities' must be specified."))

        # Set boot _boot_caps/_boot_parameters
        if boot_index is None:
            self._boot_caps = match_boots(self._get_caps(),
                                     self.image.domain.boots)
            if self._boot_caps is None:
                raise ImageInstallerException(_("Could not find suitable boot "
                                                "descriptor for this host"))
        else:
            if (boot_index < 0 or
                (boot_index + 1) > len(image.domain.boots)):
                raise ValueError(_("boot_index out of range."))
            self._boot_caps = image.domain.boots[boot_index]

        # Set up internal caps.guest object
        self._guest = self._get_caps().guestForOSType(self.boot_caps.type,
                                                      self.boot_caps.arch)
        if self._guest is None:
            raise PlatformMatchException(_("Unsupported virtualization type: "
                                           "%s %s" % (self.boot_caps.type,
                                                      self.boot_caps.arch)))

        self.os_type = self.boot_caps.type
        self._domain = self._guest.bestDomainType()
        self.type = self._domain.hypervisor_type
        self.arch = self._guest.arch
开发者ID:palli,项目名称:python-virtinst,代码行数:34,代码来源:ImageInstaller.py

示例5: set_memory

 def set_memory(self, val):
     if (type(val) is not type(1) or val <= 0):
         raise ValueError, _("Memory value must be an integer greater "
                             "than 0")
     self._memory = val
     if self._maxmemory is None or self._maxmemory < val:
         self._maxmemory = val
开发者ID:paradox12,项目名称:python-virtinst,代码行数:7,代码来源:Guest.py

示例6: set_model

 def set_model(self, new_model):
     if type(new_model) != str:
         raise ValueError, _("'model' must be a string, "
                             " was '%s'." % type(new_model))
     if not self.MODELS.count(new_model):
         raise ValueError, _("Unsupported watchdog model '%s'" % new_model)
     self._model = new_model
开发者ID:paradox12,项目名称:python-virtinst,代码行数:7,代码来源:VirtualWatchdog.py

示例7: bestDomainType

    def bestDomainType(self, accelerated=None, dtype=None, machine=None):
        domains = []
        for d in self.domains:
            if dtype and d.hypervisor_type != dtype.lower():
                continue
            if machine and machine not in d.machines:
                continue
            domains.append(d)

        if len(domains) == 0:
            domainerr = ""
            machineerr = ""
            if dtype:
                domainerr = _(", domain type '%s'") % dtype
            if machine:
                machineerr = _(", machine type '%s'") % machine

            error = (_("No domains available for virt type '%(type)s', "
                      "arch '%(arch)s'") %
                      {'type': self.os_type, 'arch': self.arch})
            error += domainerr
            error += machineerr
            raise CapabilitiesParserException(error)

        return self._favoredDomain(accelerated, domains)
开发者ID:tomlanyon,项目名称:python-virtinst,代码行数:25,代码来源:CapabilitiesParser.py

示例8: setup_original

    def setup_original(self):
        """
        Validate and setup all parameters needed for the original (cloned) VM
        """
        logging.debug("Validating original guest parameters")

        if self.original_guest == None and self.original_xml == None:
            raise RuntimeError(_("Original guest name or xml is required."))

        if self.original_guest != None and not self.original_xml:
            self._original_dom = self._lookup_vm(self.original_guest)
            self.original_xml = self._original_dom.XMLDesc(0)

        logging.debug("Original XML:\n%s", self.original_xml)

        self._guest = Guest.Guest(conn=self._hyper_conn,
                                  parsexml=self.original_xml)

        # Pull clonable storage info from the original xml
        self._original_virtual_disks = self._get_original_devices_info()

        logging.debug("Original paths: %s", self.original_devices)
        logging.debug("Original sizes: %s", self.original_devices_size)

        # If domain has devices to clone, it must be 'off' or 'paused'
        if (not self.clone_running and
            (self._original_dom and len(self.original_devices) != 0)):
            status = self._original_dom.info()[0]

            if status not in [libvirt.VIR_DOMAIN_SHUTOFF,
                              libvirt.VIR_DOMAIN_PAUSED]:
                raise RuntimeError(_("Domain with devices to clone must be "
                                     "paused or shutoff."))
开发者ID:sandeep-krishnamurthy,项目名称:vm_affinity_management_tool_for_kvm,代码行数:33,代码来源:CloneManager.py

示例9: get_char_type_desc

    def get_char_type_desc(char_type):
        """
        Return a human readable description of the passed char type
        """
        desc = ""

        if char_type == VirtualCharDevice.CHAR_PTY:
            desc = _("Pseudo TTY")
        elif char_type == VirtualCharDevice.CHAR_DEV:
            desc = _("Physical host character device")
        elif char_type == VirtualCharDevice.CHAR_STDIO:
            desc = _("Standard input/output")
        elif char_type == VirtualCharDevice.CHAR_PIPE:
            desc = _("Named pipe")
        elif char_type == VirtualCharDevice.CHAR_FILE:
            desc = _("Output to a file")
        elif char_type == VirtualCharDevice.CHAR_VC:
            desc = _("Virtual console")
        elif char_type == VirtualCharDevice.CHAR_NULL:
            desc = _("Null device")
        elif char_type == VirtualCharDevice.CHAR_TCP:
            desc = _("TCP net console")
        elif char_type == VirtualCharDevice.CHAR_UDP:
            desc = _("UDP net console")
        elif char_type == VirtualCharDevice.CHAR_UNIX:
            desc = _("Unix socket")

        return desc
开发者ID:paradox12,项目名称:python-virtinst,代码行数:28,代码来源:VirtualCharDevice.py

示例10: _set_conn

 def _set_conn(self, val):
     if not isinstance(val, libvirt.virConnect):
         raise ValueError(_("'conn' must be a libvirt connection object."))
     if not support.check_conn_support(val, support.SUPPORT_CONN_INTERFACE):
         raise ValueError(_("Passed connection is not libvirt interface "
                            "capable"))
     self._conn = val
开发者ID:tomlanyon,项目名称:python-virtinst,代码行数:7,代码来源:Interface.py

示例11: set_os_variant

    def set_os_variant(self, val):
        if type(val) is not str:
            raise ValueError(_("OS variant must be a string."))
        val = val.lower()

        if self.os_type:
            if self._OS_TYPES[self.os_type]["variants"].has_key(val):
                self._os_variant = val
            else:
                raise ValueError, _("OS variant '%(var)s' does not exist in "
                                    "our dictionary for OS type '%(ty)s'" ) % \
                                    {'var' : val, 'ty' : self._os_type}
        else:
            found = False
            for ostype in self.list_os_types():
                if self._OS_TYPES[ostype]["variants"].has_key(val) and \
                   not self._OS_TYPES[ostype]["variants"][val].get("skip"):
                    logging.debug("Setting os type to '%s' for variant '%s'" %\
                                  (ostype, val))
                    self.os_type = ostype
                    self._os_variant = val
                    found = True

            if not found:
                raise ValueError, _("Unknown OS variant '%s'" % val)
开发者ID:paradox12,项目名称:python-virtinst,代码行数:25,代码来源:Guest.py

示例12: __init__

    def __init__(self, conn, dev_type):
        if dev_type not in self.dev_types:
            raise ValueError(_("Unknown character device type '%s'") % dev_type)
        self._dev_type = dev_type
        self._virtual_device_type = self._dev_type

        VirtualDevice.VirtualDevice.__init__(self, conn)

        if not self._char_type:
            raise ValueError("Must not be instantiated through a subclass.")

        if self._char_type not in self.char_types:
            raise ValueError(_("Unknown character device type '%s'")
                             % self._char_type)

        # Init
        self._source_path = None
        self._source_mode = self.CHAR_MODE_BIND
        self._source_host = "127.0.0.1"
        self._source_port = None
        self._target_type = None
        self._target_address = None
        self._target_port = None
        self._target_name = None
        self._bind_host = None
        self._bind_port = None
        self._protocol = self.CHAR_PROTOCOL_RAW
开发者ID:paradox12,项目名称:python-virtinst,代码行数:27,代码来源:VirtualCharDevice.py

示例13: get_name

def get_name(name, guest, image_name=None):
    prompt_txt = _("What is the name of your virtual machine?")
    err_txt = _("A name is required for the virtual machine.")

    if name is None:
        name = image_name
    prompt_loop(prompt_txt, err_txt, name, guest, "name")
开发者ID:paradox12,项目名称:python-virtinst,代码行数:7,代码来源:cli.py

示例14: validate_cpuset

    def validate_cpuset(conn, val):
        if val is None or val == "":
            return

        if type(val) is not type("string") or len(val) == 0:
            raise ValueError(_("cpuset must be string"))
        if re.match("^[0-9,-^]*$", val) is None:
            raise ValueError(_("cpuset can only contain numeric, ',', or "
                               "'-' characters"))

        pcpus = _util.get_phy_cpus(conn)
        for c in val.split(','):
            # Redundant commas
            if not c:
                continue

            if "-" in c:
                (x, y) = c.split('-', 1)
                x = int(x)
                y = int(y)
                if x > y:
                    raise ValueError(_("cpuset contains invalid format."))
                if x >= pcpus or y >= pcpus:
                    raise ValueError(_("cpuset's pCPU numbers must be less "
                                       "than pCPUs."))
            else:
                if c.startswith("^"):
                    c = c[1:]
                c = int(c)

                if c >= pcpus:
                    raise ValueError(_("cpuset's pCPU numbers must be less "
                                       "than pCPUs."))
开发者ID:palli,项目名称:python-virtinst,代码行数:33,代码来源:DomainNumatune.py

示例15: devAddressToNodedev

def devAddressToNodedev(conn, addrstr):
    """
    Look up the passed host device address string as a libvirt node device,
    parse its xml, and return a NodeDevice instance.

    @param conn: libvirt.virConnect instance to perform the lookup on
    @param addrstr: host device string to parse and lookup
        - bus.addr (ex. 001.003 for a usb device)
        - vendor:product (ex. 0x1234:0x5678 for a usb device
        - (domain:)bus:slot.func (ex. 00:10.0 for a pci device)
    @param addrstr: C{str}
    """
    if not is_nodedev_capable(conn):
        raise ValueError(_("Connection does not support host device "
                           "enumeration."))

    ret = _isAddressStr(addrstr)
    if not ret:
        raise ValueError(_("Could not determine format of '%s'") % addrstr)

    cmp_func, devtype = ret

    # Iterate over node devices and compare
    nodenames = conn.listDevices(devtype, 0)
    for name in nodenames:
        nodedev = _lookupNodeName(conn, name)
        if cmp_func(nodedev):
            return nodedev

    raise ValueError(_("Did not find a matching node device for '%s'") %
                     addrstr)
开发者ID:tomlanyon,项目名称:python-virtinst,代码行数:31,代码来源:NodeDeviceParser.py


注:本文中的virtinst._函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。