Example #1
0
    def work(self):
        """worker"""

        self.check_params()
        existing = self.get_existing()
        proposed = self.get_proposed()

        # deal present or absent
        if self.state == "present":
            operation = 'merge'
        else:
            operation = 'delete'

        xml_str = bulid_xml(self.param, operation=operation)
        set_nc_config(self.module, xml_str)
        end_state = self.get_end_state()

        self.results['proposed'] = proposed
        self.results['existing'] = existing
        self.results['end_state'] = end_state
        updates_cmd = compare_config(self.module, existing, end_state)
        self.results['updates'] = updates_cmd
        if updates_cmd:
            self.results['changed'] = True
        else:
            self.results['changed'] = False

        self.module.exit_json(**self.results)
    def netconf_load_config(self, xml_str):
        """load bfd config by netconf"""

        if not xml_str:
            return

        xml_cfg = """
            <config>
            <isiscomm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
            %s
            </isiscomm>
            </config>""" % xml_str
        set_nc_config(self.module, xml_cfg)
        self.changed = True
Example #3
0
    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_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
Example #5
0
    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
Example #6
0
    def delete_mlag_interface(self):
        """delete mlag interface attribute info"""

        if self.is_mlag_interface_info_exist():
            mlag_port = "Eth-Trunk"
            mlag_port += self.eth_trunk_id
            conf_str = CE_NC_SET_LACP_MLAG_INFO_HEAD % mlag_port
            cmd = "interface %s" % mlag_port
            self.cli_add_command(cmd)

            if self.mlag_priority_id:
                cmd = "lacp m-lag priority %s" % self.mlag_priority_id
                conf_str += "<lacpMlagPriority></lacpMlagPriority>"
                self.cli_add_command(cmd, True)

            if self.mlag_system_id:
                cmd = "lacp m-lag system-id %s" % self.mlag_system_id
                conf_str += "<lacpMlagSysId></lacpMlagSysId>"
                self.cli_add_command(cmd, True)

            if self.commands:
                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.changed = True
Example #7
0
    def set_mlag_interface(self):
        """set mlag interface attribute 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 attribute 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
Example #8
0
    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
Example #9
0
    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
Example #10
0
    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
Example #11
0
    def delete_dfs_group_nick(self):

        conf_str = CE_NC_DELETE_DFS_GROUP_ATTRIBUTE_HEADER % self.dfs_group_id
        conf_str = conf_str.replace('<groupInstance  operation="delete">', '<groupInstance>')
        change = False

        if self.nickname or self.pseudo_nickname:
            conf_str += "<trillType operation='delete'>"
            if self.nickname and self.dfs_group_info["localNickname"] == self.nickname:
                conf_str += "<localNickname>%s</localNickname>" % self.nickname
                change = True
                self.updates_cmd.append("undo source nickname %s" % 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:
                    self.updates_cmd.append(
                        "undo pseudo-nickname %s priority %s" % (self.pseudo_nickname, self.pseudo_priority))
                if not self.pseudo_priority:
                    self.updates_cmd.append(
                        "undo pseudo-nickname %s" % self.pseudo_nickname)
                change = True
            conf_str += "</trillType>"

        conf_str += CE_NC_DELETE_DFS_GROUP_ATTRIBUTE_TAIL

        if change:
            recv_xml = set_nc_config(self.module, conf_str)
            if "<ok/>" not in recv_xml:
                self.module.fail_json(
                    msg='Error: Delete DFS group attribute failed.')
            self.changed = True
Example #12
0
    def delete_dfs_group_attribute(self):
        """delete dfg group attribute info"""

        conf_str = CE_NC_DELETE_DFS_GROUP_ATTRIBUTE_HEADER % self.dfs_group_id
        change = False
        if self.priority_id and self.dfs_group_info["priority"] == self.priority_id:
            conf_str += "<priority>%s</priority>" % self.priority_id
            change = True
            self.updates_cmd.append("undo priority %s" % self.priority_id)
        if self.ip_address and self.dfs_group_info["ipAddress"] == self.ip_address:
            if self.vpn_instance_name and self.dfs_group_info["srcVpnName"] == self.vpn_instance_name:
                conf_str += "<ipAddress>%s</ipAddress>" % self.ip_address
                conf_str += "<srcVpnName>%s</srcVpnName>" % self.vpn_instance_name
                self.updates_cmd.append(
                    "undo source ip %s vpn-instance %s" % (self.ip_address, self.vpn_instance_name))
            else:
                conf_str += "<ipAddress>%s</ipAddress>" % self.ip_address
                self.updates_cmd.append("undo source ip %s" % self.ip_address)
            change = True

        conf_str += CE_NC_DELETE_DFS_GROUP_ATTRIBUTE_TAIL

        if change:
            self.updates_cmd.append("undo dfs-group 1")
            recv_xml = set_nc_config(self.module, conf_str)
            if "<ok/>" not in recv_xml:
                self.module.fail_json(
                    msg='Error: Delete DFS group attribute failed.')
            self.changed = True
Example #13
0
    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_vlanview_igmp(self):
     """set igmp of vlanview"""
     if not self.changed:
         return
     addr_family = self.addr_family
     state = self.state
     igmp_xml = """\n"""
     version_xml = """\n"""
     proxy_xml = """\n"""
     if state == "present":
         if self.igmp:
             igmp_xml = get_xml(CE_NC_MERGE_IGMP_VLANVIEW_SNOENABLE,
                                self.igmp.lower())
         if str(self.version):
             version_xml = get_xml(CE_NC_MERGE_IGMP_VLANVIEW_VERSION,
                                   self.version)
         if self.proxy:
             proxy_xml = get_xml(CE_NC_MERGE_IGMP_VLANVIEW_PROXYENABLE,
                                 self.proxy.lower())
         configxmlstr = CE_NC_MERGE_IGMP_VLANVIEW % (
             addr_family, self.vlan_id, igmp_xml, version_xml, proxy_xml)
     else:
         configxmlstr = CE_NC_DELETE_IGMP_VLANVIEW % (addr_family,
                                                      self.vlan_id)
     conf_str = build_config_xml(configxmlstr)
     recv_xml = set_nc_config(self.module, conf_str)
     self._checkresponse_(recv_xml, "SET_VLANVIEW_IGMP")
Example #15
0
    def config_vap_vlan(self):
        """configure a VLAN as a service access point"""

        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
Example #16
0
    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
Example #17
0
    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
Example #19
0
    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
Example #20
0
    def netconf_set_config(self, **kwargs):
        """ Set configure by netconf """

        module = kwargs["module"]
        conf_str = kwargs["conf_str"]

        xml_str = set_nc_config(module, conf_str)

        return xml_str
Example #21
0
    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
Example #22
0
    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
Example #23
0
    def config_interface_mdn(self):
        """Configure lldp enabled and interface mdn enabled parameters"""

        if self.state == 'present':
            if self.enable_flag == 0 and self.lldpenable == 'enabled':
                xml_str = CE_NC_MERGE_GLOBA_LLDPENABLE_CONFIG % self.lldpenable
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "LLDP_ENABLE_CONFIG")
                self.changed = True
            elif self.enable_flag == 1 and self.lldpenable == 'disabled':
                xml_str = CE_NC_MERGE_GLOBA_LLDPENABLE_CONFIG % self.lldpenable
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "LLDP_ENABLE_CONFIG")
                self.changed = True
            elif self.enable_flag == 1 and self.conf_exsit:
                xml_str = CE_NC_MERGE_INTERFACE_MDNENABLE_CONFIG % (
                    self.ifname, self.mdnstatus)
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "INTERFACE_MDN_ENABLE_CONFIG")
                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
Example #25
0
    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
Example #26
0
    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
Example #27
0
    def config_delete_vni2bd(self, bd_id, vni_id):
        """remove vni to bd id"""

        if not self.is_vni_bd_exist(vni_id, bd_id):
            return
        cfg_xml = CE_NC_DELETE_VNI_BD_ID % (vni_id, bd_id)
        recv_xml = set_nc_config(self.module, cfg_xml)
        self.check_response(recv_xml, "DELETE_VNI_BD")
        self.updates_cmd.append("bridge-domain %s" % bd_id)
        self.updates_cmd.append("undo vxlan vni %s" % vni_id)

        self.changed = True
Example #28
0
    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
Example #29
0
    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
Example #30
0
    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