更新或刪除測試

請按照本頁面的步驟,瞭解如何編輯或刪除測試。您可以編輯或刪除自己和其他人建立的測試。

如要建立、查看或重新執行測試,請參閱「建立及執行 Connectivity Tests」。

如要瞭解 Connectivity Tests,請參閱「總覽」。

事前準備

Before you can use Connectivity Tests, set up the following items in Google Cloud:

  1. In the Google Cloud console, go to the project selector page.

    Go to the project selector

    Select or create a Google Cloud project.

  2. Ensure that billing is enabled for your Google Cloud project.
  3. 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 gcloud command reference.

  4. Enable the Network Management API. Enabling the API provides you with the following:

    • Example API calls that use the Network Management API

      您可以使用 API Explorer 測試 Network Management API 指令。在 Network Management API 參考文件中,使用 Try this API 欄探索 API 欄位,並執行測試

    • Sample code that uses the API Python client

      The example code assumes that you have constructed a resource named api to interact with the Network Management API. To construct a resource, use the build function. See the following example:

      from googleapiclient.discovery import build
      api = build('networkmanagement', 'v1')
      

      For more information about the API Python client, see the following:

  5. Obtain the permissions that you need to run and view tests. For details, see Assign access.

更新測試

請按照本節中的步驟更新測試。您可以變更任何欄位,但 name 測試除外。

如要在 update 測試作業執行期間查看狀態,請參閱「檢查正在執行的測試作業」。

控制台

從主要的 Connectivity Tests 頁面

  1. 前往 Google Cloud 控制台的「Connectivity Tests」 頁面。

    前往 Connectivity Tests

  2. 如要更新測試,請按一下測試名稱。

  3. 在「Connectivity Test details」(Connectivity Tests 詳細資料) 頁面中,按一下頁面頂端的「Edit」(編輯)

  4. 修改測試選項。

  5. 按一下「Save」(儲存)

    測試會自動重新執行。

從網路介面詳細資料頁面

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。

    前往 VM 執行個體

  2. 如果尚未選取,請選取包含要更新測試的執行個體專案。

  3. 按一下要更新測試的執行個體。

  4. 在「Network interfaces」(網路介面) 下方,選取要更新測試的網路介面。

  5. 在「Network analysis」(網路分析) 下方,按一下「Connectivity Tests」

  6. 按一下要更新的測試名稱。

  7. 在「Connectivity Test details」(Connectivity Tests 詳細資料) 頁面中,按一下頁面頂端的「Edit」(編輯)

  8. 修改測試選項。

  9. 按一下「Save」(儲存)

    測試會自動重新執行。

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:來源 VM 的專案 ID
  • TEST_ID:您執行的 Connectivity Tests 物件 (測試) ID
  • SOURCE_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 物件 (測試) ID
  • SOURCE_IP_ADDRESS:您要測試的內部或外部來源 IP 位址;只有在測試目的地為全域負載平衡器 VIP 時,才允許使用 IPv6 位址

updateMask 是必要參數,可指定修補程式更新的欄位。這個範例會更新 source 欄位。

刪除一或多項測試

請按照本節中的步驟刪除測試。

如要在 delete 測試作業執行期間查看狀態,請參閱「檢查正在執行的測試作業」。

控制台

從主要的 Connectivity Tests 頁面

  1. 前往 Google Cloud 控制台的「Connectivity Tests」 頁面。

    前往 Connectivity Tests

  2. 按一下要刪除的一或多項測試左側的核取方塊。

  3. 在 Google Cloud 控制台頁面頂端,按一下「Delete」(刪除)

從 Connectivity Tests 詳細資料頁面

  1. 在主要的「Connectivity Tests」 頁面中,按一下測試名稱。
  2. 在「Connectivity Test details」(Connectivity Tests詳細資料) 頁面頂端,按一下「Delete」(刪除)

從網路介面詳細資料頁面

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。

    前往 VM 執行個體

  2. 如果尚未選取,請選取包含要刪除測試的執行個體專案。

  3. 按一下要刪除測試的執行個體。

  4. 在「Network interfaces」(網路介面) 下方,選取要刪除測試的網路介面。

  5. 在「Network analysis」(網路分析) 下方,按一下「Connectivity Tests」

  6. 選取要刪除的一或多項測試左側的核取方塊。

  7. 按一下測試清單頂端的「Delete」(刪除)

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:來源 VM 的專案 ID
  • TEST_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

後續步驟