本文整理汇总了Python中boto.sdb.connection.SDBConnection.create_domain方法的典型用法代码示例。如果您正苦于以下问题:Python SDBConnection.create_domain方法的具体用法?Python SDBConnection.create_domain怎么用?Python SDBConnection.create_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.sdb.connection.SDBConnection
的用法示例。
在下文中一共展示了SDBConnection.create_domain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_1_basic
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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 ---'
示例2: __init__
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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()
示例3: get_latest_snapshot
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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: __init__
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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.
示例12: __init__
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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)
示例13: add_snapshot
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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: set_cluster_metadata
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
def set_cluster_metadata(key, access, cluster):
sdb = SDBConnection(key, access, region=region_info)
domain = sdb.create_domain(cluster)
# set the basic values in the 'master' record
metadata = domain.new_item('metadata')
#master = "{0}.{1}".format(
# os.environ['REDIS_NAME'].strip(),
# os.environ['HOSTED_ZONE_NAME'].rstrip('.'))
#metadata.add_value('master', master)
try:
if "" != os.environ['REDIS_SIZE'].strip():
metadata.add_value('size', os.environ['REDIS_SIZE'])
except:
pass
try:
if "" != os.environ['REDIS_PERSISTENCE'].strip():
metadata.add_value('persistence', os.environ['REDIS_PERSISTENCE'])
else:
metadata.add_value('persistence', 'no')
except:
metadata.add_value('persistence', 'no')
try:
if "" != os.environ['REDIS_SNAPSHOT'].strip():
metadata.add_value('snapshot', os.environ['REDIS_SNAPSHOT'])
except:
pass
try:
if "" != os.environ['REDIS_RDB'].strip():
metadata.add_value('rdb', os.environ['REDIS_RDB'])
except:
pass
try:
if "" != os.environ['REDIS_AOF'].strip():
metadata.add_value('aof', os.environ['REDIS_AOF'])
except:
pass
metadata.save()
示例15: get_latest_snapshot
# 需要导入模块: from boto.sdb.connection import SDBConnection [as 别名]
# 或者: from boto.sdb.connection.SDBConnection import create_domain [as 别名]
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