def details(self, req, id): """Return details for requested share server.""" context = req.environ['manila.context'] policy.check_policy(context, RESOURCE_NAME, 'details') try: db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) details = db_api.share_server_backend_details_get(context, id) return self._view_builder.build_share_server_details(details)
def share_server_migration_start(self, req, id, body): """Migrate a share server to the specified host.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) params = body.get('migration_start') if not params: raise exc.HTTPBadRequest(explanation=_("Request is missing body.")) bool_params = ['writable', 'nondisruptive', 'preserve_snapshots'] mandatory_params = bool_params + ['host'] utils.check_params_exist(mandatory_params, params) bool_param_values = utils.check_params_are_boolean(bool_params, params) pool_was_specified = len(params['host'].split('#')) > 1 if pool_was_specified: msg = _('The destination host can not contain pool information.') raise exc.HTTPBadRequest(explanation=msg) new_share_network = None new_share_network_id = params.get('new_share_network_id', None) if new_share_network_id: try: new_share_network = db_api.share_network_get( context, new_share_network_id) except exception.NotFound: msg = _("Share network %s not " "found.") % new_share_network_id raise exc.HTTPBadRequest(explanation=msg) common.check_share_network_is_active(new_share_network) else: share_network_id = ( share_server['share_network_subnet']['share_network_id']) current_share_network = db_api.share_network_get( context, share_network_id) common.check_share_network_is_active(current_share_network) try: self.share_api.share_server_migration_start( context, share_server, params['host'], bool_param_values['writable'], bool_param_values['nondisruptive'], bool_param_values['preserve_snapshots'], new_share_network=new_share_network) except exception.ServiceIsDown as e: # NOTE(dviroel): user should check if the host is healthy raise exc.HTTPBadRequest(explanation=e.msg) except exception.InvalidShareServer as e: # NOTE(dviroel): invalid share server meaning that some internal # resource have a invalid state. raise exc.HTTPConflict(explanation=e.msg)
def details(self, req, id): """Return details for requested share server.""" context = req.environ["manila.context"] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) return self._view_builder.build_share_server_details(share_server["backend_details"])
def details(self, req, id): """Return details for requested share server.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) return self._view_builder.build_share_server_details( share_server['backend_details'])
def share_server_migration_cancel(self, req, id, body): """Attempts to cancel share migration.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) try: self.share_api.share_server_migration_cancel(context, share_server) except (exception.InvalidShareServer, exception.ServiceIsDown) as e: raise exc.HTTPBadRequest(explanation=e.msg)
def show(self, req, id): """Return data about the requested share server.""" context = req.environ['manila.context'] try: server = db_api.share_server_get(context, id) server.project_id = server.share_network["project_id"] if server.share_network['name']: server.share_network_name = server.share_network['name'] else: server.share_network_name = server.share_network_id except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) return self._view_builder.build_share_server(server)
def show(self, req, id): """Return data about the requested share server.""" context = req.environ['manila.context'] policy.check_policy(context, RESOURCE_NAME, 'show') try: server = db_api.share_server_get(context, id) server.project_id = server.share_network["project_id"] if server.share_network['name']: server.share_network_name = server.share_network['name'] else: server.share_network_name = server.share_network_id except exception.ShareServerNotFound as e: msg = "%s" % e raise exc.HTTPNotFound(explanation=msg) return self._view_builder.build_share_server(server)
def share_server_migration_complete(self, req, id, body): """Invokes 2nd phase of share server migration.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) try: result = self.share_api.share_server_migration_complete( context, share_server) except (exception.InvalidShareServer, exception.ServiceIsDown) as e: raise exc.HTTPBadRequest(explanation=e.msg) return self._migration_view_builder.migration_complete(req, result)
def _unmanage(self, req, id, body=None): context = req.environ['manila.context'] LOG.debug("Unmanage Share Server with id: %s", id) # force's default value is False # force will be True if body is {'unmanage': {'force': True}} force = (body.get('unmanage') or {}).get('force', False) or False try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) network_subnet_id = share_server.get('share_network_subnet_id', None) if network_subnet_id: subnet = db_api.share_network_subnet_get(context, network_subnet_id) share_network_id = subnet['share_network_id'] else: share_network_id = share_server.get('share_network_id') share_network = db_api.share_network_get(context, share_network_id) common.check_share_network_is_active(share_network) allowed_statuses = [ constants.STATUS_ERROR, constants.STATUS_ACTIVE, constants.STATUS_MANAGE_ERROR, constants.STATUS_UNMANAGE_ERROR ] if share_server['status'] not in allowed_statuses: data = { 'status': share_server['status'], 'allowed_statuses': ', '.join(allowed_statuses), } msg = _("Share server's actual status is %(status)s, allowed " "statuses for unmanaging are " "%(allowed_statuses)s.") % data raise exc.HTTPBadRequest(explanation=msg) try: self.share_api.unmanage_share_server(context, share_server, force=force) except (exception.ShareServerInUse, exception.PolicyNotAuthorized) as e: raise exc.HTTPBadRequest(explanation=e.msg) return webob.Response(status_int=http_client.ACCEPTED)
def delete(self, req, id): """Delete specified share server.""" context = req.environ["manila.context"] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE] if share_server["status"] not in allowed_statuses: data = {"status": share_server["status"], "allowed_statuses": allowed_statuses} msg = _( "Share server's actual status is %(status)s, allowed " "statuses for deletion are %(allowed_statuses)s." ) % (data) raise exc.HTTPForbidden(explanation=msg) LOG.debug("Deleting share server with id: %s.", id) try: self.share_api.delete_share_server(context, share_server) except exception.ShareServerInUse as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=202)
def show(self, req, id): """Return data about the requested share server.""" context = req.environ['manila.context'] try: server = db_api.share_server_get(context, id) share_network = db_api.share_network_get( context, server.share_network_subnet['share_network_id']) server.share_network_id = share_network['id'] server.project_id = share_network['project_id'] if share_network['name']: server.share_network_name = share_network['name'] else: server.share_network_name = share_network['id'] except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) except exception.ShareNetworkNotFound: msg = _("Share server %s could not be found. Its associated " "share network does not " "exist.") % server.share_network_subnet['share_network_id'] raise exc.HTTPNotFound(explanation=msg) return self._view_builder.build_share_server(req, server)
def delete(self, req, id): """Delete specified share server.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE] if share_server['status'] not in allowed_statuses: data = { 'status': share_server['status'], 'allowed_statuses': allowed_statuses, } msg = _("Share server's actual status is %(status)s, allowed " "statuses for deletion are %(allowed_statuses)s.") % (data) raise exc.HTTPForbidden(explanation=msg) LOG.debug("Deleting share server with id: %s.", id) try: self.share_api.delete_share_server(context, share_server) except exception.ShareServerInUse as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=http_client.ACCEPTED)
def delete(self, req, id): """Delete specified share server.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e) allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE] if share_server['status'] not in allowed_statuses: data = { 'status': share_server['status'], 'allowed_statuses': allowed_statuses, } msg = _("Share server's actual status is %(status)s, allowed " "statuses for deletion are %(allowed_statuses)s.") % (data) raise exc.HTTPForbidden(explanation=msg) LOG.debug("Deleting share server with id: %s.", id) try: self.share_api.delete_share_server(context, share_server) except exception.ShareServerInUse as e: raise exc.HTTPConflict(explanation=e) return webob.Response(status_int=http_client.ACCEPTED)
def _unmanage(self, req, id, body=None): context = req.environ['manila.context'] LOG.debug("Unmanage Share Server with id: %s", id) # force's default value is False # force will be True if body is {'unmanage': {'force': True}} force = (body.get('unmanage') or {}).get('force', False) or False try: share_server = db_api.share_server_get( context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e) allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE, constants.STATUS_MANAGE_ERROR, constants.STATUS_UNMANAGE_ERROR] if share_server['status'] not in allowed_statuses: data = { 'status': share_server['status'], 'allowed_statuses': ', '.join(allowed_statuses), } msg = _("Share server's actual status is %(status)s, allowed " "statuses for unmanaging are " "%(allowed_statuses)s.") % data raise exc.HTTPBadRequest(explanation=msg) try: self.share_api.unmanage_share_server( context, share_server, force=force) except (exception.ShareServerInUse, exception.PolicyNotAuthorized) as e: raise exc.HTTPBadRequest(explanation=e) return webob.Response(status_int=http_client.ACCEPTED)