Package yakumo :: Package cmd :: Module ossh
[hide private]
[frames] | no frames]

Source Code for Module yakumo.cmd.ossh

 1  #!/usr/bin/python 
 2  # 
 3  # Copyright 2014,2015 by Akira Yoshiyama <akirayoshiyama@gmail.com>. 
 4  # All Rights Reserved. 
 5  # 
 6  #    Licensed under the Apache License, Version 2.0 (the "License"); you may 
 7  #    not use this file except in compliance with the License. You may obtain 
 8  #    a copy of the License at 
 9  # 
10  #         http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  #    Unless required by applicable law or agreed to in writing, software 
13  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
14  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
15  #    License for the specific language governing permissions and limitations 
16  #    under the License. 
17   
18   
19  import argparse 
20  import os 
21  from pprint import pprint 
22  import sys 
23   
24  import os_client_config 
25  import pbr 
26   
27  import yakumo 
28   
29   
30  ENVIRONMENT_VARIABLES = { 
31      'os_cloud': 'OS_CLOUD', 
32      'os_cert': 'OS_CERT', 
33      'os_cacert': 'OS_CACERT', 
34      'os_region_name': 'OS_REGION_NAME', 
35      'os_interface': 'OS_INTERFACE', 
36      'os_key': 'OS_KEY', 
37      'os_auth_type': 'OS_AUTH_TYPE', 
38  } 
39   
40   
41 -def main():
42 kwargs = {dest: os.environ.get(env) 43 for dest, env in ENVIRONMENT_VARIABLES.items()} 44 parser = argparse.ArgumentParser() 45 cloud_config = os_client_config.OpenStackConfig() 46 cloud_config.register_argparse_arguments(parser, sys.argv) 47 for opt in parser._actions: 48 if opt.dest in ENVIRONMENT_VARIABLES: 49 opt.metavar = ENVIRONMENT_VARIABLES[opt.dest] 50 parser.set_defaults(timeout=None, insecure=False, **kwargs) 51 parser.add_argument('--version', help='Print version and exit', 52 action='store_true') 53 parser.add_argument('--verbose', help='Verbose output', 54 action='store_true') 55 56 options = parser.parse_args() 57 if options.version: 58 print(pbr.version.VersionInfo('yakumo')) 59 sys.exit(0) 60 61 c = yakumo.Client(**options.__dict__) 62 63 local_vars = locals() 64 local_vars['pprint'] = pprint 65 try: 66 import bpython 67 bpython.embed(locals_=local_vars) 68 except ImportError: 69 import code 70 import readline 71 from yakumo import utils 72 readline.parse_and_bind("tab:complete") 73 readline.set_completer(utils.Completer(locals()).complete) 74 code.interact(None, None, local_vars)
75 76 77 if __name__ == '__main__': 78 main() 79