def _get_password(device_obj): """ Get and return decrypted password. """ password = device_obj.physical_router_user_credentials.get_password() return JobVncApi.decrypt_password(encrypted_password=password, pwd_key=device_obj.uuid)
def get_ztp_tftp_config(cls, job_ctx, fabric_uuid): tftp_config = {} try: vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY, auth_token=job_ctx.get('auth_token')) fabric = vncapi.fabric_read(id=fabric_uuid) fabric_dict = vncapi.obj_to_dict(fabric) fabric_creds = fabric_dict.get('fabric_credentials') if fabric_creds: device_creds = fabric_creds.get('device_credential') if device_creds: dev_cred = device_creds[0] password = JobVncApi.decrypt_password( encrypted_password=dev_cred['credential']['password'], admin_password=job_ctx.get('vnc_api_init_params').get( 'admin_password')) tftp_config['password'] = password except Exception as ex: logging.error( "Error getting ZTP TFTP configuration: {}".format(ex)) return tftp_config
def get_ztp_tftp_config(cls, job_ctx, fabric_uuid): tftp_config = {} try: vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY, auth_token=job_ctx.get('auth_token')) fabric = vncapi.fabric_read(id=fabric_uuid) fabric_dict = vncapi.obj_to_dict(fabric) fabric_creds = fabric_dict.get('fabric_credentials') if fabric_creds: device_creds = fabric_creds.get('device_credential') if device_creds: dev_cred = device_creds[0] password = JobVncApi.decrypt_password( encrypted_password=dev_cred['credential']['password'], admin_password=job_ctx.get( 'vnc_api_init_params').get( 'admin_password')) tftp_config['password'] = password except Exception as ex: logging.error("Error getting ZTP TFTP configuration: {}".format(ex)) return tftp_config
def initial_processing(self, concurrent): self.serial_num_flag = False self.all_serial_num = [] serial_num = [] self.per_greenlet_percentage = None self.job_ctx['current_task_index'] = 2 try: total_percent = self.job_ctx.get('playbook_job_percentage') if total_percent: total_percent = float(total_percent) # Calculate the total percentage of this entire greenlet based task # This will be equal to the percentage alloted to this task in the # weightage array off the total job percentage. For example: # if the task weightage array is [10, 85, 5] and total job % # is 95. Then the 2nd task's effective total percentage is 85% of # 95% total_task_percentage = self.module.calculate_job_percentage( self.job_ctx.get('total_task_count'), task_seq_number=self.job_ctx.get('current_task_index'), total_percent=total_percent, task_weightage_array=self.job_ctx.get( 'task_weightage_array'))[0] # Based on the number of greenlets spawned (i.e num of sub tasks) # split the total_task_percentage equally amongst the greenlets. self.logger.info("Number of greenlets: {} and total_percent: " "{}".format(concurrent, total_task_percentage)) self.per_greenlet_percentage = \ self.module.calculate_job_percentage( concurrent, total_percent=total_task_percentage)[0] self.logger.info("Per greenlet percent: " "{}".format(self.per_greenlet_percentage)) self.vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY, auth_token=self.job_ctx.get('auth_token')) except Exception as ex: self.logger.info("Percentage calculation failed with error " "{}".format(str(ex))) try: self.vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY, auth_token=self.job_ctx.get('auth_token')) except Exception as ex: self.module.results['failed'] = True self.module.results['msg'] = "Failed to connect to API server " \ "due to error: %s"\ % str(ex) self.module.exit_json(**self.module.results) # get credentials and serial number if greenfield if self.total_retry_timeout: # get device credentials fabric = self.vncapi.fabric_read(id=self.fabric_uuid) fabric_object = self.vncapi.obj_to_dict(fabric) self.credentials = fabric_object.get('fabric_credentials').get( 'device_credential') # get serial numbers fabric_namespace_obj_list = self.vncapi.fabric_namespaces_list( parent_id=self.fabric_uuid, detail=True) fabric_namespace_list = self.vncapi.obj_to_dict( fabric_namespace_obj_list) for namespace in fabric_namespace_list: if namespace.get('fabric_namespace_type') == "SERIAL_NUM": self.serial_num_flag = True serial_num.append(namespace.get( 'fabric_namespace_value').get('serial_num')) if len(serial_num) > 1: for outer_list in serial_num: for sn in outer_list: self.all_serial_num.append(sn) else: self.credentials = self.module.params['credentials'] for cred in self.credentials: if cred.get('credential', {}).get('password'): cred['credential']['password'] = JobVncApi.decrypt_password( encrypted_password=cred.get('credential', {}).get('password'), admin_password=self.job_ctx.get('vnc_api_init_params').get( 'admin_password'))
def _get_password(self, device_obj): return JobVncApi.decrypt_password( encrypted_password=device_obj.physical_router_user_credentials. get_password(), pwd_key=device_obj.uuid)
def decrypt_device_password(cls, encrypted_password, secret_key): return JobVncApi.decrypt_password( encrypted_password=encrypted_password, pwd_key=secret_key)
def read_device_data(self, device_list, request_params, job_exec_id, is_delete=False): device_data = dict() for device_id in device_list: if not is_delete: try: (ok, result) = self.db_read("physical-router", device_id, [ 'physical_router_user_credentials', 'physical_router_management_ip', 'fq_name', 'physical_router_device_family', 'physical_router_vendor_name', 'physical_router_product_name', 'fabric_refs' ]) if not ok: msg = "Error while reading the physical router " \ "with id %s : %s" % (device_id, result) raise JobException(msg, job_exec_id) except NoIdError as ex: msg = "Device not found" \ "%s: %s" % (device_id, str(ex)) raise JobException(msg, job_exec_id) except Exception as e: msg = "Exception while reading device %s %s " % \ (device_id, str(e)) raise JobException(msg, job_exec_id) device_fq_name = result.get('fq_name') device_mgmt_ip = result.get('physical_router_management_ip') user_cred = result.get('physical_router_user_credentials') device_family = result.get("physical_router_device_family") device_vendor_name = result.get("physical_router_vendor_name") device_product_name = result.get( "physical_router_product_name") fabric_refs = result.get('fabric_refs') if fabric_refs: fabric_fq_name = result.get('fabric_refs')[0].get('to') fabric_fq_name_str = ':'.join(fabric_fq_name) request_params['fabric_fq_name'] = fabric_fq_name_str else: device_mgmt_ip = request_params.get( 'input', {}).get('device_management_ip') device_abs_cfg = request_params.get( 'input', {}).get('device_abstract_config') system = device_abs_cfg.get('system', {}) device_name = system.get('name') device_username = system.get('credentials', {}).get('user_name') device_password = system.get('credentials', {}).get('password') user_cred = { "username": device_username, "password": device_password } device_family = system.get('device_family') device_vendor_name = system.get('vendor_name') device_product_name = system.get('product_name') device_fq_name = ["default-global-system-config", device_name] self.read_fabric_data(request_params, job_exec_id, is_delete) device_json = {"device_management_ip": device_mgmt_ip} device_json.update({"device_fqname": device_fq_name}) if user_cred: device_json.update( {"device_username": user_cred.get('username')}) decrypt_password = JobVncApi.decrypt_password( encrypted_password=user_cred.get('password'), pwd_key=device_id) device_json.update({"device_password": decrypt_password}) if device_family: device_json.update({"device_family": device_family}) if device_vendor_name: device_json.update({"device_vendor": device_vendor_name}) if device_product_name: device_json.update({"device_product": device_product_name}) device_data.update({device_id: device_json}) if len(device_data) > 0: request_params.update({"device_json": device_data})
def _get_password(self, device_obj): return JobVncApi.decrypt_password( encrypted_password=device_obj.physical_router_user_credentials.\ get_password(), admin_password=self.job_ctx.get('vnc_api_init_params').\ get('admin_password'))