def show(self, req, id): """Returns data about given source hypervisor type.""" context = req.environ['guts.context'] try: stype = types.get_source_type(context, id) req.cache_resource(stype, name='type') except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, stype)
def show(self, request, context, source, brief=False): """Trim away extraneous source hypervisor attributes.""" trimmed = dict(id=source.get('id'), name=source.get('name'), connection_params=source.get('connection_params'), description=source.get('description')) source_type = types.get_source_type(context, source.source_type_id) trimmed['source_type_name'] = source_type.get('name') return trimmed if brief else dict(source=trimmed)
def update(self, req, id, body): """Updates given source type.""" context = req.environ['guts.context'] authorize(context) stype = body['source_type'] name = stype.get('name', None) driver = stype.get('driver', None) description = stype.get('description', None) if not (name or driver or description): raise exception.Invalid('No attributes to update.') if driver and len(driver.strip()) == 0: msg = "Source type driver can not be empty." raise webob.exc.HTTPBadRequest(explanation=msg) utils.check_string_length(driver, 'Source Type driver', min_length=1, max_length=255) validate_type_driver(driver) if description is not None: utils.check_string_length(description, 'Type description', min_length=0, max_length=255) try: types.update(context, id, name, driver, description) modified_stype = types.get_source_type(context, id) req.cache_resource(modified_stype, name='types') self._notify_source_type_info(context, 'source_type.update', modified_stype) except exception.SourceTypeExists as err: self._notify_source_type_error(context, 'source_type.update', err, source_type=modified_stype) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.SourceTypeNotFoundByName as err: self._notify_source_type_error(context, 'source_type.update', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) return self._view_builder.show(req, modified_stype)
def update(self, req, id, body): """Updates given source type.""" context = req.environ['guts.context'] authorize(context) stype = body['source_type'] name = stype.get('name', None) driver = stype.get('driver', None) description = stype.get('description', None) if not (name or driver or description): raise exception.Invalid('No attributes to update.') if driver and len(driver.strip()) == 0: msg = "Source type driver can not be empty." raise webob.exc.HTTPBadRequest(explanation=msg) utils.check_string_length(driver, 'Source Type driver', min_length=1, max_length=255) validate_type_driver(driver) if description is not None: utils.check_string_length(description, 'Type description', min_length=0, max_length=255) try: types.update(context, id, name, driver, description) modified_stype = types.get_source_type(context, id) req.cache_resource(modified_stype, name='types') self._notify_source_type_info( context, 'source_type.update', modified_stype) except exception.SourceTypeExists as err: self._notify_source_type_error( context, 'source_type.update', err, source_type=modified_stype) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.SourceTypeNotFoundByName as err: self._notify_source_type_error( context, 'source_type.update', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) return self._view_builder.show(req, modified_stype)