in syndicate/connection/dynamo_connection.py [0:0]
def create_table(self, table_name, hash_key_name, hash_key_type,
sort_key_name=None, sort_key_type=None, read_throughput=None,
write_throughput=None, wait=True, global_indexes=None,
local_indexes=None, tags=None):
""" Table creation.
:type table_name: str
:type hash_key_name: str
:type hash_key_type: N/S/B
:type sort_key_name: str
:type sort_key_type: N/S/B
:type read_throughput: int
:type write_throughput: int
:type wait: bool
:type global_indexes: dict
:type local_indexes: dict
:type tags: list of dict
:returns created table
"""
params = dict()
if not read_throughput and not write_throughput:
_LOG.info('No write_capacity neither read_capacity are specified. '
'Setting on-demand mode')
params['BillingMode'] = 'PAY_PER_REQUEST'
else:
_LOG.info('Read or/and write capacity are specified. '
'Using provisioned mode.')
params['BillingMode'] = 'PROVISIONED'
params['ProvisionedThroughput'] = dict(
ReadCapacityUnits=read_throughput or DEFAULT_READ_CAPACITY,
WriteCapacityUnits=write_throughput or DEFAULT_WRITE_CAPACITY)
schema = [dict(AttributeName=hash_key_name, KeyType='HASH')]
definition = [dict(AttributeName=hash_key_name,
AttributeType=hash_key_type)]
stream = {'StreamEnabled': False}
if sort_key_name:
schema.append(dict(AttributeName=sort_key_name,
KeyType='RANGE'))
definition.append(dict(AttributeName=sort_key_name,
AttributeType=sort_key_type))
if global_indexes:
for index in global_indexes:
_add_index_keys_to_definition(definition=definition,
index=index)
if local_indexes:
for index in local_indexes:
_add_index_keys_to_definition(definition=definition,
index=index)
params.update(dict(
TableName=table_name, KeySchema=schema,
AttributeDefinitions=definition, StreamSpecification=stream
))
if global_indexes:
params['GlobalSecondaryIndexes'] = []
for index in global_indexes:
index_info = _build_global_index_definition(index,
read_throughput,
write_throughput)
params['GlobalSecondaryIndexes'].append(index_info)
if local_indexes:
params['LocalSecondaryIndexes'] = []
for index in local_indexes:
index_info = _build_index_definition(index)
params['LocalSecondaryIndexes'].append(index_info)
if tags:
params['Tags'] = tags
table = self.conn.create_table(**params)
if wait:
waiter = table.meta.client.get_waiter('table_exists')
waiter.wait(TableName=table_name)
return table