mirror of https://github.com/openspug/spug
improve cloud import
parent
26978ac455
commit
c4c727ceda
|
@ -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:
|
||||
|
|
|
@ -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'],
|
||||
|
|
Loading…
Reference in New Issue