def create(self, req, body): """Creates a new source hypervisor.""" ctxt = req.environ['guts.context'] authorize(ctxt) source = body['source'] name = source.get('name', None) stype = source.get('stype') connection_params = source.get('connection_params') description = source.get('description') if name is None or len(name.strip()) == 0: msg = "Source name can not be empty." raise webob.exc.HTTPBadRequest(explanation=msg) if connection_params is None or len(connection_params.strip()) == 0: msg = "Source connection params can not be empty." raise webob.exc.HTTPBadRequest(explanation=msg) utils.check_string_length(name, 'Hypervisor name', min_length=1, max_length=255) utils.check_string_length(connection_params, 'Source connection parameters', min_length=1, max_length=255) if description is not None: utils.check_string_length(description, 'Source description', min_length=0, max_length=255) try: sources.create(ctxt, name, stype, connection_params, description=description) source = sources.get_source_by_name(ctxt, name) req.cache_resource(source, name='sources') self._notify_source_info( ctxt, 'source.create', source) except exception.SourceExists as err: self._notify_source_error( ctxt, 'source.create', err, source=source) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.SourceNotFoundByName as err: self._notify_source_error( ctxt, 'source_.create', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) vms.fetch_vms(ctxt, source.get('id')) return self._view_builder.show(req, ctxt, source)
def create(self, req, body): """Creates a new source hypervisor.""" ctxt = req.environ['guts.context'] authorize(ctxt) source = body['source'] name = source.get('name', None) stype = source.get('stype') connection_params = source.get('connection_params') description = source.get('description') if name is None or len(name.strip()) == 0: msg = "Source name can not be empty." raise webob.exc.HTTPBadRequest(explanation=msg) if connection_params is None or len(connection_params.strip()) == 0: msg = "Source connection params can not be empty." raise webob.exc.HTTPBadRequest(explanation=msg) utils.check_string_length(name, 'Hypervisor name', min_length=1, max_length=255) utils.check_string_length(connection_params, 'Source connection parameters', min_length=1, max_length=255) if description is not None: utils.check_string_length(description, 'Source description', min_length=0, max_length=255) try: source = sources.create(ctxt, name, stype, connection_params, description=description) req.cache_resource(source, name='sources') self._notify_source_info( ctxt, 'source.create', source) except exception.SourceExists as err: self._notify_source_error( ctxt, 'source.create', err, source=source) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.SourceNotFoundByName as err: self._notify_source_error( ctxt, 'source_.create', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) vms.fetch_vms(ctxt, source.get('id')) return self._view_builder.show(req, ctxt, source)
def _fetch_vms(self, req, id, body): context = req.environ['guts.context'] vms.fetch_vms(context, id)