Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Python data class values

I have some python code (bigsuds) I use to display data class members names but do not know how to display the data group values. What I would like is to output the following

name value
name value
name value

Any help would be appreciated.

def member_list(b,name):
  try:
    data = b.get_string_class([name])
  except Exception, e:
    print e
  for x in data:
    myclass = x
  print name
  for m in myclass['members']:
     print m

b = f5.LocalLB.Class
member_list(b,'classname')
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Kevin,

I'm not sure how to accomplish this with bigsuds but here's the solution with the Python SDK.

from f5.bigip import ManagementRoot
import urllib3
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

mgmt = ManagementRoot('192.168.1.1', 'admin', 'admin')
dgrp = mgmt.tm.ltm.data_group.internals.get_collection()

for datagroup in dgrp:
    print(datagroup.name)
    for record in datagroup.records:
        print(record)
0
Comments on this Answer
Comment made 5 months ago by Kevin Davies 3013

Joel can you provide an example of retrieving the data group values. I am trying data = bigip.ltm.data_group.internal.load(name='k2test',partition='Common') and its failing

0
Comment made 5 months ago by Joel Breton 213

Hi Kevin,

The exemple above displays all the datagroups and their values. If you want a specific datagroup to display here`s how I was able to achieve it

from f5.bigip import ManagementRoot
import urllib3
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

mgmt = ManagementRoot('192.168.1.1', 'admin', 'admin')
dgrp = mgmt.tm.ltm.data_group.internals.get_collection()


for datagroup in dgrp:
    if (datagroup.name=='aol'):
        print(datagroup.name)
        print(datagroup.records)

Here`s an exemple of the output:

aol
[{'name': '64.12.96.0/19', 'data': ''}, {'name': '195.93.16.0/20', 'data': ''}, {'name':             
'195.93.48.0/22', 'data': ''}, {'name': '195.93.64.0/19', 'data': ''}, {'name': 
'195.93.96.0/19', 'data': ''}, {'name': '198.81.0.0/22', 'data': ''}, {'name': '198.81.8.0/23', 
'data': ''}, {'name': '198.81.16.0/20', 'data': ''}, {'name': '202.67.65.128/25', 'data': ''}, 
{'name': '205.188.112.0/20', 'data': ''}, {'name': '205.188.146.144/30', 'data': ''}, {'name': 
'205.188.192.0/20', 'data': ''}, {'name': '205.188.208.0/23', 'data': ''}, {'name': 
'207.200.112.0/21', 'data': ''}]
0
Comment made 5 months ago by Kevin Davies 3013

Thanks Joel, I did figure it out in the end. The naming convention is a little strange.

data = bigip.ltm.data_group.internals.internal.load(name='k2test',partition='Common')

0