def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ plist_xml = [] existing_plist = [] plist_node = None delete = {"delete": "delete"} if have is not None: # get the instances in running config # form existing instance list for h_rinst in have: existing_plist.append(h_rinst["name"]) # Delete target routing-instance if want: for entry in want: if entry["name"] not in existing_plist: continue plist_node = build_root_xml_node("prefix-list") build_child_xml_node(plist_node, "name", entry["name"]) plist_node.attrib.update(delete) plist_xml.append(plist_node) else: # Delete all the routing-instance plist_node = build_root_xml_node("prefix-list") plist_node.attrib.update(delete) plist_xml.append(plist_node) if plist_node is not None: plist_xml.append(plist_node) return plist_xml
def _state_merged(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the list xml configuration necessary to migrate the current configuration to the desired configuration """ family_xml = [] family_root = build_root_xml_node("family") want = remove_empties(want) # Generate xml node for autonomous-system if want.get("as_number"): build_child_xml_node( self.routing_options, "autonomous-system", want.get("as_number"), ) w_af_list = want.get("address_family") # render global address family attribute commands self.render_af(w_af_list, family_root) # render commands for group address family attribute commands if "groups" in want.keys(): groups = want.get("groups") for group in groups: groups_node = build_root_xml_node("group") build_child_xml_node(groups_node, "name", group["name"]) g_family_root = build_child_xml_node(groups_node, "family") w_gaf_list = group.get("address_family") self.render_af(w_gaf_list, g_family_root) # render neighbor address-family commands if "neighbors" in group.keys(): neighbors = group.get("neighbors") for neighbor in neighbors: neighbors_node = build_child_xml_node( groups_node, "neighbor" ) build_child_xml_node( neighbors_node, "name", neighbor["neighbor_address"], ) n_family_root = build_child_xml_node( neighbors_node, "family" ) w_naf_list = neighbor.get("address_family") self.render_af(w_naf_list, n_family_root) family_xml.append(groups_node) family_xml.append(family_root) return family_xml
def _state_deleted(self, want, have): """The xml configuration generator when state is deleted :rtype: A list :returns: the xml configuration necessary to remove the current configuration of the provided objects """ intf_xml = [] intf_obj = want if not intf_obj: # delete lag interfaces attribute for all the interface intf_obj = have for config in intf_obj: lag_name = config["name"] lag_intf_root = build_root_xml_node("interface") build_child_xml_node(lag_intf_root, "name", lag_name) lag_node = build_subtree(lag_intf_root, "aggregated-ether-options") build_child_xml_node( lag_node, "link-protection", None, {"delete": "delete"} ) lacp_node = build_child_xml_node(lag_node, "lacp") build_child_xml_node( lacp_node, "active", None, {"delete": "delete"} ) build_child_xml_node( lacp_node, "passive", None, {"delete": "delete"} ) intf_xml.append(lag_intf_root) # delete lag configuration from member interfaces for interface_obj in have: if lag_name == interface_obj["name"]: for member in interface_obj.get("members", []): lag_member_intf_root = build_root_xml_node("interface") build_child_xml_node( lag_member_intf_root, "name", member["member"] ) lag_node = build_subtree( lag_member_intf_root, "ether-options/ieee-802.3ad" ) build_child_xml_node( lag_node, "bundle", None, {"delete": "delete"} ) build_child_xml_node( lag_node, "primary", None, {"delete": "delete"} ) build_child_xml_node( lag_node, "backup", None, {"delete": "delete"} ) intf_xml.append(lag_member_intf_root) return intf_xml
def _state_deleted(self, want, have): """ The xml configuration generator when state is deleted :rtype: A list :returns: the xml configuration necessary to remove the current configuration of the provided objects """ intf_xml = [] intf_obj = want if not intf_obj: # delete lag interfaces attribute for all the interface intf_obj = have for config in intf_obj: lag_name = config['name'] lag_intf_root = build_root_xml_node('interface') build_child_xml_node(lag_intf_root, 'name', lag_name) lag_node = build_subtree(lag_intf_root, 'aggregated-ether-options') build_child_xml_node(lag_node, 'link-protection', None, {'delete': 'delete'}) lacp_node = build_child_xml_node(lag_node, 'lacp') build_child_xml_node(lacp_node, 'active', None, {'delete': 'delete'}) build_child_xml_node(lacp_node, 'passive', None, {'delete': 'delete'}) intf_xml.append(lag_intf_root) # delete lag configuration from member interfaces for interface_obj in have: if lag_name == interface_obj['name']: for member in interface_obj.get('members', []): lag_member_intf_root = build_root_xml_node('interface') build_child_xml_node(lag_member_intf_root, 'name', member['member']) lag_node = build_subtree(lag_member_intf_root, 'ether-options/ieee-802.3ad') build_child_xml_node(lag_node, 'bundle', None, {'delete': 'delete'}) build_child_xml_node(lag_node, 'primary', None, {'delete': 'delete'}) build_child_xml_node(lag_node, 'backup', None, {'delete': 'delete'}) intf_xml.append(lag_member_intf_root) return intf_xml
def _state_merged(self, want, have): """The command generator when state is merged :rtype: A list :returns: the xml necessary to merge the provided into the current configuration """ intf_xml = [] for config in want: vlan_name = str(config["name"]) vlan_id = str(config["vlan_id"]) vlan_description = config.get("description") vlan_root = build_root_xml_node("vlan") build_child_xml_node(vlan_root, "name", vlan_name) build_child_xml_node(vlan_root, "vlan-id", vlan_id) if vlan_description: build_child_xml_node(vlan_root, "description", vlan_description) if config.get("l3_interface"): build_child_xml_node(vlan_root, "l3-interface", config.get("l3_interface")) intf_xml.append(vlan_root) return intf_xml
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the list xml configuration necessary to migrate the current configuration to the desired configuration """ root = build_root_xml_node("interfaces") state = self._module.params["state"] if (state in ("merged", "replaced", "overridden", "rendered") and not want): self._module.fail_json( msg="value of config parameter must not be empty for state {0}" .format(state)) if state == "overridden": config_xmls = self._state_overridden(want, have) elif state == "deleted": config_xmls = self._state_deleted(want, have) elif state in ("merged", "rendered"): config_xmls = self._state_merged(want, have) elif state == "replaced": config_xmls = self._state_replaced(want, have) for xml in config_xmls: root.append(xml) return tostring(root)
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the list xml configuration necessary to migrate the current configuration to the desired configuration """ self.autonomous_system = None self.root = build_root_xml_node("configuration") self.protocols = build_child_xml_node(self.root, "protocols") self.routing_options = build_child_xml_node(self.root, "routing-options") state = self._module.params["state"] if state in ("merged", "replaced", "rendered") and not want: self._module.fail_json( msg="value of config parameter must not be empty for state {0}" .format(state)) config_xmls = [] if state == "deleted": config_xmls = self._state_deleted(want, have) elif state == "purged": config_xmls = self._state_purged(want, have) elif state in ("merged", "rendered"): config_xmls = self._state_merged(want, have) elif state == "replaced": config_xmls = self._state_replaced(want, have) for xml in config_xmls: self.protocols.append(xml) temp_lst = [] for xml in self.root.getchildren(): xml = tostring(xml) temp_lst.append(xml) return temp_lst
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ state = self._module.params["state"] if (state in ("merged", "replaced", "overridden", "rendered") and not want): self._module.fail_json( msg="value of config parameter must not be empty for state {0}" .format(state)) root = build_root_xml_node("configuration") routing_options = build_child_xml_node(root, "routing-options") routing_instances = build_child_xml_node(root, "routing-instances") if state == "overridden": config_xmls = self._state_overridden(want, have) elif state == "deleted": config_xmls = self._state_deleted(want, have) elif state in ("merged", "rendered"): config_xmls = self._state_merged(want, have) elif state == "replaced": config_xmls = self._state_replaced(want, have) for xml in config_xmls: if xml["root_type"] == "routing-options": routing_options.append(xml["static_route_xml"]) elif xml["root_type"] == "routing-instances": routing_instances.append(xml["static_route_xml"]) return [tostring(xml) for xml in root.getchildren()]
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ root = build_root_xml_node("firewall") state = self._module.params["state"] config_xmls = [] if state == "overridden": config_xmls = self._state_overridden(want, have) elif state == "deleted": config_xmls = self._state_deleted(want, have) elif state == "merged": config_xmls = self._state_merged(want, have) elif state == "replaced": config_xmls = self._state_replaced(want, have) for xml in config_xmls: root.append(xml) return tostring(root)
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ state = self._module.params['state'] root = build_root_xml_node('configuration') routing_options = build_child_xml_node(root, 'routing-options') routing_instances = build_child_xml_node(root, 'routing-instances') if state == 'overridden': config_xmls = self._state_overridden(want, have) elif state == 'deleted': config_xmls = self._state_deleted(want, have) elif state == 'merged': config_xmls = self._state_merged(want, have) elif state == 'replaced': config_xmls = self._state_replaced(want, have) for xml in config_xmls: if xml['root_type'] == 'routing-options': routing_options.append(xml['static_route_xml']) elif xml['root_type'] == 'routing-instances': routing_instances.append(xml['static_route_xml']) return [tostring(xml) for xml in root.getchildren()]
def _state_merged(self, want, have): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ prefix_list_xml = [] for instance in want: instance = remove_empties(instance) # generate node: prefix-list prefix_root = build_root_xml_node("prefix-list") # generate node: name if "name" in instance.keys(): build_child_xml_node(prefix_root, "name", instance.get("name")) # generate node: prefix-list-item if "address_prefixes" in instance.keys(): address_prefixes = instance.get("address_prefixes") for entry in address_prefixes: add_prefix_node = build_child_xml_node( prefix_root, "prefix-list-item") # generate name node build_child_xml_node(add_prefix_node, "name", entry) # generate node: dynamic_db if "dynamic_db" in instance.keys() and instance.get("dynamic_db"): build_child_xml_node(prefix_root, "dynamic-db") prefix_list_xml.append(prefix_root) return prefix_list_xml
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ self.router_id = None self.root = build_root_xml_node("configuration") self.protocols = build_child_xml_node(self.root, "protocols") state = self._module.params["state"] if (state in ("merged", "replaced", "overridden", "rendered") and not want): self._module.fail_json( msg="value of config parameter must not be empty for state {0}" .format(state)) config_xmls = [] commands = [] if state == "overridden": config_xmls = self._state_overridden(want, have) elif state == "deleted": config_xmls = self._state_deleted(want, have) elif state in ("merged", "rendered"): config_xmls = self._state_merged(want, have) elif state == "replaced": config_xmls = self._state_replaced(want, have) if config_xmls: for xml in config_xmls: self.protocols.append(xml) commands = [tostring(xml) for xml in self.root.getchildren()] return commands
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ self.router_id = None self.root = build_root_xml_node("configuration") self.protocols = build_child_xml_node(self.root, "protocols") self.routing_options = build_child_xml_node( self.root, "routing-options" ) state = self._module.params["state"] config_xmls = [] if state == "overridden": config_xmls = self._state_overridden(want, have) elif state == "deleted": config_xmls = self._state_deleted(want, have) elif state == "merged": config_xmls = self._state_merged(want, have) elif state == "replaced": config_xmls = self._state_replaced(want, have) for xml in config_xmls: self.protocols.append(xml) return [tostring(xml) for xml in self.root.getchildren()]
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the list xml configuration necessary to migrate the current configuration to the desired configuration """ root = build_root_xml_node('interfaces') state = self._module.params['state'] if state == 'overridden': config_xmls = self._state_overridden(want, have) elif state == 'deleted': config_xmls = self._state_deleted(want, have) elif state == 'merged': config_xmls = self._state_merged(want, have) elif state == 'replaced': config_xmls = self._state_replaced(want, have) for xml in config_xmls: root.append(xml) return tostring(root)
def _state_deleted(self, want, have): """ The xml configuration generator when state is deleted :rtype: A list :returns: the xml configuration necessary to remove the current configuration of the provided objects """ intf_xml = [] intf_obj = want if not intf_obj: # delete base interfaces attribute from all the existing interface intf_obj = have for config in intf_obj: intf = build_root_xml_node("interface") build_child_xml_node(intf, "name", config["name"]) intf_fields = ["description"] if not any( [ config["name"].startswith("gr"), config["name"].startswith("lo"), ] ): intf_fields.append("speed") if not any( [ config["name"].startswith("gr"), config["name"].startswith("fxp"), config["name"].startswith("lo"), ] ): intf_fields.append("mtu") for field in intf_fields: build_child_xml_node(intf, field, None, {"delete": "delete"}) if not any( [ config["name"].startswith("gr"), config["name"].startswith("lo"), ] ): build_child_xml_node( intf, "link-mode", None, {"delete": "delete"} ) build_child_xml_node(intf, "disable", None, {"delete": "delete"}) holdtime_ele = build_child_xml_node(intf, "hold-time") for holdtime_field in ["up", "down"]: build_child_xml_node( holdtime_ele, holdtime_field, None, {"delete": "delete"} ) intf_xml.append(intf) return intf_xml
def _state_merged(self, want, have): """ The xml configuration generator when state is merged :rtype: A list :returns: the xml configuration necessary to merge the provided into the current configuration """ intf_xml = [] for config in want: lacp_intf_name = config["name"] lacp_intf_root = build_root_xml_node("interface") build_child_xml_node(lacp_intf_root, "name", lacp_intf_name) if lacp_intf_name.startswith("ae"): element = build_subtree( lacp_intf_root, "aggregated-ether-options/lacp" ) if config["period"]: build_child_xml_node(element, "periodic", config["period"]) if config["sync_reset"]: build_child_xml_node( element, "sync-reset", config["sync_reset"] ) system = config["system"] if system: mac = system.get("mac") if mac: if mac.get("address"): build_child_xml_node( element, "system-id", mac["address"] ) if system.get("priority"): build_child_xml_node( element, "system-priority", system["priority"] ) intf_xml.append(lacp_intf_root) elif config["port_priority"] or config["force_up"] is not None: element = build_subtree( lacp_intf_root, "ether-options/ieee-802.3ad/lacp" ) if config["port_priority"] is not None: build_child_xml_node( element, "port-priority", config["port_priority"] ) else: build_child_xml_node( element, "port-priority", None, {"delete": "delete"} ) if config["force_up"]: build_child_xml_node(element, "force-up") else: build_child_xml_node( element, "force-up", None, {"delete": "delete"} ) intf_xml.append(lacp_intf_root) return intf_xml
def _state_deleted(self, want, have): """ The xml configuration generator when state is deleted :rtype: A list :returns: the xml configuration necessary to remove the current configuration of the provided objects """ l2_intf_xml = [] l2_intf_obj = want config_filter = """ <configuration> <interfaces/> </configuration> """ data = get_resource_config(self._connection, config_filter=config_filter) if not l2_intf_obj: # delete l2 interfaces attribute from all the existing interface having l2 config l2_intf_obj = have for config in l2_intf_obj: name = config["name"] enhanced_layer = True l2_mode = data.xpath( "configuration/interfaces/interface[name='%s']/unit/family/ethernet-switching/interface-mode" % name) if not len(l2_mode): l2_mode = data.xpath( "configuration/interfaces/interface[name='%s']/unit/family/ethernet-switching/port-mode" % name) enhanced_layer = False if len(l2_mode): mode = "interface-mode" if enhanced_layer else "port-mode" intf = build_root_xml_node("interface") build_child_xml_node(intf, "name", name) unit_node = build_child_xml_node(intf, "unit") unit = config["unit"] if config["unit"] else "0" build_child_xml_node(unit_node, "name", unit) eth_node = build_subtree(unit_node, "family/ethernet-switching") build_child_xml_node(eth_node, mode, None, {"delete": "delete"}) build_child_xml_node(eth_node, "vlan", None, {"delete": "delete"}) build_child_xml_node(intf, "native-vlan-id", None, {"delete": "delete"}) l2_intf_xml.append(intf) return l2_intf_xml
def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the xml necessary to migrate the current configuration to the desired configuration """ acls_xml = [] family_node = build_root_xml_node("family") delete = dict(delete="delete") if not want: want = have for config in want: try: family = "inet6" if config.get("afi") == "ipv6" else "inet" except KeyError: family = "inet" inet_node = build_child_xml_node(family_node, family) # Look deeply into have to match replace correctly existing_acls = [] for conf in have: if conf.get("afi") == config.get("afi"): existing_acls.extend(conf["acls"] or []) acl_names = [acl["name"] for acl in existing_acls] if not config["acls"]: inet_node.attrib.update(delete) continue for acl in config["acls"]: if acl["name"] not in acl_names: continue filter_node = build_child_xml_node(inet_node, "filter") build_child_xml_node(filter_node, "name", acl["name"]) if not acl.get("aces"): filter_node.attrib.update(delete) continue for ace in acl["aces"]: # if ace["name"] not in ace_names: term_node = build_child_xml_node(filter_node, "term") build_child_xml_node(term_node, "name", ace["name"]) term_node.attrib.update(delete) acls_xml.append(family_node) return acls_xml
def _state_deleted(self, want, have): """The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ rinst_xml = [] existing_rinsts = [] rinstance_node = None delete = {"delete": "delete"} if have is not None: # get the instances in running config # form existing instance list for h_rinst in have: existing_rinsts.append(h_rinst["name"]) # Delete target routing-instance if want: for instance in want: if instance["name"] not in existing_rinsts: continue rinstance_node = build_root_xml_node("instance") build_child_xml_node(rinstance_node, "name", instance["name"]) rinstance_node.attrib.update(delete) rinst_xml.append(rinstance_node) else: # Delete all the routing-instance rinstance_node = build_root_xml_node("instance") rinstance_node.attrib.update(delete) rinst_xml.append(rinstance_node) if rinstance_node is not None: rinst_xml.append(rinstance_node) return rinst_xml
def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ lacp_xml = [] lacp_root = build_root_xml_node('lacp') build_child_xml_node(lacp_root, 'system-priority', None, {'delete': 'delete'}) element = build_child_xml_node(lacp_root, 'link-protection', None, {'delete': 'delete'}) build_child_xml_node(element, 'non-revertive', None, {'delete': 'delete'}) lacp_xml.append(lacp_root) return lacp_xml
def _state_deleted(self, want, have): """ The xml configuration generator when state is deleted :rtype: A list :returns: the xml configuration necessary to remove the current configuration of the provided objects """ intf_xml = [] intf_obj = want if not intf_obj: # delete lag interfaces attribute for all the interface intf_obj = have for config in intf_obj: lacp_intf_name = config["name"] lacp_intf_root = build_root_xml_node("interface") build_child_xml_node(lacp_intf_root, "name", lacp_intf_name) if lacp_intf_name.startswith("ae"): element = build_subtree( lacp_intf_root, "aggregated-ether-options/lacp" ) build_child_xml_node( element, "periodic", None, {"delete": "delete"} ) build_child_xml_node( element, "sync-reset", None, {"delete": "delete"} ) build_child_xml_node( element, "system-id", None, {"delete": "delete"} ) build_child_xml_node( element, "system-priority", None, {"delete": "delete"} ) else: element = build_subtree( lacp_intf_root, "ether-options/ieee-802.3ad/lacp" ) build_child_xml_node( element, "port-priority", None, {"delete": "delete"} ) build_child_xml_node( element, "force-up", None, {"delete": "delete"} ) intf_xml.append(lacp_intf_root) return intf_xml
def _state_merged(self, want, have): """The xml configuration generator when state is merged :rtype: A list :returns: the xml configuration necessary to merge the provided into the current configuration """ intf_xml = [] for config in want: intf = build_root_xml_node("interface") build_child_xml_node(intf, "name", config["name"]) intf_fields = ["description", "speed"] if not config["name"].startswith("fxp"): intf_fields.append("mtu") for field in intf_fields: if config.get(field): build_child_xml_node(intf, field, config[field]) if config.get("duplex"): build_child_xml_node(intf, "link-mode", config["duplex"]) if config.get("enabled") is False: build_child_xml_node(intf, "disable") if config.get("units"): units = config.get("units") for unit in units: unit_node = build_child_xml_node(intf, "unit") build_child_xml_node(unit_node, "name", str(unit["name"])) build_child_xml_node(unit_node, "description", unit["description"]) holdtime = config.get("hold_time") if holdtime: holdtime_ele = build_child_xml_node(intf, "hold-time") for holdtime_field in ["up", "down"]: build_child_xml_node( holdtime_ele, holdtime_field, holdtime.get(holdtime_field, ""), ) intf_xml.append(intf) return intf_xml
def _state_deleted(self, want, have): """ The xml configuration generator when state is deleted :rtype: A list :returns: the xml configuration necessary to remove the current configuration of the provided objects """ intf_xml = [] intf_obj = want if not intf_obj: # delete base interfaces attribute from all the existing interface intf_obj = have for config in intf_obj: intf = build_root_xml_node('interface') build_child_xml_node(intf, 'name', config['name']) intf_fields = ['description'] if not config['name'].startswith('lo'): intf_fields.append('speed') if not any([ config['name'].startswith('fxp'), config['name'].startswith('lo') ]): intf_fields.append('mtu') for field in intf_fields: build_child_xml_node(intf, field, None, {'delete': 'delete'}) if not config['name'].startswith('lo'): build_child_xml_node(intf, 'link-mode', None, {'delete': 'delete'}) build_child_xml_node(intf, 'disable', None, {'delete': 'delete'}) holdtime_ele = build_child_xml_node(intf, 'hold-time') for holdtime_field in ['up', 'down']: build_child_xml_node(holdtime_ele, holdtime_field, None, {'delete': 'delete'}) intf_xml.append(intf) return intf_xml
def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the xml necessary to migrate the current configuration to the desired configuration """ ospf_interfaces_xml = [] delete = {"delete": "delete"} protocol = build_root_xml_node("ospf") if not want: for h in have: for af in h["address_family"]: area_node = build_child_xml_node(protocol, "area") processes = af.get("processes") area = processes.get("area") area_id = area.get("area_id") build_child_xml_node(area_node, "name", area_id) ospf_interfacesnode = build_child_xml_node( area_node, "interface" ) build_child_xml_node( ospf_interfacesnode, "name", h.get("name") ) ospf_interfacesnode.attrib.update(delete) else: for w in want: for h in have: if h["name"] == w["name"]: for af in h["address_family"]: area_node = build_child_xml_node(protocol, "area") processes = af.get("processes") area = processes.get("area") area_id = area.get("area_id") build_child_xml_node(area_node, "name", area_id) ospf_interfacesnode = build_child_xml_node( area_node, "interface" ) build_child_xml_node( ospf_interfacesnode, "name", h.get("name") ) ospf_interfacesnode.attrib.update(delete) ospf_interfaces_xml.append(protocol) return ospf_interfaces_xml
def _state_merged(self, want, have): """ The xml configuration generator when state is merged :rtype: A list :returns: the xml configuration necessary to merge the provided into the current configuration """ intf_xml = [] for config in want: enhanced_layer = True if config.get('enhanced_layer') is False: enhanced_layer = False mode = 'interface-mode' if enhanced_layer else 'port-mode' intf = build_root_xml_node('interface') build_child_xml_node(intf, 'name', config['name']) unit_node = build_child_xml_node(intf, 'unit') unit = config['unit'] if config['unit'] else '0' build_child_xml_node(unit_node, 'name', unit) eth_node = build_subtree(unit_node, 'family/ethernet-switching') if config.get('access'): vlan = config['access'].get('vlan') if vlan: build_child_xml_node(eth_node, mode, 'access') vlan_node = build_child_xml_node(eth_node, 'vlan') build_child_xml_node(vlan_node, 'members', vlan) intf_xml.append(intf) elif config.get('trunk'): allowed_vlans = config['trunk'].get('allowed_vlans') native_vlan = config['trunk'].get('native_vlan') if allowed_vlans: build_child_xml_node(eth_node, mode, 'trunk') vlan_node = build_child_xml_node(eth_node, 'vlan') for vlan in allowed_vlans: build_child_xml_node(vlan_node, 'members', vlan) if native_vlan: build_child_xml_node(intf, 'native-vlan-id', native_vlan) if allowed_vlans or native_vlan: intf_xml.append(intf) return intf_xml
def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the xml necessary to remove the current configuration of the provided objects """ intf_xml = [] if not want: want = have for config in want: vlan_name = config["name"] vlan_root = build_root_xml_node("vlan") vlan_root.attrib.update({"delete": "delete"}) build_child_xml_node(vlan_root, "name", vlan_name) intf_xml.append(vlan_root) return intf_xml
def _state_merged(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the list xml configuration necessary to migrate the current configuration to the desired configuration """ lacp_xml = [] lacp_root = build_root_xml_node('lacp') build_child_xml_node(lacp_root, 'system-priority', want.get('system_priority')) if want.get('link_protection') == 'non-revertive': build_subtree(lacp_root, 'link-protection/non-revertive') elif want.get('link_protection') == 'revertive': link_root = build_child_xml_node(lacp_root, 'link-protection') build_child_xml_node(link_root, 'non-revertive', None, {'delete': 'delete'}) lacp_xml.append(lacp_root) return lacp_xml
def _state_merged(self, want, have): """ The xml configuration generator when state is merged :rtype: A list :returns: the xml configuration necessary to merge the provided into the current configuration """ intf_xml = [] for config in want: enhanced_layer = True if config.get("enhanced_layer") is False: enhanced_layer = False mode = "interface-mode" if enhanced_layer else "port-mode" intf = build_root_xml_node("interface") build_child_xml_node(intf, "name", config["name"]) unit_node = build_child_xml_node(intf, "unit") unit = config["unit"] if config["unit"] else "0" build_child_xml_node(unit_node, "name", unit) eth_node = build_subtree(unit_node, "family/ethernet-switching") if config.get("access"): vlan = config["access"].get("vlan") if vlan: build_child_xml_node(eth_node, mode, "access") vlan_node = build_child_xml_node(eth_node, "vlan") build_child_xml_node(vlan_node, "members", vlan) intf_xml.append(intf) elif config.get("trunk"): allowed_vlans = config["trunk"].get("allowed_vlans") native_vlan = config["trunk"].get("native_vlan") if allowed_vlans: build_child_xml_node(eth_node, mode, "trunk") vlan_node = build_child_xml_node(eth_node, "vlan") for vlan in allowed_vlans: build_child_xml_node(vlan_node, "members", vlan) if native_vlan: build_child_xml_node(intf, "native-vlan-id", native_vlan) if allowed_vlans or native_vlan: intf_xml.append(intf) return intf_xml
def _state_merged(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the list xml configuration necessary to migrate the current configuration to the desired configuration """ lldp_xml = [] lldp_root = build_root_xml_node("lldp") if want.get("address"): build_child_xml_node( lldp_root, "management-address", want["address"] ) if want.get("interval"): build_child_xml_node( lldp_root, "advertisement-interval", want["interval"] ) if want.get("transmit_delay"): build_child_xml_node( lldp_root, "transmit-delay", want["transmit_delay"] ) if want.get("hold_multiplier"): build_child_xml_node( lldp_root, "hold-multiplier", want["hold_multiplier"] ) enable = want.get("enable") if enable is not None: if enable is False: build_child_xml_node(lldp_root, "disable") else: build_child_xml_node( lldp_root, "disable", None, {"delete": "delete"} ) else: build_child_xml_node( lldp_root, "disable", None, {"delete": "delete"} ) lldp_xml.append(lldp_root) return lldp_xml
def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ lldp_xml = [] lldp_root = build_root_xml_node("lldp") build_child_xml_node(lldp_root, "management-address", None, {"delete": "delete"}) build_child_xml_node(lldp_root, "advertisement-interval", None, {"delete": "delete"}) build_child_xml_node(lldp_root, "transmit-delay", None, {"delete": "delete"}) build_child_xml_node(lldp_root, "hold-multiplier", None, {"delete": "delete"}) build_child_xml_node(lldp_root, "disable", None, {"delete": "delete"}) lldp_xml.append(lldp_root) return lldp_xml