四叶草花开 2019-06-27
摘要: 本文主要介绍了弹性网卡的热插拨功能改进,弹性网卡插拔对应的实例不再要求必须为 Stopped 状态,现在只要求是稳定状态( Running Stopped )即可。以及介绍了控制台、OpenAPI如何对弹性网卡进行热插拔操作。
背景
在云计算飞速发展的今天,用户ECS服务器身处的网络环境越来越复杂,弹性网卡让ECS服务器完美游走在日益复杂的网络环境中。但是以前服务器必须是Stopped状态才可以进行弹性网卡(ENI)的插拔,这样可能会影响运行在服务器上的业务。现在很高兴的向大家宣布:弹性网卡从今天开始支持热插拨,即ECS服务器只要处在稳定状态(Running Stopped),就可以对弹性网卡进行插拔操作。
弹性网卡热插拔:控制台
控制台操作弹性网卡的位置:进入控制台 -> 云服务器 ECS -> 弹性网卡。
创建弹性网卡:点击创建弹性网卡按钮,在弹窗中填写网卡名称,选择专有网络 交换机 安全组等信息后创建弹性网卡。
热挂载弹性网卡:点击弹性网卡对应的绑定实例按钮,在弹窗中选择要绑定实例。实例状态只要求为稳定状态(Running Stopped)。
热卸载弹性网卡:点击弹性网卡对应的解绑实例按钮,确定即可解绑。实例状态只要求为稳定状态(Running Stopped)。
弹性网卡热插拔:OpenAPI
attach_eni detach_eni 分别可以根据弹性网卡ID,实例ID,进行弹性网卡的热插拔。相关API参考帮助文档:挂载弹性网卡,卸载弹性网卡。
# 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 check import json import logging from aliyunsdkcore import client from aliyunsdkecs.request.v20140526.CreateNetworkInterfaceRequest import CreateNetworkInterfaceRequest from aliyunsdkecs.request.v20140526.AttachNetworkInterfaceRequest import AttachNetworkInterfaceRequest from aliyunsdkecs.request.v20140526.DetachNetworkInterfaceRequest import DetachNetworkInterfaceRequest from aliyunsdkecs.request.v20140526.DeleteNetworkInterfaceRequest import DeleteNetworkInterfaceRequest # 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 request def _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) # create eni def create_eni(vSwitchId, securityGroupId, networkInterfaceName=None, primaryIpAddress=None, description=None, clientToken=None): request = CreateNetworkInterfaceRequest() request.set_VSwitchId(vSwitchId) request.set_SecurityGroupId(securityGroupId) if (networkInterfaceName != None): request.set_NetworkInterfaceName(networkInterfaceName) if (primaryIpAddress != None): request.set_PrimaryIpAddress(primaryIpAddress) if (description != None): request.set_Description(description) if (clientToken != None): request.set_ClientToken(clientToken) _send_request(request) # attach eni to instance def attach_eni(eniId, instanceId): request = AttachNetworkInterfaceRequest() request.set_NetworkInterfaceId(eniId) request.set_InstanceId(instanceId) _send_request(request) # detach eni from instance def detach_eni(eniId, instanceId): request = DetachNetworkInterfaceRequest() request.set_NetworkInterfaceId(eniId) request.set_InstanceId(instanceId) _send_request(request) # delete eni def delete_eni(eniId): request = DeleteNetworkInterfaceRequest() request.set_NetworkInterfaceId(eniId) _send_request(request) if __name__ == '__main__': clt = client.AcsClient('Your Access Key Id', 'Your Access Key Secrect', 'cn-zhangjiakou') vSwitchId = "vsw-test" securityGroupId = "sg-test" # create_eni(vSwitchId=vSwitchId, securityGroupId=securityGroupId) attach_eniId = "eni-test" attach_instanceId = "i-test" # attach_eni(attach_eniId, attach_instanceId) detach_eniId = "eni-test" detach_instanceId = "i-test" # detach_eni(detach_eniId, detach_instanceId) delete_eniId = "eni-test" # delete_eni(delete_eniId)
小结
现在的弹性网卡热插拔只要求实例为稳定状态即可,改进了以前实例只能为Stopped状态才能插拔弹性网卡的现状。提升了用户体验,现在服务器不用关机就能轻松配置弹性网卡,更加灵活实用。