improve cloud import

pull/342/head
vapao 2021-06-27 22:28:12 +08:00
parent 26978ac455
commit c4c727ceda
2 changed files with 4 additions and 1 deletions

View File

@ -45,12 +45,13 @@ def cloud_import(request):
host_add_ids = []
for item in instances:
instance_id = item['instance_id']
host_name = item.pop('instance_name')
item['public_ip_address'] = json.dumps(item['public_ip_address'] or [])
item['private_ip_address'] = json.dumps(item['private_ip_address'] or [])
if HostExtend.objects.filter(instance_id=instance_id).exists():
HostExtend.objects.filter(instance_id=instance_id).update(**item)
else:
host = Host.objects.create(name=instance_id, created_by=request.user)
host = Host.objects.create(name=host_name, created_by=request.user)
HostExtend.objects.create(host=host, **item)
host_add_ids.append(host.id)
if host_add_ids:

View File

@ -101,6 +101,7 @@ def fetch_ali_instances(ak, ac, region_id, page_number=1):
network_interface = []
data[item['InstanceId']] = dict(
instance_id=item['InstanceId'],
instance_name=item['InstanceName'],
os_name=item['OSName'],
os_type=check_os_type(item['OSName']),
cpu=item['Cpu'],
@ -149,6 +150,7 @@ def fetch_tencent_instances(ak, ac, region_id, page_number=1):
internet_charge_type = item['InternetAccessible']['InternetChargeType']
data.append(dict(
instance_id=item['InstanceId'],
instance_name=item['InstanceName'],
os_name=item['OsName'],
os_type=check_os_type(item['OsName']),
cpu=item['CPU'],