.. _subcollection_section:

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 :meth:`~f5.bigip.resource.Collection.get_collection` to get a list of the resources in the subcollection.

.. _subcollection_example:

.. topic:: 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.

.. topic:: Example

    .. code-block:: json
        :emphasize-lines: 26, 28, 29

        {
            "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",
                      }
                ]
            },
        }


