Esempio n. 1
0
 def from_xml_node(cls, xml_node):
     """
     Initialize the object from a XML node.
     :param xml_node: The XML node from which all necessary parameters will be parsed.
     :type xml_node: xml.etree.Element
     """
     source_network_collection_node = get_xml_node(
         xml_node, xml_tags.Elements.SOURCE_NETWORK_COLLECTION)
     source_network_collection = Exception_Network_Source_Collection.from_xml_node(
         source_network_collection_node)
     dest_network_collection_node = get_xml_node(
         xml_node, xml_tags.Elements.DEST_NETWORK_COLLECTION)
     dest_network_collection = Exception_Network_Destination_Collection.from_xml_node(
         dest_network_collection_node)
     service_collection_node = get_xml_node(
         xml_node, xml_tags.Elements.SERVICE_COLLECTION)
     service_collection = Exception_Service_Collection.from_xml_node(
         service_collection_node)
     security_requirements = XML_List.from_xml_node_by_tags(
         xml_node, xml_tags.Elements.SECURITY_REQUIREMENTS,
         xml_tags.Elements.ZONE_TO_ZONE_SECURITY_REQUIREMENT,
         Zone_To_Zone_Security_Requirement)
     comment = get_xml_text_value(xml_node, xml_tags.Elements.COMMENT)
     return cls(source_network_collection, dest_network_collection,
                service_collection, security_requirements, comment)
Esempio n. 2
0
    def from_xml_node_by_type_dict(cls, xml_node, list_element_name, child_element_name, type_to_class_dict,
                                   optional=False, default_class=None):
        xml_list_base_node = get_xml_node(xml_node, list_element_name, optional)
        list_data = []
        if xml_list_base_node:
            for child_node in xml_list_base_node.iter(tag=child_element_name):
                try:
                    type_attribute = child_node.attrib[xml_tags.Attributes.XSI_NAMESPACE_TYPE]
                except KeyError:
                    try:
                        type_attribute = child_node.attrib[xml_tags.TYPE_ATTRIB]
                    except KeyError:
                        message = "could not find type attribute in {},existing attributes: {}".format(child_node,
                                                                                                       child_node.attrib)
                        logger.error(message)
                        raise KeyError(message)
                try:
                    list_data.append(type_to_class_dict[type_attribute].from_xml_node(child_node))
                except KeyError as error:
                    if default_class:
                        list_data.append(default_class.from_xml_node(child_node))
                    else:
                        raise error

        return cls(list_element_name, list_data)
Esempio n. 3
0
 def from_xml_node_by_tags(cls, xml_node, list_element_name, child_element_name, child_class_type, optional=False):
     xml_list_base_node = get_xml_node(xml_node, list_element_name, optional)
     list_data = []
     if xml_list_base_node:
         for child_node in xml_list_base_node.iterfind(child_element_name):
             list_data.append(child_class_type.from_xml_node(child_node))
     return cls(list_element_name, list_data)
Esempio n. 4
0
 def from_xml_node(cls, xml_node):
     """
     Initialize the object from a XML node.
     :param xml_node: The XML node from which all necessary parameters will be parsed.
     :type xml_node: xml.etree.Element
     """
     action = get_xml_text_value(xml_node, xml_tags.Elements.ACTION)
     admin = get_xml_text_value(xml_node, xml_tags.Elements.ADMIN)
     auditLog = get_xml_text_value(xml_node, xml_tags.Elements.AUDITLOG)
     authorizationStatus = get_xml_text_value(
         xml_node, xml_tags.Elements.AUTHORIZATIONSTATUS)
     revision_date = get_xml_text_value(xml_node, xml_tags.Elements.DATE)
     gui_client = get_xml_text_value(xml_node, xml_tags.Elements.GUICLIENT)
     num_id = get_xml_int_value(xml_node, xml_tags.Elements.ID)
     modules_and_policy_node = get_xml_node(
         xml_node, xml_tags.Elements.MODULES_AND_POLICY, optional=True)
     if modules_and_policy_node:
         modules_and_policy = []
         for node in modules_and_policy_node.iterfind('module_and_policy'):
             modules_and_policy.append(
                 Module_And_Policy.from_xml_node(node))
     else:
         modules_and_policy = None
     policy_package = get_xml_text_value(xml_node,
                                         xml_tags.Elements.POLICYPACKAGE)
     revision_id = get_xml_int_value(xml_node, xml_tags.Elements.REVISIONID)
     revision_time = get_xml_text_value(xml_node, xml_tags.Elements.TIME)
     ready = get_xml_text_value(xml_node, xml_tags.Elements.READY)
     return cls(action, num_id, admin, auditLog, authorizationStatus,
                revision_date, revision_time, gui_client, revision_id,
                modules_and_policy, policy_package, ready)
Esempio n. 5
0
    def __init__(self, xml_node):
        # The base node has no child nodes, we are in test mode.
        if len(xml_node.getchildren()) == 0:
            raise ValueError(
                "The ticket can not be constructed as the script is in test mode."
            )
        try:
            self.id = get_xml_int_value(xml_node, Elements.ID)
            self.subject = get_xml_text_value(xml_node, Elements.SUBJECT)
            self.createDate = get_xml_text_value(xml_node,
                                                 Elements.CREATE_DATE)
            self.updateDate = get_xml_text_value(xml_node,
                                                 Elements.UPDATE_DATE)
            current_stage_node = get_xml_node(xml_node, Elements.CURRENT_STAGE,
                                              True)
            if current_stage_node:
                self.current_stage_id = get_xml_int_value(
                    current_stage_node, Elements.ID)
                self.current_stage_name = get_xml_text_value(
                    current_stage_node, Elements.NAME)
            else:
                self.current_stage_id, self.current_stage_name = None, None

            completion_data = get_xml_node(xml_node, Elements.COMPLETION_DATA,
                                           True)
            if completion_data:
                self.completion_step_id = get_xml_int_value(
                    completion_data, 'stage/' + Elements.ID)
                self.completion_step_name = get_xml_text_value(
                    completion_data, 'stage/' + Elements.NAME)
            else:
                self.completion_step_id, self.completion_step_name = None, None

            self.open_request_id = get_xml_int_value(
                get_xml_node(xml_node, Elements.OPEN_REQUEST_STAGE),
                Elements.ID)
            self.open_request_name = get_xml_text_value(
                get_xml_node(xml_node, Elements.OPEN_REQUEST_STAGE),
                Elements.NAME)
        except AttributeError as attr_error:
            message = "Could not parse ticket_info XML into Ticket_Info object, error was {0}.".format(
                attr_error)
            logger.error(message)
            raise AttributeError(message)
        super().__init__(Elements.TICKET_INFO)
Esempio n. 6
0
 def from_xml_node(cls, xml_node):
     """
     Initialize the object from a XML node.
     :param xml_node: The XML node from which all necessary parameters will be parsed.
     :type xml_node: xml.etree.Element
     """
     shadowed_rules_cleanup = Shadowed_Rules_Cleanup.from_xml_node(
         get_xml_node(xml_node, xml_tags.Elements.SHADOWED_RULES_CLEANUP))
     return cls(shadowed_rules_cleanup)