Created
August 30, 2017 17:15
-
-
Save dancaps/2991b675f11916d1d14361390b050c45 to your computer and use it in GitHub Desktop.
Args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_args(): | |
"""Get command line args from the user. | |
""" | |
parser = argparse.ArgumentParser( | |
description='Standard Arguments for talking to vCenter') | |
# because -h is reserved for 'help' we use -s for service | |
parser.add_argument('-s', '--host', | |
required=True, | |
action='store', | |
help='vSphere service to connect to') | |
# because we want -p for password, we use -o for port | |
parser.add_argument('-o', '--port', | |
type=int, | |
default=443, | |
action='store', | |
help='Port to connect on') | |
parser.add_argument('-u', '--user', | |
required=True, | |
action='store', | |
help='User name to use when connecting to host') | |
parser.add_argument('-p', '--password', | |
required=False, | |
action='store', | |
help='Password to use when connecting to host') | |
args = parser.parse_args() | |
if not args.password: | |
args.password = getpass.getpass( | |
prompt='Enter password for host %s and user %s: ' % | |
(args.host, args.user)) | |
return args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment