def put(self): """ Creating a resource instance by providing the path in the name-space hierarchy (To do) Or Updating a resource instance (Done) """ # =1= get old resources _old_resource = location_registry().get_object(self.req.path) # =2= get new resources resource_json_serializer = json_serializer.resource_serializer() _resource = resource_json_serializer.from_json(self.req.body) # =3= unregister old and register new location_registry().unregister_location(self.req.path) location_registry().register_location(self.req.path, _resource) # =4= execute the backend command by sending the resource object for _backend in backend_registry().get_backends().values(): _backend.update(_old_resource, _resource) self.res.body = 'Resource ' + self.req.path + ' has been updated' return self.res
def post(self): """ Creating a resource instance """ # =1= getting the resource to create from the json resource_json_serializer = json_serializer.resource_serializer() _resource = resource_json_serializer.from_json(self.req.body) # =2= add the created resource to the registry _user_id = 'user1' _location = '/' + self.term + '/' + _user_id + '/' + str(_resource.occi_core_id) location_registry().register_location(_location, _resource) # =3= execute the backend command by sending the resource object for _backend in backend_registry().get_backends().values(): _backend.create(_resource) # =4= return OK with the Location of the created resource location_result = json.dumps({"location": _location}) self.res.body = location_result return self.res
def get(self): """ Retrieving a resource instance """ resource_json_serializer = json_serializer.resource_serializer() _object = location_registry().get_object(self.req.path) if _object is not None: result_json = json.loads(resource_json_serializer.to_json(_object)) result_dump = cStringIO.StringIO() json.dump(result_json, result_dump, indent=4 * ' ') self.res.body = result_dump.getvalue() #for _backend in backend_registry().get_backends().values(): # _backend.read() else: #self.res.status = '' self.res.body = 'No resource with this PATH' return self.res
def put(self): """ Creating a resource instance by providing the path in the name-space hierarchy (To do) Or Updating a resource instance (Done) """ # =1= get old resources _old_resource = location_registry().get_object(self.req.path) # =2= get new resources resource_json_serializer = json_serializer.resource_serializer() _resource = resource_json_serializer.from_json(self.req.body) # =3= unregister old and register new location_registry().unregister_location(self.req.path) location_registry().register_location(self.req.path, _resource) # =4= execute the backend command by sending the resource object for _backend in backend_registry().get_backends().values(): _backend.update(_old_resource, _resource) self.res.body = 'Resource ' + self.req.path + ' has been updated' return self.res
def post(self): """ Creating a resource instance """ # =1= getting the resource to create from the json resource_json_serializer = json_serializer.resource_serializer() _resource = resource_json_serializer.from_json(self.req.body) # =2= add the created resource to the registry _user_id = 'user1' _location = '/' + self.term + '/' + _user_id + '/' + str( _resource.occi_core_id) location_registry().register_location(_location, _resource) # =3= execute the backend command by sending the resource object for _backend in backend_registry().get_backends().values(): _backend.create(_resource) # =4= return OK with the Location of the created resource location_result = json.dumps({"location": _location}) self.res.body = location_result return self.res
def get(self): """ Retrieving a resource instance """ resource_json_serializer = json_serializer.resource_serializer() _object = location_registry().get_object(self.req.path) if _object is not None: result_json = json.loads(resource_json_serializer.to_json(_object)) result_dump = cStringIO.StringIO() json.dump(result_json, result_dump, indent=4 * ' ') self.res.body = result_dump.getvalue() else: #self.res.status = '' self.res.body = 'No resource with this PATH' return self.res