This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
host.py
43 lines (35 loc) · 1.51 KB
/
host.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from .. import settings
from botocore.vendored import requests
from botocore.vendored.requests import adapters
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, NumberAttribute, UTCDateTimeAttribute, JSONAttribute
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
class CustomPynamoSession(requests.Session):
def __init__(self):
super(CustomPynamoSession, self).__init__()
self.mount('http://', adapters.HTTPAdapter(pool_maxsize=settings.value.CONNECTION_POOL_SIZE))
self.mount('https://', adapters.HTTPAdapter(pool_maxsize=settings.value.CONNECTION_POOL_SIZE))
class ServiceRepoNameIndex(GlobalSecondaryIndex):
class Meta:
projection = AllProjection()
read_capacity_units = 30
write_capacity_units = 30
service_repo_name = UnicodeAttribute(hash_key=True)
ip_address = UnicodeAttribute(range_key=True)
class Host(Model):
"""
A DynamoDB Server Host.
"""
class Meta:
table_name = settings.value.DYNAMODB_TABLE_HOSTS
if settings.value.APPLICATION_ENV == 'development':
host = settings.value.DYNAMODB_URL
session_cls = CustomPynamoSession
service = UnicodeAttribute(hash_key=True)
ip_address = UnicodeAttribute(range_key=True)
service_repo_name_index = ServiceRepoNameIndex()
service_repo_name = UnicodeAttribute(null=True)
port = NumberAttribute()
last_check_in = UTCDateTimeAttribute()
revision = UnicodeAttribute()
tags = JSONAttribute()