Unable to use .format with an API call, Vmware Aria Automation Config

101 Views Asked by At

I am working with VMWare Aria Automation Config API to automate tasks using Python. I am unable to use .format with any of the methods and I do not understand why. Here is an example

This does not work:

from sseapiclient import APIClient
client = APIClient('http://myaac.com', username, password)

mycommand = 'cmd="local",fun="test.ping",tgt={"saltmaster":{"tgt":"minion*","tgt_type":"glob"}}'
client.api.cmd.route_cmd('{}'.format(mycommand))

I get an error message:

"3004: Request validation failure.
  job_uuid:
    - Not a valid UUID.
  cmd:
    - Expected 'cmd'"

which if I understand correctly means that the value passed via .format is not considered.

However, passing parameters directly works fine:

from sseapiclient import APIClient
client = APIClient('http://myaac.com', username, password)

client.api.cmd.route_cmd(cmd="local",fun="test.ping",tgt={"saltmaster":{"tgt":"minion*","tgt_type":"glob"}})

Any ideas?

1

There are 1 best solutions below

0
OrangeDog On

str.format is used for formatting strings. '{}'.format(a) is just the same as str(a).

route_cmd is expecting several arguments, in particular one named cmd. Passing it a single string will not work.

If you want to store named arguments in a single variable, you should use a dict:

mycommand = {"cmd": "local", "fun": "test.ping", 
             "tgt": {"saltmaster": {"tgt":"minion*", "tgt_type":"glob"}}
client.api.cmd.route_cmd(**mycommand)