def get_storage(self, context): try: result = None system_info = self.rest_handler.get_rest_info('/api/v1/systems') if system_info: system_data = system_info.get('data', {}).get('systems', []) if system_data: for system in system_data: name = system.get('name') model = system.get('MTM') serial_number = system.get('sn') version = system.get('release') status = constants.StorageStatus.NORMAL if system.get('state') != 'online': status = constants.StorageStatus.ABNORMAL total = 0 free = 0 used = 0 raw = 0 if system.get('cap') != '' and \ system.get('cap') is not None: total = int(system.get('cap')) if system.get('capraw') != '' and \ system.get('capraw') is not None: raw = int(system.get('capraw')) if system.get('capalloc') != '' and \ system.get('capalloc') is not None: used = int(system.get('capalloc')) if system.get('capavail') != '' and \ system.get('capavail') is not None: free = int(system.get('capavail')) result = { 'name': name, 'vendor': 'IBM', 'model': model, 'status': status, 'serial_number': serial_number, 'firmware_version': version, 'location': '', 'total_capacity': total, 'raw_capacity': raw, 'used_capacity': used, 'free_capacity': free } break else: raise exception.StorageBackendException( "ds8k storage system info is None") else: raise exception.StorageBackendException( "ds8k storage system info is None") return result except Exception as err: err_msg = "Failed to get storage attributes from ds8k: %s" % \ (six.text_type(err)) raise exception.InvalidResults(err_msg)
def do_call(self, url, data, method, calltimeout=SOCKET_TIMEOUT): if 'http' not in url: if self.san_address: url = '%s%s' % (self.san_address, url) kwargs = {'timeout': calltimeout} if data: kwargs['data'] = json.dumps(data) if method in ('POST', 'PUT', 'GET', 'DELETE'): func = getattr(self.session, method.lower()) else: msg = _("Request method %s is invalid.") % method LOG.error(msg) raise exception.StorageBackendException(msg) res = None try: res = func(url, **kwargs) except requests.exceptions.ConnectTimeout as ct: LOG.error('Connect Timeout err: {}'.format(ct)) raise exception.InvalidIpOrPort() except requests.exceptions.ReadTimeout as rt: LOG.error('Read timed out err: {}'.format(rt)) raise exception.StorageBackendException(six.text_type(rt)) except requests.exceptions.SSLError as e: LOG.error('SSLError for %s %s' % (method, url)) err_str = six.text_type(e) if 'certificate verify failed' in err_str: raise exception.SSLCertificateFailed() else: raise exception.SSLHandshakeFailed() except Exception as err: LOG.exception( 'Bad response from server: %(url)s.' ' Error: %(err)s', { 'url': url, 'err': err }) if 'WSAETIMEDOUT' in str(err): raise exception.ConnectTimeout() elif 'Failed to establish a new connection' in str(err): LOG.error('Failed to establish: {}'.format(err)) raise exception.InvalidIpOrPort() elif 'Read timed out' in str(err): raise exception.StorageBackendException(six.text_type(err)) else: raise exception.BadResponse() return res
def login(self): try: data = {} self.init_http_head() self.session.headers.update({ "username": self.rest_username, "password": cryptor.decode(self.rest_password) }) res = self.do_call(consts.REST_AUTH_URL, data, 'GET') if res.status_code != 200: LOG.error("Login error. URL: %(url)s\n" "Reason: %(reason)s.", { "url": consts.REST_AUTH_URL, "reason": res.text }) if 'User authentication failed' in res.text: raise exception.InvalidUsernameOrPassword() else: raise exception.StorageBackendException( six.text_type(res.text)) except Exception as e: LOG.error("Login error: %s", six.text_type(e)) raise e
def login(self): """Login dell_emc unity storage array.""" try: with self.session_lock: if self.session is None: self.init_http_head() self.session.headers.update({"X-EMC-REST-CLIENT": "true"}) self.session.auth = requests.auth.HTTPBasicAuth( self.rest_username, cryptor.decode(self.rest_password)) res = self.call_with_token(RestHandler.REST_AUTH_URL) if res.status_code == 200: self.session.headers[RestHandler.AUTH_KEY] = \ cryptor.encode(res.headers[RestHandler.AUTH_KEY]) else: LOG.error("Login error.URL: %s,Reason: %s.", RestHandler.REST_AUTH_URL, res.text) if 'Unauthorized' in res.text: raise exception.InvalidUsernameOrPassword() elif 'Forbidden' in res.text: raise exception.InvalidIpOrPort() else: raise exception.StorageBackendException( six.text_type(res.text)) except Exception as e: LOG.error("Login error: %s", six.text_type(e)) raise e
def get_storage(self): domain = self.navi_handler.get_domain() agent = self.navi_handler.get_agent() status = constants.StorageStatus.NORMAL raw_cap = self.handle_disk_capacity() pool_capacity = self.handle_pool_capacity() if domain and agent: result = { 'name': domain[0].get('node'), 'vendor': consts.EMCVNX_VENDOR, 'model': agent.get('model'), 'status': status, 'serial_number': agent.get('serial_no'), 'firmware_version': agent.get('revision'), 'total_capacity': pool_capacity.get('total_capacity'), 'raw_capacity': int(raw_cap), 'used_capacity': pool_capacity.get('used_capacity'), 'free_capacity': pool_capacity.get('free_capacity') } else: err_msg = "domain or agent error: %s, %s" %\ (six.text_type(domain), six.text_type(agent)) LOG.error(err_msg) raise exception.StorageBackendException(err_msg) return result
def do_exec(self, command_str): result = '' try: with self.item() as ssh: utils.check_ssh_injection(command_str) if command_str is not None and ssh is not None: stdin, stdout, stderr = ssh.exec_command(command_str) res, err = stdout.read(), stderr.read() re = res if res else err result = re.decode() except paramiko.AuthenticationException as ae: LOG.error('doexec Authentication error:{}'.format(ae)) raise exception.InvalidUsernameOrPassword() except Exception as e: err = six.text_type(e) LOG.error(err) if 'timed out' in err \ or 'SSH connect timeout' in err\ or 'Unable to connect to port' in err: raise exception.ConnectTimeout() elif 'No authentication methods available' in err \ or 'Authentication failed' in err \ or 'Invalid username or password' in err: raise exception.InvalidUsernameOrPassword() elif 'not a valid RSA private key file' in err \ or 'not a valid RSA private key' in err: raise exception.InvalidPrivateKey() else: raise exception.SSHException(err) if 'invalid command name' in result or 'login failed' in result or\ 'is not a recognized command' in result: raise exception.StorageBackendException(result) return result
def list_storage_pools(self, storage_id): try: # Get list of SRP pool names pools = self.conn.provisioning.get_srp_list() pool_list = [] for pool in pools: pool_info = self.conn.provisioning.get_srp(pool) srp_cap = pool_info['srp_capacity'] total_cap = srp_cap['usable_total_tb'] * units.Ti used_cap = srp_cap['usable_used_tb'] * units.Ti p = { "name": pool, "storage_id": storage_id, "native_storage_pool_id": pool_info["srpId"], "description": "Dell EMC VMAX Pool", "status": constants.StoragePoolStatus.NORMAL, "storage_type": constants.StorageType.BLOCK, "total_capacity": int(total_cap), "used_capacity": int(used_cap), "free_capacity": int(total_cap - used_cap), } pool_list.append(p) return pool_list except Exception as err: msg = "Failed to get pool metrics from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def get_array_performance_metrics(self, storage_id, start_time, end_time): """Get performance metrics.""" try: # Fetch VMAX Array Performance data from REST client # TODO : # Check whether array is registered for performance collection # in unisphere perf_data = self.rest.get_array_performance_metrics( self.array_id, start_time, end_time) # parse VMAX REST response to metric->values map metrics_value_map = perf_utils.parse_performance_data(perf_data) # prepare labels required for array_leval performance data labels = {'storage_id': storage_id, 'resource_type': 'array'} # map to unified delifn metrics delfin_metrics = perf_utils.\ map_array_perf_metrics_to_delfin_metrics(metrics_value_map) metrics_array = [] for key in constants.DELFIN_ARRAY_METRICS: m = constants.metric_struct(name=key, labels=labels, values=delfin_metrics[key]) metrics_array.append(m) return metrics_array except Exception as err: msg = "Failed to get performance metrics data for VMAX: {}".format( err) LOG.error(msg) raise exception.StorageBackendException(msg)
def _filter_performance_data(self, archive_file_list, resources_map, start_time, end_time): performance_lines_map = {} try: tools = Tools() for archive_file in archive_file_list: self.navi_handler.download_archives(archive_file) archive_name_infos = archive_file.split('.') file_path = '%s%s.csv' % ( self.navi_handler.get_local_file_path(), archive_name_infos[0]) with open(file_path) as file: f_csv = csv.reader(file) next(f_csv) for row in f_csv: self._package_performance_data(row, resources_map, start_time, end_time, tools, performance_lines_map) except Exception as err: err_msg = "Failed to filter performance data: %s" % \ (six.text_type(err)) LOG.error(err_msg) raise exception.StorageBackendException(err_msg) return performance_lines_map
def do_call(self, url, data, method, calltimeout=consts.SOCKET_TIMEOUT): """Send requests to Hpe3par storage server. """ if 'http' not in url: if self.san_address: url = self.san_address + url kwargs = {'timeout': calltimeout} if data: kwargs['data'] = json.dumps(data) if method in ('POST', 'PUT', 'GET', 'DELETE'): func = getattr(self.session, method.lower()) else: msg = _("Request method %s is invalid.") % method LOG.error(msg) raise exception.StorageBackendException(reason=msg) res = None try: res = func(url, **kwargs) except requests.exceptions.ConnectTimeout as ct: LOG.error('ConnectTimeout err: {}'.format(ct)) raise exception.ConnectTimeout() except Exception as err: LOG.exception('Bad response from server: %(url)s.' ' Error: %(err)s', {'url': url, 'err': err}) if 'WSAETIMEDOUT' in str(err): raise exception.ConnectTimeout() else: raise exception.BadResponse() return res
def login(self): try: data = { 'request': { 'params': { "username": self.rest_username, "password": cryptor.decode(self.rest_password) } } } with self.session_lock: if self.session is None: self.init_http_head() res = self.call_with_token( RestHandler.REST_TOKEN_URL, data, 'POST') if res.status_code == 200: result = res.json() self.session.headers['X-Auth-Token'] = \ cryptor.encode(result.get('token').get('token')) else: LOG.error("Login error. URL: %(url)s,Reason: %(reason)s.", {"url": RestHandler.REST_TOKEN_URL, "reason": res.text}) if 'Authentication has failed' in res.text: raise exception.InvalidUsernameOrPassword() else: raise exception.StorageBackendException(res.text) except Exception as e: LOG.error("Login error: %s", six.text_type(e)) raise e finally: data = None
def init_connection(self, access_info): """ Given the access_info get a connection to VMAX storage """ try: ver, self.uni_version = self.rest.get_uni_version() LOG.info('Connected to Unisphere Version: {0}'.format(ver)) except Exception as err: msg = "Failed to connect to VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg) self.array_id = access_info.get('extra_attributes', {}). \ get('array_id', None) # Get array details from unisphere array = self.rest.get_array_detail(version=self.uni_version) if len(array['symmetrixId']) == EMBEDDED_UNISPHERE_ARRAY_COUNT: if not self.array_id: self.array_id = array['symmetrixId'][0] elif self.array_id != array['symmetrixId'][0]: msg = "Invalid array_id. Supported id: {}". \ format(array['symmetrixId']) raise exception.InvalidInput(msg) if not self.array_id: msg = "Input array_id is missing. Supported ids: {}". \ format(array['symmetrixId']) raise exception.InvalidInput(msg)
def list_volumes(self, context): try: # Get all volumes in OceanStor volumes = self.client.get_all_volumes() pools = self.client.get_all_pools() volume_list = [] for volume in volumes: # Get pool id of volume orig_pool_id = '' for pool in pools: if volume['PARENTNAME'] == pool['NAME']: orig_pool_id = pool['ID'] compressed = False if volume['ENABLECOMPRESSION'] != 'false': compressed = True deduplicated = False if volume['ENABLEDEDUP'] != 'false': deduplicated = True status = constants.VolumeStatus.ERROR if volume['RUNNINGSTATUS'] == consts.STATUS_VOLUME_READY: status = constants.VolumeStatus.AVAILABLE vol_type = constants.VolumeType.THICK if volume['ALLOCTYPE'] == consts.THIN_LUNTYPE: vol_type = constants.VolumeType.THIN sector_size = int(volume['SECTORSIZE']) total_cap = int(volume['CAPACITY']) * sector_size used_cap = int(volume['ALLOCCAPACITY']) * sector_size v = { 'name': volume['NAME'], 'storage_id': self.storage_id, 'description': 'Huawei OceanStor volume', 'status': status, 'native_volume_id': volume['ID'], 'native_storage_pool_id': orig_pool_id, 'wwn': volume['WWN'], 'type': vol_type, 'total_capacity': total_cap, 'used_capacity': used_cap, 'free_capacity': None, 'compressed': compressed, 'deduplicated': deduplicated, } volume_list.append(v) return volume_list except Exception as err: LOG.error( "Failed to get list volumes from OceanStor: {}".format(err)) raise exception.StorageBackendException( reason='Failed to get list volumes from OceanStor')
def _assert_rest_result(self, result, err_str): if result['error']['code'] != 0: msg = (_('%(err)s\nresult: %(res)s.') % { 'err': err_str, 'res': result }) LOG.error(msg) raise exception.StorageBackendException(msg)
def login(self): """Login Huawei storage array.""" device_id = None for item_url in self.san_address: url = item_url + "xx/sessions" data = { "username": self.rest_username, "password": cryptor.decode(self.rest_password), "scope": "0" } self.init_http_head() result = self.do_call(url, data, 'POST', calltimeout=consts.LOGIN_SOCKET_TIMEOUT, log_filter_flag=True) if (result['error']['code'] != 0) or ("data" not in result): LOG.error("Login error. URL: %(url)s\n" "Reason: %(reason)s.", { "url": item_url, "reason": result }) continue LOG.debug('Login success: %(url)s', {'url': item_url}) device_id = result['data']['deviceid'] self.device_id = device_id self.url = item_url + device_id self.session.headers['iBaseToken'] = result['data']['iBaseToken'] if (result['data']['accountstate'] in (consts.PWD_EXPIRED, consts.PWD_RESET)): self.logout() msg = _("Password has expired or has been reset, " "please change the password.") LOG.error(msg) raise exception.StorageBackendException(msg) break if device_id is None: msg = _("Failed to login with all rest URLs.") LOG.error(msg) raise exception.StorageBackendException(msg) return device_id
def logout(self): res = self.do_call(RestHandler.REST_SESSION_URL, None, method='DELETE') if res.status_code != consts.SUCCESS_STATUS_CODE\ or not res.json().get('username'): LOG.error( "Logout error, Deleting a Token Exception." "status_code:%s, URL: %s", res.status_code, RestHandler.REST_SESSION_URL) raise exception.StorageBackendException(res.text)
def get_storage_capacity(self): try: storage_info = self.rest.get_system_capacity( self.array_id, self.uni_version) return storage_info except Exception as err: msg = "Failed to get capacity from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def get_array_details(self): try: # Get the VMAX array properties return self.rest.get_vmax_array_details(version=self.uni_version, array=self.array_id) except Exception as err: msg = "Failed to get array details from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def get_model(self): try: # Get the VMAX model uri = "/system/symmetrix/" + self.array_id model = self.conn.common.get_request(uri, "") return model['symmetrix'][0]['model'] except Exception as err: msg = "Failed to get model from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def exec_command(self, command): re = self.ssh_pool.do_exec(command) if re: if 'invalid command name' in re or 'Invalid option' in re: LOG.warning(re) raise NotImplementedError(re) elif 'Too many local CLI connections' in re: LOG.error("command %s failed: %s" % (command, re)) raise exception.StorageBackendException(re) return re
def get_storage_capacity(self): try: uri = "/" + SUPPORTED_VERSION \ + "/sloprovisioning/symmetrix/" + self.array_id storage_info = self.conn.common.get_request(uri, "") return storage_info['system_capacity'] except Exception as err: msg = "Failed to get capacity from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def do_call(self, url, data, method, calltimeout=consts.SOCKET_TIMEOUT, log_filter_flag=False): """Send requests to Huawei storage server. Send HTTPS call, get response in JSON. Convert response into Python Object and return it. """ if self.url: url = self.url + url kwargs = {'timeout': calltimeout} if data: kwargs['data'] = json.dumps(data) if method in ('POST', 'PUT', 'GET', 'DELETE'): func = getattr(self.session, method.lower()) else: msg = _("Request method %s is invalid.") % method LOG.error(msg) raise exception.StorageBackendException(msg) try: res = func(url, **kwargs) except requests.exceptions.SSLError as e: LOG.error('SSLError exception from server: %(url)s.' ' Error: %(err)s', {'url': url, 'err': e}) err_str = six.text_type(e) if 'certificate verify failed' in err_str: raise exception.SSLCertificateFailed() else: raise exception.SSLHandshakeFailed() except Exception as err: LOG.exception('Bad response from server: %(url)s.' ' Error: %(err)s', {'url': url, 'err': err}) return {"error": {"code": consts.ERROR_CONNECT_TO_SERVER, "description": "Connect to server error."}} try: res.raise_for_status() except requests.HTTPError as exc: return {"error": {"code": exc.response.status_code, "description": six.text_type(exc)}} res_json = res.json() if not log_filter_flag: LOG.info('\n\n\n\nRequest URL: %(url)s\n\n' 'Call Method: %(method)s\n\n' 'Request Data: %(data)s\n\n' 'Response Data:%(res)s\n\n', {'url': url, 'method': method, 'data': data, 'res': res_json}) return res_json
def login(self): try: data = { 'username': self.rest_username, 'password': cryptor.decode(self.rest_password) } self.init_http_head() token_res = self.do_call(RestHandler.REST_AUTH_URL, data, method='POST') if token_res.json().get('msg') == consts.LOGIN_PASSWORD_ERR: LOG.error( "Login error, Obtaining the token is abnormal. " "status_code:%s, URL: %s", token_res.status_code, RestHandler.REST_AUTH_URL) raise exception.InvalidUsernameOrPassword( 'Obtaining the token is abnormal') if token_res.status_code != consts.SUCCESS_STATUS_CODE or not \ token_res.json().get('api_token'): LOG.error( "Login error, Obtaining the token is abnormal. " "status_code:%s, URL: %s", token_res.status_code, RestHandler.REST_AUTH_URL) raise exception.StorageBackendException( 'Obtaining the token is abnormal') session_res = self.do_call(RestHandler.REST_SESSION_URL, token_res.json(), method='POST') if session_res.status_code != consts.SUCCESS_STATUS_CODE or not \ session_res.json().get('username'): LOG.error( "Login error, Obtaining the session is abnormal." "status_code:%s, URL: %s", session_res.status_code, RestHandler.REST_SESSION_URL) raise exception.StorageBackendException( 'Obtaining the session is abnormal.') except Exception as e: LOG.error("Login error: %s", six.text_type(e)) raise e finally: data = None token_res = None
def login(self): """Login Hpe3par storage array.""" try: access_session = self.rest_client.rest_auth_token if self.rest_client.san_address: url = RestHandler.REST_AUTH_URL data = { "user": self.rest_client.rest_username, "password": cryptor.decode(self.rest_client.rest_password) } self.session_lock.acquire() if self.rest_client.rest_auth_token is not None: return self.rest_client.rest_auth_token self.rest_client.init_http_head() res = self.rest_client. \ do_call(url, data, 'POST', calltimeout=consts.SOCKET_TIMEOUT) if res is None: LOG.error('Login res is None') raise exception.InvalidResults('res is None') if res.status_code == consts. \ LOGIN_SUCCESS_STATUS_CODES: result = res.json() access_session = result.get('key') self.rest_client.rest_auth_token = access_session self.rest_client.session.headers[ RestHandler.REST_AUTH_KEY] = access_session else: LOG.error( "Login error. URL: %(url)s\n" "Reason: %(reason)s.", { "url": url, "reason": res.text }) if 'invalid username or password' in res.text: raise exception.InvalidUsernameOrPassword() else: raise exception.StorageBackendException( six.text_type(res.text)) else: LOG.error('Login Parameter error') return access_session except Exception as e: LOG.error("Login error: %s", six.text_type(e)) raise e finally: self.session_lock.release()
def get_resinfo_call(self, url, data=None, method=None): rejson = None res = self.call(url, data, method) if res is not None: if res.status_code == consts.SUCCESS_STATUS_CODES: rejson = res.json() else: if res.text and 'unsupported' in res.text: LOG.warning('rest api error: {}'.format(res.text)) else: raise exception.StorageBackendException(res.text) return rejson
def get_storage(self, context): storages = self.rest_handler.rest_call( self.rest_handler.REST_STORAGE_URL) total_capacity = None used_capacity = None if storages: for storage in storages: used_capacity = int( storage.get('total', consts.DEFAULT_CAPACITY)) total_capacity = int( storage.get('capacity', consts.DEFAULT_CAPACITY)) break raw_capacity = consts.DEFAULT_CAPACITY disks = self.list_disks(context) if disks: for disk in disks: raw_capacity = raw_capacity + disk.get('capacity') arrays = self.rest_handler.rest_call(self.rest_handler.REST_ARRAY_URL) storage_name = None serial_number = None version = None if arrays: storage_name = arrays.get('array_name') serial_number = arrays.get('id') version = arrays.get('version') model = None status = constants.StorageStatus.NORMAL controllers = self.rest_handler.rest_call( self.rest_handler.REST_CONTROLLERS_URL) if controllers: for controller in controllers: if controller.get('mode') == consts.CONTROLLER_PRIMARY: model = controller.get('model') if controller.get('status') != \ consts.NORMAL_CONTROLLER_STATUS: status = constants.StorageStatus.ABNORMAL if not all((storages, arrays, controllers)): LOG.error('get_storage error, Unable to obtain data.') raise exception.StorageBackendException('Unable to obtain data') storage_result = { 'model': model, 'total_capacity': total_capacity, 'raw_capacity': raw_capacity, 'used_capacity': used_capacity, 'free_capacity': total_capacity - used_capacity, 'vendor': 'PURE', 'name': storage_name, 'serial_number': serial_number, 'firmware_version': version, 'status': status } return storage_result
def init_connection(self, access_info): """ Given the access_info get a connection to VMAX storage """ try: ver, self.uni_version = self.rest.get_uni_version() LOG.info('Connected to Unisphere Version: {0}'.format(ver)) except exception.InvalidUsernameOrPassword as e: msg = "Failed to connect VMAX. Reason: {}".format(e.msg) LOG.error(msg) raise e except (exception.SSLCertificateFailed, exception.SSLHandshakeFailed) as e: msg = ("Failed to connect to VMAX: {}".format(e)) LOG.error(msg) raise except Exception as err: msg = ("Failed to connect to VMAX. Host or Port is not correct: " "{}".format(err)) LOG.error(msg) raise exception.InvalidIpOrPort() if not self.uni_version: msg = "Invalid input. Failed to get vmax unisphere version" raise exception.InvalidInput(msg) self.array_id = access_info.get('extra_attributes', {}). \ get('array_id', None) try: # Get array details from unisphere array = self.rest.get_array_detail(version=self.uni_version) if not array: msg = "Failed to get array details" raise exception.InvalidInput(msg) if len(array['symmetrixId']) == EMBEDDED_UNISPHERE_ARRAY_COUNT: if not self.array_id: self.array_id = array['symmetrixId'][0] elif self.array_id != array['symmetrixId'][0]: msg = "Invalid array_id. Expected id: {}". \ format(array['symmetrixId']) raise exception.InvalidInput(msg) except exception.SSLCertificateFailed: LOG.error('SSL certificate failed when init connection for VMax') raise except Exception as err: msg = "Failed to get array details from VMAX: {}".format(err) raise exception.StorageBackendException(msg) if not self.array_id: msg = "Input array_id is missing. Supported ids: {}". \ format(array['symmetrixId']) raise exception.InvalidInput(msg)
def list_storage_pools(self, storage_id): try: # Get list of SRP pool names pools = self.rest.get_srp_by_name(self.array_id, self.uni_version, srp='')['srpId'] pool_list = [] for pool in pools: pool_info = self.rest.get_srp_by_name(self.array_id, self.uni_version, srp=pool) total_cap = 0 used_cap = 0 subscribed_cap = 0 if int(self.uni_version) < 90: total_cap = pool_info['total_usable_cap_gb'] * units.Gi used_cap = pool_info['total_allocated_cap_gb'] * units.Gi subscribed_cap =\ pool_info['total_subscribed_cap_gb'] * units.Gi else: srp_cap = pool_info['srp_capacity'] total_cap = srp_cap['usable_total_tb'] * units.Ti used_cap = srp_cap['usable_used_tb'] * units.Ti subscribed_cap = srp_cap['subscribed_total_tb'] * units.Ti p = { "name": pool, "storage_id": storage_id, "native_storage_pool_id": pool_info["srpId"], "description": "Dell EMC VMAX Pool", "status": constants.StoragePoolStatus.NORMAL, "storage_type": constants.StorageType.BLOCK, "total_capacity": int(total_cap), "used_capacity": int(used_cap), "free_capacity": int(total_cap - used_cap), "subscribed_capacity": int(subscribed_cap), } pool_list.append(p) return pool_list except exception.SSLCertificateFailed: LOG.error('SSL certificate failed when list pools for VMax') raise except Exception as err: msg = "Failed to get pool metrics from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def get_storage_capacity(self): try: storage_info = self.rest.get_system_capacity( self.array_id, self.uni_version) return storage_info except exception.SSLCertificateFailed: LOG.error('SSL certificate failed when ' 'get storage capacity for VMax') raise except Exception as err: msg = "Failed to get capacity from VMAX: {}".format(err) LOG.error(msg) raise exception.StorageBackendException(msg)
def _remove_archive_file(self, archive_file_list): try: for archive_file in archive_file_list: nar_file_path = '%s%s' % ( self.navi_handler.get_local_file_path(), archive_file) archive_name_infos = archive_file.split('.') csv_file_path = '%s%s.csv' % ( self.navi_handler.get_local_file_path(), archive_name_infos[0]) for file_path in [nar_file_path, csv_file_path]: LOG.info("Delete file :{}".format(file_path)) if os.path.exists(file_path): os.remove(file_path) else: err_msg = 'no such file:%s' % file_path LOG.error(err_msg) raise exception.StorageBackendException(err_msg) except Exception as err: err_msg = "Failed to remove archive file: %s" % \ (six.text_type(err)) LOG.error(err_msg) raise exception.StorageBackendException(err_msg)