def get_all_protocols(self, protocol=None): """ Put all type of protocol into a NwfilterRulesProtocol instance. Return all protocols class list if protocol as None, else return specific protocol type class list. :param protocol: specific protocol type in rules :return: NwfilterRulesProtocol instance list """ protocols = NwfilterRulesProtocol() all_rules = self.xmltreefile.findall('rule') for i in all_rules: protocol_node = i.getchildren() if protocol_node: if protocol: # Each rule node only have one protocol node, so # only use protocol_node[0] if protocol_node[0].tag == protocol: protocol_class = librarian.get(protocol) new_one = protocol_class.new_from_element( protocol_node[0]) protocols.device_tag = protocol protocols.append(new_one) else: protocol_class = librarian.get(protocol_node[0].tag) new_one = protocol_class.new_from_element( protocol_node[0]) protocols.device_tag = protocol_node[0].tag protocols.append(new_one) return protocols
def get_all_protocols(self, protocol=None): """ Put all type of protocol into a NwfilterRulesProtocol instance. Return all protocols class list if protocol as None, else return specific protocol type class list. :param protocol: specific protocol type in rules :return: NwfilterRulesProtocol instance list """ protocols = NwfilterRulesProtocol() all_rules = self.xmltreefile.findall('rule') for i in all_rules: protocol_node = i.getchildren() if protocol_node: if protocol: # Each rule node only have one protocol node, so # only use protocol_node[0] if protocol_node[0].tag == protocol: protocol_class = librarian.get(protocol) new_one = protocol_class.new_from_element( protocol_node[0]) protocols.device_tag = protocol protocols.append(new_one) else: protocol_class = librarian.get(protocol_node[0].tag) new_one = protocol_class.new_from_element(protocol_node[0]) protocols.device_tag = protocol_node[0].tag protocols.append(new_one) return protocols
def __type_check__(other): try: # Raise error if object isn't dict-like or doesn't have key device_tag = other['device_tag'] # Check that we have support for this type librarian.get(device_tag) except (AttributeError, TypeError, xcepts.LibvirtXMLError): # Required to always raise TypeError for list API in VMXML class raise TypeError("Unsupported item type: %s" % str(type(other)))
def __type_check__(other): try: # Raise error if object isn't dict-like or doesn't have key device_tag = other['device_tag'] # Check that we have support for this type librarian.get(device_tag) except (AttributeError, TypeError, xcepts.LibvirtXMLError): # Required to always raise TypeError for list API in VMXML class raise TypeError("Unsupported item type: %s" % str(type(other)))
def new_protocol(self, **dargs): """ Return a new rule protocol instance and set properties from dargs """ protocol_tag = dargs.get("name") new_one = librarian.get(protocol_tag) for key, value in dargs.items(): setattr(new_one, key, value) return new_one
def new_protocol(self, **dargs): """ Return a new rule protocol instance and set properties from dargs """ protocol_tag = dargs.get("name") new_one = librarian.get(protocol_tag) for key, value in dargs.items(): setattr(new_one, key, value) return new_one
def get_protocol(self, protocol=None): """ Return None if protocol is None, else return specific class instance :param protocol: specific protocol type in rules :return: specific protocol class instance from librarian.get """ if protocol: protocol_class = librarian.get(protocol) protocol_node = self.xmltreefile.getroot().getchildren()[0] protocol_node.tag = protocol new_one = protocol_class.new_from_element(protocol_node) new_one.xmltreefile = self.xmltreefile else: new_one = None return new_one
def get_protocol(self, protocol=None): """ Return None if protocol is None, else return specific class instance :param protocol: specific protocol type in rules :return: specific protocol class instance from librarian.get """ if protocol: protocol_class = librarian.get(protocol) protocol_node = self.xmltreefile.getroot().getchildren()[0] protocol_node.tag = protocol new_one = protocol_class.new_from_element(protocol_node) new_one.xmltreefile = self.xmltreefile else: new_one = None return new_one