Beispiel #1
0
    def netconf_set_action(self, xml_str):
        """ netconf execute action """

        try:
            execute_nc_action(self.network_module, xml_str)
        except TimeoutExpiredError:
            pass
    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
Beispiel #3
0
    def delete_vlan_batch(self, vlan_list):
        """Delete vlan batch."""

        if not vlan_list:
            return

        vlan_bitmap = self.vlan_list_to_bitmap(vlan_list)
        xmlstr = CE_NC_DELETE_VLAN_BATCH % (vlan_bitmap, vlan_bitmap)

        recv_xml = execute_nc_action(self.module, xmlstr)
        self.check_response(recv_xml, "DELETE_VLAN_BATCH")
        self.updates_cmd.append(
            'undo vlan batch %s' %
            (self.vlan_range.replace(',', ' ').replace('-', ' to ')))
        self.changed = True
Beispiel #4
0
    def config_intf_dldp(self):
        """Config global dldp"""

        if self.same_conf:
            return

        if self.state == "present":
            enable = self.enable
            if not self.enable:
                enable = self.dldp_intf_conf['dldpEnable']
            if enable == 'enable':
                enable = 'true'
            else:
                enable = 'false'

            mode_enable = self.mode_enable
            if not self.mode_enable:
                mode_enable = self.dldp_intf_conf['dldpCompatibleEnable']
            if mode_enable == 'enable':
                mode_enable = 'true'
            else:
                mode_enable = 'false'

            local_mac = self.local_mac
            if not self.local_mac:
                local_mac = self.dldp_intf_conf['dldpLocalMac']

            if self.enable == 'disable' and self.enable != self.dldp_intf_conf[
                    'dldpEnable']:
                xml_str = CE_NC_DELETE_DLDP_INTF_CONFIG % self.interface
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "DELETE_DLDP_INTF_CONFIG")
            elif self.dldp_intf_conf[
                    'dldpEnable'] == 'disable' and self.enable == 'enable':
                xml_str = CE_NC_CREATE_DLDP_INTF_CONFIG % (
                    self.interface, 'true', mode_enable, local_mac)
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "CREATE_DLDP_INTF_CONFIG")
            elif self.dldp_intf_conf['dldpEnable'] == 'enable':
                if mode_enable == 'false':
                    local_mac = ''
                xml_str = CE_NC_MERGE_DLDP_INTF_CONFIG % (
                    self.interface, enable, mode_enable, local_mac)
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "MERGE_DLDP_INTF_CONFIG")

            if self.reset == 'enable':
                xml_str = CE_NC_ACTION_RESET_INTF_DLDP % self.interface
                ret_xml = execute_nc_action(self.module, xml_str)
                self.check_response(ret_xml, "ACTION_RESET_INTF_DLDP")

            self.changed = True
        else:
            if self.local_mac and judge_is_mac_same(
                    self.local_mac, self.dldp_intf_conf['dldpLocalMac']):
                if self.dldp_intf_conf['dldpEnable'] == 'enable':
                    dldp_enable = 'true'
                else:
                    dldp_enable = 'false'
                if self.dldp_intf_conf['dldpCompatibleEnable'] == 'enable':
                    dldp_compat_enable = 'true'
                else:
                    dldp_compat_enable = 'false'
                xml_str = CE_NC_MERGE_DLDP_INTF_CONFIG % (
                    self.interface, dldp_enable, dldp_compat_enable, '')
                ret_xml = set_nc_config(self.module, xml_str)
                self.check_response(ret_xml, "UNDO_DLDP_INTF_LOCAL_MAC_CONFIG")
                self.changed = True
Beispiel #5
0
def main():
    """ main """

    argument_spec = dict(
        rpc=dict(choices=['get', 'edit-config',
                          'execute-action', 'execute-cli'], required=True),
        cfg_xml=dict(required=True)
    )

    argument_spec.update(ce_argument_spec)
    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    rpc = module.params['rpc']
    cfg_xml = module.params['cfg_xml']
    changed = False
    end_state = dict()

    if rpc == "get":

        response = get_nc_config(module, cfg_xml)

        if "<data/>" in response:
            end_state["result"] = "<data/>"
        else:
            tmp1 = response.split(r"<data>")
            tmp2 = tmp1[1].split(r"</data>")
            result = tmp2[0].split("\n")

            end_state["result"] = result

    elif rpc == "edit-config":

        response = set_nc_config(module, cfg_xml)

        if "<ok/>" not in response:
            module.fail_json(msg='rpc edit-config failed.')

        changed = True
        end_state["result"] = "ok"

    elif rpc == "execute-action":

        response = execute_nc_action(module, cfg_xml)

        if "<ok/>" not in response:
            module.fail_json(msg='rpc execute-action failed.')

        changed = True
        end_state["result"] = "ok"

    elif rpc == "execute-cli":

        response = execute_nc_cli(module, cfg_xml)

        if "<data/>" in response:
            end_state["result"] = "<data/>"
        else:
            tmp1 = response.split(r"<data>")
            tmp2 = tmp1[1].split(r"</data>")
            result = tmp2[0].split("\n")

            end_state["result"] = result

    else:
        module.fail_json(msg='please input correct rpc.')

    results = dict()
    results['changed'] = changed
    results['end_state'] = end_state

    module.exit_json(**results)