src/droute53.py
def parseArgs():
    """
    Define and parse command line arguments.
    """
    parser = argparse.ArgumentParser()
    parser.description = 'A small script to dynamically update route53 '\
                'with the public IP address of an EC2 instance.  It can '\
                'also be run from a host with a dynamic public IP address '\
                'to update from localhost\'s public IP address.  To run in '\
                'this mode do not include an instance name/id.'
    parser.add_argument('host', metavar='Hostname',
                help='The fully qualified domain name to be modified.')
    parser.add_argument('instance', nargs='?', default=None, metavar='Instance',
                help='Instance name or ID to act as the destination for host.  '\
                    'If instance isn\'t supplied the name is associated with  '\
                    'the public IP address of localhost.')
    parser.add_argument('--region', '-r', default='us-east-1', metavar='region',
                help='region where the instance is running.  (us-east-1)')
    action = parser.add_mutually_exclusive_group()
    action.add_argument('--start', '-s', default=False, action='store_true',
                help='If the instance isn\'t running, start it.')
    action.add_argument('--kill', '-k', default=False, action='store_true',
                help='Don\'t do anything with route53.  Simply stop the instance.')

    args =  parser.parse_args()

    # route53 requires proper fqdn with '.' termination
    if args.host[-1] != '.':
        args.host += '.'

    # trying to start or stop will no instance is probably an error
    if args.instance is None and (args.start or args.kill):
        print('--start or --kill require an instance.  Exiting.')
        sys.exit(3)
    return args

    Define and parse command line arguments.
    
Define and parse command line arguments.
Define and parse command line arguments .
def parseArgs():
    parser = argparse.ArgumentParser()
    parser.description = 'A small script to dynamically update route53 '\
                'with the public IP address of an EC2 instance.  It can '\
                'also be run from a host with a dynamic public IP address '\
                'to update from localhost\'s public IP address.  To run in '\
                'this mode do not include an instance name/id.'
    parser.add_argument('host', metavar='Hostname',
                help='The fully qualified domain name to be modified.')
    parser.add_argument('instance', nargs='?', default=None, metavar='Instance',
                help='Instance name or ID to act as the destination for host.  '\
                    'If instance isn\'t supplied the name is associated with  '\
                    'the public IP address of localhost.')
    parser.add_argument('--region', '-r', default='us-east-1', metavar='region',
                help='region where the instance is running.  (us-east-1)')
    action = parser.add_mutually_exclusive_group()
    action.add_argument('--start', '-s', default=False, action='store_true',
                help='If the instance isn\'t running, start it.')
    action.add_argument('--kill', '-k', default=False, action='store_true',
                help='Don\'t do anything with route53.  Simply stop the instance.')
    args =  parser.parse_args()
    if args.host[-1] != '.':
        args.host += '.'
    if args.instance is None and (args.start or args.kill):
        print('--start or --kill require an instance.  Exiting.')
        sys.exit(3)
    return args
def parseArgs ( ) : parser = argparse . ArgumentParser ( ) parser . description = 'A small script to dynamically update route53 ' 'with the public IP address of an EC2 instance.  It can ' 'also be run from a host with a dynamic public IP address ' 'to update from localhost\'s public IP address.  To run in ' 'this mode do not include an instance name/id.' parser . add_argument ( 'host' , metavar = 'Hostname' , help = 'The fully qualified domain name to be modified.' ) parser . add_argument ( 'instance' , nargs = '?' , default = None , metavar = 'Instance' , help = 'Instance name or ID to act as the destination for host.  ' 'If instance isn\'t supplied the name is associated with  ' 'the public IP address of localhost.' ) parser . add_argument ( '--region' , '-r' , default = 'us-east-1' , metavar = 'region' , help = 'region where the instance is running.  (us-east-1)' ) action = parser . add_mutually_exclusive_group ( ) action . add_argument ( '--start' , '-s' , default = False , action = 'store_true' , help = 'If the instance isn\'t running, start it.' ) action . add_argument ( '--kill' , '-k' , default = False , action = 'store_true' , help = 'Don\'t do anything with route53.  Simply stop the instance.' ) args = parser . parse_args ( ) if args . host [ - 1 ] != '.' : args . host += '.' if args . instance is None and ( args . start or args . kill ) : print ( '--start or --kill require an instance.  Exiting.' ) sys . exit ( 3 ) return args
Define and parse command line arguments.
Define and parse command line arguments .
"""
    Define and parse command line arguments.
    """ # route53 requires proper fqdn with '.' termination # trying to start or stop will no instance is probably an error