def _discover(self, req, body): """Discover a new storage backend.""" context = req.environ['sds.context'] if not self.is_valid_body(body, 'storage_discover'): raise webob.exc.HTTPBadRequest() _info = body['storage_discover'] ip_cidr = _info.get('ip_cidr', None) storage_type = _info.get('storage_type', None) metadata = _info.get('metadata', None) if ip_cidr is None or ip_cidr == "" or storage_type is None or storage_type == "": raise webob.exc.HTTPBadRequest() try: storage_info = self.discover_api.discover(context, ip_cidr, storage_type, metadata) notifier_info = dict(storage_info=storage_info) rpc.get_notifier('storageDiscover').info( context, 'storage_discover.create', notifier_info) except Exception as err: notifier_err = dict(storage_info=_info, error_message=err) self._notify_storage_discover_error(context, 'storage_discover.create', notifier_err) raise webob.exc.HTTPNotFound() return dict(storage_discover=storage_info)
def emit(self, record): # NOTE(flaper87): This will have to be changed in the # future. Leaving for backwar compatibility if ('sds.openstack.common.notifier.log_notifier' in cfg.CONF.notification_driver): return msg = record.getMessage() rpc.get_notifier('error.publisher').error(None, 'error_notification', dict(error=msg))
def delete(self, req, id): """Deletes pool for a given pool, group, backends.""" context = req.environ['sds.context'] try: LOG.debug("deleting id: %s" % (id)) self.pool_api.delete_pool_by_id(context, id) rpc.get_notifier('storagePool').info(context, 'storage_pool.delete', dict(id=id)) return webob.Response(status_int=202) except Exception as err: LOG.warn("Exception: %s" % unicode(err)) notifier_err = dict(notifier_info=id, error_message=err) self._notify_storage_pool_error(context, 'storage_pool.delete', notifier_err) raise webob.exc.HTTPNotFound(explanation=err.message)
def _pool(self, req, body): context = req.environ['sds.context'] if not self.is_valid_body(body, 'storage_pool'): raise webob.exc.HTTPBadRequest() # get info _info = body['storage_pool'] pool = _info.get('pool') backend_name = _info.get('backend_name') if not backend_name: # use pool as backend_name name too which is nothing but volume_backend_name for cinder backend_name = pool services = _info.get('services') if not services: # use default service 'volume' services = ['volume'] hosts = _info.get('hosts') if not isinstance(services, list): services = services.split(',') backends = _info.get('backends') # check few things before proceeding if not pool or pool == "" or not backends or not isinstance( backends, list) or len(backends) < 1: LOG.warn("Pool: %s, Backend: %s values are invalid" % (pool, backends)) raise webob.exc.HTTPBadRequest() pool_info = dict(pool=pool, backend_name=backend_name, backends=backends, services=services, hosts=hosts) try: LOG.debug("calling create_pool with pool_info: %s" % (pool_info)) self.pool_api.create_pool(context, pool, backend_name, backends, services, hosts) rpc.get_notifier('storagePool').info(context, 'storage_pool.create', pool_info) except Exception as err: notifier_err = dict(notifier_info=pool_info, error_message=err) self._notify_storage_pool_error(context, 'storage_pool.create', notifier_err) raise webob.exc.HTTPNotFound() return dict(storage_pool=pool_info)
def create(self, req, tier_id, body=None): context = req.environ['sds.context'] if not self.is_valid_body(body, 'capability_specs'): raise webob.exc.HTTPBadRequest() self._check_backend_tier(context, tier_id) specs = body['capability_specs'] self._check_key_names(specs.keys()) storage_tiers.create_tier_capability_specs(context, tier_id, specs) notifier_info = dict(tier_id=tier_id, specs=specs) notifier = rpc.get_notifier('storageBackendTierExtraSpecs') notifier.info(context, 'storage_tier_capability_specs.create', notifier_info) return body
def delete(self, req, id): """Deletes an existing extra spec.""" context = req.environ['sds.context'] try: storage_tiers.destroy_tier_by_id(context, id) except Exception as error: LOG.warn("Exception: %s" % error) raise webob.exc.HTTPNotFound(explanation=error.message) notifier_info = dict(id=id) notifier = rpc.get_notifier('storageBackendTiers') notifier.info(context, 'storage_backend_tiers.delete', notifier_info) return webob.Response(status_int=202)
def delete(self, req, backend_id, id): """Deletes an existing extra spec.""" context = req.environ['sds.context'] self._check_backend(context, backend_id) try: storage_backends.destroy_backend_capability_specs( context, backend_id, id) except Exception as error: LOG.warn("Exception: %s" % error) raise webob.exc.HTTPNotFound(explanation=error.message) notifier_info = dict(backend_id=backend_id, skey=id) notifier = rpc.get_notifier('storageBackendExtraSpecs') notifier.info(context, 'storage_backend_capability_specs.delete', notifier_info) return webob.Response(status_int=202)
def create(self, req, body=None): context = req.environ['sds.context'] if not self.is_valid_body(body, 'storage_tier'): raise webob.exc.HTTPBadRequest() tier_ref = body['storage_tier'] tier_name = tier_ref.get('tier_name', None) backend_name = tier_ref.get('backend_name', None) if tier_name is None or tier_name == "": raise webob.exc.HTTPBadRequest() if backend_name is None or backend_name == "": raise webob.exc.HTTPBadRequest() try: result = storage_tiers.create_tier(context, tier_name, backend_name, tier_ref.get('capability_specs')) _backend_tier_info = storage_tiers.get_tier_by_id(context, result['id']) notifier_info = dict(tier_info=_backend_tier_info) notifier = rpc.get_notifier('storageBackendTiers') notifier.info(context, 'storage_backend_tiers.create', notifier_info) except exception.StorageTierExists as err: notifier_err = dict(tier_info=tier_ref, error_message=err) self._notify_storage_tier_error(context, 'storage_tier.create', notifier_err) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except Exception as err: LOG.warn("Exception: %s" % err) notifier_err = dict(tier_info=tier_ref, error_message=err) self._notify_storage_tier_error(context, 'storage_tier.create', notifier_err) raise webob.exc.HTTPNotFound() return self._view_builder.show(req, _backend_tier_info)
def _notify_storage_tier_error(self, context, method, payload): rpc.get_notifier('storageTier').error(context, method, payload)
def _notify_storage_pool_error(self, context, method, payload): rpc.get_notifier('storagePool').error(context, method, payload)