Пример #1
0
    def netconf_set_action(self, xml_str):
        """ netconf execute action """

        try:
            execute_nc_action(self.network_module, xml_str)
        except TimeoutExpiredError:
            pass
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    def rollback_last(self):
        """rollback last"""

        cfg_xml = ""
        self.updates_cmd.append("rollback configuration to last %s" %
                                self.last)
        cfg_xml = CE_NC_ACTION_ROLLBACK_LAST % self.last
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "ROLLBACK_LAST")
        self.changed = True
Пример #5
0
    def clear_oldest(self):
        """clear oldest"""

        cfg_xml = ""
        self.updates_cmd.append(
            "clear configuration commit oldest %s" % self.oldest)
        cfg_xml = CE_NC_ACTION_CLEAR_OLDEST_COMMIT_ID % self.oldest
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "CLEAR_COMMIT_OLDEST")
        self.changed = True
Пример #6
0
    def clear_commitid_label(self):
        """clear commitid label"""

        cfg_xml = ""
        self.updates_cmd.append(
            "clear configuration commit %s label" % self.commit_id)
        cfg_xml = CE_NC_ACTION_CLEAR_COMMIT_ID_LABEL % self.commit_id
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "CLEAR_COMMIT_LABEL")
        self.changed = True
Пример #7
0
    def rollback_last(self):
        """rollback last"""

        cfg_xml = ""
        self.updates_cmd.append(
            "rollback configuration to last %s" % self.last)
        cfg_xml = CE_NC_ACTION_ROLLBACK_LAST % self.last
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "ROLLBACK_LAST")
        self.changed = True
Пример #8
0
    def rollback_commit_id(self):
        """rollback comit_id"""

        cfg_xml = ""
        self.updates_cmd.append(
            "rollback configuration to commit-id %s" % self.commit_id)
        cfg_xml = CE_NC_ACTION_ROLLBACK_COMMIT_ID % self.commit_id
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "ROLLBACK_COMMITID")
        self.changed = True
Пример #9
0
    def rollback_filename(self):
        """rollback filename"""

        cfg_xml = ""
        self.updates_cmd.append(
            "rollback configuration to file %s" % self.filename)
        cfg_xml = CE_NC_ACTION_ROLLBACK_FILE % self.filename
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "ROLLBACK_FILENAME")
        self.changed = True
Пример #10
0
    def clear_commitid_label(self):
        """clear commitid label"""

        cfg_xml = ""
        self.updates_cmd.append("clear configuration commit %s label" %
                                self.commit_id)
        cfg_xml = CE_NC_ACTION_CLEAR_COMMIT_ID_LABEL % self.commit_id
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "CLEAR_COMMIT_LABEL")
        self.changed = True
Пример #11
0
    def clear_oldest(self):
        """clear oldest"""

        cfg_xml = ""
        self.updates_cmd.append("clear configuration commit oldest %s" %
                                self.oldest)
        cfg_xml = CE_NC_ACTION_CLEAR_OLDEST_COMMIT_ID % self.oldest
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "CLEAR_COMMIT_OLDEST")
        self.changed = True
Пример #12
0
    def rollback_filename(self):
        """rollback filename"""

        cfg_xml = ""
        self.updates_cmd.append("rollback configuration to file %s" %
                                self.filename)
        cfg_xml = CE_NC_ACTION_ROLLBACK_FILE % self.filename
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "ROLLBACK_FILENAME")
        self.changed = True
Пример #13
0
    def rollback_commit_id(self):
        """rollback comit_id"""

        cfg_xml = ""
        self.updates_cmd.append("rollback configuration to commit-id %s" %
                                self.commit_id)
        cfg_xml = CE_NC_ACTION_ROLLBACK_COMMIT_ID % self.commit_id
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "ROLLBACK_COMMITID")
        self.changed = True
Пример #14
0
    def set_commitid_label(self):
        """set commitid label"""

        cfg_xml = ""
        self.updates_cmd.append(
            "set configuration commit %s label %s" % (self.commit_id, self.label))
        cfg_xml = CE_NC_ACTION_SET_COMMIT_ID_LABEL % (
            self.commit_id, self.label)
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "SET_COMIMIT_LABEL")
        self.changed = True
Пример #15
0
    def set_commitid_label(self):
        """set commitid label"""

        cfg_xml = ""
        self.updates_cmd.append("set configuration commit %s label %s" %
                                (self.commit_id, self.label))
        cfg_xml = CE_NC_ACTION_SET_COMMIT_ID_LABEL % (self.commit_id,
                                                      self.label)
        recv_xml = execute_nc_action(self.module, cfg_xml)
        self.check_response(recv_xml, "SET_COMIMIT_LABEL")
        self.changed = True
Пример #16
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
Пример #17
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
Пример #18
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.xml.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)
Пример #19
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
Пример #20
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.xml.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)