python start_vm_ec2.py "'pts-qa12.cbxcloud.com':'35.160.168.99','pts-qa11.cbxcloud.com':'52.24.85.138'" Then it will generate HostnameExtIP_dic={'pts-qa11.cbxcloud.com':'52.24.85.138','pts-qa12.cbxcloud.com':'35.160.168.99'} when execute the py script.
时间: 2023-03-01 16:10:22 浏览: 136
pts_1214.tgz
Here is a sample Python script that takes a dictionary of hostnames and IP addresses as input and generates another dictionary with the same information in a different order:
```
def start_vm_ec2(input_dict):
# Split input string into key-value pairs
input_list = [pair.split(":") for pair in input_dict.split(",")]
# Convert key-value pairs to a dictionary
input_dict = {pair[0]: pair[1] for pair in input_list}
# Reverse the order of the items in the dictionary
hostname_ext_ip_dict = {v: k for k, v in input_dict.items()}
return hostname_ext_ip_dict
input_dict = "'pts-qa12.cbxcloud.com':'35.160.168.99','pts-qa11.cbxcloud.com':'52.24.85.138'"
print("HostnameExtIP_dic=", start_vm_ec2(input_dict))
```
This script defines a function `start_vm_ec2` that takes a string as input and converts it into a dictionary. It then reverses the order of the items in the dictionary and returns the result.
阅读全文