本文整理汇总了Python中boto.sdb.connection.SDBConnection类的典型用法代码示例。如果您正苦于以下问题:Python SDBConnection类的具体用法?Python SDBConnection怎么用?Python SDBConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SDBConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, key, access, cluster):
try:
url = "http://169.254.169.254/latest/meta-data/"
public_hostname = urlopen(url + "public-hostname").read()
zone = urlopen(url + "placement/availability-zone").read()
region = zone[:-1]
except:
sys.exit("We should be getting user-data here...")
#us-east-1 breaks the convention. See http://docs.amazonwebservices.com/general/latest/gr/rande.html#sdb_region
endpoint = "sdb.{0}.amazonaws.com".format(region) if region != "us-east-1" \
else "sdb.amazonaws.com"
region_info = RegionInfo(name=region, endpoint=endpoint)
sdb = SDBConnection(key, access, region=region_info)
self.domain = sdb.create_domain(cluster)
self.metadata = self.domain.get_item('metadata', consistent_read=True)
if None == self.metadata:
self.metadata = self.domain.new_item('metadata')
self.metadata.add_value('master', '')
self.metadata.add_value('slave', '')
self.metadata.save()
示例2: __init__
def __init__(self, api=MongoStampedAPI(), logsQuery=logsQuery()):
self.stamp_collection = api._stampDB._collection
self.acct_collection = api._userDB._collection
self.query = logsQuery
self.writer = statWriter("dashboard")
conn = SDBConnection(keys.aws.AWS_ACCESS_KEY_ID, keys.aws.AWS_SECRET_KEY)
self.domain = conn.get_domain("dashboard")
示例3: get_latest_snapshot
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']
示例4: delete_snapshot
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))
示例5: get_all_snapshots
def get_all_snapshots(key, access, cluster):
sdb = SDBConnection(key, access, region=region_info)
domain = sdb.create_domain(cluster)
now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot'".format(cluster)
snapshots = domain.select(select, consistent_read=True)
return snapshots
示例6: get_latest_snapshot
def get_latest_snapshot(key, access, cluster):
sdb = SDBConnection(key, access, region=region_info)
domain = sdb.create_domain(cluster)
try:
return domain.get_item('snapshot', True)['snapshot']
except:
return None
示例7: set_RDB
def set_RDB(key, access, cluster, location):
sdb = SDBConnection(key, access, region=region_info)
domain = sdb.create_domain(cluster)
# add the latest rdb (for automatic restores)
latest = domain.new_item('rdb')
latest.add_value('rdb', location)
# get the expiration date from the object name (for comparison)
latest.add_value('created', strftime("%Y-%m-%d %H:%M:%S", gmtime()))
latest.save()
示例8: SDB
def SDB(domain_name):
"""
Create connection to SimpleDB and return the specifed domain.
domain_name - the SimpleDB domain you wish to return
"""
conn = SDBConnection(ACCESS_KEY_ID,SECRET_ACCESS_KEY)
domain = conn.lookup(domain_name)
if not domain:
domain = conn.create_domain(domain_name)
return domain
示例9: get_expired_snapshots
def get_expired_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' and expires < '{1}'".format(name, now)
print select
snapshots = domain.select(select, consistent_read=True)
return snapshots
示例10: get_identity
def get_identity(key, access, cluster):
sdb = SDBConnection(key, access, region=region_info)
domain = sdb.create_domain(cluster)
slave_id = hashlib.md5(public_hostname).hexdigest()[:8]
slave_fqdn = "{0}.{1}".format(slave_id, cluster)
slave = domain.new_item(slave_fqdn)
slave.add_value('id', slave_id)
slave.add_value('endpoint', public_hostname)
slave.save()
return slave_fqdn
示例11: submit
def submit():
if len(sys.argv) < 3:
print "Usage:"
print " %s -seed <seed> [<spawn coords>]" % sys.argv[0]
return
# TODO use less crappy command line parsing
seed = sys.argv[2]
if len(sys.argv) == 4:
spawn = [int(x) for x in sys.argv[3].split(",")]
assert(len(spawn) == 3)
print "Generate world with this seed (\"%s\") with spawn %r [y/N]?" % (seed, spawn)
else:
spawn = None
print "Generate world with this seed (\"%s\") [y/N]?" % seed
if raw_input().lower() == 'y':
uid = uuid.uuid4()
print "Submitting job %s to queue..." % uid
sqs = SQSConnection()
sdb = SDBConnection()
queue = sqs.get_queue("overviewer-genfromseed")
db = sdb.get_domain("overviewerdb")
print queue
print db
data = dict()
data['uuid'] = str(uid)
data['seed'] = seed
data['generated'] = False
if spawn:
data['target_spawn'] = spawn
if not db.put_attributes(uid, data):
print "***Error: Failed to update the db"
return 1
msg = Message()
msg.set_body(str(uid))
if not queue.write(msg):
print "***Error: Failed to enqueue"
return 1
print "Ok, job enqueued"
else:
print "Ok, not submitting. Bye"
return
示例12: __init__
class SimpleDBBackend:
def __init__(self):
self.connection = SDBConnection(aws_credentials.accessKey,
aws_credentials.secretKey)
self.domain = self.connection.get_domain(TABLE_NAME)
def put(self, key, value):
sampler.begin()
try:
self.domain.put_attributes(key, {VALUE:value})
finally:
sampler.end()
def get(self, key):
sampler.begin()
try:
# First try an eventually consistent read.
result = self.domain.get_attributes(key, consistent_read=False)
return result[VALUE]
except KeyError:
# The eventually consistent read failed. Try a strongly consistent
# read.
result = self.domain.get_attributes(key, consistent_read=True)
return result[VALUE]
finally:
sampler.end()
def incRefCount(self, key):
# Not implemented.
pass
def decRefCount(self, key):
# Not implemented.
pass
def nuke(self):
# Delete and re-create the table.
self.connection.delete_domain(TABLE_NAME)
self.domain = self.connection.create_domain(TABLE_NAME)
def flush(self):
pass # No-op.
示例13: add_snapshot
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()
示例14: __init__
def __init__(self, key, access, cluster):
try:
url = "http://169.254.169.254/latest/meta-data/"
zone = urlopen(url + "placement/availability-zone").read()
region = zone[:-1]
except:
sys.exit("We should be getting user-data here...")
endpoint = "sdb.{0}.amazonaws.com".format(region)
region_info = RegionInfo(name=region, endpoint=endpoint)
sdb = SDBConnection(key, access, region=region_info)
self.domain = sdb.create_domain(cluster)
self.metadata = self.domain.get_item('metadata', consistent_read=True)
示例15: __init__
def __init__(self, stack):
try:
self.conn = SDBConnection(keys.aws.AWS_ACCESS_KEY_ID, keys.aws.AWS_SECRET_KEY)
except SDBResponseError:
print "SimpleDB Connection Refused"
raise
self._stack = stack