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 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 delete(self): """ Deleting a resource instance """ # =1= get resources _resource = location_registry().get_object(self.req.path) # =2= remove resources location_registry().unregister_location(self.req.path) # =3= execute the backend command by sending the resource object for _backend in backend_registry().get_backends().values(): _backend.delete(_resource) # =4= return OK with the Location of the created resource self.res.body = 'Resource with this PATH has been removed' return self.res
# register OCNI mixin locations location_registry().register_location("/Ethernet/", Ethernet()) location_registry().register_location("/IPv4/", IPv4()) location_registry().register_location("/OpenFlowCloNeNode/", OpenFlowCloNeNode()) location_registry().register_location("/OpenFlowCloNeLink/", OpenFlowCloNeLink()) location_registry().register_location("/OpenFlowCloNeNetworkInterface/", OpenFlowCloNeNetworkInterface()) location_registry().register_location("/l3vpn/", l3vpn()) location_registry().register_location("/libnetvirt/", libnetvirt()) # ====================================================================================== # the Backend registry # ====================================================================================== if config.OCNI_DUMMY == "1": backend_registry().register_backend(dummy_backend()) if config.OCNI_OPENFLOW == "1": backend_registry().register_backend(openflow_backend()) if config.OCNI_L3VPN == "1": backend_registry().register_backend(l3vpn_backend()) if config.OCNI_OPENNEBULA == "1": backend_registry().register_backend(opennebula_backend()) if config.OCNI_OPENSTACK == "1": backend_registry().register_backend(openstack_backend()) if config.OCNI_LIBNETVIRT == "1": backend_registry().register_backend(libnetvirt_backend())
OpenFlowCloNeNode()) location_registry().register_location("/OpenFlowCloNeLink/", OpenFlowCloNeLink()) location_registry().register_location("/OpenFlowCloNeNetworkInterface/", OpenFlowCloNeNetworkInterface()) location_registry().register_location("/l3vpn/", l3vpn()) # ====================================================================================== # the Backend registry # ====================================================================================== result = shell_ask.query_yes_no_quit( " \n_______________________________________________________________\n" " Do you want to register the dummy backend ?", "yes") if result == 'yes': backend_registry().register_backend(dummy_backend()) result = shell_ask.query_yes_no_quit( " \n_______________________________________________________________\n" " Do you want to register the OpenFlow backend ?", "no") if result == 'yes': backend_registry().register_backend(openflow_backend()) result = shell_ask.query_yes_no_quit( " \n_______________________________________________________________\n" " Do you want to register the L3VPN backend ?", "no") if result == 'yes': backend_registry().register_backend(l3vpn_backend()) result = shell_ask.query_yes_no_quit( " \n_______________________________________________________________\n" " Do you want to register the OpenNebula backend ?", "no") if result == 'yes': backend_registry().register_backend(opennebula_backend())