Skip to content

Instantly share code, notes, and snippets.

@dancaps
Created August 30, 2017 17:15
Show Gist options
  • Save dancaps/2991b675f11916d1d14361390b050c45 to your computer and use it in GitHub Desktop.
Save dancaps/2991b675f11916d1d14361390b050c45 to your computer and use it in GitHub Desktop.
Args
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