test.py 8.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 检查实例的运行状态
  2. def check_instance_running(instance_ids):
  3. instances_list = [
  4. {'ResourceGroupId': '', 'Memory': 8192, 'InstanceChargeType': 'PostPaid', 'Cpu': 4, 'OSName': 'CentOS 7.8 64位',
  5. 'InstanceNetworkType': 'vpc', 'InnerIpAddress': {'IpAddress': []}, 'ExpiredTime': '2099-12-31T15:59Z',
  6. 'ImageId': 'm-2ze3uv2gz5dsy0ol2i4x',
  7. 'EipAddress': {'AllocationId': '', 'IpAddress': '', 'InternetChargeType': ''}, 'ImageOptions': {},
  8. 'HostName': 'iZ2zegj32en19tn3f09u4fZ', 'Tags': {'Tag': [{'TagKey': 'acs:ecs:payType', 'TagValue': 'spot'}]},
  9. 'VlanId': '', 'Status': 'Running', 'HibernationOptions': {'Configured': False},
  10. 'MetadataOptions': {'HttpTokens': '', 'HttpEndpoint': ''}, 'InstanceId': 'i-2zegj32en19tn3f09u4f',
  11. 'StoppedMode': 'Not-applicable', 'CpuOptions': {'ThreadsPerCore': 2, 'Numa': 'N/A', 'CoreCount': 2},
  12. 'StartTime': '2023-10-16T02:57Z', 'DeletionProtection': False,
  13. 'SecurityGroupIds': {'SecurityGroupId': ['sg-2ze6zhxrqy9vueae27xy']},
  14. 'VpcAttributes': {'PrivateIpAddress': {'IpAddress': ['172.17.4.192']}, 'VpcId': 'vpc-2zee8yqxobahsyfg9d11h',
  15. 'VSwitchId': 'vsw-2ze586sxfwsaov4s5w88d', 'NatIpAddress': ''},
  16. 'InternetChargeType': 'PayByTraffic', 'InstanceName': 'img2txt', 'DeploymentSetId': '',
  17. 'InternetMaxBandwidthOut': 0, 'SerialNumber': '6428aa21-5136-44ce-952d-cb20983ff2ef', 'OSType': 'linux',
  18. 'CreationTime': '2023-10-16T02:57Z', 'AutoReleaseTime': '', 'Description': '', 'InstanceTypeFamily': 'ecs.c6',
  19. 'DedicatedInstanceAttribute': {'Tenancy': '', 'Affinity': ''}, 'SpotDuration': 1,
  20. 'PublicIpAddress': {'IpAddress': []}, 'GPUSpec': '', 'NetworkInterfaces': {'NetworkInterface': [
  21. {'Type': 'Primary', 'PrimaryIpAddress': '172.17.4.192', 'MacAddress': '00:16:3e:0a:b6:5f',
  22. 'NetworkInterfaceId': 'eni-2ze6xmbgo5yki9613pxa',
  23. 'PrivateIpSets': {'PrivateIpSet': [{'PrivateIpAddress': '172.17.4.192', 'Primary': True}]}}]},
  24. 'SpotPriceLimit': 0.0, 'DeviceAvailable': True, 'SaleCycle': '', 'InstanceType': 'ecs.c6.xlarge',
  25. 'SpotStrategy': 'SpotAsPriceGo', 'OSNameEn': 'CentOS 7.8 64 bit', 'IoOptimized': True,
  26. 'ZoneId': 'cn-beijing-g', 'ClusterId': '',
  27. 'EcsCapacityReservationAttr': {'CapacityReservationPreference': '', 'CapacityReservationId': ''},
  28. 'DedicatedHostAttribute': {'DedicatedHostId': '', 'DedicatedHostName': '', 'DedicatedHostClusterId': ''},
  29. 'GPUAmount': 0, 'OperationLocks': {'LockReason': []}, 'InternetMaxBandwidthIn': -1, 'Recyclable': False,
  30. 'RegionId': 'cn-beijing', 'CreditSpecification': ''},
  31. {'ResourceGroupId': '', 'Memory': 8192, 'InstanceChargeType': 'PostPaid', 'Cpu': 4, 'OSName': 'CentOS 7.8 64位',
  32. 'InstanceNetworkType': 'vpc', 'InnerIpAddress': {'IpAddress': []}, 'ExpiredTime': '2099-12-31T15:59Z',
  33. 'ImageId': 'm-2ze3uv2gz5dsy0ol2i4x',
  34. 'EipAddress': {'AllocationId': '', 'IpAddress': '', 'InternetChargeType': ''}, 'ImageOptions': {},
  35. 'HostName': 'iZ2ze8cqacj7opo8vu6l4lZ', 'Tags': {'Tag': [{'TagKey': 'acs:ecs:payType', 'TagValue': 'spot'}]},
  36. 'VlanId': '', 'Status': 'Running', 'HibernationOptions': {'Configured': False},
  37. 'MetadataOptions': {'HttpTokens': '', 'HttpEndpoint': ''}, 'InstanceId': 'i-2ze8cqacj7opo8vu6l4l',
  38. 'StoppedMode': 'Not-applicable', 'CpuOptions': {'ThreadsPerCore': 2, 'Numa': 'N/A', 'CoreCount': 2},
  39. 'StartTime': '2023-10-16T02:58Z', 'DeletionProtection': False,
  40. 'SecurityGroupIds': {'SecurityGroupId': ['sg-2ze6zhxrqy9vueae27xy']},
  41. 'VpcAttributes': {'PrivateIpAddress': {'IpAddress': ['172.17.4.208']}, 'VpcId': 'vpc-2zee8yqxobahsyfg9d11h',
  42. 'VSwitchId': 'vsw-2ze586sxfwsaov4s5w88d', 'NatIpAddress': ''},
  43. 'InternetChargeType': 'PayByTraffic', 'InstanceName': 'img2txt', 'DeploymentSetId': '',
  44. 'InternetMaxBandwidthOut': 0, 'SerialNumber': '36983a92-e480-4c66-832f-8085b8f26625', 'OSType': 'linux',
  45. 'CreationTime': '2023-10-16T02:57Z', 'AutoReleaseTime': '', 'Description': '', 'InstanceTypeFamily': 'ecs.c6',
  46. 'DedicatedInstanceAttribute': {'Tenancy': '', 'Affinity': ''}, 'SpotDuration': 1,
  47. 'PublicIpAddress': {'IpAddress': []}, 'GPUSpec': '', 'NetworkInterfaces': {'NetworkInterface': [
  48. {'Type': 'Primary', 'PrimaryIpAddress': '172.17.4.208', 'MacAddress': '00:16:3e:0c:5f:2f',
  49. 'NetworkInterfaceId': 'eni-2ze8uw6bxge799csyuun',
  50. 'PrivateIpSets': {'PrivateIpSet': [{'PrivateIpAddress': '172.17.4.208', 'Primary': True}]}}]},
  51. 'SpotPriceLimit': 0.0, 'DeviceAvailable': True, 'SaleCycle': '', 'InstanceType': 'ecs.c6.xlarge',
  52. 'SpotStrategy': 'SpotAsPriceGo', 'OSNameEn': 'CentOS 7.8 64 bit', 'IoOptimized': True,
  53. 'ZoneId': 'cn-beijing-g', 'ClusterId': '',
  54. 'EcsCapacityReservationAttr': {'CapacityReservationPreference': '', 'CapacityReservationId': ''},
  55. 'DedicatedHostAttribute': {'DedicatedHostId': '', 'DedicatedHostName': '', 'DedicatedHostClusterId': ''},
  56. 'GPUAmount': 0, 'OperationLocks': {'LockReason': []}, 'InternetMaxBandwidthIn': -1, 'Recyclable': False,
  57. 'RegionId': 'cn-beijing', 'CreditSpecification': ''},
  58. {'ResourceGroupId': '', 'Memory': 8192, 'InstanceChargeType': 'PostPaid', 'Cpu': 4, 'OSName': 'CentOS 7.8 64位',
  59. 'InstanceNetworkType': 'vpc', 'InnerIpAddress': {'IpAddress': []}, 'ExpiredTime': '2099-12-31T15:59Z',
  60. 'ImageId': 'm-2ze3uv2gz5dsy0ol2i4x',
  61. 'EipAddress': {'AllocationId': '', 'IpAddress': '', 'InternetChargeType': ''}, 'ImageOptions': {},
  62. 'HostName': 'iZ2zegj32en19tn3f09u4jZ', 'Tags': {'Tag': [{'TagKey': 'acs:ecs:payType', 'TagValue': 'spot'}]},
  63. 'VlanId': '', 'Status': 'Running', 'HibernationOptions': {'Configured': False},
  64. 'MetadataOptions': {'HttpTokens': '', 'HttpEndpoint': ''}, 'InstanceId': 'i-2zegj32en19tn3f09u4j',
  65. 'StoppedMode': 'Not-applicable', 'CpuOptions': {'ThreadsPerCore': 2, 'Numa': 'N/A', 'CoreCount': 2},
  66. 'StartTime': '2023-10-16T02:57Z', 'DeletionProtection': False,
  67. 'SecurityGroupIds': {'SecurityGroupId': ['sg-2ze6zhxrqy9vueae27xy']},
  68. 'VpcAttributes': {'PrivateIpAddress': {'IpAddress': ['172.17.4.194']}, 'VpcId': 'vpc-2zee8yqxobahsyfg9d11h',
  69. 'VSwitchId': 'vsw-2ze586sxfwsaov4s5w88d', 'NatIpAddress': ''},
  70. 'InternetChargeType': 'PayByTraffic', 'InstanceName': 'img2txt', 'DeploymentSetId': '',
  71. 'InternetMaxBandwidthOut': 0, 'SerialNumber': '6591e447-686e-48bb-82e9-e66977310d7d', 'OSType': 'linux',
  72. 'CreationTime': '2023-10-16T02:57Z', 'AutoReleaseTime': '', 'Description': '', 'InstanceTypeFamily': 'ecs.c6',
  73. 'DedicatedInstanceAttribute': {'Tenancy': '', 'Affinity': ''}, 'SpotDuration': 1,
  74. 'PublicIpAddress': {'IpAddress': []}, 'GPUSpec': '', 'NetworkInterfaces': {'NetworkInterface': [
  75. {'Type': 'Primary', 'PrimaryIpAddress': '172.17.4.194', 'MacAddress': '00:16:3e:34:4d:c6',
  76. 'NetworkInterfaceId': 'eni-2zefr02rdalqltlrbxk2',
  77. 'PrivateIpSets': {'PrivateIpSet': [{'PrivateIpAddress': '172.17.4.194', 'Primary': True}]}}]},
  78. 'SpotPriceLimit': 0.0, 'DeviceAvailable': True, 'SaleCycle': '', 'InstanceType': 'ecs.c6.xlarge',
  79. 'SpotStrategy': 'SpotAsPriceGo', 'OSNameEn': 'CentOS 7.8 64 bit', 'IoOptimized': True,
  80. 'ZoneId': 'cn-beijing-g', 'ClusterId': '',
  81. 'EcsCapacityReservationAttr': {'CapacityReservationPreference': '', 'CapacityReservationId': ''},
  82. 'DedicatedHostAttribute': {'DedicatedHostId': '', 'DedicatedHostName': '', 'DedicatedHostClusterId': ''},
  83. 'GPUAmount': 0, 'OperationLocks': {'LockReason': []}, 'InternetMaxBandwidthIn': -1, 'Recyclable': False,
  84. 'RegionId': 'cn-beijing', 'CreditSpecification': ''}]
  85. instances = []
  86. for instance_detail in instances_list:
  87. vpc_attributes = instance_detail.get('VpcAttributes',{}).get('PrivateIpAddress',{}).get('IpAddress',[])
  88. intranet_ip = vpc_attributes[0] if len(vpc_attributes) > 0 else None
  89. instances.append((instance_detail.get('InstanceId'), instance_detail.get('Status'),intranet_ip))
  90. return instances
  91. d={(1,2):3}
  92. for (k,v),v2 in d.items():
  93. print(k,v,v2)
  94. d.pop((1,2))
  95. print(d)