Forum Discussion

Rob_74473's avatar
Rob_74473
Icon for Cirrus rankCirrus
Jul 18, 2018

Modifying a node in python

I am trying to update a couple node params, but I'm getting an error I don't understand. The error is: KeyError('uri',) The kwargs I'm passing to update: {'description': 'sadSad::managed::my.host.com', 'name': 'C100_tools_abuse_1.2.3.4_NODE', 'partition': 'Common', 'session': 'user-disabled', 'state': 'user-down'}

 

The method: mgmt.tm.ltm.nodes.node.update(**add_args) where add_args are itemized above.

 

The question is, what is 'uri'? I'm not specifying that, so does the error mean that it is missing? And, if it is missing, what should I set 'uri' to?

 

1 Reply

  • I am guessing you want to change the state of a given node, say from up to down. Or modify ltm node state user-down (or user-up) tmsh command equivalent. If so,

    iControl REST call (sat is the name of the node and 192.168.1.1 is the management IP of the BIG-IP):

     

    curl -sku admin:admin https://192.168.1.1/mgmt/tm/ltm/node/sat \
      -X POST -H 'Content-type: application/json' \
      -d '{"state":"user-down"}'
    

     

    Python code:

     

    from f5.bigip import ManagementRoot
    mgmt = ManagementRoot('192.168.1.1', 'admin', 'admin')
    node = mgmt.tm.ltm.nodes.node.load(name='sat', partition='Common')
    node.update(state="user-down")
    

     

    To print the field values of the object (tmsh list ltm node sat), add this one.

     

    for key, value in node.__dict__.iteritems():
        print(" {}: {}".format(key, value))
    

     

    If this is not what you are after, please post the tmsh equivalent command.

    On uri: In the Node class, there is a field (property) called _meta_data: it does not exist in the tmsh world. It contains a dict, and one of the field is 'uri'. I do not know why Python complained, but possibly, updating the field is prohibited. To see the contents of uri, add the following:

    print('uri is {}'.format(node._meta_data['uri']))

    Cheers.