예제 #1
0
 def list_accounts(self):
     '''
     return a list of accounts defined in ACCOUNTS_FILE
     '''
     a = Account.Instance()
     a.parse_config_file()
     return a.list_stanzas()
예제 #2
0
 def get_account(self, stanza):
     '''
     return dictionary based on stanza alias from ACOUNTS_FILE
     '''
     out = {}
     a = Account.Instance()
     a.parse_config_file()
     out['identity_type'] = a.get_param(stanza, 'OS_AUTH_SYSTEM')
     out['username'] = a.get_param(stanza, 'OS_USERNAME')
     out['apikey'] = a.get_param(stanza, 'OS_PASSWORD')
     out['region'] = a.get_param(stanza, 'OS_REGION_NAME')
     return out
예제 #3
0
def main():
    # check '~/.pyraxshell' and config files exist, create them if missing
    if not check_dir_home():
        print("This is the first time 'pyraxshell' runs, please, configure "
              "'%s' according to your needs" % CONFIG_FILE)
        #create db
        DB()
        Sessions.Instance().create_table_sessions()  # @UndefinedVariable
        Sessions.Instance().create_table_commands()  # @UndefinedVariable
        # create default configuration file
        Configuration.Instance()  # @UndefinedVariable
        sys.exit(0)

    # ########################################
    # VERSION CHECK
    if not version.check_version_file():
        sys.exit(1)

    # ########################################
    # LOGGING
    start_logging()
    logging.debug('starting')

    #     from baseconfigfile import BaseConfigFile
    #     bcf = BaseConfigFile()

    # ########################################
    # ACCOUNTS
    accounts = Account.Instance()  # @UnusedVariable @UndefinedVariable

    # config file is read by 'BaseConfigFile' constructor
    # ########################################
    # CONFIGURATION
    cfg = Configuration.Instance()  # @UndefinedVariable
    # override settings with CLI params
    cfg.parse_cli(sys.argv)
    logging.debug("configuration: %s" % cfg)

    # set user's log level if specified
    if not Configuration.Instance().log_level == None:  # @UndefinedVariable
        l = logging.getLogger()
        for h in l.handlers:
            h.setLevel(cfg.log_level)

    # ########################################
    # START SESSION
    Sessions.Instance().start_session()  # @UndefinedVariable
    #     Sessions.Instance().insert_table_commands('IN', 'OUT')  # @UndefinedVariable

    # ########################################
    # DO STUFF
    # handle configuration
    if cfg.pyrax_http_debug == True:
        pyrax.set_http_debug(True)
    if cfg.pyrax_no_verify_ssl == True:
        # see: https://github.com/rackspace/pyrax/issues/187
        pyrax.set_setting("verify_ssl", False)
    # start notifier
    Notifier().start()
    # main loop
    Cmd_Pyraxshell().cmdloop()