Forum Discussion

tatmotiv's avatar
tatmotiv
Icon for Cirrostratus rankCirrostratus
Jun 01, 2016

Object path for list of partitions in python SDK

Hi all,

I'm trying to get the list of partitions of a BigIP using the f5-Python-SDK. In tmsh, the objects are located under auth/partition, so e.g. "tmsh list auth partition" will list the according configuration.

This is also reflected in iControl REST. Using curl, I can get that list of partitions by using the path /mgmt/tm/auth/partition as follows:

$ curl -sk -u admin:xxxxxxxxxxxx https://my_bigip/mgmt/tm/auth/partition | python -mjson.tool
{
"items": [
    {
        "defaultRouteDomain": 0,
        "description": "Repository for system objects and shared objects.",
        "fullPath": "Common",
        "generation": 1,
        "kind": "tm:auth:partition:partitionstate",
        "name": "Common",
        "selfLink": "https://localhost/mgmt/tm/auth/partition/Common?ver=11.6.0"
    },
    {
        "defaultRouteDomain": 123,
        "fullPath": "my_partition1",
        "generation": 1,
        "kind": "tm:auth:partition:partitionstate",
        "name": "my_partition1",
        "selfLink": "https://localhost/mgmt/tm/auth/partition/my_partition1?ver=11.6.0"
    },
    {
        "defaultRouteDomain": 456,
        "fullPath": "my_partition2",
        "generation": 1,
        "kind": "tm:auth:partition:partitionstate",
        "name": "my_partition2",
        "selfLink": "https://localhost/mgmt/tm/auth/partition/my_partition1?ver=11.6.0"
    },
],
"kind": "tm:auth:partition:partitioncollectionstate",
"selfLink": "https://localhost/mgmt/tm/auth/partition?ver=11.6.0"
}

However, when trying to adopt that using the python SDK, I do not get the same results:

>>> from f5.bigip import BigIP
>>> session = BigIP('1.2.3.4', 'admin', 'xxxxxxxxxxxx')
>>> for partition in session.auth.partitions.get_collection():
...    print partition.name
...
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/dist-packages/f5_sdk-0.1.5-py2.7.egg/f5/bigip/mixins.py", line 82, in __getattr__
  raise AttributeError(error_message)
AttributeError: '' object has no attribute 'auth'

So, .auth.partitions (or .auth generally) does not seem to be the right entry point.

Does anybody know:

  1. if there is a comprehensive list of mappings of tmsh / iControl REST / python SDK paths?

  2. whether the whole auth tree is still missing in the python modules and will be added later?

  3. what is the right way to get a list of partitions using the f5-python-SDK?

Any help is appreciated. Many thanks in advance!

Best regards

Martin

  • having a look to the python site-packages/f5 folder you can see all was implemented. for auth, only user and password_policy seem to be available.

     

    until the dev guide/mode doc is done, the easiest way to check is to have a look to this folder.

     

  • I put that into a separate answer for anybody's convenience because formatting in comments sucks. Maybe this will be useful for someone else, too...

    Going with the sys/folder resource in order to address this now. However, there are some differences between a system folder and a partition:

    1. The system folder "/" does not map to any partition
    2. When polling the system folders via iControl REST, separate folders for iApps are given back, which do not map to any partition. Confusingly, those iApp-folders are not listed when running "tmsh list sys folders" on the machine directly.

    You can see what I mean when comparing

      curl -sk -u admin:xxxxxxxxx https://my-lb/mgmt/tm/sys/folder | python -mjson.tool | grep name
     "name": "/",
     "name": "Common",
     "name": "backup2.app",        <--- !
     "name": "backup_scf.app",     <--- !
     "name": "PA995-LBSS-Test",
     "name": "PA997-Test1",
     "name": "PA998-Test2",
     "name": "PA999-Test1",
    

    to

    (/)(tmos) list sys folder | grep folder
    sys folder / {
    sys folder Common {
    sys folder PA995-LBSS-Test {
    sys folder PA997-Test1 {
    sys folder PA998-Test2 {
    sys folder PA999-Test1 {
    

    and

    (/)(tmos) list auth partition | grep partition
    auth partition Common {
    auth partition PA995-LBSS-Test {
    auth partition PA997-Test1 {
    auth partition PA998-Test2 { }
    auth partition PA999-Test1 {
    

    Putting all of this together, this is basically how to get a list of partitions using the python SDK (at least it works out for me):

    >>> list_of_partitions = []
    >>> for folder in session.sys.folders.get_collection():
    ...     if not folder.name == "/" and not folder.name.endswith(".app"):
    ...         list_of_partitions.append(folder.name)
    ...
    >>> print list_of_partitions
    [u'Common', u'PA995-LBSS-Test', u'PA997-Test1', u'PA998-Test2', u'PA999-Test1']