本文整理汇总了Python中dynamo3.DynamoDBConnection类的典型用法代码示例。如果您正苦于以下问题:Python DynamoDBConnection类的具体用法?Python DynamoDBConnection怎么用?Python DynamoDBConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DynamoDBConnection类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure
def configure(cls, settings):
kwargs = super(DynamoCache, cls).configure(settings)
access_key = settings.get('db.access_key')
secret_key = settings.get('db.secret_key')
region = settings.get('db.region')
host = settings.get('db.host')
port = int(settings.get('db.port', 8000))
secure = asbool(settings.get('db.secure', False))
namespace = settings.get('db.namespace', ())
if region is not None:
connection = DynamoDBConnection.connect(region,
access_key=access_key,
secret_key=secret_key)
elif host is not None:
connection = DynamoDBConnection.connect('us-east-1',
host=host,
port=port,
is_secure=secure,
access_key=access_key,
secret_key=secret_key)
else:
raise ValueError("Must specify either db.region or db.host!")
kwargs['engine'] = engine = Engine(namespace=namespace,
dynamo=connection)
engine.register(DynamoPackage, PackageSummary)
engine.create_schema()
return kwargs
示例2: initialize
def initialize(self, region='us-west-1', host='localhost', port=8000,
access_key=None, secret_key=None, config_dir=None):
""" Set up the repl for execution. """
# Tab-complete names with a '-' in them
import readline
delims = set(readline.get_completer_delims())
if '-' in delims:
delims.remove('-')
readline.set_completer_delims(''.join(delims))
self._conf_dir = (config_dir or
os.path.join(os.environ.get('HOME', '.'), '.config'))
self.session = botocore.session.get_session()
if access_key:
self.session.set_credentials(access_key, secret_key)
if region == 'local':
conn = DynamoDBConnection.connect_to_host(host, port,
session=self.session)
else:
conn = DynamoDBConnection.connect_to_region(region, self.session)
self.engine = FragmentEngine(conn)
conf = self.load_config()
display_name = conf.get('display')
if display_name is not None:
self.display = DISPLAYS[display_name]
else:
self.display = get_default_display()
self.formatter = SmartFormat(pagesize=conf.get('pagesize', 1000),
width=conf.get('width', 80))
for line in conf.get('autorun', []):
six.exec_(line, self.engine.scope)
示例3: do_use
def do_use(self, region, host='localhost', port=8000):
"""
Switch the AWS region
You may also specify 'use local host=localhost port=8000' to use the
DynamoDB Local service
"""
if region == 'local':
conn = DynamoDBConnection.connect_to_host(
host, port, session=self.session)
else:
conn = DynamoDBConnection.connect_to_region(region, self.session)
self.engine.connection = conn
示例4: configure
def configure(cls, settings):
kwargs = super(DynamoCache, cls).configure(settings)
access_key = settings.get("db.aws_access_key_id")
secret_key = settings.get("db.aws_secret_access_key")
region = settings.get("db.region_name")
host = settings.get("db.host")
port = int(settings.get("db.port", 8000))
secure = asbool(settings.get("db.secure", False))
namespace = settings.get("db.namespace", ())
graceful_reload = asbool(settings.get("db.graceful_reload", False))
tablenames = aslist(settings.get("db.tablenames", []))
if tablenames:
if len(tablenames) != 2:
raise ValueError("db.tablenames must be a 2-element list")
DynamoPackage.meta_.name = tablenames[0]
PackageSummary.meta_.name = tablenames[1]
if host is not None:
connection = DynamoDBConnection.connect(
region,
host=host,
port=port,
is_secure=secure,
access_key=access_key,
secret_key=secret_key,
)
elif region is not None:
connection = DynamoDBConnection.connect(
region, access_key=access_key, secret_key=secret_key
)
else:
raise ValueError("Must specify either db.region_name or db.host!")
kwargs["engine"] = engine = Engine(namespace=namespace, dynamo=connection)
kwargs["graceful_reload"] = graceful_reload
engine.register(DynamoPackage, PackageSummary)
LOG.info("Checking if DynamoDB tables exist")
engine.create_schema()
return kwargs
示例5: connect
def connect(self, *args, **kwargs):
""" Proxy to DynamoDBConnection.connect. """
self.connection = DynamoDBConnection.connect(*args, **kwargs)
self._session = kwargs.get("session")
if self._session is None:
self._session = botocore.session.get_session()
示例6: test_connect_to_host_without_session
def test_connect_to_host_without_session(self):
""" Can connect to a dynamo host without passing in a session """
conn = DynamoDBConnection.connect('us-west-1', host='localhost')
self.assertIsNotNone(conn.host)
示例7: test_connect_to_region_creds
def test_connect_to_region_creds(self):
""" Can connect to a dynamo region with credentials """
conn = DynamoDBConnection.connect(
'us-west-1', access_key='abc', secret_key='12345')
self.assertIsNotNone(conn.host)
示例8: test_connect_to_region
def test_connect_to_region(self):
""" Can connect to a dynamo region """
conn = DynamoDBConnection.connect('us-west-1')
self.assertIsNotNone(conn.host)
示例9: test_connect_to_host_without_session_old
def test_connect_to_host_without_session_old(self):
""" Can connect to a dynamo host without passing in a session """
conn = DynamoDBConnection.connect_to_host(access_key='abc',
secret_key='12345')
self.assertIsNotNone(conn.host)
示例10: connect
def connect(self, *args, **kwargs):
""" Connect to a specific host """
self.dynamo = DynamoDBConnection.connect(*args, **kwargs)
示例11: connect_to_region
def connect_to_region(self, region, **kwargs):
""" Connect to an AWS region """
self.dynamo = DynamoDBConnection.connect(region, **kwargs)
示例12: connect_to_host
def connect_to_host(self, *args, **kwargs):
""" Connect the engine to a specific host """
self.connection = DynamoDBConnection.connect_to_host(*args, **kwargs)
示例13: connect_to_region
def connect_to_region(self, region, *args, **kwargs):
""" Connect the engine to an AWS region """
self.connection = DynamoDBConnection.connect_to_region(region, *args,
**kwargs)