Can only disable a node, not enable.

Hello Everyone,

I am trying to use Pycontrol V2.0 to enable and disable a node:

!/bin/python

import sys

import pycontrol.pycontrol as pc

import suds

b = pc.BIGIP(

hostname = “LTM”,

username = “Uname”,

password = "Pword ",

fromurl = True,

wsdls = [‘LocalLB.NodeAddressV2’])

nodes = [‘1.2.3.4’]

state = [‘1’]

b.LocalLB.NodeAddressV2.set_session_enabled_state(nodes, state)

Regardless of what number I enter for “state” the node will disable but not enable. I feel I am overlooking something very simple and am unsure how to contrust “state”. Could someone please explain what I am overlooking of provide an example (preferably in Python)

Thanks!

Might want to use the typefactory to create the enabled state argument.

Also, if you want to avoid all the typefactory stuff, you should probably look at moving over to ‘bigsuds’ which is the replacement for pycontrol.

Yes, the type factory is a pain and I still don’t quite understand it. Is there a resource for bigsuds that will show me how to do this?

Thanks!

The good news about bigsuds is that you don’t have to deal with the typefactory stuff or WSDLs. With pycontrol, you do.

Here’s information on bigsuds:

More about the typefactory stuff:

If you really want to do this with pycontrol, try adding this:

enabledstate = b.LocalLB.NodeAddressV2.typefactory.create('Common.EnabledState')
    enabledstateseq = b.LocalLB.NodeAddressV2.typefactory.create('Common.EnabledStateSequence')
    enabledstateseq.item = enabledstate.STATE_ENABLED
    b.LocalLB.NodeAddressV2.set_session_enabled_state(nodes, enabledstateseq)

… or something like that.

However, I highly suggest using bigsuds as it is far more approachable.

I’m sure I’ll also be telling you to start using the new 11.4 REST API sooner or later, too. :wink:

Good luck,

-M

And if you want to disable, use STATE_DISABLED in the typefactory.

Thanks a lot! I switched over to Big Suds and you’re right. It’s so much easier!

!/bin/python
import suds
import bigsuds

nodes = ['IP']
b = bigsuds.BIGIP(hostname = 'IP',
      username = "Uname",
      password = "Pword",)

disable = ["STATE_DISABLED"]
enable = ["STATE_ENABLED"]
status = b.LocalLB.NodeAddressV2.set_session_enabled_state(nodes, disable)

Glad it’s working better for you! Good luck.

-M

I got errors from all of the above methods. This works for me.

import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

WhichLTM = '192.168.1.100'
LTMUser = 'admin'
LTMPass = 'admin'
PoolName = 'test.domain.com_pool'
NodePort = '1.2.3.4:80'
Partition = 'Common'

def DisablePoolMember(WhichLTM, LTMUser, LTMPass, PoolName, Partition, NodePort):
    headers = {'Content-Type': 'application/json',}
    data = '{"session":"user-disabled"}'
    response = requests.put('https://' + WhichLTM + '/mgmt/tm/ltm/pool/' + PoolName + '/members/~' + Partition + '~' + NodePort, headers=headers, data=data, verify=False, auth=(LTMUser, LTMPass))

def EnablePoolMember(WhichLTM, LTMUser, LTMPass, PoolName, Partition, NodePort):
    headers = {'Content-Type': 'application/json',}
    data = '{"session":"user-enabled"}'
    response = requests.put('https://' + WhichLTM + '/mgmt/tm/ltm/pool/' + PoolName + '/members/~' + Partition + '~' + NodePort, headers=headers, data=data, verify=False, auth=(LTMUser, LTMPass))

DisablePoolMember(WhichLTM, LTMUser, LTMPass, PoolName, Partition, NodePort)