Forum Discussion

Mohamed_Lrhazi's avatar
Mohamed_Lrhazi
Icon for Altocumulus rankAltocumulus
Jun 12, 2019

python rest api: How to get profiles details?

with code like this I can get list of virtuals and list of their applied profiles, but all I get for a profile is name and partition...

How do I get the actual profile objects so I can inspect their details?

    vips = mgmt.tm.ltm.virtuals.get_collection()
    for vip in vips:
        print(vip.name)
        profiles = vip.profiles_s.get_collection()
        for p in profiles:
            print("/{}/{}: {}".format(p.partition,p.name,p))

 

  • Dario_Garrido's avatar
    Dario_Garrido
    Jun 13, 2019

    This SelfLink doesn't contain any info regarding configuration. It's only a reference pointing itself.

    Check this ->

    # curl -sku admin:XXXX https://localhost/mgmt/tm/ltm/virtual/~Common~myvirtual/profiles/~Common~tcp | json-format 
    {
      "kind": "tm:ltm:virtual:profiles:profilesstate",
      "name": "tcp",
      "partition": "Common",
      "fullPath": "/Common/tcp",
      "generation": 239,
      "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~myvirtual/profiles/~Common~tcp?ver\u003d12.1.4.1",
      "context": "all"
    }

    But if you search just for the profile you have all the configuration ->

    # curl -sku admin:XXXX https://localhost/mgmt/tm/ltm/profile/tcp/~Common~tcp | json-format                                                
    {
      "kind": "tm:ltm:profile:tcp:tcpstate",
      "name": "tcp",
      "partition": "Common",
      "fullPath": "/Common/tcp",
      "generation": 1,
      "selfLink": "https://localhost/mgmt/tm/ltm/profile/tcp/~Common~tcp?ver\u003d12.1.4.1",
      "abc": "enabled",
      "ackOnPush": "enabled",
      "closeWaitTimeout": 5,
      ...
    }

    So, as I have already said, you need to capture both queries and associate them.

    KR,

    Dario.

  • Hello.

    To use SDK is similar of using iControl REST.

    This command captures all the profile names bonded to a specific VS (without specifying category)

    # https:// <F5_mgmt_IP>/mgmt/tm/ltm/virtual/<virtual_name>/profiles

    And this command captures all Client SSL profiles configured in the device

    # https:// <F5_mgmt_IP>/mgmt/tm/ltm/profile/client-ssl

    If I want to associate what profiles from the first output are Client SSL profiles, I need to compare both outputs.

    For SDK is the same.

    # CAPTURE ALL CLIENT SSL PROFILES
    client_ssls = session.tm.ltm.profile.client_ssls.get_collection()
    # https:// <F5_mgmt_IP>/mgmt/tm/ltm/profile/client-ssl
     
    # CAPTURE ALL VIRTUALS
    virtuals = session.tm.ltm.virtuals.get_collection()
    # https:// <F5_mgmt_IP>/mgmt/tm/ltm/virtual
     
    # SHOW VS AND THEIR CLIENT SSL PROFILES
    for virtual in virtuals:
    	print("------------")
    	print("Virtual: {}".format(virtual.name))
    	listClientSsl_inUse = []
    	for profile in virtual.profiles_s.get_collection():
    		# https:// <F5_mgmt_IP>/mgmt/tm/ltm/virtual/<virtual_name>/profiles
    		if profile.name in listClientSsl:
    			listClientSsl_inUse.append(profile.name)
    		if listClientSsl_inUse:
    			for prof in listClientSsl_inUse:
    				print("Client SSL: {}".format(prof))
    		else:
    			print("Client SSL: None")

    I recommend you to check this example

    https://devcentral.f5.com/s/articles/Displaying-VS-config-using-SDK

    KR,

    Dario.

    • Mohamed_Lrhazi's avatar
      Mohamed_Lrhazi
      Icon for Altocumulus rankAltocumulus

      Thanks a lot Dario. That is great! I wonder though, if there is a way to "load" the profile directly using the information provided by the profile object found in the virtual server.

       

      In my code above, I get the profile in variable "p", which has an attribute "attrs", which pprinted looks like this:

       

      {'context': 'all',
       'fullPath': '/Common/udp',
       'generation': 1,
       'kind': 'tm:ltm:virtual:profiles:profilesstate',
       'name': 'udp',
       'partition': 'Common',
       'selfLink': 'https://localhost/mgmt/tm/ltm/virtual/~Common~syslog-udp-514-vs/profiles/~Common~udp?ver=14.1.0.2'}

      Is there a method load(p.selfLink) or something like that?

       

       

      • Dario_Garrido's avatar
        Dario_Garrido
        Icon for MVP rankMVP

        This SelfLink doesn't contain any info regarding configuration. It's only a reference pointing itself.

        Check this ->

        # curl -sku admin:XXXX https://localhost/mgmt/tm/ltm/virtual/~Common~myvirtual/profiles/~Common~tcp | json-format 
        {
          "kind": "tm:ltm:virtual:profiles:profilesstate",
          "name": "tcp",
          "partition": "Common",
          "fullPath": "/Common/tcp",
          "generation": 239,
          "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~myvirtual/profiles/~Common~tcp?ver\u003d12.1.4.1",
          "context": "all"
        }

        But if you search just for the profile you have all the configuration ->

        # curl -sku admin:XXXX https://localhost/mgmt/tm/ltm/profile/tcp/~Common~tcp | json-format                                                
        {
          "kind": "tm:ltm:profile:tcp:tcpstate",
          "name": "tcp",
          "partition": "Common",
          "fullPath": "/Common/tcp",
          "generation": 1,
          "selfLink": "https://localhost/mgmt/tm/ltm/profile/tcp/~Common~tcp?ver\u003d12.1.4.1",
          "abc": "enabled",
          "ackOnPush": "enabled",
          "closeWaitTimeout": 5,
          ...
        }

        So, as I have already said, you need to capture both queries and associate them.

        KR,

        Dario.