def get_mgmt_ips_frm_lo_ips(self, job_ctx, lo0_ips, device_name): FilterLog.instance("GetMgmtIPFilter", device_name) _task_log("Starting to get the mgmt_ips") mgmt_ips = [] try: _task_log("Getting the vnc handle") self.vnc_lib = JobVncApi.vnc_init(job_ctx) for lo0_ip in lo0_ips: if lo0_ip: mgmt_ip, dev_name = self._get_mgmt_ip(lo0_ip) if mgmt_ip: mgmt_ips.append({mgmt_ip : (dev_name, lo0_ip)}) _task_done() return { 'status': 'success', 'get_mgmt_ip_log': FilterLog.instance().dump(), 'get_mgmt_ips': mgmt_ips } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return {'status': 'failure', 'error_msg': str(ex), 'get_mgmt_ips': mgmt_ips, 'get_mgmt_ip_log': FilterLog.instance().dump()}
def _create_neighbor_links(self, job_ctx, lldp_neighbors_payload, prouter_fqname, prouter_vendor): if not lldp_neighbors_payload.get('neighbor_info_list'): _task_log("No neighbors found") _task_done() return { 'lldp_neighbors_success_names': [], 'lldp_neighbors_failed_info': [] } vnc_lib = JobVncApi.vnc_init(job_ctx) vnc_topology_disc_payload = self.get_vnc_payload( vnc_lib, prouter_fqname, prouter_vendor, lldp_neighbors_payload['neighbor_info_list']) topology_disc_payload = self._do_further_parsing( vnc_lib, vnc_topology_disc_payload) _task_done("Parsed payload completely") _task_log("Creating links between neighboring physical interfaces") topology_discovery_resp = self._create_physical_interface_refs( vnc_lib, topology_disc_payload) return topology_discovery_resp
def get_mgmt_ips_frm_lo_ips(self, job_ctx, lo0_ips, device_name): FilterLog.instance("GetMgmtIPFilter", device_name) _task_log("Starting to get the mgmt_ips") mgmt_ips = [] try: _task_log("Getting the vnc handle") self.vnc_lib = JobVncApi.vnc_init(job_ctx) for lo0_ip in lo0_ips: if lo0_ip: mgmt_ip, dev_name = self._get_mgmt_ip(lo0_ip) if mgmt_ip: mgmt_ips.append({mgmt_ip: (dev_name, lo0_ip)}) _task_done() return { 'status': 'success', 'get_mgmt_ip_log': FilterLog.instance().dump(), 'get_mgmt_ips': mgmt_ips } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return { 'status': 'failure', 'error_msg': str(ex), 'get_mgmt_ips': mgmt_ips, 'get_mgmt_ip_log': FilterLog.instance().dump() }
def validate_schema(self, schema_type, file_path, json_obj, device_name): self._instantiate_filter_log_instance(device_name) try: _task_log("Starting to validate " + schema_type) with open(file_path) as f: schema_json = json.load(f) jsonschema.validate(json_obj, schema_json.get(schema_type)) _task_done("Completed " + schema_type + " validation") return {'status': 'success'} except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return {'status': 'failure', 'error_msg': str(ex)}
def _do_role_discovery(self, np_back_refs, prouter_name, vnc_lib, prouter_uuid, node_profile_obj_uuid_list): upd_resp = "" node_profile_refs = [] for np_back_ref in np_back_refs: if np_back_ref['uuid'] in node_profile_obj_uuid_list: upd_resp += "Creating ref between %s and %s ....\n" \ % (prouter_name, np_back_ref['to'][-1]) ref_upd_resp = vnc_lib.ref_update("physical_router", prouter_uuid, "node_profile", np_back_ref['uuid'], None, 'ADD') _task_log(ref_upd_resp) _task_done() node_profile_refs.append(np_back_ref['to'][-1]) return upd_resp, node_profile_refs
def validate_schema(self, schema_type, file_path, json_obj, device_name): self._instantiate_filter_log_instance(device_name) try: _task_log("Starting to validate " + schema_type) with open(file_path) as f: schema_json = json.load(f) jsonschema.validate(json_obj, schema_json.get(schema_type)) _task_done("Completed "+ schema_type +" validation") return {'status': 'success'} except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return { 'status': 'failure', 'error_msg': str(ex) }
def _do_role_discovery(self, np_back_refs, prouter_name, vnc_lib, prouter_uuid, node_profile_obj_uuid_list): upd_resp = "" node_profile_refs = [] for np_back_ref in np_back_refs: if np_back_ref['uuid'] in node_profile_obj_uuid_list: upd_resp += "Creating ref between %s and %s ....\n" \ % (prouter_name, np_back_ref['to'][-1]) ref_upd_resp = vnc_lib.ref_update("physical_router", prouter_uuid, "node_profile", np_back_ref['uuid'], None, 'ADD') _task_log(ref_upd_resp) _task_done() node_profile_refs.append(np_back_ref['to'][-1]) return upd_resp, node_profile_refs
def discover_role(self, job_ctx, prouter_name, prouter_uuid, prouter_vendor_name, prouter_product_name): node_profile_refs = [] try: FilterLog.instance("DiscoverRoleFilter", prouter_name) FilterModule._validate_job_ctx(job_ctx) fabric_fqname = job_ctx.get('fabric_fqname') vnc_lib = JobVncApi.vnc_init(job_ctx) # form the hardware fqname from prouter_vendor_name and # prouter_product_name hw_fq_name = [(prouter_vendor_name + '-' + prouter_product_name ).lower()] # read the hardware object with this fq_name _task_log("Reading the hardware object") try: hw_obj = vnc_lib.hardware_read(fq_name=hw_fq_name) except NoIdError as no_id_exc: _task_log("\nHardware Object not present in " "database: " + str(no_id_exc)) traceback.print_exc(file=sys.stdout) _task_log("Completing role discovery for device") _task_done() return { 'status': 'success', 'fabric_fqname': fabric_fqname, 'np_refs': node_profile_refs, 'device_name': prouter_name, 'role_discovery_log': FilterLog.instance().dump() } _task_done() # get all the node-profile back-refs for this hardware object _task_log("Getting all the node-profile back refs" \ " for the hardware: %s" % hw_fq_name[-1]) np_back_refs = hw_obj.get_node_profile_back_refs() or [] _task_done() # get the fabric object fq_name to check if the node-profile # is in the same fabric _task_log("Fetching the fabric fq_name") fab_fq_name = fabric_fqname.split(":") _task_done() # read the fabric_object to get a list of node-profiles under # this fabric_object _task_log("Reading the fabric object") fabric_obj = vnc_lib.fabric_read(fq_name=fab_fq_name) _task_done() # get the list of node profile_uuids under the given fabric _task_log("Getting the list of node-profile-uuids" \ " under this fabric object .... ") node_profiles_list = fabric_obj.get_node_profile_refs() or [] node_profile_obj_uuid_list = self._get_object_uuid_list( node_profiles_list) _task_done() # check to see which of the node-profile back refs are in the # present fabric. Assumption: at present there is only a single # node-profile that can match a hardware under the current # given fabric _task_log("Checking to see if any node-profile" \ " is under given fabric .... \n") upd_resp, node_profile_refs = self._do_role_discovery( np_back_refs, prouter_name, vnc_lib, prouter_uuid, node_profile_obj_uuid_list) _task_log(upd_resp + "\n") _task_done() return { 'status': 'success', 'np_refs': node_profile_refs, 'fabric_fqname': fabric_fqname, 'device_name': prouter_name, 'role_discovery_log': FilterLog.instance().dump() } except NoIdError as no_id_exc: _task_error_log("Object not present in database: " + str(no_id_exc)) traceback.print_exc(file=sys.stdout) return { 'status': 'failure', 'error_msg': str(no_id_exc), 'role_discovery_log': FilterLog.instance().dump() } except Exception as ex: _task_error_log(str(ex)) traceback.print_exc(file=sys.stdout) return { 'status': 'failure', 'error_msg': str(ex), 'role_discovery_log': FilterLog.instance().dump() }
def update_physical_router(self, job_ctx, prouter_name, obj_dict_payload, prouter_vendor): """ :param job_ctx: Dictionary example: { "auth_token": "EB9ABC546F98", "job_input": { "fabric_fq_name": [ "default-global-system-config", "fab01" ], "device_auth": [{ "username": "******", "password": "******" }] } } :param prouter_name: String example: "5c3-qfx8" :param obj_dict_payload: Dictionary example: { "physical_router_dataplane_ip": "10.0.0.2", "physical_router_loopback_ip": "10.0.0.2", "fq_name": ["default-global-system-config","5c3-qfx8"], "physical_router_os_version": "srx-20.65", "additional_properties": { 'Some Key that needs to be tapped': 'Some random annotations spec. to this vendor' } } :param prouter_vendor: String example: "juniper" :return: Dictionary if success, returns { 'status': 'success', 'upd_pr_log': <String: upd_pr_log>, 'physical_router_upd_resp': <Dictionary: physical_router_upd_resp> } if failure, returns { 'status': 'failure', 'error_msg': <String: exception message>, 'upd_pr_log': <String: upd_pr_log> } :param physical_router_upd_resp: Dictionary example: { "job_log_msg": <String: job log message>, "warning_info": <Dictionary: warning_info> } """ FilterLog.instance("UpdatePhysicalRouterFilter", prouter_name) _task_log("Starting Device Update") try: _task_log("Creating vnc handle") self.vnc_lib = JobVncApi.vnc_init(job_ctx) _task_log("Parsing additional physical router properties") FilterModule._parse_additional_prop_and_upd_payload( obj_dict_payload, prouter_vendor) _task_log("Updating the physical router") physical_router_upd_resp = \ self._update_physical_router_object( obj_dict_payload, prouter_name ) _task_done() return { 'status': 'success', 'upd_pr_log': FilterLog.instance().dump(), 'physical_router_upd_resp': physical_router_upd_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return { 'status': 'failure', 'error_msg': str(ex), 'upd_pr_log': FilterLog.instance().dump() }
def import_hardware_inventory_info(self, job_ctx, prouter_name, pr_product_name, prouter_vendor, hardware_inventory_payload): r"""Import Hardware Inventory. :param job_ctx: Dictionary # example: # { # "auth_token": "EB9ABC546F98", # "job_input": { # "fabric_fq_name": [ # "default-global-system-config", # "fab01" # ], # "device_auth": [{ # "username": "******", # "password": "******" # }], # "management_subnets": [ # { # "cidr": "10.87.69.0/25", # "gateway": "10.87.69.1" # } # ], # "overlay_ibgp_asn": 64512, # "node_profiles": [ # { # "node_profile_name": "juniper-qfx5k" # } # ] # } # } :param prouter_name: String example: "5c3-qfx8" :param pr_product_name: String example: "qfx5110-48s-4c" :param prouter_vendor: String example: "Juniper" :param hardware_inventory_payload: Dictionary # example: # { # "inventory_info": "\n[{'description': u'QFX5110-48S-4C', # 'parent': '', 'model_number': None, 'module': u'Chassis', # 'version': None, 'serial_number': u'WS3718350232', # 'model': None}, # {'description': None, 'parent': u'Chassis', 'model_number': None, # 'module': u'Pseudo CB 0', 'version': None, 'serial_number': None, # 'model': None}, {'description': u'RE-QFX5110-48S-4C', # 'parent': u'Chassis', # 'model_number': u'QFX5110-48S-AFI', # 'module': u'Routing Engine 0', # 'version': None, 'serial_number': u'BUILTIN', 'model': None}, # {'description': u'QFX5110-48S-4C', 'parent': u'Chassis', # 'model_number': u'QFX5110-48S-AFI', 'module': u'FPC 0', # 'version': u'REV 26', ' # serial_number': u'WS3718350232', 'model': None}, # {'description': u'FPC CPU', 'parent': u'FPC 0', 'model_number': # None, 'module': u'CPU', # 'version': None, 'serial_number': u'BUILTIN', 'model': None}, # {'description': u'48x10G-4x100G', 'parent': u'FPC 0', # 'model_number': u'QFX5110-48S-AFI', 'module': u'PIC 0', # 'version': None, 'serial_number': u'BUILTIN', 'model': None}, # {'description': u'SFP+-10G-CU2M', 'parent': u'PIC 0', # 'model_number': None, 'module': u'Xcvr 0', 'version': None, # 'serial_number': u'APF164800484VC', 'model': None}, # {'description': u'SFP+-10G-CU2M', 'parent': u'PIC 0', # 'model_number': None, 'module': u'Xcvr 45', 'version': None, # 'serial_number': u'APF164900493E7', 'model': None}, # {'description': u'SFP+-10G-CU2M', 'parent': u'PIC 0', # 'model_number': None, 'module': u'Xcvr 46', 'version': None, # 'serial_number': u'APF18220040FVH', 'model': None} # } :return: Dictionary # if success, returns # { # 'status': 'success', # 'hardware_inventory_import_log': # <String: hardware_inventory_import_log>, # 'hardware_inventory_import_resp': <Dictionary: # hardware_inventory_import_resp> # } # if failure, returns # { # 'status': 'failure', # 'error_msg': <String: exception message>, # 'hardware_inventory_import_log': # <String: hardware_inventory_import_log>, # 'hardware_inventory_import_resp': # <Dictionary: hardware_inventory_import_resp> # } """ self._instantiate_filter_log_instance(prouter_name) _task_log("Starting Hardware Inventory Import") try: _task_log("Creating hardware inventory object") hardware_inventory_import_resp = \ self._create_hardware_inventory( job_ctx, hardware_inventory_payload, prouter_name, pr_product_name, prouter_vendor ) _task_done() return { 'status': 'success', 'hardware_inventory_import_log': FilterLog.instance().dump(), 'hardware_inventory_import_resp': hardware_inventory_import_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return { 'status': 'failure', 'error_msg': str(ex), 'hardware_inventory_import_log': FilterLog.instance().dump()}
def device_import(self, job_ctx, prouter_name, interfaces_payload): """ :param job_ctx: Dictionary. example: { "auth_token": "EB9ABC546F98", "job_input": { "fabric_fq_name": [ "default-global-system-config", "fab01" ], "device_auth": [{ "username": "******", "password": "******" }], "management_subnets": [ { "cidr": "10.87.69.0/25", "gateway": "10.87.69.1" } ], "overlay_ibgp_asn": 64512, "node_profiles": [ { "node_profile_name": "juniper-qfx5k" } ] } } :param prouter_name: String example: "5c3-qfx8" :param interfaces_payload: Dictionary example: { "physical_interfaces_list": [ { "physical_interface_port_id": "526", "physical_interface_mac_address": "00:11:22:33:44:55", "physical_interface_name": "xe-0/0/1:0" } ], "logical_interfaces_list": [ { "logical_interface_name": "xe-0/0/1:0.236", "logical_interface_type": "l3", "logical_interface_vlan_tag": "1213" } ] } :return: Dictionary if success, returns { 'status': 'success', 'device_import_log': <String: device_import_log>, 'device_import_resp': <Dictionary: device_import_resp> } if failure, returns { 'status': 'failure', 'error_msg': <String: exception message>, 'device_import_log': <String: device_import_log>, 'device_import_resp': <Dictionary: device_import_resp> } :param device_import_resp: Dictionary example: { "phy_intfs_success_names": <List: <String: phy_intfs_success_name> >, "log_intfs_success_names": <List: <String: log_intfs_success_name> >, "phy_intf_failed_info": <List: <Dictionary: phy_intf_failed_object> >, "log_intf_failed_info": <List: <Dictionary: log_intf_failed_object> > } """ self._instantiate_filter_log_instance(prouter_name) _task_log("Starting Device Import") device_import_resp = {} try: _task_log("Creating interfaces") device_import_resp = \ self._create_interfaces( job_ctx, interfaces_payload, prouter_name ) _task_done() if device_import_resp.get('phy_intf_failed_info') or \ device_import_resp.get('log_intf_failed_info'): raise Exception( "Create or Update physical or logical interfaces failed") return { 'status': 'success', 'device_import_log': FilterLog.instance().dump(), 'device_import_resp': device_import_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return {'status': 'failure', 'error_msg': str(ex), 'device_import_log': FilterLog.instance().dump(), 'device_import_resp': device_import_resp}
def import_lldp_info(self, job_ctx, prouter_fqname, prouter_vendor, lldp_neighbors_payload): """Topology discovery. :param job_ctx: Dictionary # example: # { # "auth_token": "EB9ABC546F98", # "job_input": { # "fabric_fq_name": [ # "default-global-system-config", # "fab01" # ], # "device_auth": [{ # "username": "******", # "password": "******" # }], # "management_subnets": [ # { # "cidr": "10.87.69.0/25", # "gateway": "10.87.69.1" # } # ], # "overlay_ibgp_asn": 64512, # "node_profiles": [ # { # "node_profile_name": "juniper-qfx5k" # } # ] # } # } :param prouter_fqname: List example: # [ # "default-global-system-config", # "5c3-qfx2" # ] :param prouter_vendor: String example: "juniper" :param lldp_neighbors_payload: Dictionary # example: # { # "neighbor_info_list": # [ # { # "local_physical_interface_name": "xe-0/0/0", # "remote_device_name": "5b5-qfx11", # "remote_physical_interface_port_id": "536" # }, # { # "local_physical_interface_name": "xe-0/0/2", # "remote_device_chassis_id": "00:1a:53:46:7b:9e", # "remote_physical_interface_port_id": "538" # } # ] # } :return: Dictionary # if success, returns # { # 'status': 'success', # 'topology_discovery_log': # <String: topology_discovery_log>, # 'topology_discovery_resp': # <Dictionary: topology_discovery_resp> # } # if failure, returns # { # 'status': 'failure', # 'error_msg': <String: exception message>, # 'topology_discovery_log': # <String: topology_discovery_log>, # 'topology_discovery_resp': # <Dictionary: topology_discovery_resp> # } :param topology_discovery_resp: Dictionary # example: # { # "lldp_neighbors_success_names": # <List: <String: lldp_neighbors_success_pair_string>>, # "lldp_neighbors_failed_info": # <List: <Dictionary: lldp_neighbor_failed_obj> > # } # :param lldp_neighbors_success_names: List # example: # ["bng-contrail-qfx51-15 : ge-0/0/36 --> dhawan : ge-2/3/1"] # :param lldp_neighbors_failed_info: List # example: # [ # { # "lldp_neighbor": # "bng-contrail-qfx51-15 : em0 --> sw174 : ge-1/0/46", # "warning_message": # "Unknown physical interface ng-contrail-qfx51-15:em0" # } # ] """ self._instantiate_filter_log_instance(prouter_fqname[-1]) _task_log("Starting Topology Discovery") try: _task_log("Creating neighboring links") topology_discovery_resp = self._create_neighbor_links( job_ctx, lldp_neighbors_payload, prouter_fqname, prouter_vendor) _task_done() return { 'status': 'success', 'topology_discovery_log': FilterLog.instance().dump(), 'topology_discovery_resp': topology_discovery_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return { 'status': 'failure', 'error_msg': str(ex), 'topology_discovery_log': FilterLog.instance().dump() }
def import_chassis_info(self, job_ctx, prouter_name, chassis_payload, prouter_vendor): """Import chassis Mac. :param job_ctx: Dictionary # example: # { # "auth_token": "EB9ABC546F98", # "job_input": { # "fabric_fq_name": [ # "default-global-system-config", # "fab01" # ], # "device_auth": [{ # "username": "******", # "password": "******" # }], # "management_subnets": [ # { # "cidr": "10.87.69.0/25", # "gateway": "10.87.69.1" # } # ], # "overlay_ibgp_asn": 64512, # "node_profiles": [ # { # "node_profile_name": "juniper-qfx5k" # } # ] # } # } :param prouter_name: String example: "5c3-qfx8" :param prouter_vendor: String example: "juniper" :param chassis_payload: Dictionary # example: # { # "device_chassis_id_info": [ # { # "device_chassis_id": "00:11:22:33:44:55", # "chassis_id_type": "private" # } # ] # } :return: Dictionary # if success, returns # { # 'status': 'success', # 'chassis_import_log': <String: chassis_import_log>, # 'chassis_import_resp': <Dictionary: chassis_import_resp> # } # if failure, returns # { # 'status': 'failure', # 'error_msg': <String: exception message>, # 'chassis_import_log': <String: chassis_import_log> # } :param chassis_import_resp: Dictionary # example: # { # "chassis_mac_ids": # <List: <String: chassis_mac_id> >, # "warning_info": <List: warn_info> # } """ self._instantiate_filter_log_instance(prouter_name) _task_log("Starting Chassis Info Import") try: chassis_vnc_payloads = self.get_vnc_chassis_payloads( chassis_payload.get('device_chassis_id_info'), prouter_vendor ) chassis_import_resp = self._import_chassis_info( job_ctx, chassis_vnc_payloads, prouter_name, prouter_vendor ) _task_done() return { 'status': 'success', 'chassis_import_log': FilterLog.instance().dump(), 'chassis_import_resp': chassis_import_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return {'status': 'failure', 'error_msg': str(ex), 'chassis_import_log': FilterLog.instance().dump()}
def discover_role(self, job_ctx, prouter_name, prouter_uuid, prouter_vendor_name, prouter_product_name): node_profile_refs = [] try: FilterLog.instance("DiscoverRoleFilter", prouter_name) FilterModule._validate_job_ctx(job_ctx) fabric_fqname = job_ctx.get('fabric_fqname') vnc_lib = JobVncApi.vnc_init(job_ctx) # form the hardware fqname from prouter_vendor_name and # prouter_product_name hw_fq_name = [ (prouter_vendor_name + '-' + prouter_product_name).lower() ] # read the hardware object with this fq_name _task_log("Reading the hardware object") try: hw_obj = vnc_lib.hardware_read(fq_name=hw_fq_name) except NoIdError as no_id_exc: _task_log("\nHardware Object not present in " "database: " + str(no_id_exc)) traceback.print_exc(file=sys.stdout) _task_log("Completing role discovery for device") _task_done() return { 'status': 'success', 'fabric_fqname': fabric_fqname, 'np_refs': node_profile_refs, 'device_name': prouter_name, 'role_discovery_log': FilterLog.instance().dump() } _task_done() # get all the node-profile back-refs for this hardware object _task_log("Getting all the node-profile back refs" \ " for the hardware: %s" % hw_fq_name[-1]) np_back_refs = hw_obj.get_node_profile_back_refs() or [] _task_done() # get the fabric object fq_name to check if the node-profile # is in the same fabric _task_log("Fetching the fabric fq_name") fab_fq_name = fabric_fqname.split(":") _task_done() # read the fabric_object to get a list of node-profiles under # this fabric_object _task_log("Reading the fabric object") fabric_obj = vnc_lib.fabric_read(fq_name=fab_fq_name) _task_done() # get the list of node profile_uuids under the given fabric _task_log("Getting the list of node-profile-uuids" \ " under this fabric object .... ") node_profiles_list = fabric_obj.get_node_profile_refs() or [] node_profile_obj_uuid_list = self._get_object_uuid_list( node_profiles_list) _task_done() # check to see which of the node-profile back refs are in the # present fabric. Assumption: at present there is only a single # node-profile that can match a hardware under the current # given fabric _task_log("Checking to see if any node-profile" \ " is under given fabric .... \n") upd_resp, node_profile_refs = self._do_role_discovery( np_back_refs, prouter_name, vnc_lib, prouter_uuid, node_profile_obj_uuid_list) _task_log(upd_resp + "\n") _task_done() return { 'status': 'success', 'np_refs': node_profile_refs, 'fabric_fqname': fabric_fqname, 'device_name': prouter_name, 'role_discovery_log': FilterLog.instance().dump() } except NoIdError as no_id_exc: _task_error_log("Object not present in database: " + str(no_id_exc)) traceback.print_exc(file=sys.stdout) return { 'status': 'failure', 'error_msg': str(no_id_exc), 'role_discovery_log': FilterLog.instance().dump() } except Exception as ex: _task_error_log(str(ex)) traceback.print_exc(file=sys.stdout) return { 'status': 'failure', 'error_msg': str(ex), 'role_discovery_log': FilterLog.instance().dump() }
def device_import(self, job_ctx, prouter_name, interfaces_payload): """ :param job_ctx: Dictionary example: { "auth_token": "EB9ABC546F98", "job_input": { "fabric_fq_name": [ "default-global-system-config", "fab01" ], "device_auth": [{ "username": "******", "password": "******" }], "management_subnets": [ { "cidr": "10.87.69.0/25", "gateway": "10.87.69.1" } ], "overlay_ibgp_asn": 64512, "node_profiles": [ { "node_profile_name": "juniper-qfx5k" } ] } } :param prouter_name: String example: "5c3-qfx8" :param interfaces_payload: Dictionary example: { "physical_interfaces_list": [ { "physical_interface_port_id": "526", "physical_interface_mac_address": "00:11:22:33:44:55", "physical_interface_name": "xe-0/0/1:0" } ], "logical_interfaces_list": [ { "logical_interface_name": "xe-0/0/1:0.236", "logical_interface_type": "l3", "logical_interface_vlan_tag": "1213" } ], "dataplane_ip": "10.0.0.2" } :return: Dictionary if success, returns { 'status': 'success', 'device_import_log': <String: device_import_log>, 'device_import_resp': <Dictionary: device_import_resp> } if failure, returns { 'status': 'failure', 'error_msg': <String: exception message>, 'device_import_log': <String: device_import_log>, 'device_import_resp': <Dictionary: device_import_resp> } :param device_import_resp: Dictionary example: { "phy_intfs_success_names": <List: <String: phy_intfs_success_name> >, "log_intfs_success_names": <List: <String: log_intfs_success_name> >, "phy_intf_failed_info": <List: <Dictionary: phy_intf_failed_object> >, "log_intf_failed_info": <List: <Dictionary: log_intf_failed_object> >, "dataplane_ip": <String: dataplane_ip>, "dataplane_ip_upd_resp": <String: dataplane_ip_upd_resp>, "warning_info": <Dictionary: warning_info> } """ self._instantiate_filter_log_instance(prouter_name) _task_log("Starting Device Import") device_import_resp = {} try: _task_log("Creating interfaces") device_import_resp = \ self._create_interfaces_and_update_dataplane_ip( job_ctx, interfaces_payload, prouter_name ) _task_done() if device_import_resp.get('phy_intf_failed_info') or \ device_import_resp.get('log_intf_failed_info'): raise Exception( "Create or Update physical or logical interfaces failed") return { 'status': 'success', 'device_import_log': FilterLog.instance().dump(), 'device_import_resp': device_import_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return {'status': 'failure', 'error_msg': str(ex), 'device_import_log': FilterLog.instance().dump(), 'device_import_resp': device_import_resp }
def update_physical_router(self, job_ctx, prouter_name, obj_dict_payload, prouter_vendor): """ :param job_ctx: Dictionary example: { "auth_token": "EB9ABC546F98", "job_input": { "fabric_fq_name": [ "default-global-system-config", "fab01" ], "device_auth": [{ "username": "******", "password": "******" }] } } :param prouter_name: String example: "5c3-qfx8" :param obj_dict_payload: Dictionary example: { "physical_router_dataplane_ip": "10.0.0.2", "physical_router_loopback_ip": "10.0.0.2", "fq_name": ["default-global-system-config","5c3-qfx8"], "physical_router_os_version": "srx-20.65", "additional_properties": { 'Some Key that needs to be tapped': 'Some random annotations spec. to this vendor' } } :param prouter_vendor: String example: "juniper" :return: Dictionary if success, returns { 'status': 'success', 'upd_pr_log': <String: upd_pr_log>, 'physical_router_upd_resp': <Dictionary: physical_router_upd_resp> } if failure, returns { 'status': 'failure', 'error_msg': <String: exception message>, 'upd_pr_log': <String: upd_pr_log> } :param physical_router_upd_resp: Dictionary example: { "job_log_msg": <String: job log message>, "warning_info": <Dictionary: warning_info> } """ FilterLog.instance("UpdatePhysicalRouterFilter", prouter_name) _task_log("Starting Device Update") try: _task_log("Creating vnc handle") self.vnc_lib = JobVncApi.vnc_init(job_ctx) _task_log("Parsing additional physical router properties") FilterModule._parse_additional_prop_and_upd_payload( obj_dict_payload, prouter_vendor) _task_log("Updating the physical router") physical_router_upd_resp = \ self._update_physical_router_object( obj_dict_payload, prouter_name ) _task_done() return { 'status': 'success', 'upd_pr_log': FilterLog.instance().dump(), 'physical_router_upd_resp': physical_router_upd_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return {'status': 'failure', 'error_msg': str(ex), 'upd_pr_log': FilterLog.instance().dump() }
def topology_discovery(self, job_ctx, prouter_fqname, lldp_neighbors_payload): """Topology discovery. :param job_ctx: Dictionary example: { "auth_token": "EB9ABC546F98", "job_input": { "fabric_fq_name": [ "default-global-system-config", "fab01" ], "device_auth": [{ "username": "******", "password": "******" }], "management_subnets": [ { "cidr": "10.87.69.0/25", "gateway": "10.87.69.1" } ], "overlay_ibgp_asn": 64512, "node_profiles": [ { "node_profile_name": "juniper-qfx5k" } ] } } :param prouter_fqname: List example: [ "default-global-system-config", "5c3-qfx2" ] :param lldp_neighbors_payload: Dictionary example: { "neighbor_info_list": [ { "local_physical_interface_name": "xe-0/0/0", "remote_device_name": "5b5-qfx11", "remote_physical_interface_port_id": "536" } ] } :return: Dictionary if success, returns { 'status': 'success', 'topology_discovery_log': <String: topology_discovery_log>, 'topology_discovery_resp': <Dictionary: topology_discovery_resp> } if failure, returns { 'status': 'failure', 'error_msg': <String: exception message>, 'topology_discovery_log': <String: topology_discovery_log>, 'topology_discovery_resp': <Dictionary: topology_discovery_resp> } :param topology_discovery_resp: Dictionary example: { "lldp_neighbors_success_names": <List: <String: lldp_neighbors_success_pair_string>>, "lldp_neighbors_failed_info": <List: <Dictionary: lldp_neighbor_failed_obj> > } :param lldp_neighbors_success_names: List example: ["bng-contrail-qfx51-15 : ge-0/0/36 --> dhawan : ge-2/3/1"] :param lldp_neighbors_failed_info: List example: [ { "lldp_neighbor": "bng-contrail-qfx51-15 : em0 --> sw174 : ge-1/0/46", "warning_message": "Unknown physical interface ng-contrail-qfx51-15:em0" } ] """ self._instantiate_filter_log_instance(prouter_fqname[-1]) _task_log("Starting Topology Discovery") try: _task_log("Creating neighboring links") topology_discovery_resp = self._create_neighbor_links( job_ctx, lldp_neighbors_payload, prouter_fqname) _task_done() return { 'status': 'success', 'topology_discovery_log': FilterLog.instance().dump(), 'topology_discovery_resp': topology_discovery_resp } except Exception as ex: _task_error_log(str(ex)) _task_error_log(traceback.format_exc()) return { 'status': 'failure', 'error_msg': str(ex), 'topology_discovery_log': FilterLog.instance().dump() }