Esempio n. 1
0
    def create_schema(self, hash_key_name, hash_key_proto_value,
                      range_key_name=None, range_key_proto_value=None):
        """
        Create a Schema object used when creating a Table.

        :type hash_key_name: str
        :param hash_key_name: The name of the HashKey for the schema.

        :type hash_key_proto_value: int|long|float|str|unicode|Binary
        :param hash_key_proto_value: A sample or prototype of the type
            of value you want to use for the HashKey.  Alternatively,
            you can also just pass in the Python type (e.g. int, float, etc.).

        :type range_key_name: str
        :param range_key_name: The name of the RangeKey for the schema.
            This parameter is optional.

        :type range_key_proto_value: int|long|float|str|unicode|Binary
        :param range_key_proto_value: A sample or prototype of the type
            of value you want to use for the RangeKey.  Alternatively,
            you can also pass in the Python type (e.g. int, float, etc.)
            This parameter is optional.
        """
        hash_key = (hash_key_name, get_dynamodb_type(hash_key_proto_value))
        if range_key_name and range_key_proto_value is not None:
            range_key = (range_key_name,
                         get_dynamodb_type(range_key_proto_value))
        else:
            range_key = None
        return Schema.create(hash_key, range_key)
Esempio n. 2
0
    def create_schema(self,
                      hash_key_name,
                      hash_key_proto_value,
                      range_key_name=None,
                      range_key_proto_value=None):
        """
        Create a Schema object used when creating a Table.

        :type hash_key_name: str
        :param hash_key_name: The name of the HashKey for the schema.

        :type hash_key_proto_value: int|long|float|str|unicode|Binary
        :param hash_key_proto_value: A sample or prototype of the type
            of value you want to use for the HashKey.  Alternatively,
            you can also just pass in the Python type (e.g. int, float, etc.).

        :type range_key_name: str
        :param range_key_name: The name of the RangeKey for the schema.
            This parameter is optional.

        :type range_key_proto_value: int|long|float|str|unicode|Binary
        :param range_key_proto_value: A sample or prototype of the type
            of value you want to use for the RangeKey.  Alternatively,
            you can also pass in the Python type (e.g. int, float, etc.)
            This parameter is optional.
        """
        hash_key = (hash_key_name, get_dynamodb_type(hash_key_proto_value))
        if range_key_name and range_key_proto_value is not None:
            range_key = (range_key_name,
                         get_dynamodb_type(range_key_proto_value))
        else:
            range_key = None
        return Schema.create(hash_key, range_key)
Esempio n. 3
0
	def _connect(self):
		args = dict(aws_access_key_id=self.db_user,
					aws_secret_access_key=self.db_passwd,
					is_secure=self.enable_ssl)
		try:
			region = [x for x in boto.dynamodb.regions() if x.endpoint == self.db_host][0]
			args['region'] = region
		except IndexError:
			pass
		self._dynamodb = boto.connect_dynamodb(**args)
		# Look up or create a new table for this item
		try:
			self._table = self._dynamodb.lookup(self.db_name)
		except boto.exception.DynamoDBResponseError:
			self._table = None
		if not self._table:
			from boto.dynamodb.schema import Schema
			self._table = self._dynamodb.create_table(
				name=self.db_name,
				schema=Schema.create(hash_key=('__id__', 'S')),
				read_units=1,
				write_units=1)
			while self._table.status == 'CREATING':
				time.sleep(1)
				self._table.refresh()
Esempio n. 4
0
File: table.py Progetto: jacobh/boto
 def update_from_response(self, response):
     """
     Update the state of the Table object based on the response
     data received from Amazon DynamoDB.
     """
     if 'Table' in response:
         self._dict.update(response['Table'])
     elif 'TableDescription' in response:
         self._dict.update(response['TableDescription'])
     if 'KeySchema' in self._dict:
         self._schema = Schema(self._dict['KeySchema'])
def dynamodb_load(tables, in_dir, create_tables):
    conn = boto.connect_dynamodb()
    for t in tables:
        metadata_file = os.path.join(in_dir, "%s.metadata" % t)
        data_file = os.path.join(in_dir, "%s.data" % t)
        if create_tables:
            with open(metadata_file) as meta_fd:
                metadata = json.load(meta_fd)
            table = conn.create_table(
                name=t,
                schema=Schema(metadata["schema"]),
                read_units=metadata["read_units"],
                write_units=metadata["write_units"],
            )
            table.refresh(wait_for_active=True)
        else:
            table = conn.get_table(t)

        with open(data_file) as in_fd:
            load_table(table, in_fd)
Esempio n. 6
0
    def create_schema(self,
                      hash_key_name,
                      hash_key_proto_value,
                      range_key_name=None,
                      range_key_proto_value=None):
        """
        Create a Schema object used when creating a Table.

        :type hash_key_name: str
        :param hash_key_name: The name of the HashKey for the schema.

        :type hash_key_proto_value: int|long|float|str|unicode
        :param hash_key_proto_value: A sample or prototype of the type
            of value you want to use for the HashKey.  Alternatively,
            you can also just pass in the Python type (e.g. int, float, etc.).

        :type range_key_name: str
        :param range_key_name: The name of the RangeKey for the schema.
            This parameter is optional.

        :type range_key_proto_value: int|long|float|str|unicode
        :param range_key_proto_value: A sample or prototype of the type
            of value you want to use for the RangeKey.  Alternatively,
            you can also pass in the Python type (e.g. int, float, etc.)
            This parameter is optional.
        """
        schema = {}
        hash_key = {}
        hash_key['AttributeName'] = hash_key_name
        hash_key_type = get_dynamodb_type(hash_key_proto_value)
        hash_key['AttributeType'] = hash_key_type
        schema['HashKeyElement'] = hash_key
        if range_key_name and range_key_proto_value is not None:
            range_key = {}
            range_key['AttributeName'] = range_key_name
            range_key_type = get_dynamodb_type(range_key_proto_value)
            range_key['AttributeType'] = range_key_type
            schema['RangeKeyElement'] = range_key
        return Schema(schema)
Esempio n. 7
0
 def setUp(self):
     self.dynamodb = Layer2()
     self.schema = Schema.create(('foo', 'N'), ('bar', 'S'))
     self.table_name = 'testtable%s' % int(time.time())
Esempio n. 8
0
 def _get_schema(self):
     from boto.dynamodb.schema import Schema
     return Schema.create(
         hash_key=('client_id', 'S'),
         range_key=('ts', 'N'))
Esempio n. 9
0
 def setUp(self):
     self.dynamodb = Layer2()
     self.schema = Schema.create(('foo', 'N'), ('bar', 'S'))
     self.table_name = 'testtable%s' % int(time.time())