f5-python-sdk
10 TopicsF5 Python SDK - How to Get Profiles on a Virtual
I am using the F5 python SDK. It is awesome. Very useful. I am not, however, able to figure out how to access the subcollection of monitors attached to a virtual object. Any one have any idea how to do this? So far, I've gathered that you can see a link to the profiles via something like this: virtuals = srcf5.tm.ltm.virtuals.get_collection() for v in virtuals: profiles = v.profilesReference From there I was hoping I could do .get_collection(), but it does not have that method. I suppose I could go back to manually calling rest and parsing json for this one portion, but I feel like there is a way to do it in the SDK. Thanks!1.2KViews0likes4CommentsCPU, memory, disk usage and http profile using the BIG-IP Python SDK
I've been busy with the Python SDK for a couple of weeks now. While I managed to get a lot of information out of it, I'm struggling with a couple of API endpoints. Does anyone have an idea where I can find the statistics for CPU, Memory, Disk as well as the http profile? REST endpoints: mgmt/tm/sys/hostInfo (for CPU and memory) mgmt/tm/sys/disk/logical-disk (for disks) mgmt/tm/ltm/profile/http/stats (for http profile) Thanks! MikeSolved899Views0likes3CommentsObject 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: if there is a comprehensive list of mappings of tmsh / iControl REST / python SDK paths? whether the whole auth tree is still missing in the python modules and will be added later? 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 Martin599Views0likes2CommentsRelease Announcement: F5 Python SDK v1.0.0
Release Announcement 06 July 2016 We are pleased to announce the release of v1.0.0 of the F5 Python SDK.This is the first stable release of the SDK. Summary This release is not backwards compatible because support for aliased resources has been removed. This means that x = y.create(...) no longer changes both x and y . Instead, xis the created configuration object and y is a creation factory. The release also incorporates several important bug-fixes, noted below. Release Highlights The following bug-fixes are included in this release. Most importantly, the SDK now allows a minimum BIG-IP® version of `11.5.0` and has no maximum version. * #523 Add support for ltm.data_group * #491 allows all versions >= 11.5.0 by default * #492 fix the sys ntp resource * #411 calling `create` and `load` on Resources now returns a new instance of the relevant resource (a factory pattern); this fixes an aliasing bug * #497 New API endpoints for GTM datacenters and iRules * This release fixes multiple type-errors in the concrete subclasses. * #533 Turns off `_check_generation` because it is buggy. * #521 migrate clustering to support non-aliased pattern See the changelog for the full list of changes in this release. Open Issues See the project issues pagefor a full list of open issues in this release. - The F5 OpenStack Product Team and F5 Python SDK Contributors552Views0likes4CommentsHow to check existing persistence profiles with iControl REST python SDK?
First of all: please excuse possibly wrong wording in terms of coding terminology, I'm a network engineer trying to get into devops and to make use of provided tools, not a full-time programmer. That being said, I'm trying to use the iControl REST python SDK in order to check whether a persistence profile exists on a remote BigIP. But I cannot find out which function to call for that. I understand that persistences, as well as other collections, such as monitors, are organized in subcollections, depending on their type. When looking at /usr/lib/python2.7/site-packages/f5/bigip/tm/ltm/persistence.py, I see that the following subcollections are defined: self._meta_data['allowed_lazy_attributes'] = [ Source_Addrs, Hashs, Sips, Ssls, Dest_Addrs, Msrdps, Cookies, Universals ] So, I thought I could for example check for the existence of a source_address persistence profile named "persist_src_test" with the following calls: bash-4.3 python Python 2.7.11 (default, Jan 23 2016, 12:34:14) [GCC 5.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from f5.bigip import BigIP,mixins >>> session = BigIP('10.1.1.100', 'admin', 'f5') >>> if session.ltm.persistences.source_addrs.exists(name='persist_src_test', partition='Common'): ... print 'exists' ... Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/site-packages/f5/bigip/mixins.py", line 93, in __getattr__ raise LazyAttributesRequired(error_message) f5.bigip.mixins.LazyAttributesRequired: ('"allowed_lazy_attributes" not in', 'container._meta_data for class Source_Addrs') For me as a novice in terms of programming, it appears that the Source_Addrs class in /usr/lib/python2.7/site-packages/f5/bigip/tm/ltm/persistence.py is of the wrong type for using the exists() method. It needs to be of type "resource", but it is of type "collection". There is no according class of type "resource" defined. When comparing /usr/lib/python2.7/site-packages/f5/bigip/tm/ltm/monitor.py to that, I see that for example http is defined as a collection (with an 's' appended) AND as a resource: class Https(Collection): """BIG-IP® Http monitor collection.""" def __init__(self, monitor): super(Https, self).__init__(monitor) self._meta_data['allowed_lazy_attributes'] = [Http] self._meta_data['attribute_registry'] =\ {'tm:ltm:monitor:http:httpstate': Http} [...] class Http(UpdateMonitorMixin, Resource): """BIG-IP® Http monitor resource.""" def __init__(self, https): super(Http, self).__init__(https) self._meta_data['required_json_kind'] =\ 'tm:ltm:monitor:http:httpstate' There, I can do the the same thing I tried with peristences above successfully (although it took me some time to figure out where to append some 's' characters and where not): >>> if session.ltm.monitor.https.http.exists(name='monitor_http_test', partition='Common'): ... print 'exists' ... else: ... print 'does not exist' ... does not exist When looking again at /usr/lib/python2.7/site-packages/f5/bigip/tm/ltm/persistence.py, the only hint for a "Source_Addr" resource I can find is commented out: class Source_Addrs(Collection): '''A Collection concrete subclass docstring.''' def __init__(self, persistence): '''Auto generated constructor.''' super(Source_Addrs, self).__init__(persistence) self._meta_data['allowed_lazy_attributes'] = [Source_Addr] self._meta_data['attribute_registry'] =\ {u'tm:ltm:persistence:source-addr:source-addrstate': Source_Addr} self._meta_data['template_generated'] = True So, it seems to me that this one is not yet finished. Has anybody found another way of polling the available persistence profiles using this SDK? I thought about cycling through the list of all persistence profiles by doing the following, but this also does not seem to work: >>> for pers in session.ltm.persistences.source_addrs.get_collection(): ... print pers.name ... Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/site-packages/f5/bigip/resource.py", line 554, in get_collection if kind in self._meta_data['attribute_registry']: KeyError: 'attribute_registry' So, I'm really stuck here. Can anybody point out: If I'm doing anything wrong here? If the persistence classes really are not finished yet (and if so, whether there is any hint when they will be)? If there is any other way of getting a list of persistence profiles being present on the system by using the python SDK? Any hint is appreciated! Many thanks in advance! Best regards Martin PS: I'm using the development branch of the SDK available at https://github.com/F5Networks/f5-common-python which I assume is the latest publicly available version.461Views0likes2CommentsAttach SSL Profile to a VS with Python SDK
Hi, I'm banging my head how to assign an existing ssl profile to an existing VS. Tried various ways but non of them worked. I always receive an error message like that: Client SSL profile (/Common/my_client_ssl): cert-key-chain and profile cert, key or chain options cannot be specified together.","errorStack":[],"apiError":2}' Here is one of my tries using transaction: s1 = b_mg.tm.transactions.transaction with TransactionContextManager(s1) as api1: vs2 = api1.tm.ltm.virtuals.virtual.load(name=my_vs, partition=b_part) ssl_prof = api1.tm.ltm.profile.client_ssls.client_ssl.load(name=my_client_ssl,partition=b_part) api1.vs2 = ssl_prof api1.vs2.profiles_s.update() I would really like to know how to do it right, Thanks, Alex433Views0likes1CommentHandling Differences in v11/v12 in Python SDK for iControl REST
We're interested in using the f5 SDK (version: 3.0.18) to replace several cURL scripts that manage our LTM and GTM pools. One of the major draws here is that the SDK provides sufficient abstraction to work with the target API irrespective of iControl REST version (my cURL scripts need separate methods for v11 and v12 destinations): $1 (https://f5-sdk.readthedocs.io/en/latest/apidoc/f5.bigip.tm.gtm.htmlf5.bigip.tm.gtm.pool.Pools) In practice, we haven't seen this autonegotiation. Using the SDK, we've still had to employ different code to list pool and members, eg, in v11 and v12: v11 code: from f5.bigip import ManagementRoot This first block works in v11, but not v12. print ("Getting pools with v11 syntax...") mgmt = ManagementRoot('@option.GTM_Server@', '@option.F5_User@', '@option.F5_Password@') api_ver = mgmt.tmos_version pool_collection = mgmt.tm.gtm.pools.get_collection() pools = mgmt.tm.gtm.pools for pool in pool_collection: print ("Querying state of pool %s members...") % (pool.name) for member in pool.members_s.get_collection(): print ("Pool member name: %s") % (member.name) print ("Ratio: %d") % (member.ratio) Executing v11 code against a v12 API returns expected errors: Getting pools with v11 syntax... Traceback (most recent call last): print ("Querying state of pool %s members...") % (pool.name) AttributeError: 'dict' object has no attribute 'name'` v12 code: from f5.bigip import ManagementRoot This first block works in v12, but not v11. print ("Getting pools with v12 syntax...") mgmt = ManagementRoot('@option.GTM_Server@', '@option.F5_User@', '@option.F5_Password@') api_ver = mgmt.tmos_version pools = mgmt.tm.gtm.pools.a_s.get_collection() for pool in pools: print ("Querying state of pool %s members...") % (pool.name) for member in pool.members_s.get_collection(): print ("Pool member name: %s") % (member.name) print ("Ratio: %d") % (member.ratio) Executing v12 code against a v11 API returns expected errors: pools = mgmt.tm.gtm.pools.a_s.get_collection() File "/usr/local/lib/python2.7/site-packages/f5/bigip/mixins.py", line 102, in __getattr__ raise AttributeError(error_message) AttributeError: '' object has no attribute 'a_s' I'm not a Python programmer and will readily accept the likelihood that I'm just doing it wrong in code. Can we use the same code against different versions of the API using the SDK? Thanks.413Views0likes1CommentPythonSDK - Node pool membership
Good morning, everyone! When looking at a node within the GUI, you can see a section for identifying what pools the node is a member of. I cannot find an easy way within the SDK to obtain that information other than getting collections of both pools and nodes and then iterating through all pools & their members. Anyone have a simpler method? Thanks!404Views0likes2CommentsPython F5 Common SDK able to retrieve operations metrics?
I am working on replacing some legacy SSH+TMSH scripts, but have run into an issue using f5-common-python. I now have code to create and modify configuration, but need to view counters for profiles, pools, pool members and virtuals. Commands I currently run to extract stats: tmsh show /ltm profile tcp tcp.p-service raw (open, accepted, established, failed) tmsh show /ltm profile http http.p-service raw (get, post, v10, v11, responses_by_size) tmsh show /ltm virtual v.p-service.8443 raw (bits_in, bits_out, packets_in, packets_out, curr_conn, max_conn, total_conn, tot_requests) tmsh show /ltm pool p.p-service.8443 raw (tot_requests, bits_in, bits_out, max_conn, tot_conn) tmsh show /ltm pool p.p-service.8443 detail raw (tot_requests, bits_in, bits_out, max_conn, tot_conn) Maybe it's just something simple I'm missing? Here is a representation of the programming. bigip = BigIP(job['hostname'], job['username'], job['password']) if bigip.ltm.pools.pool.exists(name=job['pool']): pool = bigip.ltm.pools.pool.load(name=job['pool']) for member in pool.members_s.get_collection(): pprint.pprint(member.raw) pprint.pprint(dir(member)) pprint.pprint(pool.raw) pprint.pprint(dir(pool)) Anyone have a direction to send me in? If the SDK cannot be used in this way, I can continue SSH+TMSH, via Paramiko. Thanks in advance.344Views0likes0CommentsEffect of updating Data Group using python SDK
Hello everyone, I wrote a code that retrieve a data group from F5, do some modification and update it back. The data group list is 100K+ and are expected to reach 1M. The Question is, will updating the data group have any effect on the connections before and during the update? Another question, will storing the data in external data group has an advantage over storing in internal data group? or maybe the opposite? Thank you.218Views0likes0Comments