0

I try to use python for get VM name on VMware (vSphere) when I execute 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 execute this script.

I think 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.

1

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

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 <module> main() File "test4.py", line 130, in main si = SmartConnect(host=args.host, user=args.user, TypeError: SmartConnect() got an unexpected keyword argument 'unverified'
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.
0

If you read message carefully it already tells how to use.

usage: test2.py [-h] -s HOST [-o PORT] -u USER [-p PASSWORD] [-S]

You need to pass all required arguments to run script successfully. Arguments given in [] means optional.

[-h] is to show the help message:

$ python get_vm_names.py -h
usage: get_vm_names.py [-h] -s HOST [-o PORT] -u USER [-p PASSWORD] [-nossl]

Arguments for talking to vCenter

options:
  -h, --help            show this help message and exit

standard arguments:
  -s HOST, --host HOST  vSphere service address to connect to
  -o PORT, --port PORT  Port to connect on
  -u USER, --user USER  User name to use when connecting to host
  -p PASSWORD, --password PASSWORD
                        Password to use when connecting to host
  -nossl, --disable-ssl-verification
                        Disable ssl host certificate verification

Look at the standard arguments in above message.

To run the script pass the arguments like this:

$ python get_vm_names.py -s <vSphere Server IP> -u <username> -p <Password>

or

$ python get_vm_names.py --host <vSphere Server IP> --user <username> --password <Password>

vSphere server IP, username and password are the same value which you use to connect to vSphere manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.