本文操作示例介绍如何使用Alibaba Cloud SDK for Python创建和删除终端节点服务。

前提条件

在使用Alibaba Cloud SDK for Python前,您需要完成以下准备工作:
  • 使用Alibaba Cloud SDK for Python,您需要一个阿里云账号和访问密钥(AccessKey)。请在阿里云控制台中的AccessKey管理页面上创建和查看您的AccessKey。
  • 确保您已经安装了Alibaba Cloud SDK for Python。更多信息,请参见aliyun-python-sdk-privatelink 1.0.1
  • 进入setup.py所在的目录,执行如下命令,完成环境初始化配置。
    python setup.py install

背景信息

在德国(法兰克福)地域创建一项终端节点服务。终端节点服务创建成功后,删除终端节点服务。

完整代码

本文的完整代码如下所示,您可以自行根据实际情况修改和设置参数取值。
#!/usr/bin/env python
#coding=utf-8
#创建一个终端节点服务
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkprivatelink.request.v20200415.CreateVpcEndpointServiceRequest import CreateVpcEndpointServiceRequest
#客户端的AccessKey、AccessSecret和地域ID
client = AcsClient('<accessKeyId>', '<accessSecret>', 'eu-central-1')

request = CreateVpcEndpointServiceRequest()
request.set_accept_format('json')
request.set_ClientToken("0c593ea1-3bea-11e9-b96b-88e9fe637760")
request.set_DryRun(False)
#要设置的资源类型和资源ID
request.set_Resources([
  {
    "ResourceId": "lb-hp32z1wp5peaoox2q****",    
    "ResourceType": "slb"  
    }
])

request.set_ServiceDescription("This is my EndpointService.")
request.set_AutoAcceptEnabled(False)response = client.do_action_with_exception(request)

# python2:  print(response) 
print(str(response, encoding='utf-8'))

#删除一个终端节点服务
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkprivatelink.request.v20200415.DeleteVpcEndpointServiceRequest import DeleteVpcEndpointServiceRequest

#客户端的AccessKey、AccessSecret和地域ID
client = AcsClient('<accessKeyId>', '<accessSecret>', 'eu-central-1')

request = DeleteVpcEndpointServiceRequest()
request.set_accept_format('json')
#要删除的终端节点服务ID
request.set_ServiceId("epsrv-hp3vpx8yqxblby3i****")
request.set_ClientToken("0c593ea1-3bea-11e9-b96b-88e9fe637760")

request.set_DryRun(False)response = client.do_action_with_exception(request)
# python2:  print(response) 
print(str(response, encoding='utf-8'))
系统显示执行结果如下:
---------------------------create_endpointservice---------------------------
{
  "RequestId": "5052F988-75CC-46AD-A1A6-0E9E445BD0D5",
  "ServiceId": "epsrv-hp3vpx8yqxblby3i****",
  "ServiceName": "com.aliyuncs.privatelink.cn-huhehaote.epsrv-hp3vpx8yqxblby3i****",
  "ServiceDomain": "serv-abc.privatelink.aliyun.com",
  "ServiceDescription": "This is my EndpointService.",
  "AutoAcceptEnabled": "false",
  "ServiceStatus": "Active",
  "CreateTime": "2020-01-02T19:11:12Z"
}
---------------------------delete_endpointservice---------------------------
{
  "ServiceId": "epsrv-hp3vpx8yqxblby3i****",
  "RequestId": "5052F988-75CC-46AD-A1A6-0E9E445BD0D5"
}