按照此页面上的步骤,了解如何修改或删除测试。您可以修改或删除自己和他人创建的测试。
如需创建、查看或重新运行测试,请参阅创建和运行 Connectivity Tests。
如需了解 Connectivity Tests,请参阅概览。
准备工作
Before you can use Connectivity Tests, set up the following items in Google Cloud:
In the Google Cloud console, go to the project selector page.
Select or create a Google Cloud project.
- Ensure that billing is enabled for your Google Cloud project.
Install the Google Cloud CLI, which is part of the Google Cloud CLI. To install the latest version of the gcloud CLI, see the gcloud CLI documentation.
For a list of all commands, see the
gcloudcommand reference.Enable the Network Management API. Enabling the API provides you with the following:
Example API calls that use the Network Management API
You can test Network Management API commands by using the API Explorer. In the Network Management API reference document, use the
Try this APIcolumn to explore API fields and run a test.Sample code that uses the API Python client
The example code assumes that you have constructed a resource named
apito interact with the Network Management API. To construct a resource, use thebuildfunction. See the following example:from googleapiclient.discovery import build api = build('networkmanagement', 'v1')For more information about the API Python client, see the following:
- Google API Client Library for Python Docs in GitHub, which includes installation and authentication instructions.
- The Network Management API reference documentation for the API Python client.
- Obtain the permissions that you need to run and view tests. For details, see Assign access.
更新测试
请按照本部分中的步骤更新测试。您可以更改测试的 name 以外的任何字段。
如需在 update 测试操作正在运行时检查其状态,请参阅检查正在运行的测试操作。
控制台
在“Connectivity Tests”的主页面上
在 Google Cloud 控制台中,前往 Connectivity Tests 页面。
要更新测试,请点击其名称。
在连接测试详情页面上,点击页面顶部的修改 。
修改测试选项。
点击保存。
测试会自动重新运行。
在“网络接口详情”页面上
在 Google Cloud 控制台中,前往虚拟机实例页面。
如果尚未选择,请选择包含要为其更新测试的实例的项目。
点击您要更新测试的实例。
在网络接口下,选择您要为其更新测试的网络接口。
在网络分析下,点击 Connectivity Tests。
点击要更新的测试的名称。
在连接测试详情页面上,点击页面顶部的修改 。
修改测试选项。
点击保存。
测试会自动重新运行。
gcloud
要更新测试,请使用要更新的测试 ID 和要更改的命令选项,输入以下命令。以下示例更改了目标 IP 地址。
gcloud network-management connectivity-tests update NAME \
--destination-ip-address= DESTINATION_IP_ADDRESS
替换以下值:
NAME:Connectivity Tests 测试的名称DESTINATION_IP_ADDRESS:您要测试的内部或外部目标 IP 地址;仅当测试的目标是全球负载均衡器 VIP 时,才允许使用 IPv6 地址。
API
使用 networkmanagement.connectivitytests.patch 方法更新(修改)测试。
PATCH https: //networkmanagement.googleapis.com/v1/{resource.name=projects/PROJECT_ID/locations/global/connectivityTests/TEST_ID}
{
"source": {
"ipAddress": "SOURCE_IP_ADDRESS",
"projectId": "SOURCE_PROJECT",
},
}
替换以下值:
PROJECT_ID:来源虚拟机的项目 IDTEST_ID:您正在运行的 Connectivity Tests 对象(测试)的 IDSOURCE_IP_ADDRESS:您要测试的内部或外部源 IP 地址;仅当测试的目标是全球负载均衡器 VIP 时,才允许使用 IPv6 地址SOURCE_PROJECT:源端点的项目 ID
Python
以下示例代码更新了测试的源 IP 地址。如需了解详情,请参阅 API Python 客户端参考文档中的 patch。
project_id = "PROJECT_ID"
test_id = "TEST_ID"
test_input = {
"source": {
"ipAddress": "SOURCE_IP_ADDRESS"
},
}
request = api.projects().locations().global_().connectivityTests().patch(
name='projects/%s/locations/global/connectivityTests/%s' % (project_id, test_id),
body=test_input,
updateMask="source")
print(json.dumps(request.execute(), indent=4))
替换以下值:
PROJECT_ID:在其中创建测试的项目的项目 ID。TEST_ID:您正在运行的 Connectivity Tests 对象(测试)的 IDSOURCE_IP_ADDRESS:您要测试的内部或外部源 IP 地址;仅当测试的目标是全球负载均衡器 VIP 时,才允许使用 IPv6 地址
updateMask 是必需参数,用于指定补丁程序更新的字段。此示例更新 source 字段。
删除一个或多个测试
请按照本部分中的步骤删除测试。
如需在 delete 测试操作正在运行时检查其状态,请参阅检查正在运行的测试操作。
控制台
在“Connectivity Tests”的主页面上
在 Google Cloud 控制台中,前往 Connectivity Tests 页面。
点击一个或多个要删除的测试左侧的复选框。
在 Google Cloud 控制台页面顶部,点击删除 。
在“Connectivity Tests 测试详情”页面上
- 在 Connectivity Tests 主页面中,点击测试的名称。
- 在连接测试详情页面顶部,点击删除 。
在“网络接口详情”页面上
在 Google Cloud 控制台中,前往虚拟机实例页面。
如果尚未选择,请选择包含要从中删除测试的实例的项目。
点击要从中删除测试的实例。
在网络接口下,选择要从中删除测试的网络接口。
在网络分析下,点击 Connectivity Tests。
选中要删除的一个或多个测试左侧的复选框。
在测试列表的顶部,点击删除 。
gcloud
要删除测试,请输入以下命令。使用您要删除的测试的测试 ID。
gcloud beta network-management connectivity-tests delete NAME
将 NAME 替换为 Connectivity Tests 测试的名称。
API
使用 networkmanagement.connectivitytests.delete 方法删除测试。
DELETE https://networkmanagement.googleapis.com/v1/{name=projects/PROJECT_ID/locations/global/connectivityTests/{TEST_ID}
替换以下值:
PROJECT_ID:源虚拟机的项目 IDTEST_ID:您正在运行的 Connectivity Tests 对象(测试)的 ID
Python
以下示例代码删除了测试。如需了解详情,请参阅 API Python 客户端参考文档中的 delete。
project_id = "PROJECT_ID"
test_id = "TEST_ID"
request = api.projects().locations().global_().connectivityTests().delete(
name='projects/%s/locations/global/connectivityTests/%s' % (project_id, test_id))
print(json.dumps(request.execute(), indent=4))
替换以下值:
PROJECT_ID:在其中创建测试的项目的项目 ID。TEST_ID:您正在删除的 Connectivity Tests 对象(测试)的 ID