#!/usr/bin/env python
from openstack_account.client import AccountSetup

import argparse
import logging
import os
import sys
import yaml

log_format = '%(asctime)s-%(levelname)s-%(message)s'
log = logging.getLogger('openstack_account')
log.setLevel(logging.DEBUG)
handle = logging.StreamHandler()
handle.setLevel(logging.DEBUG)
form = logging.Formatter(log_format)
handle.setFormatter(form)
log.addHandler(handle)

def parse_args():
    p = argparse.ArgumentParser(description='Create & Setup OpenStack Accounts')
    p.add_argument('--username', help='OpenStack Auth username')
    p.add_argument('--password', help='OpenStack Auth password')
    p.add_argument('--tenant-name', help='OpenStack Auth tenant name')
    p.add_argument('--auth-url', help='OpenStack Auth keystone url')
    p.add_argument('config_file', help='Config file to use')
    return p.parse_args()

def get_env_args(args):
    # Check environment for variables if not set on command line
    if not args['username']:
        args['username'] = os.getenv('OS_USERNAME', None)
    if not args['password']:
        args['password'] = os.getenv('OS_PASSWORD', None)
    if not args['tenant_name']:
        args['tenant_name'] = os.getenv('OS_TENANT_NAME', None)
    if not args['auth_url']:
        args['auth_url'] = os.getenv('OS_AUTH_URL', None)
    must_have = ['username', 'password', 'tenant_name', 'auth_url']
    for item in must_have:
        if args[item] == None:
            log.error('Need arg:%s' % item)
            sys.exit('')
    return args

def main():
    args = vars(parse_args())
    log.debug('Reading CLI args')
    args = get_env_args(args)
    log.debug('Initialzing Account Setup')
    a = AccountSetup(args['username'],
                     args['password'],
                     args['tenant_name'],
                     args['auth_url'])
    with open(args['config_file'], 'r') as f:
        log.debug('Loading configs from:%s' % args['config_file'])
        config_data = yaml.load(f)
        a.setup_config(config_data)

if __name__ == '__main__':
    main()

@@ -969,26 +969,25 @@
 not args
-%5B'
+.
 username
 '%5D:%0A    
@@ -974,26 +974,24 @@
 rgs.username
-'%5D
 :%0A        ar
@@ -992,26 +992,25 @@
     args
-%5B'
+.
 username
 '%5D = os.
@@ -997,26 +997,24 @@
 rgs.username
-'%5D
  = os.getenv
@@ -1024,29 +1024,24 @@
 S_USERNAME',
- None
 )%0A    if not
@@ -1045,26 +1045,25 @@
 not args
-%5B'
+.
 password
 '%5D:%0A    
@@ -1054,18 +1054,16 @@
 password
-'%5D
 :%0A      
@@ -1068,26 +1068,25 @@
     args
-%5B'
+.
 password
 '%5D = os.
@@ -1077,18 +1077,16 @@
 password
-'%5D
  = os.ge
@@ -1104,21 +1104,16 @@
 SSWORD',
- None
 )%0A    if
@@ -1117,26 +1117,25 @@
  if not args
-%5B'
+.
 tenant_name'
@@ -1133,18 +1133,16 @@
 ant_name
-'%5D
 :%0A      
@@ -1139,34 +1139,33 @@
 me:%0A        args
-%5B'
+.
 tenant_name'%5D = 
@@ -1159,18 +1159,16 @@
 ant_name
-'%5D
  = os.ge
@@ -1189,21 +1189,16 @@
 T_NAME',
- None
 )%0A    if
@@ -1206,26 +1206,25 @@
 not args
-%5B'
+.
 auth_url
 '%5D:%0A    
@@ -1215,18 +1215,16 @@
 auth_url
-'%5D
 :%0A      
@@ -1229,26 +1229,25 @@
     args
-%5B'
+.
 auth_url
 '%5D = os.
@@ -1238,18 +1238,16 @@
 auth_url
-'%5D
  = os.ge
@@ -1265,21 +1265,16 @@
 TH_URL',
- None
 )%0A    mu
@@ -1377,26 +1377,31 @@
  if 
+not getattr(
 args
-%5B
+, 
 item
-%5D == None
+)
 :%0A  
@@ -1500,38 +1500,8 @@
 ():%0A
-    args = vars(parse_args())%0A
     
@@ -1554,20 +1554,28 @@
 nv_args(
+parse_
 args
+()
 )%0A    lo
@@ -1636,26 +1636,25 @@
 tup(args
-%5B'
+.
 username
 '%5D,%0A    
@@ -1641,26 +1641,24 @@
 rgs.username
-'%5D
 ,%0A          
@@ -1676,18 +1676,17 @@
 args
-%5B'
+.
 password
 '%5D,%0A
@@ -1681,18 +1681,16 @@
 password
-'%5D
 ,%0A      
@@ -1708,18 +1708,17 @@
     args
-%5B'
+.
 tenant_n
@@ -1720,18 +1720,16 @@
 ant_name
-'%5D
 ,%0A      
@@ -1751,18 +1751,17 @@
 args
-%5B'
+.
 auth_url
 '%5D)%0A
@@ -1756,18 +1756,17 @@
 auth_url
-'%5D
+,
 )%0A    wi
@@ -1773,26 +1773,25 @@
 th open(args
-%5B'
+.
 config_file'
@@ -1789,18 +1789,16 @@
 fig_file
-'%5D
 , 'r') a
@@ -1852,18 +1852,17 @@
 ' %25 args
-%5B'
+.
 config_f
@@ -1864,18 +1864,16 @@
 fig_file
-'%5D
 )%0A      
@@ -1941,43 +1941,4 @@
 ta)%0A
-%0Aif __name__ == '__main__':%0A    main()%0A

fix up command line a little