# 检查实例的运行状态 def check_instance_running(instance_ids): instances_list = [ {'ResourceGroupId': '', 'Memory': 8192, 'InstanceChargeType': 'PostPaid', 'Cpu': 4, 'OSName': 'CentOS 7.8 64位', 'InstanceNetworkType': 'vpc', 'InnerIpAddress': {'IpAddress': []}, 'ExpiredTime': '2099-12-31T15:59Z', 'ImageId': 'm-2ze3uv2gz5dsy0ol2i4x', 'EipAddress': {'AllocationId': '', 'IpAddress': '', 'InternetChargeType': ''}, 'ImageOptions': {}, 'HostName': 'iZ2zegj32en19tn3f09u4fZ', 'Tags': {'Tag': [{'TagKey': 'acs:ecs:payType', 'TagValue': 'spot'}]}, 'VlanId': '', 'Status': 'Running', 'HibernationOptions': {'Configured': False}, 'MetadataOptions': {'HttpTokens': '', 'HttpEndpoint': ''}, 'InstanceId': 'i-2zegj32en19tn3f09u4f', 'StoppedMode': 'Not-applicable', 'CpuOptions': {'ThreadsPerCore': 2, 'Numa': 'N/A', 'CoreCount': 2}, 'StartTime': '2023-10-16T02:57Z', 'DeletionProtection': False, 'SecurityGroupIds': {'SecurityGroupId': ['sg-2ze6zhxrqy9vueae27xy']}, 'VpcAttributes': {'PrivateIpAddress': {'IpAddress': ['172.17.4.192']}, 'VpcId': 'vpc-2zee8yqxobahsyfg9d11h', 'VSwitchId': 'vsw-2ze586sxfwsaov4s5w88d', 'NatIpAddress': ''}, 'InternetChargeType': 'PayByTraffic', 'InstanceName': 'img2txt', 'DeploymentSetId': '', 'InternetMaxBandwidthOut': 0, 'SerialNumber': '6428aa21-5136-44ce-952d-cb20983ff2ef', 'OSType': 'linux', 'CreationTime': '2023-10-16T02:57Z', 'AutoReleaseTime': '', 'Description': '', 'InstanceTypeFamily': 'ecs.c6', 'DedicatedInstanceAttribute': {'Tenancy': '', 'Affinity': ''}, 'SpotDuration': 1, 'PublicIpAddress': {'IpAddress': []}, 'GPUSpec': '', 'NetworkInterfaces': {'NetworkInterface': [ {'Type': 'Primary', 'PrimaryIpAddress': '172.17.4.192', 'MacAddress': '00:16:3e:0a:b6:5f', 'NetworkInterfaceId': 'eni-2ze6xmbgo5yki9613pxa', 'PrivateIpSets': {'PrivateIpSet': [{'PrivateIpAddress': '172.17.4.192', 'Primary': True}]}}]}, 'SpotPriceLimit': 0.0, 'DeviceAvailable': True, 'SaleCycle': '', 'InstanceType': 'ecs.c6.xlarge', 'SpotStrategy': 'SpotAsPriceGo', 'OSNameEn': 'CentOS 7.8 64 bit', 'IoOptimized': True, 'ZoneId': 'cn-beijing-g', 'ClusterId': '', 'EcsCapacityReservationAttr': {'CapacityReservationPreference': '', 'CapacityReservationId': ''}, 'DedicatedHostAttribute': {'DedicatedHostId': '', 'DedicatedHostName': '', 'DedicatedHostClusterId': ''}, 'GPUAmount': 0, 'OperationLocks': {'LockReason': []}, 'InternetMaxBandwidthIn': -1, 'Recyclable': False, 'RegionId': 'cn-beijing', 'CreditSpecification': ''}, {'ResourceGroupId': '', 'Memory': 8192, 'InstanceChargeType': 'PostPaid', 'Cpu': 4, 'OSName': 'CentOS 7.8 64位', 'InstanceNetworkType': 'vpc', 'InnerIpAddress': {'IpAddress': []}, 'ExpiredTime': '2099-12-31T15:59Z', 'ImageId': 'm-2ze3uv2gz5dsy0ol2i4x', 'EipAddress': {'AllocationId': '', 'IpAddress': '', 'InternetChargeType': ''}, 'ImageOptions': {}, 'HostName': 'iZ2ze8cqacj7opo8vu6l4lZ', 'Tags': {'Tag': [{'TagKey': 'acs:ecs:payType', 'TagValue': 'spot'}]}, 'VlanId': '', 'Status': 'Running', 'HibernationOptions': {'Configured': False}, 'MetadataOptions': {'HttpTokens': '', 'HttpEndpoint': ''}, 'InstanceId': 'i-2ze8cqacj7opo8vu6l4l', 'StoppedMode': 'Not-applicable', 'CpuOptions': {'ThreadsPerCore': 2, 'Numa': 'N/A', 'CoreCount': 2}, 'StartTime': '2023-10-16T02:58Z', 'DeletionProtection': False, 'SecurityGroupIds': {'SecurityGroupId': ['sg-2ze6zhxrqy9vueae27xy']}, 'VpcAttributes': {'PrivateIpAddress': {'IpAddress': ['172.17.4.208']}, 'VpcId': 'vpc-2zee8yqxobahsyfg9d11h', 'VSwitchId': 'vsw-2ze586sxfwsaov4s5w88d', 'NatIpAddress': ''}, 'InternetChargeType': 'PayByTraffic', 'InstanceName': 'img2txt', 'DeploymentSetId': '', 'InternetMaxBandwidthOut': 0, 'SerialNumber': '36983a92-e480-4c66-832f-8085b8f26625', 'OSType': 'linux', 'CreationTime': '2023-10-16T02:57Z', 'AutoReleaseTime': '', 'Description': '', 'InstanceTypeFamily': 'ecs.c6', 'DedicatedInstanceAttribute': {'Tenancy': '', 'Affinity': ''}, 'SpotDuration': 1, 'PublicIpAddress': {'IpAddress': []}, 'GPUSpec': '', 'NetworkInterfaces': {'NetworkInterface': [ {'Type': 'Primary', 'PrimaryIpAddress': '172.17.4.208', 'MacAddress': '00:16:3e:0c:5f:2f', 'NetworkInterfaceId': 'eni-2ze8uw6bxge799csyuun', 'PrivateIpSets': {'PrivateIpSet': [{'PrivateIpAddress': '172.17.4.208', 'Primary': True}]}}]}, 'SpotPriceLimit': 0.0, 'DeviceAvailable': True, 'SaleCycle': '', 'InstanceType': 'ecs.c6.xlarge', 'SpotStrategy': 'SpotAsPriceGo', 'OSNameEn': 'CentOS 7.8 64 bit', 'IoOptimized': True, 'ZoneId': 'cn-beijing-g', 'ClusterId': '', 'EcsCapacityReservationAttr': {'CapacityReservationPreference': '', 'CapacityReservationId': ''}, 'DedicatedHostAttribute': {'DedicatedHostId': '', 'DedicatedHostName': '', 'DedicatedHostClusterId': ''}, 'GPUAmount': 0, 'OperationLocks': {'LockReason': []}, 'InternetMaxBandwidthIn': -1, 'Recyclable': False, 'RegionId': 'cn-beijing', 'CreditSpecification': ''}, {'ResourceGroupId': '', 'Memory': 8192, 'InstanceChargeType': 'PostPaid', 'Cpu': 4, 'OSName': 'CentOS 7.8 64位', 'InstanceNetworkType': 'vpc', 'InnerIpAddress': {'IpAddress': []}, 'ExpiredTime': '2099-12-31T15:59Z', 'ImageId': 'm-2ze3uv2gz5dsy0ol2i4x', 'EipAddress': {'AllocationId': '', 'IpAddress': '', 'InternetChargeType': ''}, 'ImageOptions': {}, 'HostName': 'iZ2zegj32en19tn3f09u4jZ', 'Tags': {'Tag': [{'TagKey': 'acs:ecs:payType', 'TagValue': 'spot'}]}, 'VlanId': '', 'Status': 'Running', 'HibernationOptions': {'Configured': False}, 'MetadataOptions': {'HttpTokens': '', 'HttpEndpoint': ''}, 'InstanceId': 'i-2zegj32en19tn3f09u4j', 'StoppedMode': 'Not-applicable', 'CpuOptions': {'ThreadsPerCore': 2, 'Numa': 'N/A', 'CoreCount': 2}, 'StartTime': '2023-10-16T02:57Z', 'DeletionProtection': False, 'SecurityGroupIds': {'SecurityGroupId': ['sg-2ze6zhxrqy9vueae27xy']}, 'VpcAttributes': {'PrivateIpAddress': {'IpAddress': ['172.17.4.194']}, 'VpcId': 'vpc-2zee8yqxobahsyfg9d11h', 'VSwitchId': 'vsw-2ze586sxfwsaov4s5w88d', 'NatIpAddress': ''}, 'InternetChargeType': 'PayByTraffic', 'InstanceName': 'img2txt', 'DeploymentSetId': '', 'InternetMaxBandwidthOut': 0, 'SerialNumber': '6591e447-686e-48bb-82e9-e66977310d7d', 'OSType': 'linux', 'CreationTime': '2023-10-16T02:57Z', 'AutoReleaseTime': '', 'Description': '', 'InstanceTypeFamily': 'ecs.c6', 'DedicatedInstanceAttribute': {'Tenancy': '', 'Affinity': ''}, 'SpotDuration': 1, 'PublicIpAddress': {'IpAddress': []}, 'GPUSpec': '', 'NetworkInterfaces': {'NetworkInterface': [ {'Type': 'Primary', 'PrimaryIpAddress': '172.17.4.194', 'MacAddress': '00:16:3e:34:4d:c6', 'NetworkInterfaceId': 'eni-2zefr02rdalqltlrbxk2', 'PrivateIpSets': {'PrivateIpSet': [{'PrivateIpAddress': '172.17.4.194', 'Primary': True}]}}]}, 'SpotPriceLimit': 0.0, 'DeviceAvailable': True, 'SaleCycle': '', 'InstanceType': 'ecs.c6.xlarge', 'SpotStrategy': 'SpotAsPriceGo', 'OSNameEn': 'CentOS 7.8 64 bit', 'IoOptimized': True, 'ZoneId': 'cn-beijing-g', 'ClusterId': '', 'EcsCapacityReservationAttr': {'CapacityReservationPreference': '', 'CapacityReservationId': ''}, 'DedicatedHostAttribute': {'DedicatedHostId': '', 'DedicatedHostName': '', 'DedicatedHostClusterId': ''}, 'GPUAmount': 0, 'OperationLocks': {'LockReason': []}, 'InternetMaxBandwidthIn': -1, 'Recyclable': False, 'RegionId': 'cn-beijing', 'CreditSpecification': ''}] instances = [] for instance_detail in instances_list: vpc_attributes = instance_detail.get('VpcAttributes',{}).get('PrivateIpAddress',{}).get('IpAddress',[]) intranet_ip = vpc_attributes[0] if len(vpc_attributes) > 0 else None instances.append((instance_detail.get('InstanceId'), instance_detail.get('Status'),intranet_ip)) return instances d={(1,2):3} for (k,v),v2 in d.items(): print(k,v,v2) d.pop((1,2)) print(d)