def replace_config_with_oper(task):
    r = requests.post(odl_url_uniconfig_replace_config_with_operational,
                      data=json.dumps(commit_input),
                      headers=odl_headers,
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_uniconfig_replace_config_with_operational,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig replace successfull"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_uniconfig_replace_config_with_operational,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig replace failed"]
        }
Beispiel #2
0
def execute_read_cli_topology_operational(task):
    uniconfig_tx_id = task['inputData']['uniconfig_tx_id'] \
        if 'inputData' in task and 'uniconfig_tx_id' in task['inputData'] else ""

    r = requests.get(odl_url_cli_oper,
                     headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                     auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_cli_oper,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_cli_oper,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
Beispiel #3
0
def execute_mount_cli(task):
    device_id = task['inputData']['id']

    mount_body = mount_template.copy()

    mount_body["network-topology:node"]["network-topology:node-id"] = task['inputData']['id']
    mount_body["network-topology:node"]["cli-topology:host"] = task['inputData']['host']
    mount_body["network-topology:node"]["cli-topology:port"] = task['inputData']['port']
    mount_body["network-topology:node"]["cli-topology:transport-type"] = task['inputData']['protocol']
    mount_body["network-topology:node"]["cli-topology:device-type"] = task['inputData']['type']
    mount_body["network-topology:node"]["cli-topology:device-version"] = task['inputData']['version']
    mount_body["network-topology:node"]["cli-topology:username"] = task['inputData']['username']
    mount_body["network-topology:node"]["cli-topology:password"] = task['inputData']['password']

    id_url = odl_url_cli_mount + device_id

    r = requests.put(id_url, data=json.dumps(mount_body), headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'request_body': mount_body,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': ["Mountpoint with ID %s registered" % device_id]}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'request_body': mount_body,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': ["Unable to register device with ID %s" % device_id]}
def add_device(task):
    device_id = task['inputData']['id']

    id_url = Template(inventory_device_url).substitute({"id": device_id})

    add_body = add_template.copy()

    add_body["id"] = task['inputData']['id']
    add_body["host"] = task['inputData']['host']
    add_body["port"] = task['inputData']['port']
    add_body["transport_type"] = task['inputData']['protocol']
    add_body["device_type"] = task['inputData']['type']
    add_body["device_version"] = task['inputData']['version']
    add_body["username"] = task['inputData']['username']
    add_body["password"] = task['inputData']['password']

    r = requests.post(id_url, data=json.dumps(add_body))
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok or response_code == requests.codes.created:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': []}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': []}
Beispiel #5
0
def execute_check_cli_id_available(task):
    device_id = task['inputData']['device_id']
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else ""

    id_url = Template(odl_url_cli_mount).substitute({"id": device_id})

    r = requests.get(id_url,
                     headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                     auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code != requests.codes.not_found:
        # Mountpoint with such ID already exists
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Unable to mount device with ID %s" % device_id]
        }
    else:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Mountpoint with ID %s is available" % device_id]
        }
def read_components(task):
    device_id = task['inputData']['device_id']
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else ""

    id_url = Template(odl_url_components).substitute({"id": device_id})

    r = requests.get(id_url,
                     headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                     auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
Beispiel #7
0
def store_lldp(task):
    topo_id = task['inputData']['destination-topology']
    topo = task['inputData']['content']

    id_url = Template(inventory_lldp_url).substitute({"id": topo_id})

    add_body = {}
    add_body["lldp"] = task['inputData']['content']

    r = requests.post(id_url, data=json.dumps(add_body))
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok or response_code == requests.codes.created:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
Beispiel #8
0
def read_lldp(task):
    topo_id = task['inputData']['destination-topology']

    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else ""

    id_url = Template(read_lldp_url).substitute({"topo": topo_id})

    r = requests.get(id_url,
                     headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                     auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["LLDP topology read: %s" % topo_id]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Failed to read LLDP topology: %s" % topo_id]
        }
Beispiel #9
0
def export_lldp(task):
    uniconfig_tx_id = task['inputData']['uniconfig_tx_id'] \
        if 'inputData' in task and 'uniconfig_tx_id' in task['inputData'] else ""
    lldp_body = copy.deepcopy(lldp_export_template)

    r = requests.post(export_lldp_url,
                      data=json.dumps(lldp_body),
                      headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': export_lldp_url,
                'request_body': lldp_body,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["LLDP topology exported"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': export_lldp_url,
                'request_body': lldp_body,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Failed to export LLDP topology"]
        }
Beispiel #10
0
def write_structured_data(task):
    device_id = task['inputData']['device_id']
    uri = task['inputData']['uri']
    uri = uniconfig_worker.apply_functions(uri)

    template = task['inputData']['template']
    params = task['inputData']['params'] if task['inputData']['params'] else {}

    data_json = template if isinstance(template, basestring) else json.dumps(template if template else {})
    data_json = Template(data_json).substitute(params)

    id_url = Template(odl_url_unified_mount).substitute({"id": device_id}) + "/yang-ext:mount" + (uri if uri else "")
    id_url = Template(id_url).substitute(params)

    r = requests.put(id_url, data=data_json, headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.no_content or response_code == requests.codes.created:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'request_url': id_url,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': ["Mountpoint with ID %s updated successfully" % device_id]}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'request_url': id_url,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': ["Unable to update device with ID %s" % device_id]}
Beispiel #11
0
def build_lldp(task):
    topo_id = task['inputData']['destination-topology']

    lldp_body = lldp_build_template.copy()

    lldp_body["input"]["node-aggregation"] = task['inputData']['node-aggregation']
    lldp_body["input"]["link-aggregation"] = task['inputData']['link-aggregation']
    lldp_body["input"]["per-node-read-timeout"] = task['inputData']['per-node-read-timeout']
    lldp_body["input"]["concurrent-read-nodes"] = task['inputData']['concurrent-read-nodes']
    lldp_body["input"]["destination-topology"] = task['inputData']['destination-topology']

    r = requests.post(build_lldp_url, data=json.dumps(lldp_body), headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {'status': 'COMPLETED', 'output': {'url': build_lldp_url,
                                                  'request_body': lldp_body,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': ["LLDP topology built and stored in %s" % topo_id]}
    else:
        return {'status': 'FAILED', 'output': {'url': build_lldp_url,
                                               'request_body': lldp_body,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': ["Failed to build LLDP topology %s" % topo_id]}
Beispiel #12
0
def delete_l3vpn_instance(task):
    vpn_id = task['inputData']['vpn-id']

    id_url = odl_url_l3vpn + vpn_id

    r = requests.delete(id_url, headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["L3VPN with ID %s deleted" % vpn_id]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Unable to delete L3VPN with ID %s" % vpn_id]
        }
Beispiel #13
0
def commit_l3vpn(task):
    r = requests.post(odl_url_l3vpn_commit,
                      headers=odl_headers,
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_l3vpn_commit,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["L3VPN committed"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_l3vpn_commit,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Unable to commit L3VPN"]
        }
Beispiel #14
0
def delete_l3vpn_site(task):
    site_id = task['inputData']['site-id']

    id_url = odl_url_l3vpn_site + site_id

    r = requests.dalete(id_url, headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status':
            'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs':
            ["L3VPN site with ID %s deleted for VPN: %s" % (site_id, vpn_id)]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Unable to deleted L3VPN site with ID %s" % site_id]
        }
def write_structured_data(task):
    device_id = task['inputData']['id']
    uri = task['inputData']['uri']
    template = task['inputData']['template']
    params = task['inputData']['params']
    params = json.loads(params) if isinstance(params, basestring) else (params if params else {})

    data_json = template if isinstance(template, basestring) else json.dumps(template if template else {})
    data_json = Template(data_json).substitute(params)

    id_url = odl_url_uniconfig_mount + device_id + "/frinx-uniconfig-topology:configuration" + (uri if uri else "")
    id_url = Template(id_url).substitute(params)

    r = requests.put(id_url, data=data_json, headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok or response_code == requests.codes.created:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': ["Node with ID %s updated successfully" % device_id]}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': ["Unable to update device with ID %s" % device_id]}
Beispiel #16
0
def sync_from_network(task):
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else ""
    r = requests.post(odl_url_uniconfig_sync_from_network,
                      data=json.dumps(create_commit_request(task)),
                      headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok and response_json["output"][
            "overall-status"] == "complete":
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_uniconfig_sync_from_network,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig sync successfull"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_uniconfig_sync_from_network,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig sync failed"]
        }
Beispiel #17
0
def execute_mount_netconf(task):
    device_id = task['inputData']['id']

    mount_body = mount_template.copy()

    mount_body["node"]["node-id"] = task['inputData']['id']
    mount_body["node"]["netconf-node-topology:host"] = task['inputData']['host']
    mount_body["node"]["netconf-node-topology:port"] = task['inputData']['port']
    mount_body["node"]["netconf-node-topology:keepalive-delay"] = task['inputData']['keepalive-delay']
    mount_body["node"]["netconf-node-topology:tcp-only"] = task['inputData']['tcp-only']
    mount_body["node"]["netconf-node-topology:username"] = task['inputData']['username']
    mount_body["node"]["netconf-node-topology:password"] = task['inputData']['password']

    id_url = odl_url_netconf_mount + device_id

    r = requests.put(id_url, data=json.dumps(mount_body), headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'request_body': mount_body,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': ["Mountpoint with ID %s registered" % device_id]}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'request_body': mount_body,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': ["Unable to register device with ID %s" % device_id]}
Beispiel #18
0
def delete_snapshot(task):
    snapshot_body = copy.deepcopy(delete_snapshot_template)
    snapshot_body["input"]["name"] = task["inputData"]["name"]
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else ""

    r = requests.post(odl_url_uniconfig_delete_snapshot,
                      data=json.dumps(snapshot_body),
                      headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok and response_json["output"][
            "overall-status"] == "complete":
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_uniconfig_delete_snapshot,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig delete snapshot successful"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_uniconfig_delete_snapshot,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig delete snapshot failed"]
        }
Beispiel #19
0
def read_lldp(task):
    topo_id = task['inputData']['destination-topology']

    id_url = read_lldp_url + topo_id

    r = requests.get(id_url, headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["LLDP topology read: %s" % topo_id]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Failed to read LLDP topology: %s" % topo_id]
        }
Beispiel #20
0
def replace_config_with_snapshot(task):
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else ""
    snapshot_body = create_snapshot_request(task)
    r = requests.post(odl_url_uniconfig_replace_config_with_snapshot,
                      data=json.dumps(snapshot_body),
                      headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok and response_json["output"][
            "overall-status"] == "complete":
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_uniconfig_replace_config_with_snapshot,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig replace config with snapshot was successful"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_uniconfig_replace_config_with_snapshot,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig replace config with snapshot failed"]
        }
Beispiel #21
0
def export_lldp(task):

    lldp_body = lldp_export_template.copy()

    r = requests.post(export_lldp_url,
                      data=json.dumps(lldp_body),
                      headers=odl_headers,
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.created or response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': export_lldp_url,
                'request_body': lldp_body,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["LLDP topology exported"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': export_lldp_url,
                'request_body': lldp_body,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Failed to export LLDP topology"]
        }
Beispiel #22
0
def create_transaction(task):
    max_age_sec = task["inputData"]["maxAgeSec"] if 'maxAgeSec' in task[
        'inputData'] else ""
    id_url = Template(odl_url_uniconfig_create_transaction).substitute(
        {"sec": max_age_sec})
    r = requests.post(id_url,
                      data=json.dumps({}),
                      headers=odl_headers,
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)
    if response_code == requests.codes.created:
        response_json = parse_header(r)
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig create transaction was successful"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig create transaction failed"]
        }
def add_field_to_device(task):
    device_id = task['inputData']['id']
    field = task['inputData']['field']
    value = task['inputData']['value']

    id_url = Template(inventory_device_update_url).substitute({"id": device_id})
    data = Template(add_field_command).substitute({"field": field, "value": value})

    update_body = add_field_template.copy()

    update_body["script"] = data

    r = requests.post(id_url, data=json.dumps(update_body))
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': []}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': []}
Beispiel #24
0
def close_transaction(task):
    uniconfig_tx_id = task["inputData"]["uniconfig_tx_id"]
    custom_header = {
        "Cookie": "UNICONFIGTXID=" + uniconfig_tx_id
    } if uniconfig_tx_id else {
        "Cookie": ""
    }
    r = requests.post(odl_url_uniconfig_close_transaction,
                      data=json.dumps({}),
                      headers=custom_header,
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)
    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_uniconfig_close_transaction,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig close transaction was successful"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_uniconfig_close_transaction,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig close transaction failed"]
        }
Beispiel #25
0
def execute_check_connected_cli(task):
    device_id = task['inputData']['device_id']
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else ""

    id_url = Template(odl_url_cli_mount_oper).substitute({"id": device_id})

    r = requests.get(id_url,
                     headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                     auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok and response_json["node"][0][
            "cli-topology:connection-status"] == "connected":
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Mountpoint with ID %s is connected" % device_id]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Mountpoint with ID %s not yet connected" % device_id]
        }
Beispiel #26
0
def remove_device(task):
    device_id = task['inputData']['device_id']

    id_url = Template(inventory_device_url).substitute({"id": device_id})

    r = requests.delete(id_url, headers=elastic_headers)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
Beispiel #27
0
def execute_get_cli_journal(task):
    device_id = task['inputData']['device_id']
    uniconfig_tx_id = task['inputData'][
        'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else ""

    id_url = Template(odl_url_cli_read_journal).substitute({"id": device_id})

    r = requests.post(id_url,
                      headers=add_uniconfig_tx_cookie(uniconfig_tx_id),
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Mountpoint with ID %s, cannot read journal" % device_id]
        }
Beispiel #28
0
def get_show_command(task):
    command_id = task['inputData']['template_id']

    id_url = Template(inventory_show_command_get_url).substitute(
        {"id": command_id})

    r = requests.get(id_url, headers=elastic_headers)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': id_url,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': []
        }
Beispiel #29
0
def execute_execute_and_read_rpc_cli(task):
    device_id = task['inputData']['id']
    template = task['inputData']['template']
    params = task['inputData']['params'] if task['inputData']['params'] else {}
    params = params if isinstance(params, dict) else eval(params)

    commands = Template(template).substitute(params)
    exec_body = execute_and_read_template.copy()

    exec_body["input"]["ios-cli:command"] = commands

    id_url = odl_url_cli_mount_rpc + device_id + "/yang-ext:mount/cli-unit-generic:execute-and-read"

    r = requests.post(id_url, data=json.dumps(exec_body), headers=odl_headers, auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {'status': 'COMPLETED', 'output': {'url': id_url,
                                                  'request_body': exec_body,
                                                  'response_code': response_code,
                                                  'response_body': response_json},
                'logs': ["Mountpoint with ID %s configured" % device_id]}
    else:
        return {'status': 'FAILED', 'output': {'url': id_url,
                                               'request_body': exec_body,
                                               'response_code': response_code,
                                               'response_body': response_json},
                'logs': ["Unable to configure device with ID %s" % device_id]}
def sync_from_network(task):
    r = requests.post(odl_url_uniconfig_sync_from_network,
                      data=json.dumps(commit_input),
                      headers=odl_headers,
                      auth=odl_credentials)
    response_code, response_json = parse_response(r)

    if response_code == requests.codes.ok:
        return {
            'status': 'COMPLETED',
            'output': {
                'url': odl_url_uniconfig_sync_from_network,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig sync successfull"]
        }
    else:
        return {
            'status': 'FAILED',
            'output': {
                'url': odl_url_uniconfig_sync_from_network,
                'response_code': response_code,
                'response_body': response_json
            },
            'logs': ["Uniconfig sync failed"]
        }