コード例 #1
0
ファイル: info.py プロジェクト: tipabu/swiftagent
def main(args):
    '''Get information about the capabilities of a Swift cluster.

    If a swift-agent server seems to be running, that will be used
    to cache responses.
    '''
    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument('--debug',
                        action='store_true',
                        help='include debugging information')
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        'url',
        default=None,
        nargs='?',
        help='the url of the Swift cluster whose capabilities you want to get')
    group.add_argument('--auth', help='the auth endpoint to use')
    parser.add_argument(
        '--refresh',
        action='store_true',
        help='if using a swift-agent server, force a fresh response '
        'from the cluster')
    args = parser.parse_args(args[1:])

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    if args.url:
        url = args.url
    else:
        conf = config.SwiftConfig()
        authenticator = args.auth or conf.default_auth
        if not authenticator:
            logging.error('No auth endpoint specified, and no default defined')
            return

        if client.can_use_swift_agent():
            dummy, (url, dummy) = client.get_auth_with_unlock(authenticator)
        else:
            url, dummy = conf.get_auth(authenticator).get_credentials()

    if client.can_use_swift_agent():
        sock = os.environ[client.SOCKET_ENV_VAR]
        with client.SwiftAgentClient(sock) as agent_client:
            if args.refresh:
                info = agent_client.reinfo(url)
            else:
                info = agent_client.info(url)
    else:
        info = models.Cluster(auth.noauth({'storage_url': url})).info()
    # TODO: consider ways to format this better/more meaningfully
    print(json.dumps(info, indent=2, sort_keys=True))
コード例 #2
0
ファイル: info.py プロジェクト: tipabu/swiftagent
def main(args):
    '''Get information about the capabilities of a Swift cluster.

    If a swift-agent server seems to be running, that will be used
    to cache responses.
    '''
    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument(
        '--debug', action='store_true',
        help='include debugging information')
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        'url', default=None, nargs='?',
        help='the url of the Swift cluster whose capabilities you want to get')
    group.add_argument(
        '--auth', help='the auth endpoint to use')
    parser.add_argument(
        '--refresh', action='store_true',
        help='if using a swift-agent server, force a fresh response '
             'from the cluster')
    args = parser.parse_args(args[1:])

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    if args.url:
        url = args.url
    else:
        conf = config.SwiftConfig()
        authenticator = args.auth or conf.default_auth
        if not authenticator:
            logging.error('No auth endpoint specified, and no default defined')
            return

        if client.can_use_swift_agent():
            dummy, (url, dummy) = client.get_auth_with_unlock(authenticator)
        else:
            url, dummy = conf.get_auth(authenticator).get_credentials()

    if client.can_use_swift_agent():
        sock = os.environ[client.SOCKET_ENV_VAR]
        with client.SwiftAgentClient(sock) as agent_client:
            if args.refresh:
                info = agent_client.reinfo(url)
            else:
                info = agent_client.info(url)
    else:
        info = models.Cluster(auth.noauth({'storage_url': url})).info()
    # TODO: consider ways to format this better/more meaningfully
    print(json.dumps(info, indent=2, sort_keys=True))
コード例 #3
0
ファイル: agent.py プロジェクト: tipabu/swiftagent
 def __init__(self, config_dict):
     super(AgentAuthenticator, self).__init__(config_dict)
     if not client.can_use_swift_agent():
         raise TypeError('AgentAuthenticator requires a running '
                         'swift-agent process')
     try:
         self.storage_url, self.token, self.expiry = \
             client.get_auth(self.conf['auth_name'])
     except (client.SwiftAgentClientError, base.PasswordRequired):
         pass  # worth a shot
     self.ever_prompted = False
コード例 #4
0
ファイル: agent.py プロジェクト: tipabu/swiftagent
 def __init__(self, config_dict):
     super(AgentAuthenticator, self).__init__(config_dict)
     if not client.can_use_swift_agent():
         raise TypeError('AgentAuthenticator requires a running '
                         'swift-agent process')
     try:
         self.storage_url, self.token, self.expiry = \
             client.get_auth(self.conf['auth_name'])
     except (client.SwiftAgentClientError, base.PasswordRequired):
         pass   # worth a shot
     self.ever_prompted = False
コード例 #5
0
ファイル: auth.py プロジェクト: tipabu/swiftagent
def main(args):
    '''Get a storage URL and auth token for a Swift cluster.

    If a swift-agent server seems to be running, that will be used
    to authenticate.
    '''
    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument(
        '--debug', action='store_true',
        help='include debugging information')
    parser.add_argument(
        'auth', default=None, nargs='?',
        help='the auth endpoint to use')
    parser.add_argument(
        '--verify', action='store_true', default=None,
        help='verify the token is still valid if received from '
             'a swift-agent server')
    parser.add_argument(
        '--no-verify', action='store_false', dest='verify',
        help='skip token verification')
    args = parser.parse_args(args[1:])

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    conf = config.SwiftConfig()

    auth = args.auth or conf.default_auth
    if not auth:
        logging.error('No auth endpoint specified, and no default defined')
        return

    if client.can_use_swift_agent():
        authenticator = agent.AgentAuthenticator({'auth_name': auth})
    else:
        authenticator = conf.get_auth(auth)
    storage_url, token, expiry = authenticator.get_credentials()

    if args.verify is None:
        verify = conf.get_default_verify(auth)
    else:
        verify = args.verify

    if verify and client.can_use_swift_agent():
        try:
            models.Cluster(authenticator).default_account.info()
        except base.Unauthorized:
            if authenticator.ever_prompted:
                raise

            password = getpass.getpass()
            sock = os.environ[client.SOCKET_ENV_VAR]
            with client.SwiftAgentClient(sock) as agent_client:
                agent_client.unlock(auth, password)
                storage_url, token, expiry = agent_client.auth(auth)

    io.export({'OS_STORAGE_URL': storage_url,
               'OS_AUTH_TOKEN': token,
               'OS_AUTH_TOKEN_EXPIRES': expiry})
コード例 #6
0
def main(args):
    '''Get a storage URL and auth token for a Swift cluster.

    If a swift-agent server seems to be running, that will be used
    to authenticate.
    '''
    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument('--debug',
                        action='store_true',
                        help='include debugging information')
    parser.add_argument('auth',
                        default=None,
                        nargs='?',
                        help='the auth endpoint to use')
    parser.add_argument(
        '--verify',
        action='store_true',
        default=None,
        help='verify the token is still valid if received from '
        'a swift-agent server')
    parser.add_argument('--no-verify',
                        action='store_false',
                        dest='verify',
                        help='skip token verification')
    args = parser.parse_args(args[1:])

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    conf = config.SwiftConfig()

    auth = args.auth or conf.default_auth
    if not auth:
        logging.error('No auth endpoint specified, and no default defined')
        return

    if client.can_use_swift_agent():
        authenticator = agent.AgentAuthenticator({'auth_name': auth})
    else:
        authenticator = conf.get_auth(auth)
    storage_url, token, expiry = authenticator.get_credentials()

    if args.verify is None:
        verify = conf.get_default_verify(auth)
    else:
        verify = args.verify

    if verify and client.can_use_swift_agent():
        try:
            models.Cluster(authenticator).default_account.info()
        except base.Unauthorized:
            if authenticator.ever_prompted:
                raise

            password = getpass.getpass()
            sock = os.environ[client.SOCKET_ENV_VAR]
            with client.SwiftAgentClient(sock) as agent_client:
                agent_client.unlock(auth, password)
                storage_url, token, expiry = agent_client.auth(auth)

    io.export({
        'OS_STORAGE_URL': storage_url,
        'OS_AUTH_TOKEN': token,
        'OS_AUTH_TOKEN_EXPIRES': expiry
    })