class Resource(object):
Known subclasses: acme.resources.ALPC.ALPC, acme.resources.ALST.ALST, acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.AnnouncedResource.AnnouncedResource, acme.resources.CRS.CRS, acme.resources.DAC.DAC, acme.resources.NTP.NTP, acme.resources.NTPR.NTPR, acme.resources.PCH.PCH, acme.resources.PDR.PDR, acme.resources.REQ.REQ, acme.resources.SUB.SUB, acme.resources.VirtualResource.VirtualResource
Constructor: Resource(dct, create)
Base class for all oneM2M resource types,
| Method | __contains__ |
Implementation of the membership test operator. |
| Method | __delitem__ |
Implementation of the self[key| operation for deleting attributes. |
| Method | __eq__ |
Test for equality of the resource to another resource. |
| Method | __getattr__ |
Map the normal object attribute access to the internal resource attribute dictionary. |
| Method | __getitem__ |
Implementation of the self[key| operation for retrieving attributes. |
| Method | __init__ |
Initialization of a Resource instance. |
| Method | __repr__ |
Object representation as string. |
| Method | __setitem__ |
Implementation of the self[key] operation for assigning to attributes. |
| Method | __str__ |
String representation of the resource's attributes. |
| Method | activate |
This method is called to activate a resource, usually in a CREATE request. |
| Method | as |
Get the JSON resource representation. |
| Method | attribute |
Return the value of an attribute. |
| Method | can |
Check whether resource is a valild child resource for this resource. |
| Method | child |
Called after a child resource was added to the resource. |
| Method | child |
Called when a child resource of the resource was removed. |
| Method | child |
Called when a child resource was updated. |
| Method | child |
Called before a child will be added to a resource. |
| Method | create |
Create a child resource from a JSON dictionary. |
| Method | db |
Add the resource to the database. |
| Method | db |
Delete the resource from the database. |
| Method | db |
Load a new copy of the same resource from the database. |
| Method | db |
Reload the resource instance from the database. |
| Method | db |
Update the resource in the database. |
| Method | deactivate |
Deactivate an active resource. |
| Method | decrement |
Decrement the subscription counter for the resource. |
| Method | del |
Delete the attribute 'key' from the resource. |
| Method | get |
Get all attributes of the resource. |
| Method | get |
Retrieve the current originator. This could be different from the originator / creator of the resource in case of the custodian attribute is set. |
| Method | get |
Determine and return the final value of an attribute during an update. |
| Method | get |
Retrieve a resource's location coordinates (internal attribute). |
| Method | get |
Retrieve a resource's originator. |
| Method | get |
Retrieve a resource's release version indicator. |
| Method | get |
Retrieve a resource's full structured resource name. |
| Method | get |
Retrieve the subscription counter for the resource. |
| Method | handle |
Process a CREATE request that is directed to a virtual resource. |
| Method | handle |
Process a DELETE request that is directed to a virtual resource. |
| Method | handle |
Process a notification request that is directed to a resource. |
| Method | handle |
Process a RETRIEVE request that is directed to a virtual resource. |
| Method | handle |
Process a UPDATE request that is directed to a virtual resource. |
| Method | has |
Check whether an attribute exists for the resource. |
| Method | has |
Test whether a resource supports the specified attribute. This method may be overwritten in sub-classes, for example for virtual resources. |
| Method | increment |
Increment the subscription counter for the resource. |
| Method | initialize |
This method is called when a new resource is created and before written to the database. |
| Method | is |
Test whether a the resource's type is an announced type. |
| Method | is |
Test whether a resource has been created for another resource. |
| Method | is |
Test whether this resource has been modified after another resource. |
| Method | is |
Test whether the resource is a virtual resource. |
| Method | retrieve |
Retrieve the parent resource of this resouce. |
| Method | retrieve |
Retrieve the raw (!) parent resource of this resouce. |
| Method | select |
Determine the selected attributes for a partial retrieve of a resource. |
| Method | set |
Assign a value to a resource attribute. |
| Method | set |
Save the resource ID for which this resource was created for. |
| Method | set |
Set a resource's location coordinates (internal attribute). |
| Method | set |
Set a resource's originator. |
| Method | set |
Set the resource ID for the resource if not already set. |
| Method | set |
Set the resource name. |
| Method | set |
Assign the release version for a resource. |
| Method | set |
Set a resource's full structured resource name. |
| Method | structured |
Determine the structured path of a resource. |
| Method | type |
Return the resource type as a string. If the resource is a flex container, the specialization is added. |
| Method | update |
Update, add or remove resource attributes. |
| Method | updated |
Signal to a resource that is was successfully updated. |
| Method | validate |
Validate a resource. |
| Method | will |
This method is called before a resource will be deactivated. |
| Method | will |
This method is called before a resource will be send back in a RETRIEVE response. |
| Method | will |
This method is called before a resource will be updated and before calling the update() method. |
| Class Variable | __slots__ |
Slots for the class. |
| Class Variable | dispatcher |
Injected Dispatcher instance. |
| Class Variable | factory |
Injected Factory instance. |
| Class Variable | importer |
Injected Importer instance. |
| Class Variable | notification |
Injected NotificationManager instance. |
| Class Variable | request |
Injected RequestManager instance. |
| Class Variable | storage |
Injected Storage instance. |
| Class Variable | validator |
Injected Validator instance. |
| Instance Variable | dict |
Dictionary for public and internal resource attributes. |
| Method | _check |
Check whether a referenced ACP resoure exists, and if yes, change the ID in the list to CSE relative unstructured format. |
| Method | _normalize |
Normalize the URLs in the given attribute. |
| Class Variable | _exclude |
Resource attributes that are excluded when updating the resource |
| Instance Variable | _original |
Original dictionary as it was created. This is used for validation in activate() later. |
Implementation of the membership test operator.
It maps to the hasAttribute() method.
| Parameters | |
key:str | Resource attribute name to test for. |
| Returns | |
bool | Boolean, indicating the existens of an attribute |
Implementation of the self[key| operation for deleting attributes.
It maps to the delAttribute() method, with setNone implicitly set to the default.
| Parameters | |
key:str | Resource attribute name to delete. This can be a path (see findXPath). |
Test for equality of the resource to another resource.
| Parameters | |
other:object | Other object to test for. |
| Returns | |
bool | If the other object is a Resource instance and has the same resource ID, then True is returned, of False otherwise. |
Map the normal object attribute access to the internal resource attribute dictionary.
It maps to the attribute() method, but there is no default value.
| Parameters | |
key:str | Resource attribute name to get. |
| Returns | |
Any | The attribute's value, or None |
Implementation of the self[key| operation for retrieving attributes.
It maps to the attribute() method, but there is no default value.
| Parameters | |
key:str | Resource attribute name to look for. This can be a path (see findXPath). |
| Returns | |
Any | The attribute's value, or None |
acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.FCNTAnnc.FCNTAnncInitialization of a Resource instance.
| Parameters | |
dct:JSON | Mandatory resource attributes. |
create:bool | None | Undocumented |
Implementation of the self[key] operation for assigning to attributes.
It maps to the setAttribute() method, and always overwrites existing values.
| Parameters | |
key:str | The resource attribute's name. This can be a path (see setXPath). |
value:Any | Value to assign to the attribute. |
String representation of the resource's attributes.
| Returns | |
str | String with the resource formatted as a JSON structure |
acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.CRS.CRS, acme.resources.NTP.NTP, acme.resources.PCH.PCH, acme.resources.PDR.PDR, acme.resources.SUB.SUBThis method is called to activate a resource, usually in a CREATE request.
This is not always the case, e.g. when a resource object is just used temporarly. NO notification on activation/creation happens in this method!
This method is implemented in sub-classes as well.
| Parameters | |
parentResource | The resource's parent resource. |
originator:str | The request's originator. |
| Raises | |
BAD_REQUEST | In case of an invalid attribute. |
bool | None = True, update: bool | None = False, noACP: bool | None = False, sort: bool = False) -> JSON:
¶
Get the JSON resource representation.
| Parameters | |
embedded:bool | None | Optional indicator whether the resource should be embedded in another resource structure. In this case it is not embedded in its own "domain:name" structure. |
update:bool | None | Optional indicator whether only the updated attributes shall be included in the result. |
nobool | None | Optional indicator whether the acpi attribute shall be included in the result. |
sort:bool | Undocumented |
| Returns | |
JSON | A JSON object with the resource representation. |
Return the value of an attribute.
| Parameters | |
key:str | Resource attribute name to look for. This can be a path (see findXPath). |
default:Any | None | A default value to return if the attribute is not set. |
| Returns | |
Any | The attribute's value, the default value, or None |
Check whether resource is a valild child resource for this resource.
| Parameters | |
resource:Resource | The resource to test. |
| Returns | |
bool | Boolean indicating whether resource is a an allowed resorce for this resource. |
Called after a child resource was added to the resource.
This method is implemented in some sub-classes.
| Parameters | |
childResource | The child resource that was be added as a child to the resource. |
originator:str | The request originator. |
Called when a child resource of the resource was removed.
This method is implemented in some sub-classes.
| Parameters | |
childResource | The removed child resource. |
originator:str | The request originator. |
acme.resources.AE.AE, acme.resources.CNT.CNT, acme.resources.CRS.CRS, acme.resources.CSEBase.CSEBase, acme.resources.CSR.CSR, acme.resources.FCNT.FCNT, acme.resources.SUB.SUB, acme.resources.TS.TSCalled before a child will be added to a resource.
This method is implemented in some sub-classes.
| Parameters | |
childResource | Resource that will be added as a child to the resource. |
originator:str | The request originator. |
JSON, ty: ResourceTypes | None = None, originator: str | None = None, preCreateCB: Callable[ [ Resource], None] | None = None) -> tuple[ Resource, str]:
¶
Create a child resource from a JSON dictionary.
| Parameters | |
dct:JSON | The JSON dictionary with the resource attributes. |
ty:ResourceTypes | None | Optional resource type. If not provided, then the type is determined from the dictionary. |
originator:str | None | Optional request originator. |
preCallable[ | Optional callback function that is called with the resource instance before it is stored in the database. This can be used to perform some checks and adjustments before the resource is created. |
| Returns | |
tuple[ | Tuple with the created resource and its resource ID. |
Add the resource to the database.
| Parameters | |
overwrite:bool | None | If true an already existing resource with the same resource ID is overwritten. |
| Returns | |
| Result object indicating success or failure. |
Load a new copy of the same resource from the database.
The current resource is NOT changed.
Note
The version of the resource in the database might be different, e.g. when the resource instance has been modified but not updated in the database.
| Returns | |
Resource | Resource instance. |
Reload the resource instance from the database.
The current resource's internal attributes are updated with the versions from the database.
| Returns | |
Resource | Updated Resource instance. |
Update the resource in the database.
This also raises a CSE internal updateResource event.
| Parameters | |
finalize:bool | Treat this database write as a final update to the resource. Only then an event is raised. |
| Returns | |
Resource | Result object indicating success or failure. |
acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.CRS.CRS, acme.resources.SUB.SUBDeactivate an active resource.
This usually happens when creating the resource via a request. A subscription check for deletion is performed.
This method is implemented in sub-classes as well.
| Parameters | |
originator:str | The requests originator that let to the deletion of the resource. |
parentResource | The resource's parent resource. |
Decrement the subscription counter for the resource.
This is used to determine whether a resource has active subscriptions.
Delete the attribute 'key' from the resource.
| Parameters | |
key:str | Name of the resource attribute name to delete. |
setbool | None | By default (True) the attribute is not deleted but set to None and later removed when storing the resource in the DB. If setNone' is *False, then the attribute is immediately deleted from the resource instance's internal dictionary. |
Get all attributes of the resource.
| Parameters | |
includingbool | Optional indicator whether internal attributes shall be included. |
| Returns | |
dict[ | Dictionary with a copy of all attributes. |
Retrieve the current originator. This could be different from the originator / creator of the resource in case of the custodian attribute is set.
| Returns | |
str | The current originator. |
Determine and return the final value of an attribute during an update.
| Parameters | |
key:str | Attribute name. |
dct:JSON | None | The dictionary with updated attributes. |
| Returns | |
Any | The either updated attribute, or old value if the attribute is not updated. The method returns None if the attribute does not exists. |
Retrieve a resource's location coordinates (internal attribute).
| Returns | |
list | The resource's location coordinates. Might be None. |
Retrieve a resource's originator.
This is the originator that created the resource. It is stored internally within the resource.
| Returns | |
str | The resource's originator. |
Retrieve a resource's full structured resource name.
| Returns | |
str | The resource's full structured resource name. |
Retrieve the subscription counter for the resource.
| Returns | |
int | The current subscription counter value. |
acme.resources.CNT_LA.CNT_LA, acme.resources.CNT_OL.CNT_OL, acme.resources.FCNT_LA.FCNT_LA, acme.resources.FCNT_OL.FCNT_OL, acme.resources.GRP_FOPT.GRP_FOPT, acme.resources.PCH_PCU.PCH_PCU, acme.resources.TS_LA.TS_LA, acme.resources.TS_OL.TS_OLProcess a CREATE request that is directed to a virtual resource.
This method must be implemented by virtual resource class.
| Parameters | |
request:CSERequest | The request to process. |
id:str | The structured or unstructured resource ID of the target resource. |
originator:str | The request's originator. |
| Returns | |
Result | Result object indicating success or failure. |
acme.resources.CNT_LA.CNT_LA, acme.resources.CNT_OL.CNT_OL, acme.resources.FCNT_LA.FCNT_LA, acme.resources.FCNT_OL.FCNT_OL, acme.resources.GRP_FOPT.GRP_FOPT, acme.resources.NTSR.NTSR, acme.resources.PCH_PCU.PCH_PCU, acme.resources.TS_LA.TS_LA, acme.resources.TS_OL.TS_OLProcess a DELETE request that is directed to a virtual resource.
This method must be implemented by virtual resource class.
| Parameters | |
request:CSERequest | The request to process. |
id:str | The structured or unstructured resource ID of the target resource. |
originator:str | The request's originator. |
| Returns | |
Result | Result object indicating success or failure. |
acme.resources.CRS.CRSProcess a notification request that is directed to a resource.
This method is implemented in some sub-classes. Those implementations override this method to handle the notification request.
| Parameters | |
request:CSERequest | The request to process. |
originator:str | The request's originator. |
| Raises | |
INTERNAL_SERVER_ERROR | In case the method is not implemented and overridden in a sub-class. |
CSERequest | None = None, id: str | None = None, originator: str | None = None) -> Result:
¶
acme.resources.CNT_LA.CNT_LA, acme.resources.CNT_OL.CNT_OL, acme.resources.FCNT_LA.FCNT_LA, acme.resources.FCNT_OL.FCNT_OL, acme.resources.GRP_FOPT.GRP_FOPT, acme.resources.NTSR.NTSR, acme.resources.PCH_PCU.PCH_PCU, acme.resources.TS_LA.TS_LA, acme.resources.TS_OL.TS_OLProcess a RETRIEVE request that is directed to a virtual resource.
This method must be implemented by virtual resource class.
| Parameters | |
request:CSERequest | None | The request to process. |
id:str | None | The structured or unstructured resource ID of the target resource. |
originator:str | None | The request's originator. |
| Returns | |
Result | Result object indicating success or failure. |
acme.resources.CNT_LA.CNT_LA, acme.resources.CNT_OL.CNT_OL, acme.resources.FCNT_LA.FCNT_LA, acme.resources.FCNT_OL.FCNT_OL, acme.resources.GRP_FOPT.GRP_FOPT, acme.resources.NTSR.NTSR, acme.resources.PCH_PCU.PCH_PCU, acme.resources.TS_LA.TS_LA, acme.resources.TS_OL.TS_OLProcess a UPDATE request that is directed to a virtual resource.
This method must be implemented by virtual resource class.
| Parameters | |
request:CSERequest | The request to process. |
id:str | The structured or unstructured resource ID of the target resource. |
originator:str | The request's originator. |
| Returns | |
Result | Result object indicating success or failure. |
Check whether an attribute exists for the resource.
| Parameters | |
key:str | Resource attribute name to look for. |
| Returns | |
bool | Boolean, indicating the existens of an attribute |
acme.resources.CNT_LA.CNT_LA, acme.resources.CNT_OL.CNT_OL, acme.resources.FCNT.FCNT, acme.resources.FCNT_LA.FCNT_LA, acme.resources.FCNT_OL.FCNT_OL, acme.resources.TS_LA.TS_LA, acme.resources.TS_OL.TS_OLTest whether a resource supports the specified attribute. This method may be overwritten in sub-classes, for example for virtual resources.
| Parameters | |
name:str | Attribute to test. |
| Returns | |
bool | Boolean with the result of the test. |
Increment the subscription counter for the resource.
This is used to determine whether a resource has active subscriptions.
acme.resources.CIN.CIN, acme.resources.CNT.CNT, acme.resources.CRS.CRS, acme.resources.CSEBase.CSEBase, acme.resources.CSR.CSR, acme.resources.FCNT.FCNT, acme.resources.GRP.GRP, acme.resources.MgmtObjAnnc.MgmtObjAnnc, acme.resources.NOD.NOD, acme.resources.PCH.PCH, acme.resources.SMD.SMD, acme.resources.TS.TS, acme.resources.TSB.TSB, acme.resources.TSI.TSI, acme.resources.VirtualResource.VirtualResourceThis method is called when a new resource is created and before written to the database.
| Parameters | |
pi:str | The parent resource's ID. |
Test whether a the resource's type is an announced type.
| Returns | |
bool | True if the resource is an announced resource type. |
Test whether a resource has been created for another resource.
| Returns | |
bool | True if this resource has been created for another resource. |
Test whether this resource has been modified after another resource.
| Parameters | |
otherResource | Another resource used for the test. |
| Returns | |
bool | True if this resource has been modified after otherResource. |
Test whether the resource is a virtual resource.
| Returns | |
bool | True when the resource is a virtual resource. |
Determine the selected attributes for a partial retrieve of a resource.
| Parameters | |
request:CSERequest | Undocumented |
attributelist[ | The list of attributes to filter. |
| Raises | |
BAD_REQUEST | In case an attribute is not defined for the resource. |
Assign a value to a resource attribute.
If the attribute doesn't exist then it is created.
| Parameters | |
key:str | The resource attribute's name. This can be a path (see setXPath). |
value:Any | Value to assign to the attribute. |
overwrite:bool | None | Overwrite the value if already set. |
Save the resource ID for which this resource was created for.
This has some impacts on internal handling and checks.
| Parameters | |
ri:str | Resource ID of the resource for which this resource has been created for. |
Set a resource's location coordinates (internal attribute).
| Parameters | |
crd:JSON | The location coordinates to assign to a resource. |
Set a resource's originator.
This is the originator that created the resource. It is stored internally within the resource.
| Parameters | |
originator:str | The originator to assign to a resource. |
overwrite:bool | None | Undocumented |
Set the resource name.
Also set/update the internal structured resource name.
| Parameters | |
rn:str | The new resource name for the resource. |
Assign the release version for a resource.
This is usually assigned from the rvi indicator in the resource's CREATE request.
| Parameters | |
rvi:str | Original CREATE request's rvi. |
Set a resource's full structured resource name.
| Parameters | |
srn:str | The full structured resource name to assign to a resource. |
Determine the structured path of a resource.
| Returns | |
str | None | Structured path of the resource or None |
Return the resource type as a string. If the resource is a flex container, the specialization is added.
| Returns | |
str | The resource type as a string. |
JSON | None = None, originator: str | None = None, doValidateAttributes: bool | None = True):
¶
acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.CRS.CRS, acme.resources.FCIAnnc.FCIAnnc, acme.resources.PCH.PCH, acme.resources.SUB.SUBUpdate, add or remove resource attributes.
A subscription check for update is performed.
This method is implemented in sub-classes as well.
Note
This method updates the resource in the database. It should be called only after all other checks where performed.
| Parameters | |
dct:JSON | None | An optional JSON dictionary with the attributes to be updated. |
originator:str | None | The optional requests originator that let to the update of the resource. |
dobool | None | If True optionally call the resource's validate() method. |
| Raises | |
CONTENTS_UNACCEPTABLE | In case of a resource mismatch. |
BAD_REQUEST | In case of an invalid attribute. |
INTERNAL_SERVER_ERROR | In case the parent resource coudln't be retrieved. |
Signal to a resource that is was successfully updated.
This handler can be used to perform additional actions after the resource was updated, stored etc.
This method is implemented in some sub-classes.
| Parameters | |
dct:JSON | None | Optional JSON dictionary with the updated attributes. |
originator:str | None | The optional request originator. |
str | None = None, dct: JSON | None = None, parentResource: Resource | None = None):
¶
acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.CRS.CRS, acme.resources.NTP.NTP, acme.resources.NTPR.NTPR, acme.resources.SUB.SUBValidate a resource.
Usually called within activate() or update() methods.
This method is implemented in some sub-classes.
- Raises
BAD_REQUEST: In case of a validation error.
| Parameters | |
originator:str | None | Optional request originator |
dct:JSON | None | Updated attributes to validate |
parentResource | None | The parent resource |
str, parentResource: Resource, parentDelete: bool = False):
¶
acme.resources.CIN.CIN, acme.resources.NTP.NTP, acme.resources.REQ.REQ, acme.resources.STTE.STTEThis method is called before a resource will be deactivated.
This method is implemented in some sub-classes, which may throw an
execption if the resource cannot be deactivated. If it is implemented
it should call the super class' willBeDeactivated() method to check
for child resources.
| Parameters | |
originator:str | The request originator. |
parentResource | The resource's parent resource. |
parentbool | Undocumented |
str | None, request: CSERequest | None = None, subCheck: bool | None = True):
¶
This method is called before a resource will be send back in a RETRIEVE response.
This method is implemented in some sub-classes.
| Parameters | |
originator:str | None | The request originator. |
request:CSERequest | None | The RETRIEVE request. |
subbool | None | Optional indicator that a blocking Retrieve shall be performed, if configured. |
JSON | None = None, originator: str | None = None, subCheck: bool | None = True):
¶
This method is called before a resource will be updated and before calling the update() method.
This method is implemented in some sub-classes.
| Parameters | |
dct:JSON | None | JSON dictionary with the attributes that will be updated. |
originator:str | None | The request originator. |
subbool | None | Optional indicator that a blocking Update shall be performed, if configured. |
acme.resources.ACP.ACP, acme.resources.ACTR.ACTR, acme.resources.AE.AE, acme.resources.CIN.CIN, acme.resources.ContainerResource.ContainerResource, acme.resources.CRS.CRS, acme.resources.CSEBase.CSEBase, acme.resources.CSR.CSR, acme.resources.LCP.LCP, acme.resources.NOD.NOD, acme.resources.NTPR.NTPR, acme.resources.PCH.PCH, acme.resources.PDR.PDR, acme.resources.PRMR.PRMR, acme.resources.STTE.STTE, acme.resources.TGR.TGR, acme.resources.VirtualResource.VirtualResourceInjected Dispatcher instance.
acme.resources.AnnouncedResource.AnnouncedResource, acme.resources.CNT.CNT, acme.resources.PCH_PCU.PCH_PCU, acme.resources.TS.TSInjected RequestManager instance.
acme.resources.ACP.ACP, acme.resources.CNT.CNT, acme.resources.NTP.NTP, acme.resources.SCH.SCH, acme.resources.TS.TSInjected Storage instance.
acme.resources.AnnounceableResource.AnnounceableResource, acme.resources.CRS.CRS, acme.resources.PCH_PCU.PCH_PCU, acme.resources.SUB.SUBInjected Validator instance.
Check whether a referenced ACP resoure exists, and if yes, change the ID in the list to CSE relative unstructured format.
| Parameters | |
acpi:list[ | List if resource IDs to ACP resources. |
| Returns | |
list[ | If fully successful (ie. all ACP resources exist), then a new list with all IDs converted is returned. |
Normalize the URLs in the given attribute.
Various changes are made to the URI in case they are not fully compliant. This could be, for example, poa, nu and other attributes that usually hold a URI.
If the target attribute is a list of URI then all the URIs in the list are normalized.
| Parameters | |
attributestr | Name of the attribute to normalize. |
Original dictionary as it was created. This is used for validation in activate() later.