F5 Python SDK Documentation¶
Introduction¶
This project implements an object model based SDK for the F5 Networks® BIG-IP® iControl® REST interface. Users of this library can create, edit, update, and delete configuration objects on a BIG-IP®. For more information on the basic principals that the SDK uses, see the User Guide.
Quick Start¶
Installation¶
$ pip install f5-sdk
Basic Example¶
from f5.bigip import ManagementRoot
# Connect to the BigIP
mgmt = ManagementRoot("bigip.example.com", "admin", "somepassword")
# Get a list of all pools on the BigIP and print their names and their
# members' names
pools = mgmt.tm.ltm.pools.get_collection()
for pool in pools:
print pool.name
for member in pool.members_s.get_collection():
print member.name
# Create a new pool on the BIG-IP
mypool = mgmt.tm.ltm.pools.pool.create(name='mypool', partition='Common')
# Load an existing pool and update its description
pool_a = mgmt.tm.ltm.pools.pool.load(name='mypool', partition='Common')
pool_a.description = "New description"
pool_a.update()
# Delete a pool if it exists
if mgmt.tm.ltm.pools.pool.exists(name='mypool', partition='Common'):
pool_b = mgmt.tm.ltm.pools.pool.load(name='mypool', partition='Common')
pool_b.delete()
Detailed Documentation¶
User Guide¶
To get the most out of using our SDK, it’s useful to understand the basic concepts and principals we used when we designed it. It is also important that you are familiar with the F5® BIG-IP® and, at a minimum, how to configure BIG-IP® using the configuration utility (the GUI). More useful still would be if you are already familiar with the iControl® REST API.
Basic Concepts¶
Familiarizing yourself with the following underlying basic concepts will help you get up and running with the SDK.
Important
When using the SDK, you’ll notice that collection objects are referenced using the plural version of the Resource
objects they contain. When the Resource
object’s type is plural (ends in an s
), you need to add _s
to the name when referring to the collection.
This _s
rule applies to all object collections where the object in the collection already ends in s
.
Examples:
- LTM Pool objects are collected in
f5.bigip.tm.ltmpool.Pools
and are accessible via the pathf5.bigip.pools.get_collection()
. - Network Tunnels objects are stored in
f5.bip.net.tunnels.Tunnels_s
and are accessible viaf5.bigip.net.tunnels_s.get_collection()
.
REST URIs¶
You can directly infer REST URIs from the python expressions, and vice versa.
Examples
Expression: mgmt = ManagementRoot('<ip_address>', '<username>', '<password>')
URI Returned: https://<ip_address>/mgmt/
Expression: cm = mgmt.cm('<ip_address>', '<username>', '<password>')
URI Returned: https://<ip_address>/mgmt/cm
Expression: tm = mgmt.tm('<ip_address>', '<username>', '<password>')
URI Returned: https://<ip_address>/mgmt/tm
Expression: ltm = mgmt.tm.ltm('<ip_address>', '<username>', '<password>')
URI Returned: https://<ip_address>/mgmt/tm/ltm/
Expression: pools1 = mgmt.tm.ltm.pools
URI Returned: https://<ip_address>/mgmt/tm/ltm/pool
Expression: pool_a = pools1.create(partition="Common", name="foo")
URI Returned: https://<ip_address>/mgmt/tm/ltm/pool/~Common~foo
REST Endpoints¶
A set of basic REST endpoints can be derived from the object’s URI and kind
(listed below).
Dynamic Attributes¶
The python object’s attribute can be created dynamically based on the JSON returned when querying the REST API.
iControl® REST kind
Parameters¶
Almost all iControl® REST API entries contain a parameter named kind
. This parameter provides information about the object that lets you know what you should expect to follow it. The iControl® REST API uses three types of kind
: collectionstate
, state
, and stats
.
kind |
Associated Objects | Methods |
---|---|---|
collectionstate |
OrganizingCollection ,
Collection |
exists() |
state |
Resource |
create() , update() , refresh() , delete() ,
load() , exists() |
stats |
Resource |
refresh() , load() , exists() |
Methods¶
Method | HTTP Command | Action(s) |
---|---|---|
create() |
POST | creates a new resource on the device with its own URI
|
update() |
PUT | submits a new configuration to the device resource; sets the
Resource attributes to the state reported by the device
|
refresh() |
GET | obtains the state of a device resource; sets the representing
Python Resource Object; tracks device state via its attributes
|
delete() |
DELETE | removes the resource from the device, sets
self.__dict__ to
{'deleted': True} |
load() |
GET | obtains the state of an existing resource on the device; sets
the Resource attributes to match that state
|
exists() |
GET | checks for the existence of an object on the BIG-IP®
|
Note
Available methods are restricted according to the object’s kind
.
REST API Endpoints¶
Overview¶
REST URI Segments¶
We’ll start exploring the iControl® REST API’s endpoints with an example detailing how the endpoint types map to the different parts of the URI. The different types of resources used by the SDK shown in the example are explained in detail later in this guide.
Example: The URI below returns the JSON for an LTM pool member.
http://192.168.1.1/mgmt/tm/ltm/pool/~Common~mypool/members/~Common~m1:80
|----|--|---|----|--------------|-------|-------------|
|root|OC|OC |Coll| Resource | SC |SubColl Resrc|
OC | Organizing Collection |
Coll | Collection |
Resource | Resource |
SC | Subcollection |
SubColl Resrc | Subcollection Resource |
Endpoints¶
Organizing Collection¶
kind
: collectionstate
In iControl® REST, the URI represents the tree structure of modules and components in the BIG-IP®. The root is represented by mgmt
; the REST API representation of the BIG-IP® module follows.
Example:
The URI structure for the Traffic Management shell (tmsh) is /mgmt/tm/
.
The REST representations of BIG-IP® modules which contain submodules are called organizing collections. In the above example, /tm/
is an organizing collection. Its submodules – ‘Statistics’, ‘iApps’, ‘DNS’, ‘Local Traffic’, etc. – are all organizing collections as well.
The F5® SDK follows the same mapping model as the REST API. Organizing collections, which appear under f5.bigip
, correspond to the various modules available on the BIG-IP®.
Example:
f5.bigip.tm
maps totmsh
f5.bigip.tm.sys
maps to ‘System’f5.bigip.tm.ltm
module maps to ‘Local Traffic’
OrganizingCollection
objects are not configurable; rather, they contain other submodules which either contain configurable objects (Collection
) or are configurable objects (Resource
).
Example:
https://192.168.25.42/mgmt/tm/ltm/
refers to the BIG-IP® Local Traffic module (organizing collection)
https://192.168.25.42/mgmt/tm/ltm/pool
refers to the Local Traffic Pools submodule (collection)
https://192.168.25.42/mgmt/tm/ltm/pool/~Common~pool2
refers to a specific pool (resource)
Example: Perform an HTTP GET
for the ltm
organizing collection object; the JSON blob returned contains a list of references to subordinate objects that are either collections or resources.
{
kind: "tm:ltm:ltmcollectionstate",
selfLink: "https://localhost/mgmt/tm/ltm?ver=11.6.0",
items: [
{
reference: {
link: "https://localhost/mgmt/tm/ltm/auth?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/data-group?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/dns?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/global-settings?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/html-rule?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/message-routing?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/monitor?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/persistence?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/profile?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/default-node-monitor?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/eviction-policy?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/ifile?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/nat?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/node?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/policy?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/policy-strategy?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/pool?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/rule?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/snat?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/snat-translation?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/snatpool?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/traffic-class?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/virtual?ver=11.6.0"
}
},
{
reference: {
link: "https://localhost/mgmt/tm/ltm/virtual-address?ver=11.6.0"
}
}
]
}
Collection¶
kind
: collectionstate
A collection is similar to an Organizing Collection in it is not a configurable object. Unlike an organiziont collection, however, a collection only contains references to objects (or, resources) of the same type.
Important
When using the SDK, you’ll notice that collection objects are referenced using the plural version of the Resource
objects they contain. When the Resource
object’s type is plural (ends in an s
), you need to add _s
to the name when referring to the collection.
This _s
rule applies to all object collections where the object in the collection already ends in s
.
Examples:
- LTM Pool objects are collected in
f5.bigip.tm.ltmpool.Pools
and are accessible via the pathf5.bigip.pools.get_collection()
. - Network Tunnels objects are stored in
f5.bip.net.tunnels.Tunnels_s
and are accessible viaf5.bigip.net.tunnels_s.get_collection()
.
Example: Use f5.bigip.resource.Collection.get_collection()
to get a list of the objects in the f5.bigip.tm.ltm.pool
collection.
The items
attribute in the JSON returned contains Resource objects that all share the same kind
. We can tell that these objects are resources because the kind
ends in state
.
{
kind: "tm:ltm:pool:poolcollectionstate",
selfLink: "https://localhost/mgmt/tm/ltm/pool?ver=11.6.0",
items: [
{
kind: "tm:ltm:pool:poolstate",
name: "my_newpool",
partition: "Common",
fullPath: "/Common/my_newpool",
generation: 76,
selfLink: "https://localhost/mgmt/tm/ltm/pool/~Common~my_newpool?ver=11.6.0",
allowNat: "yes",
allowSnat: "yes",
description: "This is my pool",
ignorePersistedWeight: "disabled",
ipTosToClient: "pass-through",
ipTosToServer: "pass-through",
linkQosToClient: "pass-through",
linkQosToServer: "pass-through",
loadBalancingMode: "round-robin",
minActiveMembers: 0,
minUpMembers: 0,
minUpMembersAction: "failover",
minUpMembersChecking: "disabled",
queueDepthLimit: 0,
queueOnConnectionLimit: "disabled",
queueTimeLimit: 0,
reselectTries: 0,
serviceDownAction: "none",
slowRampTime: 10,
membersReference: {
link: "https://localhost/mgmt/tm/ltm/pool/~Common~my_newpool/members?ver=11.6.0",
isSubcollection: true
}
},
{
kind: "tm:ltm:pool:poolstate",
name: "mypool",
partition: "Common",
fullPath: "/Common/mypool",
generation: 121,
selfLink: "https://localhost/mgmt/tm/ltm/pool/~Common~mypool?ver=11.6.0",
allowNat: "yes",
allowSnat: "yes",
ignorePersistedWeight: "disabled",
ipTosToClient: "pass-through",
ipTosToServer: "pass-through",
linkQosToClient: "pass-through",
linkQosToServer: "pass-through",
loadBalancingMode: "round-robin",
minActiveMembers: 0,
minUpMembers: 0,
minUpMembersAction: "failover",
minUpMembersChecking: "disabled",
queueDepthLimit: 0,
queueOnConnectionLimit: "disabled",
queueTimeLimit: 0,
reselectTries: 0,
serviceDownAction: "none",
slowRampTime: 10,
membersReference: {
link: "https://localhost/mgmt/tm/ltm/pool/~Common~mypool/members?ver=11.6.0",
isSubcollection: true
}
},
]
}
Resource¶
kind
: state
A resource is a fully configurable object for which the CURDLE methods are supported.
In the F5® SDK, a resource is instantiated via its collection. Once created or loaded, resources contain attributes that map to the JSON fields returned by the BIG-IP®.
Example: Load a f5.bigip.tm.ltm.node.Node
Resource
object.
>>> from f5.bigip import ManagementRoot
>>> mgmt = ManagementRoot('192.168.1.1', 'myuser', 'mypass')
>>> n = mgmt.tm.ltm.nodes.node.load(partition='Common', name='192.168.15.15')
>>> print n.raw
{
"kind":"tm:ltm:node:nodestate",
"name":"192.168.15.15",
"partition":"Common",
"fullPath":"/Common/192.168.15.15",
"generation":16684,
"selfLink":"https://localhost/mgmt/tm/ltm/node/~Common~192.168.15.15?ver=11.6.0",
"address":"192.168.15.15",
"connectionLimit":0,
"dynamicRatio":1,
"ephemeral":"false",
"fqdn":{
"addressFamily":"ipv4",
"autopopulate":"disabled",
"downInterval":5,
"interval":3600
},
"logging":"disabled",
"monitor":"default",
"rateLimit":"disabled",
"ratio":1,
"session":"user-enabled",
"state":"unchecked"
}
The output of the f5.bigip.tm.ltm.node.Node.raw
(above) shows all of the available attributes.
Once you have loaded the object, you can access the attributes as shown below.
>>> n.fqdn['downInterval'] = 10
>>> n.logging = 'enabled'
>>> n.update()
Subcollection¶
kind
: collectionstate
A subcollection is a Collection
that’s attached to a higher-level Resource
object. Subcollections are almost exactly the same as collections; the exception is that they can only be accessed via the resource they’re attached to (the ‘parent’ resource). A subcollection can be identified by the value isSubcollection: true
, followed by an items
attribute listing the subcollection’s resources. Just as with collections, you can use get_collection()
to get a list of the resources in the subcollection.
Example
A pool
resource has a members_s
subcollection attached to it; you must create or load the ‘parent’ resource (pool
) before you can access the subcollection (members_s
).
>>> from f5.bigip import ManagementRoot
>>> mgmt = ManagementRoot('192.168.1.1', 'myuser', 'mypass')
>>> pool = mgmt.tm.ltm.pools.pool.load(partition='Common', name='p1')
>>> members = pool.members_s.get_collection()
Note
In the above example, the subcollection object – members_s
– ends
in _s
because the subcollection resource object name (members
)
is already plural.
The JSON returned for a pool with one member is shown below. Note the highlighted rows, which indicate the subcollection.
Example
{
"kind": "tm:ltm:pool:poolstate",
"name": "p1",
"partition": "Common",
"fullPath": "/Common/p1",
"generation": 18703,
"selfLink": "https://localhost/mgmt/tm/ltm/pool/~Common~p1?expandSubcollections=true&ver=11.6.0",
"allowNat": "yes",
"allowSnat": "yes",
"ignorePersistedWeight": "disabled",
"ipTosToClient": "pass-through",
"ipTosToServer": "pass-through",
"linkQosToClient": "pass-through",
"linkQosToServer": "pass-through",
"loadBalancingMode": "round-robin",
"minActiveMembers": 0,
"minUpMembers": 0,
"minUpMembersAction": "failover",
"minUpMembersChecking": "disabled",
"queueDepthLimit": 0,
"queueOnConnectionLimit": "disabled",
"queueTimeLimit": 0,
"reselectTries": 0,
"serviceDownAction": "none",
"slowRampTime": 10,
"membersReference": {
"link": "https://localhost/mgmt/tm/ltm/pool/~Common~p1/members?ver=11.6.0",
"isSubcollection": true,
"items": [
{
"kind": "tm:ltm:pool:members:membersstate",
"name": "n1:80",
"partition": "Common",
"fullPath": "/Common/n1:80",
"generation": 18703,
"selfLink": "https://localhost/mgmt/tm/ltm/pool/~Common~p1/members/~Common~n1:80?ver=11.6.0",
"address": "192.168.51.51",
"connectionLimit": 0,
"dynamicRatio": 1,
"ephemeral": "false",
"fqdn": {
"autopopulate": "disabled",
}
"inheritProfile": "enabled",
"logging": "disabled",
"monitor": "default",
"priorityGroup": 0,
"rateLimit": "disabled",
"ratio": 1,
"session": "user-enabled",
"state": "unchecked",
}
]
},
}
Subcollection Resource¶
kind
: state
A subcollection resource is essentially the same as a resource. As with collections and subcollections, the only difference between the two is that you must access the subcollection resource via the subcollection attached to the main resource.
Example
To build on the subcollection example: pool
is the resource, members_s
is the subcollection, and members
(the actual pool member) is the subcollection resource.
>>> from f5.bigip import ManagementRoot
>>> mgmt = ManagementRoot('192.168.1.1', 'myuser', 'mypass')
>>> pool = mgmt.tm.ltm.pools.pool.load(partition='Common', name='p1')
>>> member = pool.members_s.members.load(partition='Common', name='n1:80')
The JSON below shows a f5.bigip.tm.ltm.pool.members_s.members
object.
{
"kind": "tm:ltm:pool:members:membersstate",
"name": "n1:80",
"partition": "Common",
"fullPath": "/Common/n1:80",
"generation": 18703,
"selfLink": "https://localhost/mgmt/tm/ltm/pool/~Common~p1/members/~Common~n1:80?ver=11.6.0",
"address": "192.168.51.51",
"connectionLimit": 0,
"dynamicRatio": 1,
"ephemeral": "false",
"fqdn": {
"autopopulate": "disabled",
}
"inheritProfile": "enabled",
"logging": "disabled",
"monitor": "default",
"priorityGroup": 0,
"rateLimit": "disabled",
"ratio": 1,
"session": "user-enabled",
"state": "unchecked",
}
Tip
It’s easy to tell that this is a Resource object because the kind
is state
, not collectionstate
.
Python Object Paths¶
The object classes used in the SDK directly correspond to the REST endpoints you’d use to access the objects via the API. Remembering the patterns below will help you easily derive an SDK object class from an object URI.
- Objects take the form
f5.<product>.<organizing_collection>.<collection>.<resource>.<subcollection>.<resource>
. - The collection and the resource generally have the same name, so the collection is the plural version of the resource. This means that you add
s
to the end of the resource to get the collection, unless the resource already ends ins
. If the resource is already plural, add_s
to get the collection. - The object itself is accessed by its CamelCase name, but the usage of the object is all lowercase.
- The characters
.
and-
are always replaced with_
in the SDK.
Because the REST API endpoints have a hierarchical structure, you need to load/create the highest-level objects before you can load lower-level ones. The example below shows how the pieces of the URI correspond to the REST endpoints/SDK classes. The first part of the URI is the IP address of your BIG-IP®.
http://192.168.1.1/mgmt/tm/ltm/pool/~Common~mypool/members/~Common~m1:80
|----|--|---|----|--------------|-------|-------------|
|root|OC|OC |Coll| Resource | SC |SubColl Resrc|
OC | Organizing Collection |
Coll | Collection |
Resource | Resource |
SC | Subcollection |
SubColl Resrc | Subcollection Resource |
In the sections below, we’ll walk through the Python object paths using LTM® pools and pool members as examples. You can also skip straight to the Coding Example.
Organizing Collection¶
The tm
and ltm
organizing collections define what area of the BIG-IP® you’re going to work with. The tm
organizing collection corresponds to the traffic management plane of your BIG-IP® (tmsh
). Loading ltm
indicates that we’re going to work with the BIG-IP®’s Local Traffic module.
Endpoint | http://192.168.1.1/mgmt/tm/ |
Kind | tm:restgroupresolverviewstate |
Type | organizing collection |
Class | f5.bigip.tm.Tm |
Instantiation | tm = mgmt.tm |
Endpoint | http://192.168.1.1/mgmt/tm/ltm |
Kind | tm:ltm:collectionstate |
Type | organizing collection |
Class | f5.bigip.tm.ltm.Ltm |
Instantiation | ltm = mgmt.tm.ltm |
Example: Connect to the BIG-IP® and load the ltm
organizing collection
from f5.bigip import ManagementRoot
mgmt = ManagementRoot('192.168.1.1', 'myuser', 'mypass')
ltm = mgmt.tm.ltm
>>> print mgmt
<f5.bigip.ManagementRoot object at 0x1044e3210>
>>> print ltm
<f5.bigip.tm.ltm.Ltm object at 0x104aee7d0>
Collection¶
Now that the higher-level organizing collections are loaded (in other words, we signed in to the BIG-IP® and accessed the LTM® module), we can load the pool
collection.
Endpoint | http://192.168.1.1/mgmt/tm/ltm/pool |
Kind | tm:ltm:pool:poolcollectionstate |
Type | collection |
Class | f5.bigip.tm.ltm.pool.Pools |
Instantiation | pools = mgmt.tm.ltm.pools |
Example: Load the pools
collection
pool_collection = mgmt.tm.ltm.pools.get_collection()
pools = mgmt.tm.ltm.pools
for pool in pool_collection:
print pool.name
pool1
pool2
In the above example, we used the f5.bigip.tm.ltm.pool.Pools.get_collection()
method to fetch the collection (in other words, a list of the pool resources configured on the BIG-IP®). Then, we instantiated the class f5.bigip.tm.ltm.pool.Pools
.
Resource¶
In the SDK, we refer to a single instance of a configuration object as a resource. As shown in the previous sections, we are able to access the pool
resources on the BIG-IP® after loading the /mgmt/tm/ltm/
organizing collections and the pools
collection.
Endpoint | http://192.168.1.1/mgmt/tm/ltm/pool/~Common~mypool/ |
Kind | tm:ltm:pool:poolstate |
Type | resource |
Class | f5.bigip.tm.ltm.pool.Pool |
Instantiation |
|
Example: Load a pool
resource
pool = pools.pool
pool1 = pool.load(partition='Common', name='pool1')
In the example above, we instantiated the class f5.bigip.tm.ltm.pool.Pool
and used it to load the f5.bigip.tm.ltm.pools.pool
object. The object is a python representation of an actual BIG-IP® pool in the Common partition (or, Common/pool1
).
Tip
You can always see the representation of an object using the raw()
method.
>>> pool1.raw
{
u'generation': 208,
u'minActiveMembers': 0,
u'ipTosToServer': u'pass-through',
u'loadBalancingMode': u'round-robin',
u'allowNat': u'yes',
u'queueDepthLimit': 0,
u'membersReference': {
u'isSubcollection': True,
u'link': u'https://localhost/mgmt/tm/ltm/pool/~Common~pool1/members?ver=11.6.0'},
u'minUpMembers': 0,
u'slowRampTime': 10,
u'minUpMembersAction': u'failover',
'_meta_data': {
'attribute_registry': {
'tm:ltm:pool:memberscollectionstate': <class 'f5.bigip.tm.ltm.pool.Members_s'>
},
'container': <f5.bigip.tm.ltm.pool.Pools object at 0x102e6c550>,
'exclusive_attributes': [],
'read_only_attributes': [],
'allowed_lazy_attributes': [<class 'f5.bigip.tm.ltm.pool.Members_s'>],
'uri': u'https://10.190.7.161:443/mgmt/tm/ltm/pool/~Common~pool1/',
'required_json_kind': 'tm:ltm:pool:poolstate',
'bigip': <f5.bigip.ManagementRoot object at 0x1006e4bd0>,
'icontrol_version': '',
'icr_session': <icontrol.session.iControlRESTSession object at 0x1006e4c90>,
'required_load_parameters': set(['name']),
'required_creation_parameters': set(['name']),
'creation_uri_frag': '',
'creation_uri_qargs': {
u'ver': [u'11.6.0']
}
},
u'minUpMembersChecking': u'disabled',
u'queueTimeLimit': 0,
u'linkQosToServer': u'pass-through',
u'description': u'This is my pool',
u'queueOnConnectionLimit': u'disabled',
u'fullPath': u'/Common/pool1',
u'kind': u'tm:ltm:pool:poolstate',
u'name': u'pool1',
u'partition': u'Common',
u'allowSnat': u'yes',
u'ipTosToClient': u'pass-through',
u'reselectTries': 0,
u'selfLink': u'https://localhost/mgmt/tm/ltm/pool/~Common~pool1?ver=11.6.0',
u'serviceDownAction': u'none',
u'ignorePersistedWeight': u'disabled',
u'linkQosToClient': u'pass-through'
}
Subcollection¶
A subcollection is a collection of resources that can only be accessed via its parent resource. To continue our example:
The f5.bigip.tm.ltm.pool.Pool
resource object contains f5.bigip.tm.ltm.pool.Members
subcollection resource objects. These subcollection resources – the real-servers that are attached to the pool, or ‘pool members’ – are part of the members_s
subcollection in the SDK. (Remember, we have to add _s
to the end of collection object names if the name of the resource object it contains already ends in s
).
Endpoint | http://192.168.1.1/mgmt/tm/ltm/pool/~Common~mypool/members |
Kind | tm:ltm:pool:members:memberscollectionstate |
Type | subcollection |
Class | f5.bigip.tm.ltm.pool.Members_s |
Instantiation | members = mgmt.tm.ltm.pools.pool.members_s |
Example: Load the members_s
collection to view a list of members
members_collection = pool.members_s.get_collection()
members = pool.members_s
print members_collection
[<f5.bigip.tm.ltm.pool.Members object at 0x9d7ff0>, <f5.bigip.tm.ltm.pool.Members object at 0x9d7830>]
Subcollection Resource¶
As explained in the previous section, a subcollection contains subcollection resources. These subcollection resources can only be loaded after all of the parent objects (organizing collections, resource, and subcollection) have been loaded.
Endpoint | http://192.168.1.1/mgmt/tm/ltm/pool/~Common~mypool/members/~Common~member1 |
Kind | tm:ltm:pool:members:membersstate |
Type | subcollection resource |
Class | f5.bigip.tm.ltm.pool.Members |
Instantiation |
|
Example: Load members
objects
members = pool.members_s
member = pool.members_s.members
print member
<f5.bigip.tm.ltm.pool.Members object at 0x9fd530>
Coding Example¶
Managing LTM Pools and Members via the F5 SDK
from f5.bigip import ManagementRoot
# Connect to the BigIP and configure the basic objects
mgmt = ManagementRoot('10.190.7.161', 'admin', 'admin')
ltm = mgmt.tm.ltm
pools = mgmt.tm.ltm.pools
pool = mgmt.tm.ltm.pools.pool
# Create a pool
pool1 = mgmt.tm.ltm.pools.pool.create(name='pool1', partition='Common')
# Define a pool object and load an existing pool
pool_obj = mgmt.tm.ltm.pools.pool
pool_1 = pool_obj.load(partition='Common', name='pool1')
# We can also skip creating the object and load the pool directly
pool_2 = mgmt.tm.ltm.pools.pool.load(partition='Common', name='pool1')
# Make sure 1 and 2 have the same names and generation
assert pool_1.name == pool_2.name
assert pool_1.generation == pool_2.generation
print pool_1.name
pool1
print pool_2.name
pool1
print pool_1.generation
209
print pool_2.generation
209
# Update the pool description
pool_1.description = "This is my pool"
pool_1.update()
# Check the updated description
print pool_1.description
This is my first pool
# Since we haven't refreshed pool_2 it shouldn't match pool_1 any more
print pool_2.description
This is my pool
# Refresh pool_2 and check that is now equal
pool_2.refresh()
print pool_2.description
This is my first pool
print pool_1.generation
210
print pool_2.generation
208
# Create members on pool_1
members = pool_1.members_s
member = pool_1.members_s.members
m1 = pool_1.members_s.members.create(partition='Common', name='m1:80')
m2 = pool_1.members_s.members.create(partition='Common', name='m2:80')
# load the pool members
m1 = pool_1.members_s.members.load(partition='Common', name='m1:80')
m2 = pool_1.members_s.members.load(partition='Common', name='m2:80')
# Get all of the pool members for pool_1 and print their names
for member in members:
print member.name
# Delete our pool member m1
m1.delete()
# Make sure it is gone
if pool_1.members_s.members.exists(partition='Common', name='m1:80'):
raise Exception("Object should have been deleted")
# We are done with this pool so remove it from BIG-IP®
pool_1.delete()
# Make sure it is gone
if mgmt_rt.tm.ltm.pools.pool.exists(partition='Common', name='mypool'):
raise Exception("Object should have been deleted")
Developer Guide¶
COMING SOON
f5¶
f5 package¶
f5.bigip¶
f5.bigip module¶
Classes and functions for configuring BIG-IP
cm |
Classes and functions for configuring BIG-IP |
ltm |
|
net |
|
shared |
Classes and functions for configuring BIG-IP |
sys |
This module provides access to some objects used or maintained by the interpreter and to functions that interact strongly with the interpreter. |
resource.ResourceBase (container) |
Base class for all BIG-IP® iControl REST API endpoints. |
resource.OrganizingCollection (container) |
Base class for objects that collect resources under them. |
resource.Collection (container) |
Base class for objects that collect a list of Resources |
resource.Resource (container) |
Base class to represent a Configurable Resource on the device. |
resource.PathElement (container) |
Base class to represent a URI path element that does not contain data. |
resource.KindTypeMismatch (*args, **kwargs) |
Raise this when server JSON keys are incorrect for the Resource type. |
resource.DeviceProvidesIncompatibleKey (...) |
Raise this when server JSON keys are incompatible with Python. |
resource.InvalidResource (*args, **kwargs) |
Raise this when a caller tries to invoke an unsupported CRUDL op. |
resource.MissingRequiredCreationParameter (...) |
Various values MUST be provided to create different Resources. |
resource.MissingRequiredReadParameter (*args, ...) |
Various values MUST be provided to refresh some Resources. |
resource.UnregisteredKind (*args, **kwargs) |
The returned server JSON kind key wasn’t expected by this Resource. |
resource.GenerationMismatch (*args, **kwargs) |
The server reported BIG-IP® is not the expacted value. |
resource.InvalidForceType |
Must be of type bool. |
resource.URICreationCollision (*args, **kwargs) |
self._meta_data[‘uri’] can only be assigned once. In create or load. |
resource.UnsupportedOperation (*args, **kwargs) |
Object does not support the method that was called. |
mixins.ToDictMixin |
Convert an object’s attributes to a dictionary |
mixins.LazyAttributesMixin |
|
mixins.ExclusiveAttributesMixin |
Overrides __setattr__ to remove exclusive attrs from the object. |
mixins.UnnamedResourceMixin |
This makes a resource object work if there is no name. |
mixins.LazyAttributesRequired (*args, **kwargs) |
Raised when a object accesses a lazy attribute that is not listed |
-
class
f5.bigip.
ManagementRoot
(hostname, username, password, **kwargs)[source]¶ Bases:
f5.bigip.resource.OrganizingCollection
An interface to a single BIG-IP
-
create
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
delete
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
get_collection
(**kwargs)¶ Call to obtain a list of the reference dicts in the instance items
Returns: List of self.items
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
refresh
(**kwargs)¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
update
(**kwargs)¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
-
class
f5.bigip.
BigIP
(hostname, username, password, **kwargs)[source]¶ Bases:
f5.bigip.ManagementRoot
A shim class used to access the default config resources in ‘mgmt/tm.’
This class is solely implemented for backwards compatibility.
-
create
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
delete
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
get_collection
(**kwargs)¶ Call to obtain a list of the reference dicts in the instance items
Returns: List of self.items
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
refresh
(**kwargs)¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
update
(**kwargs)¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
Classes and functions for configuring BIG-IP
device |
|
device_group |
|
traffic_group |
-
class
f5.bigip.cm.
Cm
(bigip)[source]¶ Bases:
f5.bigip.resource.OrganizingCollection
An organizing collection for CM resources.
-
create
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
delete
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
get_collection
(**kwargs)¶ Call to obtain a list of the reference dicts in the instance items
Returns: List of self.items
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
refresh
(**kwargs)¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
update
(**kwargs)¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
resource module¶
This module provides classes that specify how RESTful resources are handled.
THE MOST IMPORTANT THING TO KNOW ABOUT THIS API IS THAT YOU CAN DIRECTLY INFER REST URIs FROM PYTHON EXPRESSIONS, AND VICE VERSA.
Examples:
- Expression: bigip = BigIP(‘a’, ‘b’, ‘c’)
- URI Returned: https://a/mgmt/tm/
- Expression: bigip.ltm
- URI Returned: https://a/mgmt/tm/ltm/
- Expression: pools1 = bigip.ltm.pools
- URI Returned: https://a/mgmt/tm/ltm/pool
- Expression: pool_a = pools1.create(partition=”Common”, name=”foo”)
- URI Returned: https://a/mgmt/tm/ltm/pool/~Common~foo
There are different types of resources published by the BIG-IP® REST Server, they are represented by the classes in this module.
We refer to a server-provided resource as a “service”. Thus far all URI referenced resources are “services” in this sense.
We use methods named Create, Refresh, Update, Load, and Delete to manipulate BIG-IP® device services.
Methods:
create – uses HTTP POST, creates a new resource and with its own URI on the device
refresh – uses HTTP GET, obtains the state of a device resource, and sets the representing Python Resource Object tracks device state via its attrs
- update – uses HTTP PUT, submits a new configuration to the device resource
and sets the Resource attrs to the state the device reports
load – uses HTTP GET, obtains the state of an existing resource on the device and sets the Resource attrs to that state
delete – uses HTTP DELETE, removes the resource from the device, and sets self.__dict__ to {‘deleted’: True}
- Available Classes:
ResourceBase – only refresh is generally supported in all resource types, this class provides refresh. ResourceBase objects are usually instantiated via setting lazy attributes. ResourceBase provides a constructor to match its call in LazyAttributeMixin.__getattr__. The expected behavior is that all resource subclasses depend on this constructor to correctly set their self._meta_data[‘uri’]. All ResourceBase objects (except BIG-IPs) have a container (BIG-IPs contain themselves). The container is the object the ResourceBase is an attribute of.
OrganizingCollection – These resources support lists of “reference” “links”. These are json blobs without a Python class representation.
Example URI_path: /mgmt/tm/ltm/
- Collection – These resources support lists of ResourceBase Objects.
Example URI_path: /mgmt/tm/ltm/nat
Resource – These resources are the only resources that support create, update, and delete operations. Because they support HTTP post (via _create) they uniquely depend on 2 uri’s, a uri that supports the creating post, and the returned uri of the newly created resource.
Example URI_path: /mgmt/tm/ltm/nat/~Common~testnat1
-
exception
f5.bigip.resource.
KindTypeMismatch
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Raise this when server JSON keys are incorrect for the Resource type.
-
exception
f5.bigip.resource.
DeviceProvidesIncompatibleKey
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Raise this when server JSON keys are incompatible with Python.
-
exception
f5.bigip.resource.
InvalidResource
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Raise this when a caller tries to invoke an unsupported CRUDL op.
All resources support refresh and raw. Only Resource‘s support load, create, update, and delete.
-
exception
f5.bigip.resource.
MissingRequiredCreationParameter
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Various values MUST be provided to create different Resources.
-
exception
f5.bigip.resource.
MissingRequiredReadParameter
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Various values MUST be provided to refresh some Resources.
-
exception
f5.bigip.resource.
UnregisteredKind
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
The returned server JSON kind key wasn’t expected by this Resource.
-
exception
f5.bigip.resource.
GenerationMismatch
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
The server reported BIG-IP® is not the expacted value.
-
exception
f5.bigip.resource.
InvalidForceType
[source]¶ Bases:
exceptions.ValueError
Must be of type bool.
-
exception
f5.bigip.resource.
URICreationCollision
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
self._meta_data[‘uri’] can only be assigned once. In create or load.
-
exception
f5.bigip.resource.
UnsupportedOperation
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Object does not support the method that was called.
-
class
f5.bigip.resource.
PathElement
(container)[source]¶ Bases:
f5.bigip.mixins.LazyAttributeMixin
Base class to represent a URI path element that does not contain data.
The BIG-IP® iControl REST API has URIs that are made up of path components that do not return data when they are queried. This class represents those elements and does not support any of the CURDLE methods that the other objects do.
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
-
class
f5.bigip.resource.
ResourceBase
(container)[source]¶ Bases:
f5.bigip.resource.PathElement
,f5.bigip.mixins.ToDictMixin
Base class for all BIG-IP® iControl REST API endpoints.
The BIG-IP® is represented by an object that converts device-published uri’s into Python objects. Each uri maps to a Python object. The mechanism for instantiating these objects is the __getattr__ Special Function in the LazyAttributeMixin. When a registered attribute is dot referenced, on the device object (e.g.
bigip.ltm
or simplybigip
), an appropriate object is instantiated and attributed to the referencing object:bigip.ltm = LTM(bigip) bigip.ltm.nats nat1 = bigip.ltm.nats.nat.create('Foo', 'Bar', '0.1.2.3', '1.2.3.4')
This can be shortened to just the last line:
nat1 = bigip.ltm.nats.nat.create('Foo', 'Bar', '0.1.2.3', '1.2.3.4')
Critically this enforces a convention relating device published uris to API objects, in a hierarchy similar to the uri paths. I.E. the uri corresponding to a
Nats
object ismgmt/tm/ltm/nat/
. If you query the BIG-IP’s uri (e.g. print(bigip._meta_data[‘uri’]) ), you’ll see that it ends in:/mgmt/tm/
, if you query theltm
object’s uri (e.g. print(bigip.ltm._meta_data[‘uri’]) ) you’ll see it ends in/mgmt/tm/ltm/
.In general the objects build a required self._meta_data[‘uri’] attribute by: 1. Inheriting this class. 2. calling super(Subclass, self).__init__(container) 3. self.uri = self.container_uri[‘uri’] + ‘/’ + self.__class__.__name__
The net result is a succinct mapping between uri’s and objects, that represents objects in a hierarchical relationship similar to the device’s uri path hierarchy.
-
update
(**kwargs)[source]¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
refresh
(**kwargs)[source]¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
create
(**kwargs)[source]¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
delete
(**kwargs)[source]¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
-
class
f5.bigip.resource.
OrganizingCollection
(container)[source]¶ Bases:
f5.bigip.resource.ResourceBase
Base class for objects that collect resources under them.
OrganizingCollection
objects fulfill the following functions:- represent a uri path fragment immediately ‘below’ /mgmt/tm
- provide a list of dictionaries that contain uri’s to other resources on the device.
-
get_collection
(**kwargs)[source]¶ Call to obtain a list of the reference dicts in the instance items
Returns: List of self.items
-
create
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
delete
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
refresh
(**kwargs)¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
update
(**kwargs)¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
class
f5.bigip.resource.
Collection
(container)[source]¶ Bases:
f5.bigip.resource.ResourceBase
Base class for objects that collect a list of
Resources
The Collection Resource is responsible for providing a list of Python objects, where each object represents a unique URI, the URI contains the URI of the Collection at the front of its path, and the ‘kind’ of the URI-associated-JSON has been registered with the attribute registry of the Collection subclass.
Note
Any subclass of this base class must have
s
at the end of its name unless it ends ins
then it must have_s
.-
get_collection
(**kwargs)[source]¶ Get an iterator of Python
Resource
objects that represent URIs.The returned objects are Pythonic Resource`s that map to the most recently `refreshed state of uris-resources published by the device. In order to instantiate the correct types, the concrete subclass must populate its registry with acceptable types, based on the kind field returned by the REST server.
Note
This method implies a single REST transaction with the Collection subclass URI.
Raises: UnregisteredKind Returns: list of reference dicts and Python Resource
objects
-
create
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
delete
(**kwargs)¶ Implement this by overriding it in a subclass of Resource
Raises: InvalidResource
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
refresh
(**kwargs)¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
update
(**kwargs)¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
-
class
f5.bigip.resource.
Resource
(container)[source]¶ Bases:
f5.bigip.resource.ResourceBase
Base class to represent a Configurable Resource on the device.
Warning
Objects instantiated from subclasses of Resource do NOT contain a URI (self._meta_data[‘uri’]) at instantiation!
Resource objects provide the interface for the Creation of new services on the device. Once a new service has been created, (via
self.create
orself.load
), the instance constructs its URI and stores it asself._meta_data['uri']
.It is an error to attempt to call
create()
orload()
on an instance more than once.self._meta_data['uri']
MUST not be changed after creation or load.Note
creation query args, and creation hash fragments are stored as separate _meta_data values.
By “Configurable” we mean that submitting JSON via the PUT method to the URI managed by subclasses of Resource, changes the state of the corresponding service on the device.
It also means that the URI supports DELETE.
-
create
(**kwargs)[source]¶ Create the resource on the BIG-IP®.
Uses HTTP POST to the collection URI to create a resource associated with a new unique URI on the device.
Parameters: kwargs – All the key-values needed to create the resource NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.post method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS! :returns:
self
- A python object that represents the object’sconfiguration and state on the BIG-IP®.
-
load
(**kwargs)[source]¶ Load an already configured service into this instance.
This method uses HTTP GET to obtain a resource from the BIG-IP®.
Parameters: kwargs – typically contains “name” and “partition” NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.get method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS! :returns: a Resource Instance (with a populated _meta_data[‘uri’])
-
delete
(**kwargs)[source]¶ Delete the resource on the BIG-IP®.
Uses HTTP DELETE to delete the resource on the BIG-IP®.
After this method is called, and status_code 200 response is received
instance.__dict__
is replace with{'deleted': True}
Parameters: kwargs – The only current use is to pass kwargs to the requests API. If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.delete method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
exists
(**kwargs)[source]¶ Check for the existence of the named object on the BIG-IP
Sends an HTTP GET to the URI of the named object and if it fails with a :exc:~requests.HTTPError` exception it checks the exception for status code of 404 and returns
False
in that case.If the GET is successful it returns
True
.For any other errors are raised as-is.
Parameters: kwargs – Keyword arguments required to get objects NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.get method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS! :returns: bool – The objects exists on BIG-IP® or not. :raises:
requests.HTTPError
, Any HTTP error that was not statuscode 404.
-
raw
¶ Display the attributes that the current object has and their values.
Returns: A dictionary of attributes and their values
-
refresh
(**kwargs)¶ Use this to make the device resource be represented by self.
This method makes an HTTP GET query against the device service. This method is run for its side-effects on self. If successful the instance attribute __dict__ is replaced with the dict representing the device state. To figure out what that state is, run a subsequest query of the object like this: As with all CURDLE methods use a “requests_params” dict to pass parameters to requests.session.HTTPMETHOD. See test_requests_params.py for an example. >>> resource_obj.refresh() >>> print(resource_obj.raw)
-
update
(**kwargs)¶ Update the configuration of the resource on the BIG-IP®.
This method uses HTTP PUT alter the resource state on the BIG-IP®.
The attributes of the instance will be packaged as a dictionary. That dictionary will be updated with kwargs. It is then submitted as JSON to the device.
Various edge cases are handled: * read-only attributes that are unchangeable are removed
Parameters: kwargs – keys and associated values to alter on the device NOTE: If kwargs has a ‘requests_params’ key the corresponding dict will be passed to the underlying requests.session.put method where it will be handled according to that API. THIS IS HOW TO PASS QUERY-ARGS!
-
mixins module¶
-
exception
f5.bigip.mixins.
InvalidCommand
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Raise this if command argument supplied is invalid.
-
exception
f5.bigip.mixins.
UnsupportedMethod
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Raise this if a method supplied is unsupported.
-
exception
f5.bigip.mixins.
LazyAttributesRequired
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
Raised when a object accesses a lazy attribute that is not listed
-
class
f5.bigip.mixins.
ToDictMixin
[source]¶ Bases:
object
Convert an object’s attributes to a dictionary
-
class
f5.bigip.mixins.
LazyAttributeMixin
[source]¶ Bases:
object
Allow attributes to be created lazily based on the allowed values
-
class
f5.bigip.mixins.
ExclusiveAttributesMixin
[source]¶ Bases:
object
Overrides
__setattr__
to remove exclusive attrs from the object.
-
class
f5.bigip.mixins.
UnnamedResourceMixin
[source]¶ Bases:
object
This makes a resource object work if there is no name.
These objects do not support create or delete and are often found as Resources that are under an organizing collection. For example the mgmt/tm/sys/global-settings is one of these and has a kind of tm:sys:global-settings:global-settingsstate and the URI does not match the kind.
-
class
f5.bigip.mixins.
CommandExecutionMixin
[source]¶ Bases:
object
This adds command execution option on the objects.
These objects do not support create, delete, load, and require a separate method of execution. Commands do not have direct mapping to an HTTP method so usage of POST and an absolute URI is required.
f5.common¶
Subpackages¶
Submodules¶
f5.common.constants module¶
f5.common.iapp_parser module¶
-
class
f5.common.iapp_parser.
IappParser
(template_str)[source]¶ Bases:
object
-
template_sections
= [u'presentation', u'implementation', u'html-help', u'role-acl']¶
-
tcl_list_for_attr_re
= '{(\\s*\\w+\\s*)+}'¶
-
tcl_list_for_section_re
= '(\\s*\\w+\\s*)+'¶
-
section_map
= {u'html-help': u'htmlHelp', u'role-acl': u'roleAcl'}¶
-
attr_map
= {u'requires-modules': u'requiresModules'}¶
-
sections_not_required
= [u'html-help', u'role-acl']¶
-
tcl_list_patterns
= {u'requires-modules': '{(\\s*\\w+\\s*)+}', u'role-acl': '(\\s*\\w+\\s*)+'}¶
-
template_attrs
= [u'description', u'partition', u'requires-modules']¶
-
-
exception
f5.common.iapp_parser.
EmptyTemplateException
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
-
args
¶
-
message
¶
-
-
exception
f5.common.iapp_parser.
CurlyBraceMismatchException
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
-
args
¶
-
message
¶
-
-
exception
f5.common.iapp_parser.
NonextantSectionException
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
-
args
¶
-
message
¶
-
-
exception
f5.common.iapp_parser.
NonextantTemplateNameException
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
-
args
¶
-
message
¶
-
-
exception
f5.common.iapp_parser.
MalformedTCLListException
(*args, **kwargs)[source]¶ Bases:
f5.sdk_exception.F5SDKError
-
args
¶
-
message
¶
-
f5.common.logger module¶
Module contents¶
f5.sdk_exception¶
A base exception for all exceptions in this library.
Base Exception¶
F5SDKError (*args, **kwargs) |
Import and subclass this exception in all exceptions in this library. |
Copyright¶
Copyright 2014-2016 F5 Networks Inc.
License¶
Apache V2.0¶
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributor License Agreement¶
Individuals or business entities who contribute to this project must have completed and submitted the F5 Contributor License Agreement to Openstack_CLA@f5.com prior to their code submission being included in this project.