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

Filter by:
  • Solution
  • Technology
Answers

Error return on modifying pool member property with python script

Hi,

I have tried to use python script to modify the 'ratio' field for the member of pool and I always get following message in spite of using 'put' or 'patch' method:

{u'errorStack': [], u'message': u'invalid property value "state":"up"', u'code': 400, u'apiError': 26214401}

If using iControl REST curl command, the value of 'ratio' can be changed without problem.

Anyone can help me to figure out ?

Thanks,

Roger

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Roger,

I assume this is the task you want to do:

tmsh:

modify ltm pool <pool> members modify { <poolMamber> { ratio <myNewRatio> } }

iControl REST (curl):

curl -sku <user:secret> -H "Content-type: application/json" -X PATCH -d '{"ratio":<myNewRatio>}' https://<mgmtPort>/mgmt/tm/ltm/pool/<poolName>/members/<poolMamber>

e.g. (changing the ratio of the member ~Commmon~apache:80 in the pool CentOS to 10),

curl -sku admin:admin -H "Content-type: application/json" -X PATCH -d '{"ratio":10}' https://192.168.0.2/mgmt/tm/ltm/pool/CentOS/members/~Common~apache:80

A Python code for the above example would look like this (there should be better ways to do this):

from f5.bigip import ManagementRoot

mgmt = ManagementRoot('192.168.0.2', 'admin', 'admin')
pool = mgmt.tm.ltm.pools.pool.load(name='CentOS', partition='Common')
members = pool.members_s.get_collection()
for member in members:
    print '{}: Ratio {}'.format(member.name, member.ratio)
    if member.name == 'apache:80':
        member.update(ratio=10)
        break
    
0
Comments on this Answer
Comment made 21-Aug-2017 by rliu 2

Hi Satoshi,

Thank you very much for your response! And this is exactly what I want to deal with.

But when I try to excute 'from f5.bigip import ManagementRoot' on my F5, it complains 'ImportError: No module named bigip', do you know how to install this module into F5 (I did try to use 'pip install f5-sdk', and it failed with '-bash: pip: command not found')?

Thanks,

Roger

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Probably you do not have pip installed or it is located somewhere not in your path. Install it first (I use yum so yum install python2-pip.noarch for my Python 2.7.5).

0
Comments on this Answer
Comment made 21-Aug-2017 by rliu 2

My Python vesion is 2.6.6 and also get error '-bash: yum: command not found'.

[root@BigIP:Active:Standalone] / # yum install python2-pip.noarch -bash: yum: command not found

SyntaxError: invalid syntax File "", line 1 SyntaxError: invalid syntax ^ SyntaxError: invalid syntax

0
Comment made 22-Aug-2017 by Joel Breton 213

You can't install python on the BIG-IP directly you need to install it on a management workstation running Linux, MacOS, or Windows.

If you are running Windows it is not install by default you need to download and install https://www.python.org/

Here's the f5-sdk documentation - http://f5-sdk.readthedocs.io/en/latest/

Here's a great blog post from Jason Rahm - Explaining the python f5-sdk basics https://devcentral.f5.com/articles/getting-started-with-the-f5-common-python-sdk-27438

0
Comment made 22-Aug-2017 by rliu 2

Hi Joel,

Thank you for pointing this out! The purpose of this modifying the 'ratio' field script is to let BIG-IP to directly run it when BIG-IP receives specific http request. If I couldn't install this python-sdk on BIG-IP, do you have any suggestion to let BIG-IP doing this task?

Thanks,

Roger

0
Comment made 25-Aug-2017 by Joel Breton 213

Hi Roger,

Could you help me understand what you mean by "The purpose of this modifying the 'ratio' field script is to let BIG-IP to directly run it when BIG-IP receives specific http request.

Are you trying to remove nodes or add nodes when a specific http request?

Have you looked at Local Traffic Policies or iRules? I think they are more suitable for what you are trying to achieve.

Joel

0