-
Notifications
You must be signed in to change notification settings - Fork 135
API Requirements
Resource Object - Terminal object in the API. For example a single nat instance. These are things that have a type and do not have 'collection' in their kind attribute (i.e. "kind":"natstate"
). They usually have a URL that ends in /~<partition>~<name>/
.
Sub-Collection - Some more complicated objects have sub-resources, but are accessed through the main resource object (i.e. pool/~Common~mypool/members/
)
Sub-Resource Object - These are the actual objects that are part of the sub-collection and accessed via the main resource object (i.e. pool/~Common~mypool/members/~Common~m1:80/
)
Resource Collection - This is a list of resource objects. For example all nat instances configured on the system. These are things that do have 'collection' in their kind attribute (i.e. "kind":"natcollectionstate"
). The have a URL that ends in the name of the objects you are getting a list of (i.e. ltm/nat/
).
Organizing Collection - This is the high level objects that organize the resource collections. These things are generally just lists of references to the resource collections they contain. This are things like ltm
, sys
, cm
etc.
Example using the URL that points to the member sub-resource object of the pool resource object that is contained in the ltm organizing collection
http://192.168.1.1/mgmt/tm/ltm/pool/~Common~mypool/members/~Common~m1:80/
|-------|---|----|--------------|-------|-------------|
OC OC RC Resource Obj SC Sub-Resrc Obj
-
BigIP objects SHOULD be represented by their configuration structure on the BigIPhttps://192.168.1.1/mgmt/tm/ltm/nat --> BigIP.ltm.nathttps://192.168.1.1/mgmt/tm/ltm/monitor/http/ --> BigIP.ltm.monitor.http
- After working with this an considering the consumer we felt it was better more closely mirror the organization structure of the various objects.
from f5.bigip import BigIP
bigip = BigIP('192.168.1.1', 'admin', 'admin')
# Returns an OrganizingCollection (list) that contains the URLs for the resource collections
ltm_collections = bigip.ltm
# Returns a ResourceCollection (list) that contains Pool objects. This does GET to BigIP and returns a list
pools = bigip.ltm.pool_collection
for pool in pools[1:3]:
print pool.name
# Create a new pool
new_pool = bigip.ltm.pool_collection.pool(name='new_pool', partition='mypartition', attr1='foo', attr2='bar')
# Get an existing pool
existing_pool = bigip.ltm.pool_collection.pool(name='existing_pool', partition='mypartition')
# Update a pool
new_pool.description = "New Description"
new_pool.update()
# or
new_pool.update(description="New Description")
# Refresh a pool - This will 'refresh' the object with the current state on the BIGIP
new_pool.refresh()
# Delete a pool
new_pool.delete()
# Get the members of a pool, this returns a Sub-Resource Collection
members = new_pool.member_collection
for member in members[::-1]:
print members.name
# Get a single member of a pool
member_0 = new_pool.member_collection[0]
# Get a list of members with some criteria
member_my = new_pool.member_collection.find(enabled=True, partition='mypartion)
# Create a new member
new_member = new_pool.member_collection.member(name='m1:80', partition='mypartition', arg1='foo', arg2='bar', ...)
- Users MUST be able to create new resource objects on the BigIP including their sub-resource objects
- Creation of new resource objects must return the object that can be operated on with supported CRUD methods.
- Users MUST be able to access existing resource objects on the system by specifying the partition and name of the object
- Accessing existing objects MUST return the object that can be operated on with supported CRUD methods.
- Objects that have sub-resource collections (i.e. Pools which have members) must include those collections as lists of proper sub-resource objects.
- Create methods for resource objects MUST only be accessed via their resource collection (or a manager attached to it). Calling an unsupported method MUST raise an appropriate exception.
- Consumers of the API MUST be able to list all of the resource collection's child objects via the resource collection object (or a manager attached to it)
- Resource collections SHOULD be filterable according to the BigIP filter rules
- READ, UPDATE, DELETE operations MUST only be available on resource objects. Calling an unsupported method MUST raise an appropriate exception.
- The
__str__
attribute for the resource objects SHOULD be defined such that the the consumer can uniquely identify the object. Something likeltm/nat/~Common~mynat
orCommon/mynat
would be good. - The
__repr__
attribute for the resource objects SHOULD be defined such that the consumer can use it for debugging. - The
__eq__
for resource objects SHOULD be defined such that the consumer can easily compare objects to see if they have the same value. The equivalence check may be as simple as having the same partition, name and generation values. - Create methods for resource objects SHOULD validate that all required arguments are present prior to sending them to the BigIP in the request.
- Update methods for objects SHOULD validate that all read-only attributes that cause an error on the system if present are validated/errored prior to sending the update request to the BigIP.
- Delete methods for objects SHOULD delete the object on the BigIP and delete its self in such a way that the object is no longer valid for users to operate on.
- HTTP Errors raised by the request to the BigIP MUST be raised by the API back to the caller. For example if the use of the API causes a 404 then this should raise an error that the caller can catch.