コード例 #1
0
 def set_ip(self, value):
     if not issubclass(type(value), IPXML):
         raise xcepts.LibvirtXMLError("value must be a IPXML or subclass")
     xmltreefile = self.__dict_get__('xml')
     # IPXML root element is whole IP element tree
     root = xmltreefile.getroot()
     root.append(value.xmltreefile.getroot())
     xmltreefile.write()
コード例 #2
0
ファイル: vm_xml.py プロジェクト: xutian/virt-test
    def sync(self, options=None):
        """Rebuild VM with the config file."""
        # If target vm no longer exist, this will raise an exception.
        try:
            backup = self.new_from_dumpxml(self.vm_name)
        except IOError:
            logging.debug("Failed to backup %s.", self.vm_name)
            backup = None

        if not self.undefine(options):
            raise xcepts.LibvirtXMLError("Failed to undefine %s." %
                                         self.vm_name)
        if not self.define():
            if backup:
                backup.define()
            raise xcepts.LibvirtXMLError("Failed to define %s, from %s." %
                                         (self.vm_name, self.xml))
コード例 #3
0
 def marshal_from_address(item, index, libvirtxml):
     """Convert an Address instance into tag + attributes"""
     root = item.xmltreefile.getroot()
     if root.tag == 'address':
         return (root.tag, dict(list(root.items())))
     else:
         raise xcepts.LibvirtXMLError("Expected a list of address "
                                      "instances, not a %s" % str(item))
コード例 #4
0
 def marshal_from_route(item, index, libvirtxml):
     """Convert a dictionary into a tag + attributes"""
     del index  # not used
     del libvirtxml  # not used
     if not isinstance(item, dict):
         raise xcepts.LibvirtXMLError("Expected a dictionary of interface "
                                      "attributes, not a %s" % str(item))
     return ('route', dict(item))  # return copy of dict, not reference
コード例 #5
0
 def set_portgroup(self, value):
     if not issubclass(type(value), PortgroupXML):
         raise xcepts.LibvirtXMLError("value must be a PortgroupXML"
                                      "instance or subclass.")
     self.del_portgroup()
     root = self.xmltreefile.getroot()
     root.append(value.xmltreefile.getroot())
     self.xmltreefile.write()
コード例 #6
0
 def get_cap(self):
     """
     Return the capability of nodedev_xml.
     """
     try:
         cap_root = self.xmltreefile.reroot('/capability')
     except KeyError, detail:
         raise xcepts.LibvirtXMLError(detail)
コード例 #7
0
 def get_portgroup(self):
     try:
         portgroup_root = self.xmltreefile.reroot('/portgroup')
     except KeyError as detail:
         raise xcepts.LibvirtXMLError(detail)
     portgroup_xml = PortgroupXML(virsh_instance=self.__dict_get__('virsh'))
     portgroup_xml.xmltreefile = portgroup_root
     return portgroup_xml
コード例 #8
0
 def marshal_from_values(item, index, libvirtxml):
     """Convert a EnumXML instance into a tag + attributes"""
     del index  # not used
     del libvirtxml  # not used
     if isinstance(item, six.string_types):
         return ("value", {}, item)
     else:
         raise xcepts.LibvirtXMLError("Expected a str attributes,"
                                      " not a %s" % str(item))
コード例 #9
0
 def marshal_from_hosts(item, index, libvirtxml):
     """
     Convert an xml object to host tag and xml element
     """
     if isinstance(item, DhcpHostXML):
         return 'host', item
     else:
         raise xcepts.LibvirtXMLError("Expected a list of ip dhcp host "
                                      "instances, not a %s" % str(item))
コード例 #10
0
 def marshal_from_hostname(item, index, libvirtxml):
     """Convert a HostnameXML instance into a tag + attributes"""
     del index           # not used
     del libvirtxml      # not used
     if isinstance(item, str):
         return ("hostname", {}, item)
     else:
         raise xcepts.LibvirtXMLError("Expected a str attributes,"
                                      " not a %s" % str(item))
コード例 #11
0
 def get_ip(self):
     xmltreefile = self.__dict_get__('xml')
     try:
         ip_root = xmltreefile.reroot('/ip')
     except KeyError as detail:
         raise xcepts.LibvirtXMLError(detail)
     ipxml = IPXML(virsh_instance=self.__dict_get__('virsh'))
     ipxml.xmltreefile = ip_root
     return ipxml
コード例 #12
0
 def define(self):
     """
     Define network from self.xml.
     """
     cmd_result = self.virsh.net_define(self.xml)
     if cmd_result.exit_status:
         raise xcepts.LibvirtXMLError("Failed to define network %s.\n"
                                      "Detail: %s" %
                                      (self.name, cmd_result.stderr))
コード例 #13
0
 def start(self):
     """
     Start network with self.virsh.
     """
     cmd_result = self.virsh.net_start(self.name)
     if cmd_result.exit_status:
         raise xcepts.LibvirtXMLError("Failed to start network %s.\n"
                                      "Detail: %s" %
                                      (self.name, cmd_result.stderr))
コード例 #14
0
 def create(self):
     """
     Adds non-persistant / transient network to libvirt with net-create
     """
     cmd_result = self.virsh.net_create(self.xml)
     if cmd_result.exit_status:
         raise xcepts.LibvirtXMLError("Failed to create transient network %s.\n"
                                      "Detail: %s" %
                                      (self.name, cmd_result.stderr))
コード例 #15
0
ファイル: pool_xml.py プロジェクト: vipmike007/virt-test
 def set_source(self, value):
     if not issubclass(type(value), SourceXML):
         raise xcepts.LibvirtXMLError(
             "Value must be a SourceXML or subclass")
     xmltreefile = self.__dict_get__('xml')
     self.del_source()
     root = xmltreefile.getroot()
     root.append(value.xmltreefile.getroot())
     xmltreefile.write()
コード例 #16
0
ファイル: network_xml.py プロジェクト: humanux/virt-test
 def set_ip(self, value):
     if not issubclass(type(value), IPXML):
         raise xcepts.LibvirtXMLError("value must be a IPXML or subclass")
     xmltreefile = self.dict_get('xml')
     # nuke any existing IP block
     self.del_ip()
     # IPXML root element is whole IP element tree
     root = xmltreefile.getroot()
     root.append(value.getroot())
コード例 #17
0
 def new_from_element(cls, element, virsh_instance=base.base.virsh):
     # element uses type attribute, class uses type_name
     edict = dict(list(element.items()))
     try:
         edict['type_name'] = edict.pop('type')
     except (KeyError, AttributeError):
         raise xcepts.LibvirtXMLError("type attribute is manditory for "
                                      "Address class")
     return cls.new_from_dict(edict, virsh_instance=virsh_instance)
コード例 #18
0
def get(name):
    """
    Returns named device xml element's handler class
    """
    # Module names and device-tags are always all lower-case
    name = str(name).lower()
    errmsg = ("Unknown/unsupported type '%s', supported types %s" %
              (str(name), DEVICE_TYPES))
    if name not in DEVICE_TYPES:
        raise xcepts.LibvirtXMLError(errmsg)
    mod_path = os.path.abspath(os.path.dirname(__file__))
    try:
        filename, pathname, description = imp.find_module(name, [mod_path])
        mod_obj = imp.load_module(name, filename, pathname, description)
        # Enforce capitalized class names
        return getattr(mod_obj, name.capitalize())
    except TypeError, detail:
        raise xcepts.LibvirtXMLError(errmsg + ': %s' % str(detail))
コード例 #19
0
ファイル: base.py プロジェクト: bingbu/virt-test
 def set_xmltreefile(self, value):
     """
     Point instance directly at an already initialized XMLTreeFile instance
     """
     if not issubclass(type(value), xml_utils.XMLTreeFile):
         raise xcepts.LibvirtXMLError(
             "xmltreefile value must be XMLTreefile"
             " type or subclass, not a %s" % type(value))
     self.dict_set('xml', value)
コード例 #20
0
ファイル: disk.py プロジェクト: waynesun09/virt-test
 def marshal_from_seclabel(item, index, libvirtxml):
     """Convert a Seclabel instance into tag + attributes"""
     del index  # not used
     del libvirtxml  # not used
     root = item.xmltreefile.getroot()
     if root.tag == 'seclabel':
         return (root.tag, dict(root.items))
     else:
         raise xcepts.LibvirtXMLError("Expected a list of seclabel "
                                      "instances, not a %s" % str(item))
コード例 #21
0
ファイル: capability_xml.py プロジェクト: mxie91/avocado-vt
 def marshal_from_cpu(item, index, libvirtxml):
     """
     Convert a dict to cpu tag and attributes.
     """
     del index
     del libvirtxml
     if not isinstance(item, dict):
         raise xcepts.LibvirtXMLError("Expected a dictionary of cpu "
                                      "attributes, not a %s" % str(item))
     return ('cpu', dict(item))
コード例 #22
0
 def undefine(self):
     """
     Undefine network witch name is self.name.
     """
     self.virsh.net_destroy(self.name)
     cmd_result = self.virsh.net_undefine(self.name)
     if cmd_result.exit_status:
         raise xcepts.LibvirtXMLError("Failed to undefine network %s.\n"
                                      "Detail: %s" %
                                      (self.name, cmd_result.stderr))
コード例 #23
0
ファイル: mac.py プロジェクト: pepi-enea/virt-test
    def get_attr(self):
        """
        Return mac attribute dict

        :return: None if no mac in xml, dict of mac's attributes.
        """
        try:
            mac_node = self.xmltreefile.reroot('/mac')
        except KeyError, detail:
            raise xcepts.LibvirtXMLError(detail)
コード例 #24
0
    def get_attr(self):
        """
        Return all-ipv6 attribute dict

        :return: None if no all-ipv6 in xml, dict of all-ipv6's attributes.
        """
        try:
            all_node = self.xmltreefile.reroot('/all-ipv6')
        except KeyError, detail:
            raise xcepts.LibvirtXMLError(detail)
コード例 #25
0
    def get_attr(self):
        """
        Return icmp attribute dict

        :return: None if no icmp in xml, dict of icmp's attributes.
        """
        try:
            icmp_node = self.xmltreefile.reroot('/icmp')
        except KeyError, detail:
            raise xcepts.LibvirtXMLError(detail)
コード例 #26
0
 def marshal_from_sources(item, index, libvirtxml):
     """
     Convert a dict to serial source attributes.
     """
     del index
     del libvirtxml
     if not isinstance(item, dict):
         raise xcepts.LibvirtXMLError("Expected a dictionary of source "
                                      "attributes, not a %s" % str(item))
     return ('source', dict(item))
コード例 #27
0
ファイル: udplite.py プロジェクト: yanghangliu/virt-test
    def get_attr(self):
        """
        Return udplite attribute dict

        :return: None if no udplite in xml, dict of udplite's attributes.
        """
        try:
            udplite_node = self.xmltreefile.reroot('/udplite')
        except KeyError, detail:
            raise xcepts.LibvirtXMLError(detail)
コード例 #28
0
 def __call__(self):
     element = self.element_by_parent(self.parent_xpath,
                                          self.tag_name, create=False)
     try:
         result = int(element.text, self.radix)
     except ValueError:
         raise xcepts.LibvirtXMLError("Value of %s in %s is %s,"
                                      "not a Integer." % (self.tag_name,
                                      self.parent_xpath, element.text))
     return result
コード例 #29
0
    def set_rule(self, value, rule_index=0):
        """
        Delete rule with specific index and add new given value

        :param rule_index: rule's index number
        :param value: NwfilterXMLRules instance
        """
        if not issubclass(type(value), NwfilterXMLRules):
            raise xcepts.LibvirtXMLError(
                "Value must be a NwfilterXMLRules or subclass")
        try:
            source_root = self.xmltreefile.findall('rule')
        except KeyError as detail:
            raise xcepts.LibvirtXMLError(detail)
        if source_root[rule_index] is not None:
            self.del_rule(rule_index)
        root = self.xmltreefile.getroot()
        root.insert(rule_index, value.xmltreefile.getroot())
        self.xmltreefile.write()
コード例 #30
0
ファイル: vm_xml.py プロジェクト: xutian/virt-test
 def marshal_from_timer(item, index, libvirtxml):
     """Convert a Timer instance into tag + attributes"""
     del index
     del libvirtxml
     timer = item.xmltreefile.find("clock/timer")
     try:
         return (timer.tag, dict(timer.items()))
     except AttributeError:  # Didn't find timer
         raise xcepts.LibvirtXMLError("Expected a list of timer "
                                      "instances, not a %s" % str(item))