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 = [] config_filter = """ <configuration> <interfaces/> </configuration> """ data = self._connection.get_configuration(filter=config_filter) for config in want: lag_name = config['name'] # if lag interface not already configured fail module. if not data.xpath("configuration/interfaces/interface[name='%s']" % lag_name): self._module.fail_json(msg="lag interface %s not configured, configure interface" " %s before assigning members to lag" % (lag_name, lag_name)) lag_intf_root = build_root_xml_node('interface') build_child_xml_node(lag_intf_root, 'name', lag_name) ether_options_node = build_subtree(lag_intf_root, 'aggregated-ether-options') if config['mode']: lacp_node = build_child_xml_node(ether_options_node, 'lacp') build_child_xml_node(lacp_node, config['mode']) link_protection = config['link_protection'] if link_protection: build_child_xml_node(ether_options_node, 'link-protection') elif link_protection is False: build_child_xml_node(ether_options_node, 'link-protection', None, {'delete': 'delete'}) intf_xml.append(lag_intf_root) members = config['members'] for member in 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', config['name']) link_type = member.get('link_type') if link_type == "primary": build_child_xml_node(lag_node, 'primary') elif link_type == "backup": build_child_xml_node(lag_node, 'backup') 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_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 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 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') 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 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 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('protocols') lldp_intf_ele = build_subtree(root, 'lldp') 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: lldp_intf_ele.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 """ 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 """ 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 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 = self._connection.get_configuration(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 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_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_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') build_child_xml_node(element, 'port-priority', config['port_priority']) if config['force_up'] is False: build_child_xml_node(element, 'force-up', None, {'delete': 'delete'}) else: build_child_xml_node(element, 'force-up') 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: 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") build_child_xml_node(element, "port-priority", config["port_priority"]) if config["force_up"] is False: build_child_xml_node(element, "force-up", None, {"delete": "delete"}) else: build_child_xml_node(element, "force-up") intf_xml.append(lacp_intf_root) return intf_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_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): """ 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_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
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
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) intf_xml.append(vlan_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 """ lldp_intf_xml = [] intf_obj = want if not intf_obj: # delete lldp interfaces attribute from all the existing interface intf_obj = have for config in intf_obj: lldp_intf_root = build_root_xml_node('interface') lldp_intf_root.attrib.update({'delete': 'delete'}) build_child_xml_node(lldp_intf_root, 'name', config['name']) lldp_intf_xml.append(lldp_intf_root) return lldp_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): """ 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_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("enable") is False: build_child_xml_node(intf, "disable") 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_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_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 """ lldp_intf_xml = [] for config in want: lldp_intf_root = build_root_xml_node('interface') if config.get('name'): build_child_xml_node(lldp_intf_root, 'name', config['name']) if config.get('enable') is not None: if config['enable'] is False: build_child_xml_node(lldp_intf_root, 'disable') else: build_child_xml_node(lldp_intf_root, 'disable', None, {'delete': 'delete'}) else: build_child_xml_node(lldp_intf_root, 'disable', None, {'delete': 'delete'}) lldp_intf_xml.append(lldp_intf_root) return lldp_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_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 """ lldp_intf_xml = [] for config in want: lldp_intf_root = build_root_xml_node("interface") if config.get("name"): build_child_xml_node(lldp_intf_root, "name", config["name"]) if config.get("enable") is not None: if config["enable"] is False: build_child_xml_node(lldp_intf_root, "disable") else: build_child_xml_node(lldp_intf_root, "disable", None, {"delete": "delete"}) else: build_child_xml_node(lldp_intf_root, "disable", None, {"delete": "delete"}) lldp_intf_xml.append(lldp_intf_root) return lldp_intf_xml