john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

s3 boto cumulus compatible create bucket callingformat

# connect to a local S3 compatible service
# python cumulus-testing.py -H localhost -p 5555 -a nBW3JHHUk334CofaxyN8b -s QU4g3L2rab65T8vf9DyW94K5R5FCvylpMSNaqseYHq  -b johnbucket

# http://boto.readthedocs.org/en/latest/s3_tut.html
# http://boto.readthedocs.org/en/latest/ref/s3.html#module-boto.s3.connection
# https://github.com/boto/boto

import os
import sys
import argparse
import time
import logging
import tempfile

from boto.s3.connection import S3Connection
from boto.s3.connection import S3ResponseError
from boto.s3.connection import ProtocolIndependentOrdinaryCallingFormat
from boto.s3.connection import OrdinaryCallingFormat

if __name__ == '__main__':
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument( '-H', '--host', help='host', required=True )
        parser.add_argument( '-p', '--port', help='port', required=True )
        parser.add_argument( '-a', '--access', help='Access Key', required=True )
        parser.add_argument( '-s', '--secret', help='Secret Key', required=True )
        parser.add_argument( '-b', '--bucketname', help='Bucket Name', required=True )
        parser.add_argument( '-L', '--log', help='specify log file location' )
        parser.add_argument( '-P', '--prefix', help='prefix filtered listing' )
        parser.add_argument( '-T', '--localdirectory', help='local storage for files' )
        args = parser.parse_args()

        logging_output = args.log if args.log else os.path.join( os.path.normpath( '/tmp' ) , sys.argv[0] + '.log' )
        logging_level = logging.INFO
        logging.basicConfig(
            name = 'BucketLogParser' ,
            level = logging_level ,
            format = '%(asctime)s %(levelname)s %(message)s',
            filename = logging_output,
            filemode = 'a' )

        parser = argparse.ArgumentParser()
        logging.info('connecting...')
#        ProtocolIndependent requires host be http://fqdn
#        calling_format = ProtocolIndependentOrdinaryCallingFormat()

        calling_format = OrdinaryCallingFormat()
        connection = S3Connection(args.access, args.secret, is_secure=False, port=int(args.port), host=args.host,
                                  calling_format=calling_format)
        print connection
        headers ={'host': 'localhost:4288'}
        connection.create_bucket(args.bucketname, headers=headers)
        print connection.get_all_buckets()

    except KeyboardInterrupt:
        pass

    except S3ResponseError as error:
        print error
        logging.error( error )

    print 'done'
    logging.info( 'done' )

  • « Postgresql install intro
  • ruby basics variable type if array hash map exception »

Published

Apr 24, 2014

Category

python

~174 words

Tags

  • boto 6
  • bucket 7
  • callingformat 1
  • compatible 1
  • create 14
  • cumulus 2
  • python 180
  • s3 17