35 lines
1.6 KiB
Plaintext
35 lines
1.6 KiB
Plaintext
async def ecs_describe_security_group_association_statistics(ns={}):
|
|
import aiohttp
|
|
NETWORK_URL = 'http://api.capitalonline.net/sg/v1'
|
|
action = 'DescribeSecurityGroupAssociationStatistics'
|
|
method = "GET"
|
|
param = {
|
|
'SecurityGroupId': ns.get('SecurityGroupId')
|
|
}
|
|
url = get_signature(action, method, NETWORK_URL, param=param)
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.request(method, url) as response:
|
|
resp = await response.text()
|
|
result = json.loads(resp)
|
|
if result['Code'] == 'Success':
|
|
result['status'] = True
|
|
result.pop('Code')
|
|
result['data'] = result.pop('Data')
|
|
sgi_list = []
|
|
if result['data']['InstanceCount'] > 0:
|
|
for sgi in result['data']['InstanceStatistics']:
|
|
if ns['orgid'] == sgi['InstanceName'].split('0_____0')[0]:
|
|
sgi['InstanceName'] = sgi['InstanceName'].split('0_____0')[-1]
|
|
sgi['Vpc'] = sgi['Vpc'].split('0_____0')[-1]
|
|
sgi_list.append(sgi)
|
|
result['data']['InstanceStatistics'] = sgi_list
|
|
result['data']['InstanceCount'] = len(sgi_list)
|
|
result['msg'] = result.pop('Message')
|
|
else:
|
|
result['status'] = False
|
|
result['msg'] = result.pop('Message')
|
|
return result
|
|
|
|
ret = await ecs_describe_security_group_association_statistics(params_kw)
|
|
return ret
|
|
|