Exemple #1
0
def get_latest_snapshot(key, access, name):
    sdb = SDBConnection(key, access, region=region_info)

    domain = sdb.lookup(name, True)
    if domain == None:
        domain = sdb.create_domain(name)

    return domain.get_item('snapshot', True)['snapshot']
Exemple #2
0
def delete_snapshot(key, access, name, snapshot_id):
    sdb = SDBConnection(key, access, region=region_info)

    domain = sdb.lookup(name, True)
    if domain == None:
        domain = sdb.create_domain(name)

    return domain.delete_item(domain.get_item(snapshot_id))
    def test_1_basic(self):
        print '--- running SDBConnection tests ---'
        c = SDBConnection()
        rs = c.get_all_domains()
        num_domains = len(rs)

        # try illegal name
        try:
            domain = c.create_domain('bad:domain:name')
        except SDBResponseError:
            pass

        # now create one that should work and should be unique (i.e. a new one)
        domain_name = 'test%d' % int(time.time())
        domain = c.create_domain(domain_name)
        rs = c.get_all_domains()
        assert len(rs) == num_domains + 1

        # now let's a couple of items and attributes
        item_1 = 'item1'
        same_value = 'same_value'
        attrs_1 = {'name1': same_value, 'name2': 'diff_value_1'}
        domain.put_attributes(item_1, attrs_1)
        item_2 = 'item2'
        attrs_2 = {'name1': same_value, 'name2': 'diff_value_2'}
        domain.put_attributes(item_2, attrs_2)
        time.sleep(10)

        # try to get the attributes and see if they match
        item = domain.get_attributes(item_1)
        assert len(item.keys()) == len(attrs_1.keys())
        assert item['name1'] == attrs_1['name1']
        assert item['name2'] == attrs_1['name2']

        # try a search or two
        rs = domain.query("['name1'='%s']" % same_value)
        n = 0
        for item in rs:
            n += 1
        assert n == 2
        rs = domain.query("['name2'='diff_value_2']")
        n = 0
        for item in rs:
            n += 1
        assert n == 1

        # delete all attributes associated with item_1
        stat = domain.delete_attributes(item_1)
        assert stat

        # now delete the domain
        stat = c.delete_domain(domain)
        assert stat

        print '--- tests completed ---'
Exemple #4
0
def get_all_snapshots(key, access, name):
    sdb = SDBConnection(key, access, region=region_info)

    domain = sdb.lookup(name, True)
    if domain == None:
        domain = sdb.create_domain(name)

    now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot'".format(
        name)
    snapshots = domain.select(select, consistent_read=True)
    return snapshots
Exemple #5
0
def get_expired_snapshots(key, access, cluster):
    sdb = SDBConnection(key, access, region=region_info)

    domain = sdb.lookup(cluster, True)
    if domain == None:
        domain = sdb.create_domain(cluster)

    now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot' and expires < '{1}'".format(
        cluster, now)
    snapshots = domain.select(select, consistent_read=True)
    return snapshots
def connect_sdb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
    """
    :type aws_access_key_id: string
    :param aws_access_key_id: Your AWS Access Key ID

    :type aws_secret_access_key: string
    :param aws_secret_access_key: Your AWS Secret Access Key

    :rtype: :class:`boto.sdb.connection.SDBConnection`
    :return: A connection to Amazon's SDB
    """
    from boto.sdb.connection import SDBConnection
    return SDBConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
Exemple #7
0
def connect_sdb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
    """
    @type aws_access_key_id: string
    @param aws_access_key_id: Your AWS Access Key ID
    
    @type aws_secret_access_key: string
    @param aws_secret_access_key: Your AWS Secret Access Key
    
    @rtype: L{SDBConnection<boto.sdb.connection.SDBConnection>}
    @return: A connection to Amazon's SDB
    """
    from boto.sdb.connection import SDBConnection
    return SDBConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
 def connect(self, **kw_params):
     """
     Connect to this Region's endpoint. Returns an SDBConnection
     object pointing to the endpoint associated with this region.
     You may pass any of the arguments accepted by the SDBConnection
     object's constructor as keyword arguments and they will be
     passed along to the SDBConnection object.
     
     :rtype: :class:`boto.sdb.connection.SDBConnection`
     :return: The connection to this regions endpoint
     """
     from boto.sdb.connection import SDBConnection
     return SDBConnection(region=self, **kw_params)
Exemple #9
0
def add_snapshot(key, access, cluster, name, snapshot):
    sdb = SDBConnection(key, access, region=region_info)

    domain = sdb.lookup(cluster, True)
    if domain == None:
        domain = sdb.create_domain(cluster)

    now = strftime("%Y-%m-%d %H:%M:%S", gmtime())

    # add the snapshot for expiration
    backup = domain.new_item(snapshot[0])
    backup.add_value('name', name)
    backup.add_value('snapshot', snapshot[0])
    backup.add_value('created', now)
    backup.add_value('expires', snapshot[1])
    backup.save()
Exemple #10
0
def get_latest_snapshot(key, access, cluster, name):
    sdb = SDBConnection(key, access, region=region_info)
    now = strftime("%Y-%m-%d %H:%M:%S", gmtime())

    domain = sdb.lookup(cluster, True)
    if domain == None:
        domain = sdb.create_domain(cluster)

    select = "select * from `{0}` where name = '{1}' and created < '{2}' order by created desc limit 1".format(
        cluster, name, now)
    snapshots = domain.select(select, consistent_read=True)

    try:
        snapshot = snapshots.next()
        return snapshot['snapshot']
    except:
        return None
Exemple #11
0
    def test_1_basic(self):
        print '--- running SDBConnection tests ---'
        c = SDBConnection()
        rs = c.get_all_domains()
        num_domains = len(rs)

        # try illegal name
        try:
            domain = c.create_domain('bad:domain:name')
        except SDBResponseError:
            pass

        # now create one that should work and should be unique (i.e. a new one)
        domain_name = 'test%d' % int(time.time())
        domain = c.create_domain(domain_name)
        rs = c.get_all_domains()
        assert len(rs) == num_domains + 1

        # now let's a couple of items and attributes
        item_1 = 'item1'
        same_value = 'same_value'
        attrs_1 = {'name1' : same_value, 'name2' : 'diff_value_1'}
        domain.put_attributes(item_1, attrs_1)
        item_2 = 'item2'
        attrs_2 = {'name1' : same_value, 'name2' : 'diff_value_2'}
        domain.put_attributes(item_2, attrs_2)

        # try to get the attributes and see if they match
        item = domain.get_attributes(item_1, consistent_read=True)
        assert len(item.keys()) == len(attrs_1.keys())
        assert item['name1'] == attrs_1['name1']
        assert item['name2'] == attrs_1['name2']

        # try a search or two
        query = 'select * from %s where name1="%s"' % (domain_name, same_value)
        rs = domain.select(query, consistent_read=True)
        n = 0
        for item in rs:
            n += 1
        assert n == 2
        query = 'select * from %s where name2="diff_value_2"' % domain_name
        rs = domain.select(query, consistent_read=True)
        n = 0
        for item in rs:
            n += 1
        assert n == 1

        # delete all attributes associated with item_1
        stat = domain.delete_attributes(item_1)
        assert stat

        # now try a batch put operation on the domain
        item3 = {'name3_1' : 'value3_1',
                 'name3_2' : 'value3_2',
                 'name3_3' : ['value3_3_1', 'value3_3_2']}

        item4 = {'name4_1' : 'value4_1',
                 'name4_2' : ['value4_2_1', 'value4_2_2'],
                 'name4_3' : 'value4_3'}
        items = {'item3' : item3, 'item4' : item4}
        domain.batch_put_attributes(items)

        item = domain.get_attributes('item3', consistent_read=True)
        assert item['name3_2'] == 'value3_2'

        # now try a batch delete operation (variation #1)
        items = {'item3' : item3}
        stat = domain.batch_delete_attributes(items)

        item = domain.get_attributes('item3', consistent_read=True)
        assert not item

        # now try a batch delete operation (variation #2)
        stat = domain.batch_delete_attributes({'item4' : None})

        item = domain.get_attributes('item4', consistent_read=True)
        assert not item

        # now delete the domain
        stat = c.delete_domain(domain)
        assert stat

        print '--- tests completed ---'