def create_transaction(task): max_age_sec = task["inputData"]["maxAgeSec"] if 'maxAgeSec' in task[ 'inputData'] else "" id_url = Template(uniconfig_url_uniconfig_create_transaction).substitute( {"sec": max_age_sec}) r = requests.post(id_url, data=json.dumps({}), headers=uniconfig_headers, **additional_uniconfig_request_params) 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 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(uniconfig_url_uniconfig_replace_config_with_snapshot, data=json.dumps(snapshot_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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': uniconfig_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': uniconfig_url_uniconfig_replace_config_with_snapshot, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig replace config with snapshot failed"] }
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(uniconfig_url_uniconfig_close_transaction, data=json.dumps({}), headers=custom_header, **additional_uniconfig_request_params) response_code, response_json = parse_response(r) if response_code == requests.codes.ok: return { 'status': 'COMPLETED', 'output': { 'url': uniconfig_url_uniconfig_close_transaction, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig close transaction was successful"] } else: return { 'status': 'FAILED', 'output': { 'url': uniconfig_url_uniconfig_close_transaction, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig close transaction failed"] }
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(uniconfig_url_uniconfig_delete_snapshot, data=json.dumps(snapshot_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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': uniconfig_url_uniconfig_delete_snapshot, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig delete snapshot successful"] } else: return { 'status': 'FAILED', 'output': { 'url': uniconfig_url_uniconfig_delete_snapshot, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig delete snapshot failed"] }
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), headers=elastic_headers) 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': [] }
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(uniconfig_url_cli_oper, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) if response_code == requests.codes.ok: return { 'status': 'COMPLETED', 'output': { 'url': uniconfig_url_cli_oper, 'response_code': response_code, 'response_body': response_json }, 'logs': [] } else: return { 'status': 'FAILED', 'output': { 'url': uniconfig_url_cli_oper, 'response_code': response_code, 'response_body': response_json }, 'logs': [] }
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), **additional_uniconfig_request_params) 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"] }
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(uniconfig_url_cli_mount).substitute({"id": device_id}) r = requests.get(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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 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(uniconfig_url_cli_mount_oper).substitute( {"id": device_id}) r = requests.get(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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] }
def sync_from_network(task): uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else "" r = requests.post(uniconfig_url_uniconfig_sync_from_network, data=json.dumps(create_commit_request(task)), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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': uniconfig_url_uniconfig_sync_from_network, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig sync successfull"] } else: return { 'status': 'FAILED', 'output': { 'url': uniconfig_url_uniconfig_sync_from_network, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig sync failed"] }
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), **additional_uniconfig_request_params) 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] }
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(uniconfig_url_cli_read_journal).substitute( {"id": device_id}) r = requests.post(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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] }
def read_structured_data(task): device_id = task['inputData']['device_id'] uri = task['inputData']['uri'] uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else "" id_url = Template(uniconfig_url_netconf_mount).substitute( {"id": device_id}) + "/yang-ext:mount" + (uri if uri else "") r = requests.get(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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': ["Node with ID %s read successfully" % device_id] } else: return { 'status': 'FAILED', 'output': { 'url': id_url, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Unable to read device with ID %s" % device_id] }
def execute_mount_cli(task): device_id = task['inputData']['device_id'] uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else "" mount_body = copy.deepcopy(mount_template) mount_body["network-topology:node"][0]["network-topology:node-id"] = task[ 'inputData']['device_id'] mount_body["network-topology:node"][0]["cli-topology:host"] = task[ 'inputData']['host'] mount_body["network-topology:node"][0]["cli-topology:port"] = task[ 'inputData']['port'] mount_body["network-topology:node"][0][ "cli-topology:transport-type"] = task['inputData']['protocol'] mount_body["network-topology:node"][0]["cli-topology:device-type"] = task[ 'inputData']['type'] mount_body["network-topology:node"][0][ "cli-topology:device-version"] = task['inputData']['version'] mount_body["network-topology:node"][0]["cli-topology:username"] = task[ 'inputData']['username'] mount_body["network-topology:node"][0]["cli-topology:password"] = task[ 'inputData']['password'] mount_body["network-topology:node"][0][ "cli-topology:parsing-engine"] = task['inputData'].get( 'parsing-engine', "tree-parser") id_url = Template(uniconfig_url_cli_mount).substitute({"id": device_id}) r = requests.put(id_url, data=json.dumps(mount_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) if response_code == requests.codes.created or response_code == requests.codes.no_content: 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 read_selected_devices(url, devices, uniconfig_tx_id): response_code = requests.codes.ok response_json = {'topology': [{'node': []}]} devices_array = [device.strip() for device in devices.split(',')] for d in devices_array: r = requests.get(Template(url).substitute({"id": d}), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json_tmp = parse_response(r) response_json['topology'][0]['node'].append( response_json_tmp['node'][0]) if response_code != requests.codes.ok: raise "Cannot read device '" + d + "' from uniconfig topology" return response_code, response_json
def build_lldp(task): topo_id = task['inputData']['destination-topology'] lldp_body = copy.deepcopy(lldp_build_template) 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'] uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else "" r = requests.post(build_lldp_url, data=json.dumps(lldp_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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] }
def write_structured_data(task): device_id = task['inputData']['device_id'] uri = task['inputData']['uri'] uri = uniconfig_worker.apply_functions(uri) uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else "" template = task['inputData']['template'] params = task['inputData']['params'] if task['inputData']['params'] else {} data_json = template if isinstance( template, str) else json.dumps(template if template else {}) data_json = Template(data_json).substitute(params) id_url = Template(uniconfig_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=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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] }
def read_all_devices(url, uniconfig_tx_id): r = requests.get(url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) actual_nodes = response_json['topology'][0]['node'] filtered_nodes = [] for node in actual_nodes: if node['cli-topology:connection-status'] == "connected": filtered_nodes.append(node) response_json['topology'][0].pop('node') response_json['topology'][0].update({'node': filtered_nodes}) return response_code, response_json
def execute_and_read_rpc_cli(task): device_id = task['inputData']['device_id'] template = task['inputData']['template'] params = task['inputData']['params'] if task['inputData']['params'] else {} params = params if isinstance(params, dict) else eval(params) uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else "" commands = Template(template).substitute(params) exec_body = copy.deepcopy(execute_and_read_template) exec_body["input"]["ios-cli:command"] = commands id_url = Template(uniconfig_url_cli_mount_rpc).substitute({ "id": device_id }) + "/yang-ext:mount/cli-unit-generic:execute-and-read" r = requests.post(id_url, data=json.dumps(exec_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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 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(uniconfig_url_components).substitute({"id": device_id}) r = requests.get(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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': []}
def execute_unmount_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(uniconfig_url_cli_mount).substitute({"id": device_id}) r = requests.delete(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) return { 'status': 'COMPLETED', 'output': { 'url': id_url, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Mountpoint with ID %s removed" % device_id] }
def read_structured_data(task): device_id = task['inputData']['device_id'] uri = task['inputData']['uri'] uri = uniconfig_worker.apply_functions(uri) uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else "" id_url = Template(uniconfig_url_unified_mount).substitute({ "id": device_id }) + "/yang-ext:mount" + (uri if uri else "") + "?content=config" # If headers in additional_uniconfig_request_parm delete them (using custom headers with tx cookie) if "headers" in additional_uniconfig_request_params: del additional_uniconfig_request_params['headers'] r = requests.get(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) 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': ["Mountpoint with ID %s read successfully" % device_id] } else: return { 'status': 'FAILED', 'output': { 'url': id_url, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Unable to read device with ID %s" % device_id] }
def delete_structured_data(task): device_id = task['inputData']['device_id'] uri = task['inputData']['uri'] uri = uniconfig_worker.apply_functions(uri) uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else "" id_url = Template(uniconfig_url_unified_mount).substitute( {"id": device_id}) + "/yang-ext:mount" + (uri if uri else "") r = requests.delete(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) if response_code == requests.codes.no_content: 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] }
def execute_check_uniconfig_node_exists(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(uniconfig_url_uniconfig_mount).substitute({ "id": device_id }) + "/frinx-uniconfig-topology:connection-status?content=nonconfig" r = requests.get(id_url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) if response_code != requests.codes.not_found and response_json[ "frinx-uniconfig-topology:connection-status"] == "installed": # Mountpoint with such ID already exists return { 'status': 'COMPLETED', 'output': { 'url': id_url, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig mountpoint with ID %s exists" % device_id] } else: return { 'status': 'FAILED', 'output': { 'url': id_url, 'response_code': response_code, 'response_body': response_json }, 'logs': ["Uniconfig mountpoint with ID %s doesn't exist" % device_id] }
def read_all_devices(url, uniconfig_tx_id): r = requests.get(url, headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) return response_code, response_json
def execute_mount_netconf(task): device_id = task['inputData']['device_id'] uniconfig_tx_id = task['inputData'][ 'uniconfig_tx_id'] if 'uniconfig_tx_id' in task['inputData'] else "" mount_body = copy.deepcopy(mount_template) mount_body["node"][0]["node-id"] = task['inputData']['device_id'] mount_body["node"][0]["netconf-node-topology:host"] = task['inputData'][ 'host'] mount_body["node"][0]["netconf-node-topology:port"] = task['inputData'][ 'port'] mount_body["node"][0]["netconf-node-topology:keepalive-delay"] = task[ 'inputData']['keepalive-delay'] mount_body["node"][0]["netconf-node-topology:tcp-only"] = task[ 'inputData']['tcp-only'] mount_body["node"][0]["netconf-node-topology:username"] = task[ 'inputData']['username'] mount_body["node"][0]["netconf-node-topology:password"] = task[ 'inputData']['password'] if 'reconcile' in task['inputData'] and task['inputData']['reconcile'] is not None\ and task['inputData']['reconcile'] is not"": mount_body["node"][0]["node-extension:reconcile"] = task['inputData'][ 'reconcile'] if 'sleep-factor' in task['inputData'] and task['inputData']['sleep-factor'] is not None\ and task['inputData']['sleep-factor'] is not "": mount_body["node"][0]["netconf-node-topology:sleep-factor"] = task[ 'inputData']['sleep-factor'] if 'between-attempts-timeout-millis' in task['inputData'] and task['inputData']['between-attempts-timeout-millis'] is not None\ and task['inputData']['between-attempts-timeout-millis'] is not "": mount_body["node"][0][ "netconf-node-topology:between-attempts-timeout-millis"] = task[ 'inputData']['between-attempts-timeout-millis'] if 'connection-timeout-millis' in task['inputData'] and task['inputData']['connection-timeout-millis'] is not None\ and task['inputData']['connection-timeout-millis'] is not "": mount_body["node"][0][ "netconf-node-topology:connection-timeout-millis"] = task[ 'inputData']['connection-timeout-millis'] if 'uniconfig-native' in task['inputData'] and task['inputData']['uniconfig-native'] is not None\ and task['inputData']['uniconfig-native'] is not "": mount_body["node"][0][ "uniconfig-config:uniconfig-native-enabled"] = task['inputData'][ 'uniconfig-native'] if 'blacklist' in task['inputData'] and task['inputData'][ 'blacklist'] is not None: mount_body["node"][0]["uniconfig-config:blacklist"] = { 'uniconfig-config:path': [] } model_array = [ model.strip() for model in task['inputData']['blacklist'].split(',') ] for model in model_array: mount_body["node"][0]["uniconfig-config:blacklist"][ "uniconfig-config:path"].append(model) if 'dry-run-journal-size' in task['inputData'] and task['inputData'][ 'dry-run-journal-size'] is not None: mount_body["node"][0][ "netconf-node-topology:dry-run-journal-size"] = task['inputData'][ 'dry-run-journal-size'] id_url = Template(uniconfig_url_netconf_mount).substitute( {"id": device_id}) r = requests.put(id_url, data=json.dumps(mount_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params) response_code, response_json = parse_response(r) if response_code == requests.codes.created or response_code == requests.codes.no_content: 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] }