def migration_start(self, req, id, body): """Migrate a share to the specified host.""" context = req.environ['manila.context'] try: share = self.share_api.get(context, id) except exception.NotFound: msg = _("Share %s not found.") % id raise exc.HTTPNotFound(explanation=msg) params = body.get('migration_start') if not params: raise exc.HTTPBadRequest(explanation=_("Request is missing body.")) driver_assisted_params = ['preserve_metadata', 'writable', 'nondisruptive', 'preserve_snapshots'] bool_params = (driver_assisted_params + ['force_host_assisted_migration']) mandatory_params = driver_assisted_params + ['host'] utils.check_params_exist(mandatory_params, params) bool_param_values = utils.check_params_are_boolean(bool_params, params) new_share_network = None new_share_type = None new_share_network_id = params.get('new_share_network_id', None) if new_share_network_id: try: new_share_network = db.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) new_share_type_id = params.get('new_share_type_id', None) if new_share_type_id: try: new_share_type = db.share_type_get( context, new_share_type_id) except exception.NotFound: msg = _("Share type %s not found.") % new_share_type_id raise exc.HTTPBadRequest(explanation=msg) try: return_code = self.share_api.migration_start( context, share, params['host'], bool_param_values['force_host_assisted_migration'], bool_param_values['preserve_metadata'], bool_param_values['writable'], bool_param_values['nondisruptive'], bool_param_values['preserve_snapshots'], new_share_network=new_share_network, new_share_type=new_share_type) except exception.Conflict as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=return_code)
def get_share_type(ctxt, id, expected_fields=None): """Retrieves single share type by id.""" if id is None: msg = _("id cannot be None") raise exception.InvalidShareType(reason=msg) if ctxt is None: ctxt = context.get_admin_context() return db.share_type_get(ctxt, id, expected_fields=expected_fields)
def migration_start(self, req, id, body): """Migrate a share to the specified host.""" context = req.environ['manila.context'] try: share = self.share_api.get(context, id) except exception.NotFound: msg = _("Share %s not found.") % id raise exc.HTTPNotFound(explanation=msg) params = body.get('migration_start') if not params: raise exc.HTTPBadRequest(explanation=_("Request is missing body.")) try: host = params['host'] except KeyError: raise exc.HTTPBadRequest(explanation=_("Must specify 'host'.")) force_host_assisted_migration = params.get( 'force_host_assisted_migration', False) try: force_host_assisted_migration = strutils.bool_from_string( force_host_assisted_migration, strict=True) except ValueError: msg = _("Invalid value %s for 'force_host_assisted_migration'. " "Expecting a boolean.") % force_host_assisted_migration raise exc.HTTPBadRequest(explanation=msg) new_share_network = None new_share_type = None preserve_metadata = params.get('preserve_metadata', True) try: preserve_metadata = strutils.bool_from_string(preserve_metadata, strict=True) except ValueError: msg = _("Invalid value %s for 'preserve_metadata'. " "Expecting a boolean.") % preserve_metadata raise exc.HTTPBadRequest(explanation=msg) writable = params.get('writable', True) try: writable = strutils.bool_from_string(writable, strict=True) except ValueError: msg = _("Invalid value %s for 'writable'. " "Expecting a boolean.") % writable raise exc.HTTPBadRequest(explanation=msg) nondisruptive = params.get('nondisruptive', False) try: nondisruptive = strutils.bool_from_string(nondisruptive, strict=True) except ValueError: msg = _("Invalid value %s for 'nondisruptive'. " "Expecting a boolean.") % nondisruptive raise exc.HTTPBadRequest(explanation=msg) new_share_network_id = params.get('new_share_network_id', None) if new_share_network_id: try: new_share_network = db.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) new_share_type_id = params.get('new_share_type_id', None) if new_share_type_id: try: new_share_type = db.share_type_get(context, new_share_type_id) except exception.NotFound: msg = _("Share type %s not found.") % new_share_type_id raise exc.HTTPBadRequest(explanation=msg) try: self.share_api.migration_start(context, share, host, force_host_assisted_migration, preserve_metadata, writable, nondisruptive, new_share_network=new_share_network, new_share_type=new_share_type) except exception.Conflict as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=202)
def migration_start(self, req, id, body): """Migrate a share to the specified host.""" context = req.environ['manila.context'] try: share = self.share_api.get(context, id) except exception.NotFound: msg = _("Share %s not found.") % id raise exc.HTTPNotFound(explanation=msg) params = body.get('migration_start') if not params: raise exc.HTTPBadRequest(explanation=_("Request is missing body.")) driver_assisted_params = [ 'preserve_metadata', 'writable', 'nondisruptive', 'preserve_snapshots' ] bool_params = (driver_assisted_params + ['force_host_assisted_migration']) mandatory_params = driver_assisted_params + ['host'] utils.check_params_exist(mandatory_params, params) bool_param_values = utils.check_params_are_boolean(bool_params, params) new_share_network = None new_share_type = None new_share_network_id = params.get('new_share_network_id', None) if new_share_network_id: try: new_share_network = db.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) new_share_type_id = params.get('new_share_type_id', None) if new_share_type_id: try: new_share_type = db.share_type_get(context, new_share_type_id) except exception.NotFound: msg = _("Share type %s not found.") % new_share_type_id raise exc.HTTPBadRequest(explanation=msg) try: return_code = self.share_api.migration_start( context, share, params['host'], bool_param_values['force_host_assisted_migration'], bool_param_values['preserve_metadata'], bool_param_values['writable'], bool_param_values['nondisruptive'], bool_param_values['preserve_snapshots'], new_share_network=new_share_network, new_share_type=new_share_type) except exception.Conflict as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=return_code)
def migration_start(self, req, id, body): """Migrate a share to the specified host.""" context = req.environ['manila.context'] try: share = self.share_api.get(context, id) except exception.NotFound: msg = _("Share %s not found.") % id raise exc.HTTPNotFound(explanation=msg) params = body.get('migration_start') if not params: raise exc.HTTPBadRequest(explanation=_("Request is missing body.")) try: host = params['host'] except KeyError: raise exc.HTTPBadRequest(explanation=_("Must specify 'host'.")) force_host_assisted_migration = params.get( 'force_host_assisted_migration', False) try: force_host_assisted_migration = strutils.bool_from_string( force_host_assisted_migration, strict=True) except ValueError: msg = _("Invalid value %s for 'force_host_assisted_migration'. " "Expecting a boolean.") % force_host_assisted_migration raise exc.HTTPBadRequest(explanation=msg) new_share_network = None new_share_type = None preserve_metadata = params.get('preserve_metadata', True) try: preserve_metadata = strutils.bool_from_string( preserve_metadata, strict=True) except ValueError: msg = _("Invalid value %s for 'preserve_metadata'. " "Expecting a boolean.") % preserve_metadata raise exc.HTTPBadRequest(explanation=msg) writable = params.get('writable', True) try: writable = strutils.bool_from_string(writable, strict=True) except ValueError: msg = _("Invalid value %s for 'writable'. " "Expecting a boolean.") % writable raise exc.HTTPBadRequest(explanation=msg) nondisruptive = params.get('nondisruptive', False) try: nondisruptive = strutils.bool_from_string( nondisruptive, strict=True) except ValueError: msg = _("Invalid value %s for 'nondisruptive'. " "Expecting a boolean.") % nondisruptive raise exc.HTTPBadRequest(explanation=msg) new_share_network_id = params.get('new_share_network_id', None) if new_share_network_id: try: new_share_network = db.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) new_share_type_id = params.get('new_share_type_id', None) if new_share_type_id: try: new_share_type = db.share_type_get( context, new_share_type_id) except exception.NotFound: msg = _("Share type %s not found.") % new_share_type_id raise exc.HTTPBadRequest(explanation=msg) try: self.share_api.migration_start( context, share, host, force_host_assisted_migration, preserve_metadata, writable, nondisruptive, new_share_network=new_share_network, new_share_type=new_share_type) except exception.Conflict as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=202)