def create(self, req, body): """Register a new storage device.""" ctxt = req.environ['delfin.context'] access_info_dict = body # Lock to avoid synchronous creating. for access in constants.ACCESS_TYPE: if access_info_dict.get(access) is not None: host = access_info_dict.get(access).get('host') break lock_name = 'storage-create-' + host lock = coordination.Lock(lock_name) with lock: if self._storage_exist(ctxt, access_info_dict): raise exception.StorageAlreadyExists() storage = self.driver_api.discover_storage(ctxt, access_info_dict) # Registration success, sync resource collection for this storage try: self.sync(req, storage['id']) # Post registration, trigger alert sync self.task_rpcapi.sync_storage_alerts(ctxt, storage['id'], query_para=None) except Exception as e: # Unexpected error occurred, while syncing resources. msg = _('Failed to sync resources for storage: %(storage)s. ' 'Error: %(err)s') % { 'storage': storage['id'], 'err': e } LOG.error(msg) try: # Trigger Performance monitoring capabilities = self.driver_api.get_capabilities( context=ctxt, storage_id=storage['id']) validation.validate_capabilities(capabilities) perf_job_controller.create_perf_job(ctxt, storage['id'], capabilities) except exception.EmptyResourceMetrics: msg = _("Resource metric provided by capabilities is empty for " "storage: %s") % storage['id'] LOG.info(msg) except Exception as e: # Unexpected error occurred, while performance monitoring. msg = _('Failed to trigger performance monitoring for storage: ' '%(storage)s. Error: %(err)s') % { 'storage': storage['id'], 'err': six.text_type(e) } LOG.error(msg) return storage_view.build_storage(storage)
def get_capabilities(self, req, id): """ The API fetches capabilities from driver associated with the storage device. """ # Check and fetch storage with storage_id ctx = req.environ['delfin.context'] storage_info = db.storage_get(ctx, id) # Fetch supported driver's capability capabilities = self.driver_api. \ get_capabilities(ctx, storage_info['id']) # validate capabilities validation.validate_capabilities(capabilities) return storage_view.build_capabilities(storage_info, capabilities)