示例#1
0
def localPrivateBucket():
    loc1 = dsslib.getConnection(dsslib.USER_keystone803)
    b1 = loc1.create_bucket('shivanshudemo001')
    dsslib.createMaxBuckets(dsslib.USER_keystone803, 10, 'shivanshudemo001')
    b1.set_acl('private')
    loc2 = dsslib.getConnection(dsslib.USER_keystone804)
    b2 = loc2.get_bucket('shivanshudemo001')
    print b2.list()
    return
示例#2
0
def multipartObjectUpload():
    result = 0
    obj = dsslib.getConnection(CALLER)
    dsslib.whisper("Making bucket and listing...")
    obj.create_bucket('rjilshivanshuautoq')
    dsslib.whisper(str(obj.get_all_buckets()))

    source_path = '/boot/initrd.img-3.16.0-30-generic'
    source_size = os.stat(source_path).st_size
    chunk_size = 5242880  ## 5 mb
    #chunk_size = 1048576  ## 1 mb
    #chunk_size  = 2100000
    chunk_count = int(math.ceil(source_size / float(chunk_size)))

    b1 = obj.get_bucket('rjilshivanshuautoq')
    dsslib.whisper("Got bucket: " + str(b1))
    try:
        mp = b1.initiate_multipart_upload(os.path.basename(source_path))
        for i in range(chunk_count):
            dsslib.whisper("Uploading chunk: " + str(i))
            offset = chunk_size * i
            bytes = min(chunk_size, source_size - offset)
            with FileChunkIO(source_path, 'r', offset=offset,
                             bytes=bytes) as fp:
                mp.upload_part_from_file(fp, part_num=i + 1)
        mp.complete_upload()
    except:
        print "Unexpected error: ", sys.exc_info()
        result = -1

    dsslib.cleanupUser(obj, 'rjilshiv')
    return result
示例#3
0
def publicUrlTest():
    result = 0
    obj = dsslib.getConnection(CALLER)
    b1 = obj.create_bucket('urlbucket1')
    k = Key(b1)
    k.key = 'obj1'
    k.set_contents_from_string('Data of URL object')
    print "Setting ACL on obj"
    k.set_acl('public-read')
    print "Setting ACL on bucket"
    b1.set_acl('public-read')

    m = Key(b1)
    m.key = 'obj1'
    urlname = m.generate_url(1000)
    print "\nThe obj URL is: " + str(urlname)
    urlname = b1.generate_url(1000)
    print "\nThe bucket URL is: " + str(urlname)

    for i in range(1, 21):
        time.sleep(1)
        if i % 5 == 0:
            print str(20 - i) + " Seconds left before Obj deletion"

    m.delete()
    print "Object deleted\n"

    for i in range(1, 21):
        time.sleep(1)
        if i % 5 == 0:
            print str(20 - i) + " Seconds left before bucket deletion"

    obj.delete_bucket('urlbucket1')
    print "Bucket deleted\n"
    return result
示例#4
0
def bucketMaxNumber():
    obj = dsslib.getConnection(dsslib.USER_keystone995)
    #dsslib.createMaxBuckets(dsslib.USER_keystone1,   1000, 'rjilshivanshubucket')
    dsslib.createMaxBuckets(dsslib.USER_keystone800, 1000, 'rjil800bucket')
    #dsslib.createMaxBuckets(dsslib.USER_keystone801, 1000, 'rjil801bucket')
    #dsslib.createMaxBuckets(dsslib.USER_keystone802, 1000, 'rjil802bucket')
    #dsslib.createMaxBuckets(dsslib.USER_keystone803, 1000, 'rjil803bucket')

    ## Make 1001 bucket
    try:
        obj.create_bucket('brandnewshinybucket')
        print "Bucket created unexpectedly!!"
        print "1001th bucket"
        return -1
    except:
        dsslib.whisper("\nExpected failure: " + str(sys.exc_info()) + "\n")

    ## Delete one bucket and try again
    try:
        dsslib.whisper("Deleting a bucket")
        obj.delete_bucket('rjilshivanshubucket100')
        dsslib.whisper("Creating one more bucket")
        obj.create_bucket('rjilshivanshubucket100')
    except:
        print "Unexpected failure. Cannot create bucket after deleting one: " + str(
            sys.exc_info())
        return -1
    return 0
def multipartObjectUpload():
    result = 0
    obj = dsslib.getConnection(CALLER)
    dsslib.whisper("Making bucket and listing...")
    obj.create_bucket('rjilshivanshuautoq')
    dsslib.whisper(str(obj.get_all_buckets()))

    source_path = '/boot/initrd.img-3.16.0-30-generic'
    source_size = os.stat(source_path).st_size
    chunk_size = 5242880 ## 5 mb
    #chunk_size = 1048576  ## 1 mb
    #chunk_size  = 2100000
    chunk_count = int(math.ceil(source_size / float(chunk_size)))

    b1 = obj.get_bucket('rjilshivanshuautoq')
    dsslib.whisper("Got bucket: " + str(b1))
    try:
        mp = b1.initiate_multipart_upload(os.path.basename(source_path))
        for i in range(chunk_count):
            dsslib.whisper("Uploading chunk: " + str(i))
            offset = chunk_size * i
            bytes = min(chunk_size, source_size - offset)
            with FileChunkIO(source_path, 'r', offset=offset, bytes=bytes) as fp:
                mp.upload_part_from_file(fp, part_num=i + 1)
        mp.complete_upload()
    except:
        print "Unexpected error: ", sys.exc_info()
        result = -1

    dsslib.cleanupUser(obj, 'rjilshiv')
    return result
def bucketMaxNumber():
    obj = dsslib.getConnection(dsslib.USER_keystone995)
    #dsslib.createMaxBuckets(dsslib.USER_keystone1,   1000, 'rjilshivanshubucket')
    dsslib.createMaxBuckets(dsslib.USER_keystone800, 1000, 'rjil800bucket')
    #dsslib.createMaxBuckets(dsslib.USER_keystone801, 1000, 'rjil801bucket')
    #dsslib.createMaxBuckets(dsslib.USER_keystone802, 1000, 'rjil802bucket')
    #dsslib.createMaxBuckets(dsslib.USER_keystone803, 1000, 'rjil803bucket')

    ## Make 1001 bucket
    try:
        obj.create_bucket('brandnewshinybucket')
        print "Bucket created unexpectedly!!"
        print "1001th bucket"
        return -1
    except:
        dsslib.whisper("\nExpected failure: " + str(sys.exc_info()) + "\n")

    ## Delete one bucket and try again
    try:
        dsslib.whisper("Deleting a bucket")
        obj.delete_bucket('rjilshivanshubucket100')
        dsslib.whisper("Creating one more bucket")
        obj.create_bucket('rjilshivanshubucket100')
    except:
        print "Unexpected failure. Cannot create bucket after deleting one: " + str(sys.exc_info())
        return -1
    return 0
def publicUrlTest():
    result = 0
    obj = dsslib.getConnection(CALLER)
    b1 = obj.create_bucket('urlbucket1')
    k = Key(b1)
    k.key = 'obj1'
    k.set_contents_from_string('Data of URL object')
    print "Setting ACL on obj"
    k.set_acl('public-read')
    print "Setting ACL on bucket"
    b1.set_acl('public-read')

    m = Key(b1)
    m.key = 'obj1'
    urlname = m.generate_url(1000)
    print "\nThe obj URL is: " + str(urlname)
    urlname = b1.generate_url(1000)
    print "\nThe bucket URL is: " + str(urlname)

    for i in range(1, 21):
        time.sleep(1)
        if i % 5 == 0:
            print str(20 - i) + " Seconds left before Obj deletion"

    m.delete()
    print "Object deleted\n"

    for i in range(1, 21):
        time.sleep(1)
        if i % 5 == 0:
            print str(20 - i) + " Seconds left before bucket deletion"

    obj.delete_bucket('urlbucket1')
    print "Bucket deleted\n"
    return result
示例#8
0
def writeVishalBucket():
    u2Obj = dsslib.getConnection(dsslib.USER_aws2)
    u2print("Putting objects in Vishals bucket")
    dsslib.createMaxBuckets(dsslib.USER_aws2, 10, 'shivanshubucketman00')
    u2b = u2Obj.get_bucket('shivanshubucketman00')
    k = Key(u2b)
    k.key = 'shivanshubucketman00_OBJ_2'
    k.set_acl('public-read')
    return
示例#9
0
def crBucket():
    u1Obj = dsslib.getConnection(dsslib.USER_aws1)
    try:
        u1print("Creating bucket in my own tenant")
        u1Obj.create_bucket('shivanshu21demobucket1')
        dsslib.createMaxBuckets(dsslib.USER_aws1, 10, 'shivanshu21demobucket1')
        u1print("Created bucket!")
    except:
        u1print("Failed to create bucket: " + str(sys.exc_info()))
    return
示例#10
0
def u1Bucket():
    u2Obj = dsslib.getConnection(dsslib.USER_aws2)
    BUCKET = 'shivanshu21demobucket1'
    u2print("\nTrying to get bucket of my own tenant")
    try:
        u2b = u2Obj.get_bucket(BUCKET)
        u2print("Got bucket!")
        for k in u2b.list():
            u2print("Object: " + str(k))
    except:
        u2print("Failed to get bucket: " + str(sys.exc_info()))
    return
示例#11
0
def vishalBucket():
    u2Obj = dsslib.getConnection(dsslib.USER_aws2)
    BUCKET = 'shivanshubucketman00' ## In Vishal tenant<<<<<<<<<<
    u2print("Trying to get bucket in diff tenant")
    try:
        u2b = u2Obj.get_bucket(BUCKET)
        u2print("Got bucket!")
        for k in u2b.list():
            u2print("Object: " + str(k))
    except:
        u2print("Failed to get bucket: " + str(sys.exc_info()))
    return
示例#12
0
def dnsNamesTest():
    obj = dsslib.getConnection(CALLER)
    result = 0
    longHundredChars = 'a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789'
    longFiftyChars = 'a123456789a123456789a123456789a123456789a123456789'
    longTFTchars = longHundredChars + longHundredChars + longFiftyChars + 'qwe'
    try:
        obj.create_bucket(longTFTchars)
        obj.delete_bucket(longTFTchars)
        print "Able to create bucket with 253 chars in name"
    except:
        print "Failed to create or delete a valid bucket name"
        print "Unexpected error: ", sys.exc_info()
        return -1

    try:
        badName = longTFTchars + 'abc'
        obj.create_bucket(badName)
        print "Unexpectedly created bucket with illegally long name"
        dsslib.listBucketNum(obj, "user3")
        dsslib.listBucket(obj, "user3")
        obj.delete_bucket(badName)
        result = -1
    except:
        print "Expected failure in creating 256 char bucket name"
        print "Expected error: ", sys.exc_info()

    try:
        badName = 'Abc'
        obj.create_bucket(badName)
        print "Unexpectedly created bucket with capital letter name"
        dsslib.listBucketNum(obj, "user3")
        dsslib.listBucket(obj, "user3")
        obj.delete_bucket(badName)
        result = -1
    except:
        print "Expected failure in creating bucket name with CAPS"
        print "Expected error: ", sys.exc_info()

    try:
        badName = 'bc/'
        obj.create_bucket(badName)
        print "Unexpectedly created bucket with slash in name"
        dsslib.listBucketNum(obj, "user3")
        dsslib.listBucket(obj, "user3")
        obj.delete_bucket(badName)
        result = -1
    except:
        print "Expected failure in creating bucket name with slash"
        print "Expected error: ", sys.exc_info()

    return result
示例#13
0
def dnsNamesTest():
    obj = dsslib.getConnection(CALLER)
    result = 0
    longHundredChars = 'a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789'
    longFiftyChars = 'a123456789a123456789a123456789a123456789a123456789'
    longTFTchars = longHundredChars + longHundredChars + longFiftyChars + 'qwe'
    try:
        obj.create_bucket(longTFTchars)
        obj.delete_bucket(longTFTchars)
        print "Able to create bucket with 253 chars in name"
    except:
        print "Failed to create or delete a valid bucket name"
        print "Unexpected error: ", sys.exc_info()
        return -1

    try:
        badName = longTFTchars + 'abc'
        obj.create_bucket(badName)
        print "Unexpectedly created bucket with illegally long name"
        dsslib.listBucketNum(obj, "user3")
        dsslib.listBucket(obj, "user3")
        obj.delete_bucket(badName)
        result = -1
    except:
        print "Expected failure in creating 256 char bucket name"
        print "Expected error: ", sys.exc_info()

    try:
        badName = 'Abc'
        obj.create_bucket(badName)
        print "Unexpectedly created bucket with capital letter name"
        dsslib.listBucketNum(obj, "user3")
        dsslib.listBucket(obj, "user3")
        obj.delete_bucket(badName)
        result = -1
    except:
        print "Expected failure in creating bucket name with CAPS"
        print "Expected error: ", sys.exc_info()

    try:
        badName = 'bc/'
        obj.create_bucket(badName)
        print "Unexpectedly created bucket with slash in name"
        dsslib.listBucketNum(obj, "user3")
        dsslib.listBucket(obj, "user3")
        obj.delete_bucket(badName)
        result = -1
    except:
        print "Expected failure in creating bucket name with slash"
        print "Expected error: ", sys.exc_info()

    return result
示例#14
0
    b1 = loc1.create_bucket('shivanshudemo001')
    dsslib.createMaxBuckets(dsslib.USER_keystone803, 10, 'shivanshudemo001')
    b1.set_acl('private')
    loc2 = dsslib.getConnection(dsslib.USER_keystone804)
    b2 = loc2.get_bucket('shivanshudemo001')
    print b2.list()
    return
#=======================================

#crBucket()
#u1Bucket()
#vishalBucket()
#writeVishalBucket()
#localPrivateBucket()

u2Obj = dsslib.getConnection(dsslib.USER_aws2)



'''
obj = dsslib.getConnection(dsslib.USER_aws3)
bb = obj.get_bucket('shivanshubucketman00')
for k in bb.list():
    u1print(str(k.get_acl()))

pers3 = dsslib.getConnection(dsslib.USER_aws4)
#pers3.create_bucket('shivanshubucketauto99')
#pers3.create_bucket('shivanshubucketauto98')
pers3.delete_bucket('shivanshubucketauto99')
pers3.delete_bucket('shivanshubucketauto98')
'''
示例#15
0
import sys
import time
import dsslib
import math, os
from boto.s3.key import Key
from filechunkio import FileChunkIO

dsslib.GLOBAL_DEBUG = 1

'''=========================================================
### API Doc testing
'''
usr_str = "user804"
obj = dsslib.getConnection(dsslib.USER_keystone804)
dsslib.listBucket(obj, usr_str)
b = obj.create_bucket('docsbuck001')
dsslib.listBucket(obj, usr_str)
b.set_acl('public-read-write')

k = Key(b)
k.key = 'obj1'
k.set_contents_from_string('Data of object')
print "Setting ACL on obj"
k.set_acl('public-read')

print "\nObject has ACL============="
print str(k.get_acl())
##====================================================================


'''=========================================================
示例#16
0
import dsslib
import math, os
from filechunkio import FileChunkIO
import sys
import time
from boto.s3.key import Key

dsslib.GLOBAL_DEBUG = 1
CALLER = dsslib.USER_keystone800

obj = dsslib.getConnection(CALLER)
acl_list = ('public-read', 'private')
for i in range(1, 11):
    b1 = obj.get_bucket('rjil800bucket200010')
    print "Changing ACL to " + acl_list[i % 2]
    b1.set_acl(acl_list[i % 2])
    time.sleep(1)
示例#17
0
import sys
import time
import dsslib
import math, os
from boto.s3.key import Key
from filechunkio import FileChunkIO

dsslib.GLOBAL_DEBUG = 1
'''=========================================================
### API Doc testing
'''
usr_str = "user804"
obj = dsslib.getConnection(dsslib.USER_keystone804)
dsslib.listBucket(obj, usr_str)
b = obj.create_bucket('docsbuck001')
dsslib.listBucket(obj, usr_str)
b.set_acl('public-read-write')

k = Key(b)
k.key = 'obj1'
k.set_contents_from_string('Data of object')
print "Setting ACL on obj"
k.set_acl('public-read')

print "\nObject has ACL============="
print str(k.get_acl())
##====================================================================
'''=========================================================
## AWS user policy prevents user from listing bucket but allows getting objects inside the particular bucket
## Make listing buckets allowed. Generate signed URLs then make listing buckets not allowed in user policy.
## Check if the URLs still work.