def netconf_load_config(self, xml_str): """load bfd config by netconf""" if not xml_str: return xml_cfg = """ <config> <bfd xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"> %s </bfd> </config>""" % xml_str set_nc_config(self.module, xml_cfg) self.changed = True
def config_interface_vrf(self): """ configure VPN instance of the interface""" if not self.conf_exist and self.state == 'present': xml_str = CE_NC_MERGE_VRF_INTERFACE % ( self.vrf, self.vpn_interface) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "VRF_INTERFACE_CONFIG") self.changed = True elif self.state == 'absent': xml_str = CE_NC_DEL_INTF_VPN % (self.vrf, self.vpn_interface) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "DEL_VRF_INTERFACE_CONFIG") self.changed = True
def config_interface_vrf(self): """ configure VPN instance of the interface""" if not self.conf_exist and self.state == 'present': xml_str = CE_NC_MERGE_VRF_INTERFACE % (self.vrf, self.vpn_interface) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "VRF_INTERFACE_CONFIG") self.changed = True elif self.state == 'absent': xml_str = CE_NC_DEL_INTF_VPN % (self.vrf, self.vpn_interface) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "DEL_VRF_INTERFACE_CONFIG") self.changed = True
def default_interface(self, ifname): """default_interface""" change = False xmlstr = "" self.updates_cmd.append("interface %s" % ifname) # set description default if self.intf_info["ifDescr"]: xmlstr += CE_NC_XML_MERGE_INTF_DES % (ifname, '') self.updates_cmd.append("undo description") change = True # set admin_status default if is_admin_state_enable(self.intf_type) \ and self.intf_info["ifAdminStatus"] != 'up': xmlstr += CE_NC_XML_MERGE_INTF_STATUS % (ifname, 'up') self.updates_cmd.append("undo shutdown") change = True # set portswitch default if is_portswitch_enalbe(self.intf_type) \ and self.intf_info["isL2SwitchPort"] != "true": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % (ifname, 'enable') self.updates_cmd.append("portswitch") change = True if not change: return conf_str = '<config> ' + xmlstr + ' </config>' recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "SET_INTF_DEFAULT") self.changed = True
def config_global_dldp(self): """Config global dldp""" if self.same_conf: return enable = self.enable if not self.enable: enable = self.dldp_conf['dldpEnable'] if enable == 'enable': enable = 'true' else: enable = 'false' internal = self.internal if not self.internal: internal = self.dldp_conf['dldpInterval'] work_mode = self.work_mode if not self.work_mode: work_mode = self.dldp_conf['dldpWorkMode'] if work_mode == 'enhance' or work_mode == 'dldpEnhance': work_mode = 'dldpEnhance' else: work_mode = 'dldpNormal' auth_mode = self.auth_mode if not self.auth_mode: auth_mode = self.dldp_conf['dldpAuthMode'] if auth_mode == 'md5': auth_mode = 'dldpAuthMD5' elif auth_mode == 'simple': auth_mode = 'dldpAuthSimple' elif auth_mode == 'sha': auth_mode = 'dldpAuthSHA' elif auth_mode == 'hmac-sha256': auth_mode = 'dldpAuthHMAC-SHA256' elif auth_mode == 'none': auth_mode = 'dldpAuthNone' xml_str = CE_NC_MERGE_DLDP_GLOBAL_CONFIG_HEAD % ( enable, internal, work_mode) if self.auth_mode: if self.auth_mode == 'none': xml_str += "<dldpAuthMode>dldpAuthNone</dldpAuthMode>" else: xml_str += "<dldpAuthMode>%s</dldpAuthMode>" % auth_mode xml_str += "<dldpPasswords>%s</dldpPasswords>" % self.auth_pwd xml_str += CE_NC_MERGE_DLDP_GLOBAL_CONFIG_TAIL ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "MERGE_DLDP_GLOBAL_CONFIG") if self.reset == 'enable': xml_str = CE_NC_ACTION_RESET_DLDP ret_xml = execute_nc_action(self.module, xml_str) self.check_response(ret_xml, "ACTION_RESET_DLDP") self.changed = True
def create_interface(self, ifname, description, admin_state, mode, l2sub): """Create interface.""" if l2sub: self.updates_cmd.append("interface %s mode l2" % ifname) else: self.updates_cmd.append("interface %s" % ifname) if not description: description = '' else: self.updates_cmd.append("description %s" % description) if l2sub: xmlstr = CE_NC_XML_CREATE_INTF_L2SUB % (ifname, description) else: xmlstr = CE_NC_XML_CREATE_INTF % (ifname, description) if admin_state and is_admin_state_enable(self.intf_type): xmlstr += CE_NC_XML_MERGE_INTF_STATUS % (ifname, admin_state) if admin_state == 'up': self.updates_cmd.append("undo shutdown") else: self.updates_cmd.append("shutdown") if mode and is_portswitch_enalbe(self.intf_type): if mode == "layer2": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % (ifname, 'enable') self.updates_cmd.append('portswitch') elif mode == "layer3": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % (ifname, 'disable') self.updates_cmd.append('undo portswitch') conf_str = '<config> ' + xmlstr + ' </config>' recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "CREATE_INTF") self.changed = True
def merge_debug_source(self): """ Merge debug source """ conf_str = CE_MERGE_DEBUG_SOURCE_HEADER if self.module_name: conf_str += "<moduleName>%s</moduleName>" % self.module_name if self.channel_id: conf_str += "<icChannelId>%s</icChannelId>" % self.channel_id if self.debug_enable != 'no_use': conf_str += "<dbgEnFlg>%s</dbgEnFlg>" % self.debug_enable if self.debug_level: conf_str += "<dbgEnLevel>%s</dbgEnLevel>" % self.debug_level conf_str += CE_MERGE_DEBUG_SOURCE_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json(msg='Error: Merge debug source failed.') cmd = "info-center source" if self.module_name: cmd += " %s" % self.module_name if self.channel_id: cmd += " channel %s" % self.channel_id if self.debug_enable != 'no_use': if self.debug_enable == "true": cmd += " debug state on" else: cmd += " debug state off" if self.debug_level: cmd += " level %s" % self.debug_level self.updates_cmd.append(cmd) self.changed = True
def set_mlag_interface(self): """set mlag interface atrribute info""" if self.is_mlag_interface_info_change(): mlag_port = "Eth-Trunk" mlag_port += self.eth_trunk_id conf_str = CE_NC_SET_LACP_MLAG_INFO_HEAD % mlag_port if self.mlag_priority_id: conf_str += "<lacpMlagPriority>%s</lacpMlagPriority>" % self.mlag_priority_id if self.mlag_system_id: conf_str += "<lacpMlagSysId>%s</lacpMlagSysId>" % self.mlag_system_id conf_str += CE_NC_SET_LACP_MLAG_INFO_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json( msg='Error: set mlag interface atrribute info failed.') self.updates_cmd.append("interface %s" % mlag_port) if self.mlag_priority_id: self.updates_cmd.append( "lacp m-lag priority %s" % self.mlag_priority_id) if self.mlag_system_id: self.updates_cmd.append( "lacp m-lag system-id %s" % self.mlag_system_id) self.changed = True
def config_vap_sub_intf(self): """configure a Layer 2 sub-interface as a service access point""" if not self.vap_info: self.module.fail_json( msg="Error: Bridge domain %s does not exist." % self.bridge_domain_id) xml_str = "" if self.state == "present": if self.l2_sub_interface not in self.vap_info["intfList"]: self.updates_cmd.append("interface %s" % self.l2_sub_interface) self.updates_cmd.append("bridge-domain %s" % self.bridge_domain_id) xml_str = CE_NC_MERGE_BD_INTF % (self.bridge_domain_id, self.l2_sub_interface) else: if self.l2_sub_interface in self.vap_info["intfList"]: self.updates_cmd.append("interface %s" % self.l2_sub_interface) self.updates_cmd.append("undo bridge-domain %s" % self.bridge_domain_id) xml_str = CE_NC_DELETE_BD_INTF % (self.bridge_domain_id, self.l2_sub_interface) if not xml_str: return recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "CONFIG_VAP_SUB_INTERFACE") self.changed = True
def config_vap_sub_intf(self): """configure a Layer 2 sub-interface as a service access point""" if not self.vap_info: self.module.fail_json(msg="Error: Bridge domain %s does not exist." % self.bridge_domain_id) xml_str = "" if self.state == "present": if self.l2_sub_interface not in self.vap_info["intfList"]: self.updates_cmd.append("interface %s" % self.l2_sub_interface) self.updates_cmd.append("bridge-domain %s" % self.bridge_domain_id) xml_str = CE_NC_MERGE_BD_INTF % ( self.bridge_domain_id, self.l2_sub_interface) else: if self.l2_sub_interface in self.vap_info["intfList"]: self.updates_cmd.append("interface %s" % self.l2_sub_interface) self.updates_cmd.append( "undo bridge-domain %s" % self.bridge_domain_id) xml_str = CE_NC_DELETE_BD_INTF % ( self.bridge_domain_id, self.l2_sub_interface) if not xml_str: return recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "CONFIG_VAP_SUB_INTERFACE") self.changed = True
def config_vap_vlan(self): """configure a VLAN as a service access point""" if not self.vap_info: self.module.fail_json( msg="Error: Bridge domain %s does not exist." % self.bridge_domain_id) xml_str = "" if self.state == "present": if not is_vlan_in_bitmap(self.bind_vlan_id, self.vap_info["vlanList"]): self.updates_cmd.append("bridge-domain %s" % self.bridge_domain_id) self.updates_cmd.append("l2 binding vlan %s" % self.bind_vlan_id) vlan_bitmap = vlan_vid_to_bitmap(self.bind_vlan_id) xml_str = CE_NC_MERGE_BD_VLAN % (self.bridge_domain_id, vlan_bitmap, vlan_bitmap) else: if is_vlan_in_bitmap(self.bind_vlan_id, self.vap_info["vlanList"]): self.updates_cmd.append("bridge-domain %s" % self.bridge_domain_id) self.updates_cmd.append("undo l2 binding vlan %s" % self.bind_vlan_id) vlan_bitmap = vlan_vid_to_bitmap(self.bind_vlan_id) xml_str = CE_NC_MERGE_BD_VLAN % (self.bridge_domain_id, "0" * 1024, vlan_bitmap) if not xml_str: return recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "CONFIG_VAP_VLAN") self.changed = True
def config_global_dldp(self): """Config global dldp""" if self.same_conf: return enable = self.enable if not self.enable: enable = self.dldp_conf['dldpEnable'] if enable == 'enable': enable = 'true' else: enable = 'false' internal = self.internal if not self.internal: internal = self.dldp_conf['dldpInterval'] work_mode = self.work_mode if not self.work_mode: work_mode = self.dldp_conf['dldpWorkMode'] if work_mode == 'enhance' or work_mode == 'dldpEnhance': work_mode = 'dldpEnhance' else: work_mode = 'dldpNormal' auth_mode = self.auth_mode if not self.auth_mode: auth_mode = self.dldp_conf['dldpAuthMode'] if auth_mode == 'md5': auth_mode = 'dldpAuthMD5' elif auth_mode == 'simple': auth_mode = 'dldpAuthSimple' elif auth_mode == 'sha': auth_mode = 'dldpAuthSHA' elif auth_mode == 'hmac-sha256': auth_mode = 'dldpAuthHMAC-SHA256' elif auth_mode == 'none': auth_mode = 'dldpAuthNone' xml_str = CE_NC_MERGE_DLDP_GLOBAL_CONFIG_HEAD % (enable, internal, work_mode) if self.auth_mode: if self.auth_mode == 'none': xml_str += "<dldpAuthMode>dldpAuthNone</dldpAuthMode>" else: xml_str += "<dldpAuthMode>%s</dldpAuthMode>" % auth_mode xml_str += "<dldpPasswords>%s</dldpPasswords>" % self.auth_pwd xml_str += CE_NC_MERGE_DLDP_GLOBAL_CONFIG_TAIL ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "MERGE_DLDP_GLOBAL_CONFIG") if self.reset == 'enable': xml_str = CE_NC_ACTION_RESET_DLDP ret_xml = execute_nc_action(self.module, xml_str) self.check_response(ret_xml, "ACTION_RESET_DLDP") self.changed = True
def netconf_set_config(self, xml_str, xml_name): """ netconf set config """ recv_xml = set_nc_config(self.module, xml_str) if "<ok/>" not in recv_xml: self.module.fail_json(msg='Error: %s failed.' % xml_name)
def set_mlag_interface(self): """set mlag interface atrribute info""" if self.is_mlag_interface_info_change(): mlag_port = "Eth-Trunk" mlag_port += self.eth_trunk_id conf_str = CE_NC_SET_LACP_MLAG_INFO_HEAD % mlag_port if self.mlag_priority_id: conf_str += "<lacpMlagPriority>%s</lacpMlagPriority>" % self.mlag_priority_id if self.mlag_system_id: conf_str += "<lacpMlagSysId>%s</lacpMlagSysId>" % self.mlag_system_id conf_str += CE_NC_SET_LACP_MLAG_INFO_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json( msg='Error: set mlag interface atrribute info failed.') self.updates_cmd.append("interface %s" % mlag_port) if self.mlag_priority_id: self.updates_cmd.append("lacp m-lag priority %s" % self.mlag_priority_id) if self.mlag_system_id: self.updates_cmd.append("lacp m-lag system-id %s" % self.mlag_system_id) self.changed = True
def config_delete_vni_peer_ip(self, nve_name, vni_id, peer_ip_list): """remove vni peer ip""" for peer_ip in peer_ip_list: if not self.is_vni_peer_list_exist(nve_name, vni_id, peer_ip): self.module.fail_json(msg='Error: The %s does not exist' % peer_ip) config = self.get_current_config(vni_id, peer_ip_list) if not config: cfg_xml = CE_NC_DELETE_VNI_PEER_ADDRESS_IP_HEAD % ( nve_name, vni_id) for peer_ip in peer_ip_list: cfg_xml += CE_NC_DELETE_VNI_PEER_ADDRESS_IP_DELETE % peer_ip cfg_xml += CE_NC_DELETE_VNI_PEER_ADDRESS_IP_END else: cfg_xml = CE_NC_DELETE_PEER_ADDRESS_IP_HEAD % ( nve_name, vni_id) for peer_ip in peer_ip_list: cfg_xml += CE_NC_DELETE_VNI_PEER_ADDRESS_IP_DELETE % peer_ip cfg_xml += CE_NC_DELETE_PEER_ADDRESS_IP_END recv_xml = set_nc_config(self.module, cfg_xml) self.check_response(recv_xml, "DELETE_VNI_PEER_IP") self.updates_cmd.append("interface %s" % nve_name) for peer_ip in peer_ip_list: cmd_output = "undo vni %s head-end peer-list %s" % (vni_id, peer_ip) self.updates_cmd.append(cmd_output) self.changed = True
def config_vap_vlan(self): """configure a VLAN as a service access point""" if not self.vap_info: self.module.fail_json(msg="Error: Bridge domain %s does not exist." % self.bridge_domain_id) xml_str = "" if self.state == "present": if not is_vlan_in_bitmap(self.bind_vlan_id, self.vap_info["vlanList"]): self.updates_cmd.append("bridge-domain %s" % self.bridge_domain_id) self.updates_cmd.append( "l2 binding vlan %s" % self.bind_vlan_id) vlan_bitmap = vlan_vid_to_bitmap(self.bind_vlan_id) xml_str = CE_NC_MERGE_BD_VLAN % ( self.bridge_domain_id, vlan_bitmap, vlan_bitmap) else: if is_vlan_in_bitmap(self.bind_vlan_id, self.vap_info["vlanList"]): self.updates_cmd.append("bridge-domain %s" % self.bridge_domain_id) self.updates_cmd.append( "undo l2 binding vlan %s" % self.bind_vlan_id) vlan_bitmap = vlan_vid_to_bitmap(self.bind_vlan_id) xml_str = CE_NC_MERGE_BD_VLAN % ( self.bridge_domain_id, "0" * 1024, vlan_bitmap) if not xml_str: return recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "CONFIG_VAP_VLAN") self.changed = True
def delete_process(self): """Delete ospf process""" xml_str = CE_NC_DELETE_PROCESS % self.process_id recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "DELETE_PROCESS") self.updates_cmd.append("undo ospf %s" % self.process_id) self.changed = True
def undo_config_vlan(self, vlanid): """Delete vlan.""" conf_str = CE_NC_DELETE_VLAN % vlanid recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "DELETE_VLAN") self.changed = True self.updates_cmd.append('undo vlan %s' % self.vlan_id)
def create_dfs_group(self): """create dfs group info""" conf_str = CE_NC_CREATE_DFS_GROUP_INFO_HEADER % self.dfs_group_id if self.priority_id and self.priority_id != 100: conf_str += "<priority>%s</priority>" % self.priority_id if self.ip_address: conf_str += "<ipAddress>%s</ipAddress>" % self.ip_address if self.vpn_instance_name: if not self.ip_address: self.module.fail_json( msg= 'Error: ip_address can not be null if vpn_instance_name is exist.' ) conf_str += "<srcVpnName>%s</srcVpnName>" % self.vpn_instance_name if self.nickname or self.pseudo_nickname or self.pseudo_priority: conf_str += "<trillType>" if self.nickname: conf_str += "<localNickname>%s</localNickname>" % self.nickname if self.pseudo_nickname: conf_str += "<pseudoNickname>%s</pseudoNickname>" % self.pseudo_nickname if self.pseudo_priority: if not self.pseudo_nickname: self.module.fail_json( msg= 'Error: pseudo_nickname can not be null if pseudo_priority is exist.' ) conf_str += "<pseudoPriority>%s</pseudoPriority>" % self.pseudo_priority conf_str += "</trillType>" conf_str += CE_NC_CREATE_DFS_GROUP_INFO_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json(msg='Error: Merge DFS group info failed.') self.updates_cmd.append("dfs-group 1") if self.priority_id: self.updates_cmd.append("priority %s" % self.priority_id) if self.ip_address: if self.vpn_instance_name: self.updates_cmd.append( "source ip %s vpn-instance %s" % (self.ip_address, self.vpn_instance_name)) else: self.updates_cmd.append("source ip %s" % self.ip_address) if self.nickname: self.updates_cmd.append("source nickname %s" % self.nickname) if self.pseudo_nickname: if self.pseudo_priority: self.updates_cmd.append( "pseudo-nickname %s priority %s" % (self.pseudo_nickname, self.pseudo_priority)) else: self.updates_cmd.append("pseudo-nickname %s" % self.pseudo_nickname) self.changed = True
def netconf_set_config(self, **kwargs): """ Set configure through netconf """ module = kwargs["module"] conf_str = kwargs["conf_str"] xml_str = set_nc_config(module, conf_str) return xml_str
def delete_interface(self, ifname): """ Delete interface.""" xmlstr = CE_NC_XML_DELETE_INTF % ifname conf_str = '<config> ' + xmlstr + ' </config>' self.updates_cmd.append('undo interface %s' % ifname) recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "DELETE_INTF") self.changed = True
def modify_dfs_group(self): """modify dfs group info""" if self.is_dfs_group_info_change(): conf_str = CE_NC_MERGE_DFS_GROUP_INFO_HEADER % self.dfs_group_id if self.priority_id and self.dfs_group_info["priority"] != self.priority_id: conf_str += "<priority>%s</priority>" % self.priority_id if self.ip_address and self.dfs_group_info["ipAddress"] != self.ip_address: conf_str += "<ipAddress>%s</ipAddress>" % self.ip_address if self.vpn_instance_name and self.dfs_group_info["srcVpnName"] != self.vpn_instance_name: if not self.ip_address: self.module.fail_json( msg='Error: ip_address can not be null if vpn_instance_name is exist.') conf_str += "<srcVpnName>%s</srcVpnName>" % self.vpn_instance_name if self.nickname or self.pseudo_nickname or self.pseudo_priority: conf_str += "<trillType>" if self.nickname and self.dfs_group_info["localNickname"] != self.nickname: conf_str += "<localNickname>%s</localNickname>" % self.nickname if self.pseudo_nickname and self.dfs_group_info["pseudoNickname"] != self.pseudo_nickname: conf_str += "<pseudoNickname>%s</pseudoNickname>" % self.pseudo_nickname if self.pseudo_priority and self.dfs_group_info["pseudoPriority"] != self.pseudo_priority: if not self.pseudo_nickname: self.module.fail_json( msg='Error: pseudo_nickname can not be null if pseudo_priority is exist.') conf_str += "<pseudoPriority>%s</pseudoPriority>" % self.pseudo_priority conf_str += "</trillType>" conf_str += CE_NC_MERGE_DFS_GROUP_INFO_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json( msg='Error: Merge DFS group info failed.') self.updates_cmd.append("dfs-group 1") if self.priority_id: self.updates_cmd.append("priority %s" % self.priority_id) if self.ip_address: if self.vpn_instance_name: self.updates_cmd.append( "source ip %s vpn-instance %s" % (self.ip_address, self.vpn_instance_name)) else: self.updates_cmd.append("source ip %s" % self.ip_address) if self.nickname: self.updates_cmd.append("source nickname %s" % self.nickname) if self.pseudo_nickname: if self.pseudo_priority: self.updates_cmd.append( "pseudo-nickname %s priority %s" % (self.pseudo_nickname, self.pseudo_priority)) else: self.updates_cmd.append( "pseudo-nickname %s" % self.pseudo_nickname) self.changed = True
def config_traffic_encap_qinq(self): """configure traffic encapsulation type qinq""" xml_str = "" self.updates_cmd.append("interface %s" % self.l2_sub_interface) if self.state == "present": if self.encapsulation != self.l2sub_info.get("flowType"): if self.ce_vid: vlan_bitmap = vlan_vid_to_bitmap(self.ce_vid) xml_str = CE_NC_SET_ENCAP_QINQ % (self.l2_sub_interface, self.pe_vid, vlan_bitmap, vlan_bitmap) self.updates_cmd.append( "encapsulation %s vid %s ce-vid %s" % (self.encapsulation, self.pe_vid, self.ce_vid)) else: xml_str = CE_NC_SET_ENCAP % ( self.l2_sub_interface, self.encapsulation) self.updates_cmd.append( "encapsulation %s" % self.encapsulation) else: if self.ce_vid: if not is_vlan_in_bitmap(self.ce_vid, self.l2sub_info.get("ceVids")) \ or self.pe_vid != self.l2sub_info.get("peVlanId"): vlan_bitmap = vlan_vid_to_bitmap(self.ce_vid) xml_str = CE_NC_SET_ENCAP_QINQ % (self.l2_sub_interface, self.pe_vid, vlan_bitmap, vlan_bitmap) self.updates_cmd.append( "encapsulation %s vid %s ce-vid %s" % (self.encapsulation, self.pe_vid, self.ce_vid)) else: if self.encapsulation == self.l2sub_info.get("flowType"): if self.ce_vid: if is_vlan_in_bitmap(self.ce_vid, self.l2sub_info.get("ceVids")) \ and self.pe_vid == self.l2sub_info.get("peVlanId"): xml_str = CE_NC_UNSET_ENCAP % self.l2_sub_interface self.updates_cmd.append( "undo encapsulation %s vid %s ce-vid %s" % (self.encapsulation, self.pe_vid, self.ce_vid)) else: xml_str = CE_NC_UNSET_ENCAP % self.l2_sub_interface self.updates_cmd.append( "undo encapsulation %s" % self.encapsulation) if not xml_str: self.updates_cmd.pop() return recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "CONFIG_INTF_ENCAP_QINQ") self.changed = True
def config_merge_vni2bd(self, bd_id, vni_id): """config vni to bd id""" if self.is_vni_bd_change(vni_id, bd_id): cfg_xml = CE_NC_MERGE_VNI_BD_ID % (vni_id, bd_id) recv_xml = set_nc_config(self.module, cfg_xml) self.check_response(recv_xml, "MERGE_VNI_BD") self.updates_cmd.append("bridge-domain %s" % bd_id) self.updates_cmd.append("vxlan vni %s" % vni_id) self.changed = True
def config_merge_mode(self, nve_name, mode): """config nve mode""" if self.is_nve_mode_change(nve_name, mode): cfg_xml = CE_NC_MERGE_NVE_MODE % (nve_name, mode) recv_xml = set_nc_config(self.module, cfg_xml) self.check_response(recv_xml, "MERGE_MODE") self.updates_cmd.append("interface %s" % nve_name) self.updates_cmd.append("mode l3") self.changed = True
def config_ntp_auth_keyid(self): """Config ntp authentication keyid""" if self.trusted_key == 'enable': trusted_key = 'true' else: trusted_key = 'false' xml_str = CE_NC_MERGE_NTP_AUTH_CONFIG % ( self.key_id, self.auth_mode.upper(), self.password, trusted_key) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "NTP_AUTH_KEYID_CONFIG")
def delete_dfs_group(self): """delete dfg group""" conf_str = CE_NC_DELETE_DFS_GROUP_INFO_HEADER % self.dfs_group_id conf_str += CE_NC_DELETE_DFS_GROUP_INFO_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json(msg='Error: Delete DFS group id failed.') self.updates_cmd.append("undo dfs-group 1") self.changed = True
def config_merge_source_ip(self, nve_name, source_ip): """config nve source ip""" if self.is_nve_source_ip_change(nve_name, source_ip): cfg_xml = CE_NC_MERGE_NVE_SOURCE_IP_PROTOCOL % ( nve_name, source_ip) recv_xml = set_nc_config(self.module, cfg_xml) self.check_response(recv_xml, "MERGE_SOURCE_IP") self.updates_cmd.append("interface %s" % nve_name) self.updates_cmd.append("source %s" % source_ip) self.changed = True
def config_ntp_auth_enable(self): """Config ntp authentication enable""" if self.ntp_auth_conf['authentication'] != self.authentication: if self.authentication == 'enable': state = 'true' else: state = 'false' xml_str = CE_NC_MERGE_NTP_AUTH_ENABLE % state ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "NTP_AUTH_ENABLE")
def config_vlan(self, vlan_id, name='', description=''): """Create vlan.""" if name is None: name = '' if description is None: description = '' conf_str = CE_NC_CREATE_VLAN % (vlan_id, name, description) recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "CREATE_VLAN") self.changed = True
def delete_dfs_group(self): """delete dfg group""" conf_str = CE_NC_DELETE_DFS_GROUP_INFO_HEADER % self.dfs_group_id conf_str += CE_NC_DELETE_DFS_GROUP_INFO_TAIL recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json( msg='Error: Delete DFS group id failed.') self.updates_cmd.append("undo dfs-group 1") self.changed = True
def merge_interfaces(self, iftype, description, admin_state, mode): """ Merge interface attributes by type.""" xmlstr = '' change = False intfs_list = self.intfs_info.get(iftype.lower()) if not intfs_list: return for intf in intfs_list: if_change = False self.updates_cmd.append("interface %s" % intf['ifName']) if description and intf["ifDescr"] != description: xmlstr += CE_NC_XML_MERGE_INTF_DES % ( intf['ifName'], description) self.updates_cmd.append("description %s" % description) if_change = True if admin_state and is_admin_state_enable(self.intf_type)\ and intf["ifAdminStatus"] != admin_state: xmlstr += CE_NC_XML_MERGE_INTF_STATUS % ( intf['ifName'], admin_state) if_change = True if admin_state == "up": self.updates_cmd.append("undo shutdown") else: self.updates_cmd.append("shutdown") if is_portswitch_enalbe(self.intf_type): if mode == "layer2" \ and intf["isL2SwitchPort"] != "true": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % ( intf['ifName'], 'enable') self.updates_cmd.append("portswitch") if_change = True elif mode == "layer3" \ and intf["isL2SwitchPort"] != "false": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % ( intf['ifName'], 'disable') self.updates_cmd.append("undo portswitch") if_change = True if if_change: change = True else: self.updates_cmd.pop() if not change: return conf_str = '<config> ' + xmlstr + ' </config>' recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "MERGE_INTFS_ATTR") self.changed = True
def merge_interfaces(self, iftype, description, admin_state, mode): """ Merge interface attributes by type.""" xmlstr = '' change = False intfs_list = self.intfs_info.get(iftype.lower()) if not intfs_list: return for intf in intfs_list: if_change = False self.updates_cmd.append("interface %s" % intf['ifName']) if description and intf["ifDescr"] != description: xmlstr += CE_NC_XML_MERGE_INTF_DES % (intf['ifName'], description) self.updates_cmd.append("description %s" % description) if_change = True if admin_state and is_admin_state_enable(self.intf_type)\ and intf["ifAdminStatus"] != admin_state: xmlstr += CE_NC_XML_MERGE_INTF_STATUS % (intf['ifName'], admin_state) if_change = True if admin_state == "up": self.updates_cmd.append("undo shutdown") else: self.updates_cmd.append("shutdown") if is_portswitch_enalbe(self.intf_type): if mode == "layer2" \ and intf["isL2SwitchPort"] != "true": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % (intf['ifName'], 'enable') self.updates_cmd.append("portswitch") if_change = True elif mode == "layer3" \ and intf["isL2SwitchPort"] != "false": xmlstr += CE_NC_XML_MERGE_INTF_L2ENABLE % (intf['ifName'], 'disable') self.updates_cmd.append("undo portswitch") if_change = True if if_change: change = True else: self.updates_cmd.pop() if not change: return conf_str = '<config> ' + xmlstr + ' </config>' recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "MERGE_INTFS_ATTR") self.changed = True
def set_ntp(self, *args): """Configure ntp parameters""" if self.state == 'present': if self.ip_ver == 'IPv4': xml_str = CE_NC_MERGE_NTP_CONFIG % ( args[0], args[1], '::', args[2], args[3], args[4], args[5], args[6]) elif self.ip_ver == 'IPv6': xml_str = CE_NC_MERGE_NTP_CONFIG % ( args[0], '0.0.0.0', args[1], args[2], args[3], args[4], args[5], args[6]) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "NTP_CORE_CONFIG") else: if self.ip_ver == 'IPv4': xml_str = CE_NC_DELETE_NTP_CONFIG % ( args[0], args[1], '::', args[2], args[3]) elif self.ip_ver == 'IPv6': xml_str = CE_NC_DELETE_NTP_CONFIG % ( args[0], '0.0.0.0', args[1], args[2], args[3]) ret_xml = set_nc_config(self.module, xml_str) self.check_response(ret_xml, "UNDO_NTP_CORE_CONFIG")
def delete_peer_link(self): """delete peer link info""" eth_trunk_id = "Eth-Trunk" eth_trunk_id += self.eth_trunk_id conf_str = CE_NC_DELETE_PEER_LINK_INFO % (self.peer_link_id, eth_trunk_id) recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json(msg='Error: Delete peer link failed.') self.updates_cmd.append("undo peer-link %s" % self.peer_link_id) self.changed = True
def remove_area(self): """remove ospf area""" if not self.is_area_exist(): return xml_area = CE_NC_XML_BUILD_DELETE_AREA % (self.get_area_ip(), "") xml_str = CE_NC_XML_BUILD_PROCESS % (self.process_id, xml_area) recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "DELETE_AREA") self.updates_cmd.append("ospf %s" % self.process_id) self.updates_cmd.append("undo area %s" % self.get_area_ip()) self.changed = True
def config_delete_vni_protocol_type(self, nve_name, vni_id, protocol_type): """remove vni protocol type""" if not self.is_vni_protocol_exist(nve_name, vni_id, protocol_type): return cfg_xml = CE_NC_DELETE_VNI_PROTOCOL % (nve_name, vni_id, protocol_type) recv_xml = set_nc_config(self.module, cfg_xml) self.check_response(recv_xml, "DELETE_VNI_PEER_PROTOCOL") self.updates_cmd.append("interface %s" % nve_name) self.updates_cmd.append( "undo vni %s head-end peer-list protocol bgp " % vni_id) self.changed = True
def config_delete_source_ip(self, nve_name, source_ip): """nve source ip""" if not self.is_nve_source_ip_exist(nve_name, source_ip): return ipaddr = "0.0.0.0" cfg_xml = CE_NC_MERGE_NVE_SOURCE_IP_PROTOCOL % ( nve_name, ipaddr) recv_xml = set_nc_config(self.module, cfg_xml) self.check_response(recv_xml, "DELETE_SOURCE_IP") self.updates_cmd.append("interface %s" % nve_name) self.updates_cmd.append("undo source %s" % source_ip) self.changed = True
def delete_peer_link(self): """delete peer link info""" eth_trunk_id = "Eth-Trunk" eth_trunk_id += self.eth_trunk_id conf_str = CE_NC_DELETE_PEER_LINK_INFO % ( self.peer_link_id, eth_trunk_id) recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json( msg='Error: Delete peer link failed.') self.updates_cmd.append("undo peer-link %s" % self.peer_link_id) self.changed = True
def create_mlag_error_down(self): """create mlag error down info""" if self.is_mlag_error_down_info_change(): conf_str = CE_NC_CREATE_MLAG_ERROR_DOWN_INFO % self.interface recv_xml = set_nc_config(self.module, conf_str) if "<ok/>" not in recv_xml: self.module.fail_json( msg='Error: create mlag error down info failed.') self.updates_cmd.append("interface %s" % self.interface) self.updates_cmd.append("m-lag unpaired-port suspend") self.changed = True
def remove_nexthop(self): """remove ospf nexthop weight""" if not self.is_nexthop_exist(): return xml_nh = CE_NC_XML_DELETE_NEXTHOP % self.nexthop_addr xml_topo = CE_NC_XML_BUILD_TOPO % xml_nh xml_str = CE_NC_XML_BUILD_PROCESS % (self.process_id, xml_topo) recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "DELETE_NEXTHOP_WEIGHT") self.updates_cmd.append("ospf %s" % self.process_id) self.updates_cmd.append("undo nexthop %s" % self.nexthop_addr) self.changed = True
def config_traffic_encap(self): """configure traffic encapsulation types""" if not self.l2sub_info: self.module.fail_json(msg="Error: Interface %s does not exist." % self.l2_sub_interface) if not self.encapsulation: return xml_str = "" if self.encapsulation in ["default", "untag"]: if self.state == "present": if self.encapsulation != self.l2sub_info.get("flowType"): xml_str = CE_NC_SET_ENCAP % ( self.l2_sub_interface, self.encapsulation) self.updates_cmd.append( "interface %s" % self.l2_sub_interface) self.updates_cmd.append( "encapsulation %s" % self.encapsulation) else: if self.encapsulation == self.l2sub_info.get("flowType"): xml_str = CE_NC_UNSET_ENCAP % self.l2_sub_interface self.updates_cmd.append( "interface %s" % self.l2_sub_interface) self.updates_cmd.append( "undo encapsulation %s" % self.encapsulation) elif self.encapsulation == "none": if self.state == "present": if self.encapsulation != self.l2sub_info.get("flowType"): xml_str = CE_NC_UNSET_ENCAP % self.l2_sub_interface self.updates_cmd.append( "interface %s" % self.l2_sub_interface) self.updates_cmd.append( "undo encapsulation %s" % self.l2sub_info.get("flowType")) elif self.encapsulation == "dot1q": self.config_traffic_encap_dot1q() return elif self.encapsulation == "qinq": self.config_traffic_encap_qinq() return else: pass if not xml_str: return recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "CONFIG_INTF_ENCAP") self.changed = True
def operate_vrf(self): """config/delete vrf""" if not self.changed: return if self.state == "present": if self.description is None: configxmlstr = CE_NC_CREATE_VRF % (self.vrf, '') else: configxmlstr = CE_NC_CREATE_VRF % (self.vrf, self.description) else: configxmlstr = CE_NC_DELETE_VRF % (self.vrf, self.description) conf_str = build_config_xml(configxmlstr) recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "OPERATE_VRF")
def netconf_load_config(self, xml_str): """load log config by netconf""" if not xml_str: return xml_cfg = """ <config> <syslog xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"> %s </syslog> </config>""" % xml_str recv_xml = set_nc_config(self.module, xml_cfg) self.check_response(recv_xml, "SET_LOG") self.changed = True
def delete_interfaces(self, iftype): """ Delete interfaces with type.""" xmlstr = '' intfs_list = self.intfs_info.get(iftype.lower()) if not intfs_list: return for intf in intfs_list: xmlstr += CE_NC_XML_DELETE_INTF % intf['ifName'] self.updates_cmd.append('undo interface %s' % intf['ifName']) conf_str = '<config> ' + xmlstr + ' </config>' recv_xml = set_nc_config(self.module, conf_str) self.check_response(recv_xml, "DELETE_INTFS") self.changed = True
def remove_area_network(self): """remvoe ospf area network""" if not self.is_network_exist(): return xml_network = CE_NC_XML_DELETE_NETWORKS % ( self.addr, self.get_wildcard_mask()) xml_area = CE_NC_XML_BUILD_AREA % (self.get_area_ip(), xml_network) xml_str = CE_NC_XML_BUILD_PROCESS % (self.process_id, xml_area) recv_xml = set_nc_config(self.module, xml_str) self.check_response(recv_xml, "DELETE_AREA_NETWORK") self.updates_cmd.append("ospf %s" % self.process_id) self.updates_cmd.append("area %s" % self.get_area_ip()) self.updates_cmd.append("undo network %s %s" % (self.addr, self.get_wildcard_mask())) self.changed = True