zale zale - 4 months ago 13
Python Question

'tags' parameter at Python Softlayer API call SoftLayer.VSManager.list_instances() not working as expected

I am implementing a cloud bursting system with Softlayer instances and Slurm. But I got a problem with Python Softlayer API.

When I try to get a list of some specific instances with the API call SoftLayer.VSManager.list_instances() I use the parameter 'tags', since I tagged the instances to classify them. But it does not work as expected.

It is supposed to find instances whose 'tagReferences' field matches with the value of the parameter 'tags' you passed in the API call.

However, I get a list with all the nodes whose 'tagReferences' field is not empty. Whatever is the value I pass as 'tags' parameter.

I have the following nodes:


  • hostname: 'node000' tags: 'slurm, node'

  • hostname: 'node005' tags: 'test'



I run this script:

import os
import SoftLayer

os.environ["SL_USERNAME"] = "***"
os.environ["SL_API_KEY"] = "******"

client = SoftLayer.Client()
mgr = SoftLayer.VSManager(client)

for vsi in mgr.list_instances(tags = 'slurm'):
print vsi['hostname']


This is the output I get:

node000
node005


I tried passing different values as 'tags' parameter (see below), but I always get the same result shown above, even with the last one.

Set of values passed as 'tags' parameter:

slurm, node
slurm
node
test
random


Did I miss anything?

I wrote a ticket to Softlayer support team but they believe my script should work and they assured me that the tags feature does work. Even they told me explicitly to come here to ask because they have no idea of what is happening.

Answer

According the documentation of the method that you are using, you need to send a list of tags, so change the string by a list like this:

client = SoftLayer.Client()
mgr = SoftLayer.VSManager(client)

for vsi in mgr.list_instances(tags = ['mytag']):
  print (vsi['hostname'])

Regards