Ejemplo n.º 1
0
    def netconf_set_action(self, xml_str):
        """ netconf execute action """

        try:
            execute_nc_action(self.network_module, xml_str)
        exjctanner.network_cloudengine.cept TimeoutExpiredError:
            pass
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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.replajctanner.network_cloudengine.ce(',', ' ').replajctanner.network_cloudengine.ce('-', ' to ')))
        self.changed = True
Ejemplo n.º 9
0
def main():
    """ main """

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

    argument_spec.update(jctanner.network_cloudengine.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)