本文共 3463 字,大约阅读时间需要 11 分钟。
配置私网多IP。登录分配多IP的ECS,这时使用命令ifconfig不能看到分配的私网多IP,要使用ifconfig配置分配的IP之后才能看到。此时私网多IP配置完成,可以使用。
命令格式(此种配置方式重启失效):# ifconfig eth0:{new ip name} {your ip address} netmask {your netmask} upfor example: # ifconfig eth0:0 192.168.1.1 netmask 255.255.255.0 up
状态限制:
(InUse)
或 可用(Available)
状态。(Running)
或者 已停止(Stopped)
状态Quota限制,查询规格私网IP Quota途径:,或者接口
Available
状态,最多能分配10个私网IP。安全组
# coding=utf-8# if the python sdk is not install using 'sudo pip install aliyun-python-sdk-ecs'# if the python sdk is install using 'sudo pip install --upgrade aliyun-python-sdk-ecs'# make sure the sdk version is 4.7.1, you can use command 'pip show aliyun-python-sdk-ecs' to checkimport jsonimport loggingfrom aliyunsdkcore import clientfrom aliyunsdkecs.request.v20140526.AssignPrivateIpAddressesRequest import AssignPrivateIpAddressesRequestfrom aliyunsdkecs.request.v20140526.UnassignPrivateIpAddressesRequest import UnassignPrivateIpAddressesRequest# configuration the log output formatter, if you want to save the output to file,# append ",filename='ecs_invoke.log'" after datefmt.logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S')# send open api requestdef _send_request(request): request.set_accept_format('json') try: response_str = clt.do_action(request) logging.info(response_str) response_detail = json.loads(response_str) return response_detail except Exception as e: logging.error(e)# assign private ip addresses to enidef assign_private_ip_addresses(eniId, count, private_ip_address_list): request = AssignPrivateIpAddressesRequest() request.set_NetworkInterfaceId(eniId) if (count != None): request.set_SecondaryPrivateIpAddressCount(count) if (private_ip_address_list != None): request.set_PrivateIpAddresss(private_ip_address_list) _send_request(request)# assign private ip addresses to eni by secondary private ip address countdef assign_private_ip_by_count(eniId, count): assign_private_ip_addresses(eniId, count, None)# assign private ip addresses to eni by secondary private ip address listdef assign_private_ip_by_addresses(eniId, private_ip_address_list): assign_private_ip_addresses(eniId, None, private_ip_address_list)# unassign private ip addresses by secondary private ip address listdef unassign_private_ip_addresses(eniId, private_ip_address_list): request = UnassignPrivateIpAddressesRequest() request.set_NetworkInterfaceId(eniId) request.set_PrivateIpAddresss(private_ip_address_list) _send_request(request)if __name__ == '__main__': # client init clt = client.AcsClient('Your Access Key Id', 'Your Access Key Secrect', 'cn-zhangjiakou') # assign_private_ip_by_count("eni-id", 1) # # assign_private_ip_by_addresses("eni-id", ["192.168.1.1", "192.168.1.2"]) # # unassign_private_ip_addresses("eni-id", ["192.168.1.1", "192.168.1.2"])
转载地址:http://msxkl.baihongyu.com/