-
Notifications
You must be signed in to change notification settings - Fork 1
/
aws.py
37 lines (27 loc) · 1.13 KB
/
aws.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
import re
import json
from pydash.objects import get
from app.repository.externalMaestroData import ExternalMaestroData
from app.libs.cache import CacheMemory
class HookedAWS(object):
@staticmethod
def cpuAndMemoryByInstanceType(obj, conn):
instance = get(obj, 'datacenters.instance')
if instance:
data = CacheMemory.get(instance)
if not data:
query = json.dumps({'api_name': instance})
result = ExternalMaestroData() \
.post_request(path="flavors_public", body={'query': query}) \
.get_results('items')
if result:
content = get(result, '[0]')
vcpus = get(content, 'vcpus')
memory = get(content, 'memory')
if vcpus and memory:
data = {
'cpu': int(re.search(r'([0-9]*)', vcpus).group()),
'memory': float(re.search(r'([0-9\.]*)', memory).group()),
}
CacheMemory.set(instance, data)
return data