clustoapi.apps.attribute: Attribute Application¶
The attribute application handles all attribute specific operations like
querying, adding, deleting and updating attributes.
-
clustoapi.apps.attribute.add_attr(name, **kwargs)[source]¶ Add an attribute to this object.
- Requires parameters
name,key, andvalue - Optional parameters are
subkey`,` ``number, anddatatype - Additionally,
maskcan be provided for a datetime attribute. - These parameters can be either be passed with a querystring
- or a json body. If json is supplied, multiple attributes may be
- added at the same time.
Example:
$ ${post} -d 'name=addattrserver' ${server_url}/entity/basicserver [ "/basicserver/addattrserver" ] HTTP: 201 Content-type: application/json$ ${post} -d 'key=group' -d 'value=web' ${server_url}/attribute/addattrserver [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "web" } ] HTTP: 201 Content-type: application/jsonWill:
- Create an entity called
addattrserver - Add the attribute with
key=groupandvalue=webto it
Example:
$ ${post} -d 'key=group' -d 'subkey=owner' -d 'value=web' ${server_url}/attribute/addattrserver [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "web" }, { "datatype": "string", "key": "group", "number": null, "subkey": "owner", "value": "web" } ] HTTP: 201 Content-type: application/jsonWill add the attribute with key
groupand subkeyownerand valuejoeto the previously created entityaddattrserver$ ${post} -d 'key=group' -d 'subkey=id' -d 'value=6' -d 'datatype=int' ${server_url}/attribute/addattrserver [ ... { "datatype": "int", "key": "group", "number": null, "subkey": "id", "value": 6 } ] HTTP: 201 Content-type: application/jsonWill add the attribute with key
groupand subkeyidand value1with the correct datatype to the previously created entityaddattrserver$ ${post} -d 'key=inception' -d 'value=/basicserver/addattrserver' -d 'datatype=relation' ${server_url}/attribute/addattrserver [ ... { "datatype": "relation", "key": "inception", "number": null, "subkey": null, "value": "/basicserver/addattrserver" } ] HTTP: 201 Content-type: application/jsonWill add the attribute with key
inceptionand itself as a relation using therelationdatatype.$ ${post} -d 'key=birthday' -d 'subkey=jtcunning' -d 'value=1991-07-09T14:46:51.321435' -d 'datatype=datetime' ${server_url}/attribute/addattrserver [ { "datatype": "datetime", "key": "birthday", "number": null, "subkey": "jtcunning", "value": "1991-07-09T14:46:51.321435" }, ... ] HTTP: 201 Content-type: application/jsonWill add the attribute with key
birthdayand subkeyjtcunningwith thedatetimepython object as the datatype.$ ${post} -H 'Content-Type: application/json' -d '${sample_json_attrs}' ${server_url}/attribute/addattrserver [ ... { "datatype": "string", "key": "group", "number": null, "subkey": "admin", "value": "apache" }, { "datatype": "string", "key": "group", "number": null, "subkey": "member", "value": "webapp" }, ... ] HTTP: 201 Content-type: application/jsonWill add two attributes in bulk by stating that the content type is
application/json.- Requires parameters
-
clustoapi.apps.attribute.attrs(name, key=None, subkey=None, number=None)[source]¶ Query attributes from this object.
Example:
$ ${post} -d 'name=attrpool1' ${server_url}/entity/pool [ "/pool/attrpool1" ] HTTP: 201 Content-type: application/json$ ${get} ${server_url}/attribute/attrpool1 [] HTTP: 200 Content-type: application/jsonWill show all the attributes from the object
attrpool1:$ ${get} -d 'driver=pool' ${server_url}/attribute/attrpool1 [] HTTP: 200 Content-type: application/jsonWill show all the attributes from the object
attrpool1if the driver forattrpool1ispool. In the same vein this code:$ ${get} -d 'driver=basicserver' ${server_url}/attribute/attrpool1 ... HTTP: 409 ...Should fail, because the
attrpool1object is of typepool, notbasicserverExample:
$ ${get} ${server_url}/attribute/attrpool1/owner [] HTTP: 200 Content-type: application/jsonWill show the attributes for
server1if their key isowner.
-
clustoapi.apps.attribute.del_attrs(name, key, subkey=None, number=None)[source]¶ Deletes an attribute from this object
- Requires HTTP path
key - Optional parameters are
subkey,value, andnumber
Examples:
$ ${post} -d 'name=deleteserver1' ${server_url}/entity/basicserver [ "/basicserver/deleteserver1" ] HTTP: 201 Content-type: application/json$ ${put} -d 'value=joe' ${server_url}/attribute/deleteserver1/group/owner [ { "datatype": "string", "key": "group", "number": null, "subkey": "owner", "value": "joe" } ] HTTP: 200 Content-type: application/json$ ${delete} ${server_url}/attribute/deleteserver1/group/owner [] HTTP: 200 Content-type: application/jsonWill create a
basicserverobject calleddeleteserver1, then it will add an attribute (the only attribute so far), then it will delete it.$ ${post} -d 'name=deleteserver2' ${server_url}/entity/basicserver [ "/basicserver/deleteserver2" ] HTTP: 201 Content-type: application/json$ ${put} -d 'value=engineering' ${server_url}/attribute/deleteserver2/group [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "engineering" } ] HTTP: 200 Content-type: application/json$ ${put} -d 'value=joe' ${server_url}/attribute/deleteserver2/group/owner [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "engineering" }, { "datatype": "string", "key": "group", "number": null, "subkey": "owner", "value": "joe" } ] HTTP: 200 Content-type: application/json$ ${delete} ${server_url}/attribute/deleteserver2/group/owner [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "engineering" } ] HTTP: 200 Content-type: application/jsonThis example should add two attributes with the same key, but different subkey, then it will delete only the second value.
- Requires HTTP path
-
clustoapi.apps.attribute.set_attr(name, **kwargs)[source]¶ Sets an attribute from this object. If the attribute doesn’t exist it will be added, if the attribute already exists then it will be updated.
- Requires HTTP parameters
keyandvalue - Optional parameters are
subkey`,` ``number, anddatatype - Additionally,
maskcan be provided for a datetime attribute.
Example:
$ ${post} -d 'name=setattrserver' ${server_url}/entity/basicserver [ "/basicserver/setattrserver" ] HTTP: 201 Content-type: application/json$ ${post} -d 'key=group' -d 'value=web' ${server_url}/attribute/setattrserver [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "web" } ] HTTP: 201 Content-type: application/json$ ${put} -d 'value=db' ${server_url}/attribute/setattrserver/group [ { "datatype": "string", "key": "group", "number": null, "subkey": null, "value": "db" } ] HTTP: 200 Content-type: application/jsonWill:
- Create the entity
setattrserver - Add the attribute with
key=groupandvalue=web - Update the attribute to
value=db
Example:
$ ${post} -d 'name=setattrserver2' ${server_url}/entity/basicserver [ "/basicserver/setattrserver2" ] HTTP: 201 Content-type: application/json$ ${put} -d 'value=joe' ${server_url}/attribute/setattrserver2/group/owner [ { "datatype": "string", "key": "group", "number": null, "subkey": "owner", "value": "joe" } ] HTTP: 200 Content-type: application/json$ ${put} -d 'value=bob' ${server_url}/attribute/setattrserver2/group/owner [ { "datatype": "string", "key": "group", "number": null, "subkey": "owner", "value": "bob" } ] HTTP: 200 Content-type: application/jsonWill:
- Create a new object
setattrserver2of typebasicserver - Set the attribute with key
groupand subkeyownerwith valuejoeto the objectsetattrserver1. Since this is the only attribute so far, this operation works just likeadd_attr() - Update the attribute we set above, now the
valuewill readbob
- Requires HTTP parameters
clustoapi.apps.entity: Entity Application¶
The entity application will hold all methods related to entity management
in clusto. That is: creation, querying, modification and overall entity
manipulation.
-
clustoapi.apps.entity.action(driver, name)[source]¶ Inserts/removes the given device from the request parameters into/from the object
Example:
$ ${post} -d 'name=pool1' ${server_url}/entity/pool [ "/pool/pool1" ] HTTP: 201 Content-type: application/json$ ${post} -d 'name=server1' ${server_url}/entity/basicserver [ "/basicserver/server1" ] HTTP: 201 Content-type: application/json$ ${post} -d 'device=server1' -d 'action=insert' ${server_url}/entity/pool/pool1 { "attrs": [], "contents": [ "/basicserver/server1" ], "driver": "pool", "name": "pool1", "parents": [] } HTTP: 200 Content-type: application/json$ ${post} -d 'device=server1' -d 'action=remove' ${server_url}/entity/pool/pool1 { "attrs": [], "contents": [], "driver": "pool", "name": "pool1", "parents": [] } HTTP: 200 Content-type: application/jsonWill:
- Create a pool entity called
pool1 - Create a basicserver entity called
server1 - Insert the entity
server1into the entitypool1 - Remove the entity
server1from the entitypool1
Examples:
$ ${post} -d 'name=pool2' ${server_url}/entity/pool [ "/pool/pool2" ] HTTP: 201 Content-type: application/json$ ${post} -d 'name=server2' -d 'name=server3' ${server_url}/entity/basicserver [ "/basicserver/server2", "/basicserver/server3" ] HTTP: 201 Content-type: application/json$ ${post} -d 'device=server2' -d 'device=server3' -d 'action=insert' ${server_url}/entity/pool/pool2 { "attrs": [], "contents": [ "/basicserver/server2", "/basicserver/server3" ], "driver": "pool", "name": "pool2", "parents": [] } HTTP: 200 Content-type: application/json$ ${post} -d 'device=server2' -d 'device=server3' -d 'action=remove' ${server_url}/entity/pool/pool2 { "attrs": [], "contents": [], "driver": "pool", "name": "pool2", "parents": [] } HTTP: 200 Content-type: application/jsonThe above will:
- Create a pool entity called
pool2 - Create two basicserver entities called
server2andserver3 - Insert both basicserver entities into the pool entity
- Remove both basicserver entities from the pool entity
- Create a pool entity called
-
clustoapi.apps.entity.create(driver)[source]¶ Creates a new object of the given driver.
- Requires HTTP parameters
name
Example:
$ ${post} -d 'name=createpool1' ${server_url}/entity/pool [ "/pool/createpool1" ] HTTP: 201 Content-type: application/jsonWill create a new
pool1object with apooldriver. If thepool1object already exists, the status code returned will be 202, and you will see whatever warnings in theWarningsheader:$ ${post_i} -d 'name=createpool1' ${server_url}/entity/pool HTTP/1.0 202 Accepted ... Warnings: Entity(s) /pool/createpool1 already exist(s)... [ "/pool/createpool1" ]If you try to create a server of an unknown driver, you should receive a 412 status code back:
$ ${post} -d 'name=createobject' ${server_url}/entity/nondriver "Requested driver "nondriver" does not exist" HTTP: 412 Content-type: application/jsonThe following example:
$ ${post_i} -d 'name=createpool1' -d 'name=createpool2' ${server_url}/entity/pool HTTP/1.0 202 Accepted ... Warnings: Entity(s) /pool/createpool1 already exist(s)... [ "/pool/createpool1", "/pool/createpool2" ]Will attempt to create new objects
createpool1andcreatepool2with apooldriver. As all objects are validated prior to creation, if any of them already exists the return code will be 202 (Accepted) and you will get an extra headerWarningswith the message.- Requires HTTP parameters
-
clustoapi.apps.entity.delete(driver, name)[source]¶ Deletes an object if it matches the given driver
- Requires HTTP parameters
name
Examples:
$ ${post} -d 'name=servercreated' ${server_url}/entity/basicserver [ "/basicserver/servercreated" ] HTTP: 201 Content-type: application/json$ ${delete} ${server_url}/entity/nondriver/servercreated "Requested driver "nondriver" does not exist" HTTP: 412 Content-type: application/json$ ${delete} ${server_url}/entity/basicserver/servercreated HTTP: 204 Content-type:$ ${delete} ${server_url}/entity/basicserver/servercreated HTTP: 404 Content-type: NoneWill create a new
servercreatedobject with abasicserverdriver. Then it will proceed to delete it. If the operation succeeded, it will return a 200, if the object doesn’t exist, it will return a 404.- Requires HTTP parameters
-
clustoapi.apps.entity.list(driver=None)[source]¶ Returns all entities, or (optionally) all entities of the given driver
Example:
$ ${get} ${server_url}/entity/ [ ... ] HTTP: 200 Content-type: application/jsonWill list all entities
Example:
$ ${get} ${server_url}/entity/clustometa [ "/clustometa/clustometa" ] HTTP: 200 Content-type: application/jsonWill list all entities that match the driver
clustometaThe following example should fail because there is no driver
nondriver:$ ${get} ${server_url}/entity/nondriver "The requested driver "nondriver" does not exist" HTTP: 412 Content-type: application/json
-
clustoapi.apps.entity.show(driver, name)[source]¶ Returns a json representation of the given object
Example:
$ ${post} -d 'name=showpool' ${server_url}/entity/pool [ "/pool/showpool" ] HTTP: 201 Content-type: application/json$ ${get} ${server_url}/entity/pool/showpool { "attrs": [], "contents": [], "driver": "pool", "name": "showpool", "parents": [] } HTTP: 200 Content-type: application/jsonWill return a JSON representation of the previously created
showpool.$ ${get} ${server_url}/entity/basicserver/showpool "The driver for object "showpool" is not "basicserver"" HTTP: 409 Content-type: application/jsonWill yield a 409 (Conflict) because the object
showpoolis not abasicserverobject.
clustoapi.apps.resourcemanager: Resource Manager Application¶
The resourcemanager application will hold all methods related to resource
management in clusto. Pretty much allocating and deallocating resources.
-
clustoapi.apps.resourcemanager.allocate(driver, manager)[source]¶ This allocates a new resource to a given thing. Said thing can be either a driver (and the result will be a newly created object subclasses from this driver) or an object, and the resource manager will allocate (bind) a resource to it.
Examples:
$ ${post} -d 'name=allocator' ${server_url}/resourcemanager/simpleentitynamemanager { "attrs": [ ... ], "contents": [], "count": 0, "driver": "simpleentitynamemanager", "name": "allocator", "parents": [] } HTTP: 201 Content-type: application/json $ ${post} -d 'driver=basicserver' ${server_url}/resourcemanager/simpleentitynamemanager/allocator "/basicserver/01" HTTP: 201 Content-type: application/jsonWill request a new name from the object
allocator(which is an object ofSimpleEntityManagerthat we just created with default values) and then it will create a newBasicServerobject.$ ${post} -d 'driver=basicserver' -d 'resource=99' ${server_url}/resourcemanager/simpleentitynamemanager/allocator "/basicserver/99" HTTP: 201 Content-type: application/jsonWill create a new
BasicServerobject from thetestnamesresource manager with the specific name ofs99.
-
clustoapi.apps.resourcemanager.create(driver)[source]¶ This differs from the standard way of creating entities is that resource managers can have a number of extra parameters added to them that not necessarily match any of the other entities. These parameters are defined by each resource manager driver and are pretty much arbitrary. Seems like a good idea to separate these crucial differences.
Examples:
$ ${post} -d 'name=nameman1' ${server_url}/resourcemanager/simplenamemanager { "attrs": [ ... ], "contents": [], "count": 0, "driver": "simplenamemanager", "name": "nameman1", "parents": [] } HTTP: 201 Content-type: application/jsonWill create a
SimpleNameManagerresource manager namednamemgr1with all default values set.$ ${post} -d 'name=ipman1' -d 'gateway=192.168.1.1' -d 'netmask=255.255.255.0' -d 'baseip=192.168.1.10' ${server_url}/resourcemanager/ipmanager { "attrs": [ { "datatype": "string", "key": "baseip", "number": null, "subkey": "property", "value": "192.168.1.10" }, { "datatype": "string", "key": "gateway", "number": null, "subkey": "property", "value": "192.168.1.1" }, { "datatype": "string", "key": "netmask", "number": null, "subkey": "property", "value": "255.255.255.0" } ], "contents": [], "count": 0, "driver": "ipmanager", "name": "ipman1", "parents": [] } HTTP: 201 Content-type: application/jsonWill create a
IPManagerresource manager namedipman1with some additional arguments such asnetmask,gatewayandbaseip
-
clustoapi.apps.resourcemanager.deallocate(driver, manager)[source]¶ Resource managers should allow you to deallocate things just the same as allocating things.
Examples:
$ ${post} -d 'name=ipman2' -d 'gateway=192.168.1.1' -d 'netmask=255.255.255.0' -d 'baseip=192.168.1.10' ${server_url}/resourcemanager/ipmanager { "attrs": [ { "datatype": "string", "key": "baseip", "number": null, "subkey": "property", "value": "192.168.1.10" }, { "datatype": "string", "key": "gateway", "number": null, "subkey": "property", "value": "192.168.1.1" }, { "datatype": "string", "key": "netmask", "number": null, "subkey": "property", "value": "255.255.255.0" } ], "contents": [], "count": 0, "driver": "ipmanager", "name": "ipman2", "parents": [] } HTTP: 201 Content-type: application/json $ ${post} -d 'name=names2' -d 'basename=a' ${server_url}/resourcemanager/simpleentitynamemanager { "attrs": [ ... ], "contents": [], "count": 0, "driver": "simpleentitynamemanager", "name": "names2", "parents": [] } HTTP: 201 Content-type: application/json $ ${post} -d 'driver=basicserver' ${server_url}/resourcemanager/simpleentitynamemanager/names2 "/basicserver/a01" HTTP: 201 Content-type: application/json $ ${post} -d 'object=a01' ${server_url}/resourcemanager/ipmanager/ipman2 { "datatype": "int", "key": "ip", "number": 0, "subkey": null, "value": 1084752130 } HTTP: 201 Content-type: application/json $ ${delete} -d 'object=a01' ${server_url}/resourcemanager/ipmanager/ipman2 HTTP: 204 Content-type:
-
clustoapi.apps.resourcemanager.list(driver=None)[source]¶ Lists all resource managers found in the clusto database. Optionally you can list all resource managers that match the given
driverExamples:
$ ${post} -d 'name=zmanager' ${server_url}/resourcemanager/simplenamemanager { "attrs": [ ... ], "contents": [], "count": 0, "driver": "simplenamemanager", "name": "zmanager", "parents": [] } HTTP: 201 Content-type: application/jsonThe above will create a simple name manager called “zmanager”
$ ${get} ${server_url}/resourcemanager/ [ "/simpleentitynamemanager/testnames", "/simplenamemanager/zmanager" ] HTTP: 200 Content-type: application/jsonThe above will list all resource managers in clusto, which should have “zmanager”
$ ${get} ${server_url}/resourcemanager/simpleentitynamemanager [ "/simpleentitynamemanager/testnames" ] HTTP: 200 Content-type: application/jsonWill list all resource managers of driver
SimpleNameManager$ ${get} ${server_url}/resourcemanager/notadriver "Not a valid driver "notadriver" (driver name notadriver doesn't exist.)" HTTP: 404 Content-type: application/jsonWill return a
404error because that resource manager driver doesn’t exist
-
clustoapi.apps.resourcemanager.show(driver, manager)[source]¶ Shows the details of the given resource manager, if it is a resource manager
Examples:
$ ${post} -d 'name=nameman2' ${server_url}/resourcemanager/simplenamemanager { "attrs": [ ... ], "contents": [], "count": 0, "driver": "simplenamemanager", "name": "nameman2", "parents": [] } HTTP: 201 Content-type: application/json $ ${get} ${server_url}/resourcemanager/simplenamemanager/nameman1 { "attrs": [ ... ], "contents": [], "count": 0, "driver": "simplenamemanager", "name": "nameman1", "parents": [] } HTTP: 200 Content-type: application/jsonWill create the
nameman2resource manager, then show its details. In this case both operations yield the same data.$ ${get} ${server_url}/resourcemanager/simpleentitynamemanager/nonames "Object "nonames" not found (nonames does not exist.)" HTTP: 404 Content-type: application/jsonWill return a
404error since the resource manager wasn’t found$ ${get} ${server_url}/resourcemanager/nomanager/testnames "The driver "nomanager" is not a valid driver" HTTP: 412 Content-type: application/jsonWill return a
412because the drivernomanagerdoesn’t exist$ ${get} ${server_url}/resourcemanager/basicserver/testserver1 "The object "testserver1" is not a resource manager" HTTP: 409 Content-type: application/jsonWill return a
412instead because even though the driverbasicserverexists, it is not a resource manager driver