0

i try to use python for get vm name on vmware (vsphere) when i execut this python script:

https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/get_vm_names.py

i have this message :

python3 test2.py --host ip_of_vmware
usage: test2.py [-h] -s HOST [-o PORT] -u USER [-p PASSWORD] [-S]
test2.py: error: the following arguments are required: -u/--user

i don't know how to execut this script.

i think its this line which used to put in parameter:

 si = SmartConnectNoSSL(host=args.host,
                               user=args.user,
                               pwd=args.password,
                               port=int(args.port))
        atexit.register(Disconnect, si)

i want to know how to execute this script. thanks for any response,

  • Does this answer your question? [Python: pass arguments to a script](https://stackoverflow.com/questions/22846858/python-pass-arguments-to-a-script) – amsh Oct 09 '20 at 06:57

1 Answers1

0

The arguments required for the program are built by setup_args function in that program which in turn appears to be constructed by this line:

parser = cli.build_arg_parser()

This is in a package I don't have so I can't see what it is doing.

Nevertheless the help message, without explicitly stating which arguments are mandatory, is hinting in that general direction. I believe the arguments in [ ] are optional and everything else is required, so you need at least -s HOST and -u USER

python3 test2.py -s HOST -u USER

or

python3 test2.py --host HOST --user USER
Jonathan
  • 181
  • 7
  • my script is executed with : python3 test4.py --host xxx --port 80 --user xxx --password xxx, but i have this message : Traceback (most recent call last): File "test4.py", line 171, in main() File "test4.py", line 130, in main si = SmartConnect(host=args.host, user=args.user, TypeError: SmartConnect() got an unexpected keyword argument 'unverified' – Erica Oct 09 '20 at 07:19
  • You have changed to using SmartConnect from using SmartConnectNoSSL...'unverified' smells suspiciously of SSL related errors and not syntax errors relating the the execution of the script. – Jonathan Oct 11 '20 at 22:28