import sys import boto.s3.connection #------------------------------------------------------------------------------ HOST_S3 = 'ss3.scayle.es' PORT_S3 = 443 #------------------------------------------------------------------------------ # FUNCTION: S3 Connection # DESCRIPTION: Connection to Server S3 # PARAMETERS: accessKey: Encoded token to access with AD User #------------------------------------------------------------------------------ def S3Connection (accessKey): global conn try: conn = boto.connect_s3( aws_access_key_id=accessKey, aws_secret_access_key=accessKey, host=HOST_S3, port=PORT_S3, is_secure=True, calling_format=boto.s3.connection.OrdinaryCallingFormat(), ) except: print ("AD User with access data <%s> has not privileges or does not exist." % (accessKey)) sys.exit(-1) #------------------------------------------------------------------------------ # FUNCTION: createBucket # DESCRIPTION: Bucket Creation # PARAMETERS: bucketName Name associated to the new bucket #------------------------------------------------------------------------------ def createBucket (bucketName): try: bucket = conn.create_bucket(bucketName) except: print ("!!! WARNING Bucket %s can not be created. " % (bucketName)) print ("Review %s log information. \nPlease attention to field CODE if exists. " % (sys.exc_info()[1])) print ("When CODE is AccessDenied then the Connection to OpenCayle can not be done, please review your AccessKey:") print ("1) Run program s3AccessKey.py") print ("2) Run program s3CheckConnection.py") print ("If problem persists then contact to Scayle through HelpDesk tool.") sys.exit(-2) ######################################################################################################### # PROGRAM ######################################################################################################### # ----------------------------- PARAMETERS EVALUATION ----------------------------- if len(sys.argv) >= 3: accessKey = str(sys.argv[1]) bucketName = str(sys.argv[2]) print ("PARAMETERS: Access Key <%s> Bucket <%s>." % (accessKey,bucketName)) else: print ("USE: python s3CreateBucket.py ") sys.exit(-1) # ----------------------- CONECTION ------------------------------------------------ S3Connection (accessKey) # -------- CREAR BUCKETS EN BASE A PARAMETROS -------------------------------------- createBucket (bucketName) # -------------- END PROCESS ------------------------------------------- print ("Bucket %s created successfully." % (bucketName)) sys.exit(0)