yakumo.cmd.ossh

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
    26  import yakumo
    27
    28
    29  ENVIRONMENT_VARIABLES = {
    30      'os_cloud': 'OS_CLOUD',
    31      'os_cert': 'OS_CERT',
    32      'os_cacert': 'OS_CACERT',
    33      'os_region_name': 'OS_REGION_NAME',
    34      'os_interface': 'OS_INTERFACE',
    35      'os_key': 'OS_KEY',
    36      'os_auth_type': 'OS_AUTH_TYPE',
    37  }
    38
    39
    40 -def main():
    41      kwargs = {dest: os.environ.get(env)
    42                for dest, env in ENVIRONMENT_VARIABLES.items()}
    43      parser = argparse.ArgumentParser()
    44      cloud_config = os_client_config.OpenStackConfig()
    45      cloud_config.register_argparse_arguments(parser, sys.argv)
    46      for opt in parser._actions:
    47          if opt.dest in ENVIRONMENT_VARIABLES:
    48              opt.metavar = ENVIRONMENT_VARIABLES[opt.dest]
    49      parser.set_defaults(timeout=None, insecure=False, **kwargs)
    50      parser.add_argument('--verbose', help='Verbose output',
    51                          action='store_true')
    52
    53      options = parser.parse_args()
    54      c = yakumo.Client(**options.__dict__)
    55
    56      local_vars = locals()
    57      local_vars['pprint'] = pprint
    58      try:
    59          import bpython
    60          bpython.embed(locals_=local_vars)
    61      except ImportError:
    62          try:
    63              import code
    64              import readline
    65              readline.parse_and_bind("tab:complete")
    66          except ImportError:
    67              pass
    68          code.interact(None, None, local_vars)
    69
    70  if __name__ == '__main__':
    71      main()
    72