当前位置: 首页>>代码示例>>Python>>正文


Python layer1.DynamoDBConnection类代码示例

本文整理汇总了Python中boto.dynamodb2.layer1.DynamoDBConnection的典型用法代码示例。如果您正苦于以下问题:Python DynamoDBConnection类的具体用法?Python DynamoDBConnection怎么用?Python DynamoDBConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DynamoDBConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Storage

class Storage():
    def __init__(self, storage_conf):

        self.conf = storage_conf
        self.max_results = storage_conf["max_results"]
        self.publishers = self.conf["publishers"]

        if self.conf["region"] == "localhost":
            from boto.dynamodb2.layer1 import DynamoDBConnection
            self.connection = DynamoDBConnection(
                host='localhost',
                port=8000,
                aws_secret_access_key='anything',
                is_secure=False)

        else:
            self.connection = boto.dynamodb2.connect_to_region(self.conf["region"])

        self.tables = dict()
        for prod in self.publishers:
            self.tables[prod] = Table(self.connection, max_results=self.max_results, **self.conf[prod])

    def close(self):
        """ Closes the connection. This allows you to use with contextlib's closing.
        Mostly necessary for the test DB which seems to only allow a single connection.
        """

        self.connection.close()
开发者ID:iwsmith,项目名称:babel_datapipeline,代码行数:28,代码来源:storage.py

示例2: _make_table

def _make_table(table_func, tablename, read_throughput, write_throughput):
    """Private common function to make a table with a table func"""
    db = DynamoDBConnection()
    dblist = db.list_tables()["TableNames"]
    if tablename not in dblist:
        return table_func(tablename, read_throughput, write_throughput)
    else:
        return Table(tablename)
开发者ID:tomzhang,项目名称:autopush,代码行数:8,代码来源:db.py

示例3: delete_dynamodb

def delete_dynamodb():

    conn = DynamoDBConnection(aws_access_key_id=AWS_ACCESS_KEY,
                              aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
                              region = RegionInfo(name=REGION,
                                                  endpoint='dynamodb.{0}.amazonaws.com'.format(REGION)))

    conn.delete_table(EASY_LIST_TBL)
    conn.close()
开发者ID:yoavfrancis,项目名称:CloudCachingProxy,代码行数:9,代码来源:dynamodb.py

示例4: get_rotating_message_table

def get_rotating_message_table(prefix="message", delta=0):
    """Gets the message table for the current month."""
    db = DynamoDBConnection()
    dblist = db.list_tables()["TableNames"]
    tablename = make_rotating_tablename(prefix, delta)
    if tablename not in dblist:
        return create_rotating_message_table(prefix=prefix, delta=delta)
    else:
        return Table(tablename)
开发者ID:tomzhang,项目名称:autopush,代码行数:9,代码来源:db.py

示例5: test_custom_tablename

    def test_custom_tablename(self):
        db = DynamoDBConnection()
        db_name = "storage_%s" % uuid.uuid4()
        dblist = db.list_tables()["TableNames"]
        assert db_name not in dblist

        create_storage_table(db_name)
        dblist = db.list_tables()["TableNames"]
        assert db_name in dblist
开发者ID:ncalexan,项目名称:autopush,代码行数:9,代码来源:test_db.py

示例6: Init

def Init():
    """
    Connect to DynamoDB Local. If you want to connect to the real DynamoDB set the 'local'
    variable below to Fals, but make sure either you have a .boto file or you
    pass both the aws_access_key_id and aws_secret_access_key parameters to the create
    (this code fetches them from settings.cfg).
    """
    local = True

    if local:
        # Connect to local DynamoDB server. Make sure you have that running first.
        conn = DynamoDBConnection(
            host='localhost',
            port=8001,
            aws_secret_access_key='anything',
            is_secure=False)
    else:
        # Connect to the real DynamoDB.
        config = ConfigParser.RawConfigParser()
        config.read("settings.cfg")
        id = config.get('DynamoDB', 'aws_access_key_id')
        key = config.get('DynamoDB', 'aws_secret_access_key')

        conn = boto.dynamodb2.connect_to_region('us-west-2',
            aws_access_key_id = id, aws_secret_access_key = key)

    # Get a list of all tables from DynamoDB.
    tables = conn.list_tables()
    #print "Tables:", tables

    """
    If there isn't an employees table then create it. The table has a primary key of the
    employee type and id, allowing you to query them. It has a secondary index on the 
    employee type and title, allowing you to query them as well.
    """

    if 'employees' not in tables['TableNames']:
        # Create table of employees
        print "Creating new table"
        employees = Table.create('employees',
                                 schema = [HashKey('etype'), RangeKey('id')],
                                 indexes = [AllIndex('TitleIndex', parts = [
                                                HashKey('etype'),
                                                RangeKey('title')])],
                                 connection = conn)
        # Wait for table to be created (DynamoDB has eventual consistency)
        while True:
            time.sleep(5)
            try:
                conn.describe_table('employees')
            except Exception, e:
                print e
            else:
                break
开发者ID:dkothari777,项目名称:CSC346,代码行数:54,代码来源:helpers.py

示例7: test_dynamodb

    def test_dynamodb(self):
        host = os.getenv('DYNAMODB_PORT_8000_TCP_ADDR')
        port = int(os.getenv('DYNAMODB_PORT_8000_TCP_PORT'))
        
        conn = DynamoDBConnection(
            host=host,
            port=port,
            aws_access_key_id='anything',
            aws_secret_access_key='anything',
            is_secure=False)

        tables = conn.list_tables()
开发者ID:UltronTeam,项目名称:docker-dynamodb,代码行数:12,代码来源:main.py

示例8: main

def main():
    if len(sys.argv) == 2 and sys.argv[1] == 'check':
        print "*** Checking the table in dynamoDB, create one if not exist..."
        try:
            ddbc = DynamoDBConnection()
            src = ddbc.describe_table(iperf_table_name)['Table']
            logs = Table(iperf_table_name, schema=[HashKey('path'),RangeKey('datetime'),])
            logs.describe()
            sys.exit(0)
        except JSONResponseError:
            logs = Table.create(iperf_table_name, schema=[HashKey('path'),RangeKey('datetime'),])
            while ddbc.describe_table(iperf_table_name)['Table']['TableStatus'] != 'ACTIVE':
                sleep(3)
            sys.exit(1)
    if len(sys.argv) != 4:
        print "usage: %s <iperf_client_name> <datetime> <iperf_server_name>" % sys.argv[0]
        sys.exit(2)

    # Store arg lists
    iperf_client_name = sys.argv[1]
    datetime = sys.argv[2]
    iperf_server_name = sys.argv[3]
    path = iperf_client_name + '-' + iperf_server_name

    # Retrieve dynamoDB object
    try:
        logs = Table(iperf_table_name, schema=[HashKey('path'),RangeKey('datetime'),])
        tmp = logs.describe()
    except JSONResponseError:
        print "The table %s doesn't exist!" % iperf_table_name
        sys.exit(1)

    # Parse iperf log
    iperf = {}
    iperf['path'] = path
    iperf['datetime'] = datetime
    line = open(os.path.dirname(os.path.abspath(__file__))+'/log/'+datetime+'.log','r').readlines()[6]
    m = re.search(r"sec\s+(\d+\s+\w+)\s+(\d+\s+[\w/]+)", line)
    transfer = m.group(1)
    bandwidth = m.group(2)
    iperf['transfer'] = transfer
    iperf['bandwidth'] = bandwidth

    # Put the log to the dynamoDB table
    try:
        logs.put_item(data=iperf, overwrite=True)
    except ValidationException:
        pprint(iperf)
    except JSONResponseError:
        pass
开发者ID:iomz,项目名称:cloud-bench,代码行数:50,代码来源:upload_iperf_log.py

示例9: init_tables

def init_tables(models_module):
    models = [getattr(models_module, name) for name in dir(models_module)]
    models = [model for model in models
              if inspect.isclass(model) and issubclass(model, Model) and not model == Model]

    conn = DynamoDBConnection()
    table_names = conn.list_tables()['TableNames']
    for model in models:
        if getattr(model, 'skip_create', False):
            continue
        if model.get_table_name() in table_names:
            continue
        model.create_table()
        [load_fixture(model, fixture) for fixture in getattr(model, '__fixtures__', [])]
开发者ID:BalanceCareerInc,项目名称:BynamoDB,代码行数:14,代码来源:manage.py

示例10: get_storage_table

def get_storage_table(tablename="storage", read_throughput=5,
                      write_throughput=5):
    """Get the main storage table object

    Creates the table if it doesn't already exist, otherwise returns the
    existing table.

    """
    db = DynamoDBConnection()
    dblist = db.list_tables()["TableNames"]
    if tablename not in dblist:
        return create_storage_table(tablename, read_throughput,
                                    write_throughput)
    else:
        return Table(tablename)
开发者ID:crodjer,项目名称:autopush,代码行数:15,代码来源:db.py

示例11: connect_local_dynamodb

 def connect_local_dynamodb(self):
     self.conn = DynamoDBConnection(
         host='localhost',
         port=8010,
         aws_access_key_id='anything',
         aws_secret_access_key='anything',
         is_secure=False)
开发者ID:leehosung,项目名称:nursery-crawl,代码行数:7,代码来源:test_common.py

示例12: connect_fake

 def connect_fake(self):
     self.conn = DynamoDBConnection(
         aws_access_key_id='foo',
         aws_secret_access_key='bar',
         host='localhost',
         port=8000,
         is_secure=False)
开发者ID:idxp,项目名称:pyidxp,代码行数:7,代码来源:dynamodb.py

示例13: pytest_runtest_teardown

def pytest_runtest_teardown():
    conn = DynamoDBConnection()
    conn.delete_table(Message.get_table_name())
    conn.delete_table(ChannelJoinInfo.get_table_name())
    conn.delete_table(ChannelUsageLog.get_table_name())
    conn.delete_table(Channel.get_table_name())
    conn.delete_table(ChannelWithdrawalLog.get_table_name())

    Message.create_table()
    ChannelWithdrawalLog.create_table()
    ChannelJoinInfo.create_table()
    ChannelUsageLog.create_table()
    Channel.create_table()
开发者ID:madhuneal,项目名称:dnachat,代码行数:13,代码来源:conftest.py

示例14: getDynamoDBConnection

def getDynamoDBConnection(config=None, endpoint=None, port=None, local=False, use_instance_metadata=False):
    if local:
        db = DynamoDBConnection(
            host=endpoint,
            port=port,
            aws_secret_access_key='AKIAIZ2NKAVOD4UIJNVQ', 
            aws_access_key_id='7W5NMo91HGR7cuojCx0kPizKtk65btiB6co315qt',   
            is_secure=False)

        print "==============="
        print db.list_tables()
        print "==============="

    else:
        params = {
            'is_secure': True
            }

        # Read from config file, if provided
        if config is not None:
            if config.has_option('dynamodb', 'region'):
                params['region'] = config.get('dynamodb', 'region')
            if config.has_option('dynamodb', 'endpoint'):
                params['host'] = config.get('dynamodb', 'endpoint')

            if config.has_option('dynamodb', 'aws_access_key_id'):
                params['aws_access_key_id'] = config.get('dynamodb', 'aws_access_key_id')
                params['aws_secret_access_key'] = config.get('dynamodb', 'aws_secret_access_key')

        # Use the endpoint specified on the command-line to trump the config file
        if endpoint is not None:
            params['host'] = endpoint
            if 'region' in params:
                del params['region']

        # Only auto-detect the DynamoDB endpoint if the endpoint was not specified through other config
        if 'host' not in params and use_instance_metadata:
            response = urllib2.urlopen('http://169.254.169.254/latest/dynamic/instance-identity/document').read()
            doc = json.loads(response);
            params['host'] = 'dynamodb.%s.amazonaws.com' % (doc['region'])
            if 'region' in params:
                del params['region']

        db = DynamoDBConnection(**params)
    return db
开发者ID:cqw1,项目名称:medical_db,代码行数:45,代码来源:setupDynamoDB.py

示例15: __init__

    def __init__(self):
        aws_access_key_id = os.environ['S3_KEY']  # I AM OPS U NO GET MY KEYS
        aws_secret_access_key = os.environ['S3_SECRET']  # DIS IS MY JOB

        self._conn = DynamoDBConnection(
            aws_access_key_id=aws_access_key_id, 
            aws_secret_access_key=aws_secret_access_key)
        self.works_table = Table('ao3rdr-works', connection=self._conn)
        self.immutable_fields = ['work_id', 'user_id']
开发者ID:clach04,项目名称:AO3rdr-backend,代码行数:9,代码来源:dbconn.py


注:本文中的boto.dynamodb2.layer1.DynamoDBConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。