def get_device_info( self, job_ctx, device_uuid, ): try: FilterLog.instance("HitlessUpgradeFilter") self.job_input = FilterModule._validate_job_ctx(job_ctx) self.fabric_uuid = self.job_input['fabric_uuid'] self.vncapi = JobVncApi.vnc_init(job_ctx) self.job_ctx = job_ctx self.ja = JobAnnotations(self.vncapi) self.advanced_parameters = self._get_advanced_params() self._cache_job_input() self.device_uuid = device_uuid device_info = self._get_device_info() return device_info except Exception as ex: errmsg = "Unexpected error getting device info: %s\n%s" % ( str(ex), traceback.format_exc()) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, }
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 get_hitless_upgrade_plan(self, job_ctx, image_upgrade_list, device_json): try: FilterLog.instance("HitlessUpgradeFilter") self.job_input = FilterModule._validate_job_ctx(job_ctx) self.fabric_uuid = self.job_input['fabric_uuid'] self.vncapi = JobVncApi.vnc_init(job_ctx) self.job_ctx = job_ctx self.ja = JobAnnotations(self.vncapi) self.advanced_parameters = self._get_advanced_params() self._cache_job_input() self.batch_limit = self.advanced_parameters.get( 'bulk_device_upgrade_count') self.image_upgrade_list = image_upgrade_list self.device_json = device_json upgrade_plan = self._get_hitless_upgrade_plan() return upgrade_plan except Exception as ex: errmsg = "Unexpected error: %s\n%s" % (str(ex), traceback.format_exc()) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, }
def validate_critical_roles_for_hitless(self, job_ctx, image_upgrade_list): try: FilterLog.instance("HitlessUpgradeFilter") self.job_input = FilterModule._validate_job_ctx(job_ctx) self.fabric_uuid = self.job_input['fabric_uuid'] self.vncapi = JobVncApi.vnc_init(job_ctx) self.job_ctx = job_ctx self.ja = JobAnnotations(self.vncapi) self.advanced_parameters = self._get_advanced_params() self._cache_job_input() self.image_upgrade_list = image_upgrade_list self.device_uuid_list = [] for image_entry in self.image_upgrade_list: device_list = image_entry.get('device_list') image_uuid = image_entry.get('image_uuid') image_obj = self.vncapi.device_image_read(id=image_uuid) for device_uuid in device_list: device_obj = self.vncapi.physical_router_read( id=device_uuid) if image_obj.device_image_os_version !=\ device_obj.physical_router_os_version: self.device_uuid_list.append(device_uuid) results = self._validate_critical_roles_for_hitless_upgrade() return results except Exception as ex: errmsg = "Unexpected error validating: %s\n%s" % ( str(ex), traceback.format_exc()) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, }
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 render_fabric_config(self, job_ctx): try: FilterLog.instance("FabricConfigFilter") self._initialize(job_ctx) self._get_feature_list() return self._render_config() except Exception as ex: errmsg = "Unexpected error: %s\n%s" % (str(ex), traceback.format_exc()) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, 'onboard_log': FilterLog.instance().dump() }
def rma_devices_to_ztp(self, job_ctx, rma_devices_list): try: FilterLog.instance("RmaDevicesFilter") self.job_input = FilterModule._validate_job_ctx(job_ctx) self.vncapi = JobVncApi.vnc_init(job_ctx) self.job_ctx = job_ctx return self._rma_devices_to_ztp(rma_devices_list) except Exception as ex: errmsg = "Unexpected error: %s\n%s" % (str(ex), traceback.format_exc()) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, }
def report_percentage_completion(self, job_ctx, percentage): logger = FilterLog.instance("WritePercentToFileFilter").logger() job_file_write = JobFileWrite(logger) exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx) job_file_write.write_to_file( exec_id, unique_pb_id, JobFileWrite.JOB_PROGRESS, str(percentage) ) return { 'status': 'success', 'write_to_file_log': 'Successfully wrote progress to streaming file'}
def report_percentage_completion(self, job_ctx, percentage): logger = FilterLog.instance("WritePercentToFileFilter").logger() job_file_write = JobFileWrite(logger) exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx) job_file_write.write_to_file( exec_id, unique_pb_id, JobFileWrite.JOB_PROGRESS, str(percentage) ) return { 'status': 'success', 'write_to_file_log': 'Successfully wrote progress to streaming file' }
def report_playbook_results(self, job_ctx, pb_results): logger = FilterLog.instance("WritePbResultsToFileFilter").logger() job_file_write = JobFileWrite(logger) exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx) job_file_write.write_to_file( exec_id, unique_pb_id, JobFileWrite.GEN_DEV_OP_RES, str(pb_results) ) return { 'status': 'success', 'write_to_file_log': 'Successfully wrote command results to streaming file'}
def report_playbook_results(self, job_ctx, pb_results): logger = FilterLog.instance("WritePbResultsToFileFilter").logger() job_file_write = JobFileWrite(logger) exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx) job_file_write.write_to_file( exec_id, unique_pb_id, JobFileWrite.GEN_DEV_OP_RES, str(pb_results) ) return { 'status': 'success', 'write_to_file_log': 'Successfully wrote command results to streaming file' }
def _render_config(self): # Get list of all legacy feature directories legacy_feature_list = \ [name[4:] for name in os.listdir('./roles') if name.startswith('cfg_')] feature_list = [name for name in os.listdir('./config_templates')] # Loop through all the features for feature in self.feature_apply_order: # If not managing underlay for this feature, skip if 'underlay' in feature and not self.manage_underlay \ and 'ip_clos' not in feature: continue feature_based_only = feature not in legacy_feature_list apply_feature_based = feature in self.feature_based_list if feature in feature_list and \ (apply_feature_based or feature_based_only): is_empty = not apply_feature_based feature_template_dir = './config_templates/' + feature else: feature_template_dir = './roles/cfg_' + feature + '/templates' is_empty = feature not in self.dev_feature_list feature_template_list = self._get_feature_templates( feature_template_dir, feature) # If feature not supported on this platform, skip if not feature_template_list: continue # For each feature template, including model-specific templates, # render the jinja template for template in feature_template_list: self._render_feature_config(feature, template, is_empty) # Write to config file which will be sent to device with open(self.combined_config_path, 'w') as f: f.write(self.final_config) # Generate return output to be used by playbook render_output = { 'conf_dir': self.conf_dir, 'combined_config': self.combined_config_path, 'device_mgmt_ip': self.device_mgmt_ip, 'device_vendor': self.device_vendor, 'device_name': self.device_name, 'device_uuid': self.device_uuid, 'device_username': self.device_username, 'device_password': "******", 'is_delete': self.is_delete, 'enterprise_style': self.enterprise_style, 'onboard_log': FilterLog.instance().dump(), 'results': {}, 'status': "success" } _task_error_log("render_output: %s" % render_output) render_output['device_password'] = self.device_password return render_output
def get_device_info(self, job_ctx, device_uuid): try: FilterLog.instance("HitlessUpgradeFilter") self.job_input = FilterModule._validate_job_ctx(job_ctx) self.fabric_uuid = self.job_input['fabric_uuid'] self.vncapi = JobVncApi.vnc_init(job_ctx) self.job_ctx = job_ctx self.ja = JobAnnotations(self.vncapi) self.advanced_parameters = self._get_advanced_params() self._cache_job_input() self.device_uuid = device_uuid device_info = self._get_device_info() return device_info except Exception as ex: errmsg = "Unexpected error getting device info: %s\n%s" % ( str(ex), traceback.format_exc() ) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, }
def get_hitless_upgrade_plan(self, job_ctx, image_upgrade_list): try: FilterLog.instance("HitlessUpgradeFilter") self.job_input = FilterModule._validate_job_ctx(job_ctx) self.fabric_uuid = self.job_input['fabric_uuid'] self.vncapi = JobVncApi.vnc_init(job_ctx) self.job_ctx = job_ctx self.ja = JobAnnotations(self.vncapi) self.advanced_parameters = self._get_advanced_params() self._cache_job_input() self.batch_limit = self.advanced_parameters.get( 'bulk_device_upgrade_count') self.image_upgrade_list = image_upgrade_list upgrade_plan = self._get_hitless_upgrade_plan() return upgrade_plan except Exception as ex: errmsg = "Unexpected error: %s\n%s" % ( str(ex), traceback.format_exc() ) _task_error_log(errmsg) return { 'status': 'failure', 'error_msg': errmsg, }
def _render_config(self): # Get list of all config feature directories feature_dir_list = \ [name for name in os.listdir("./roles") if name.startswith("cfg_")] feature_list = [feature_dir[4:] for feature_dir in feature_dir_list] feature_list.sort() # Loop through all the features for feature in feature_list: feature_template_dir = './roles/cfg_' + feature + '/templates' feature_template_list = self._get_feature_templates( feature_template_dir, feature) # If feature not supported on this platform, skip if not feature_template_list: continue # If not managing underlay for this feature, skip if 'underlay' in feature and not self.manage_underlay: continue # For each feature template, including model-specific templates, # render the jinja template for feature_template in feature_template_list: self._render_feature_config( feature, feature_template, False if feature in self.dev_feature_list else True) self._render_feature_based_config() # Write to config file which will be sent to device with open(self.combined_config_path, 'w') as f: f.write(self.final_config) # Generate return output to be used by playbook render_output = { 'conf_dir': self.conf_dir, 'combined_config': self.combined_config_path, 'device_mgmt_ip': self.device_mgmt_ip, 'device_vendor': self.device_vendor, 'device_name': self.device_name, 'device_username': self.device_username, 'device_password': self.device_password, 'is_delete': self.is_delete, 'onboard_log': FilterLog.instance().dump(), 'results': {}, 'status': "success" } return render_output
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 _instantiate_filter_log_instance(self, device_name): FilterLog.instance("DeviceImportFilter", device_name)
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 _instantiate_filter_log_instance(self, device_name): FilterLog.instance("Import_lldp_info_Filter", device_name)
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 _instantiate_filter_log_instance(self, device_name): FilterLog.instance("ValidateSchemaFilter", device_name)
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 _instantiate_filter_log_instance(self, device_name): FilterLog.instance("Import_hardware_inventory_info_Filter", device_name)
def _instantiate_filter_log_instance(self, device_name): FilterLog.instance("Cli sync filter", device_name)
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 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 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 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 _instantiate_filter_log_instance(self, device_name): FilterLog.instance("TopologyDiscoveryFilter", device_name)
def _instantiate_filter_log_instance(self, device_name): FilterLog.instance("Import_interfaces_infoFilter", device_name)
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() }