本文件說明如何檢查是否已啟用巢狀虛擬化,以及如何修改布林限制,控制是否為機構、專案或資料夾啟用巢狀虛擬化。
機構政策中的布林值限制會決定您是否可以建立巢狀 VM。巢狀虛擬化的布林限制是限制,也就是說,當這項限制生效時,它會告知機構政策限制建立巢狀 VM。如要進一步瞭解布林值限制,請參閱「瞭解限制」一文。
根據預設,系統不會強制執行「停用 VM 巢狀虛擬化」限制,因此您不必修改任何布林限制即可啟用巢狀虛擬化。即便如此,Google 仍建議您明確設定限制的值,以免貴機構、資料夾和專案依賴預設設定。如果您的專案不隸屬於機構,則系統預設不會強制執行限制,您也無法變更限制。
事前準備
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
檢查是否允許巢狀虛擬化
使用 Google Cloud 控制台、Google Cloud CLI 或 REST,檢查機構、資料夾或專案是否允許巢狀虛擬化。
主控台
如要確認是否可以在機構、資料夾或專案中建立巢狀 VM,請確認是否未強制執行停用巢狀虛擬化的布林值限制。如果機構政策未強制執行「停用 VM 巢狀虛擬化」限制,您就可以建立巢狀 VM。
前往 Google Cloud 控制台的「Organization policies」(機構政策)頁面。
在機構、資料夾和專案選取器中,選取要查看機構政策的實體。
選取「停用 VM 巢狀虛擬化」限制條件,開啟「政策詳細資料」頁面。
查看「強制執行」的值:
如果值為「Not enforced」,則會啟用巢狀虛擬化,您可以建立巢狀 VM。
如果值為「Enforced」,則會停用巢狀虛擬化,且您無法建立巢狀 VM。
gcloud
使用 gcloud resource-manager org-policies describe
指令檢查 compute.disableNestedVirtualization
布林值限制的值。
如果 Google Cloud CLI 輸出內容未顯示 booleanPolicy
的值,則表示允許巢狀虛擬化,您可以建立巢狀 VM。
如果 booleanPolicy
的 Google Cloud CLI 輸出值為 enforced: true
,則表示組織政策正在強制執行巢狀虛擬化限制,因此您無法建立巢狀 VM。
gcloud resource-manager org-policies \ describe constraints/compute.disableNestedVirtualization \ (--organization=ORGANIZATION_ID | --folder=FOLDER_ID | --project=PROJECT_ID) --effective
請更換下列任一項目:
ORGANIZATION_ID
:要取得限制值的機構 ID。如要取得可存取的機構清單及其 ID,請執行gcloud organizations list
指令。FOLDER_ID
:要取得限制值的資料夾 ID。如要查看可存取的資料夾清單及其 ID,請執行gcloud resource-manager folders list
指令。PROJECT_ID
:要取得限制值的專案 ID。如要取得可存取專案和 ID 的清單,請執行gcloud projects list
指令。
REST
使用 REST 檢查 compute.disableNestedVirtualization
布林限制的值,該值會決定您是否可以在機構、資料夾或專案中建立巢狀 VM。
如果 REST 回應未針對限制條件傳回 "booleanPolicy"
的值,則不會停用巢狀虛擬化,您可以建立巢狀 VM。
如果輸出內容中的 "booleanPolicy"
值為 "enforced": true
,表示已停用巢狀虛擬化,因此無法建立巢狀 VM。
POST https://cloudresourcemanager.googleapis.com/v1/RESOURCE/RESOURCE_ID:getOrgPolicy { "constraint": "compute.disableNestedVirtualization" }
更改下列內容:
RESOURCE
:取得機構政策的資源。請將其設為下列其中一個值:organizations
:呼叫organizations.getOrgPolicy
方法folders
:呼叫folders.getOrgPolicy
方法projects
:呼叫projects.getOrgPolicy
方法
RESOURCE_ID
:要檢查停用巢狀虛擬化限制條件狀態的機構、資料夾或專案
修改巢狀虛擬化機構政策
如果您具備適當的角色,可以控制機構、資料夾或專案是否能建立巢狀 VM。使用巢狀虛擬化的布林限制來控制這項強制執行機制。
使用 Google Cloud 控制台、Google Cloud CLI 或 REST,為機構、資料夾或專案啟用巢狀虛擬化功能。
主控台
如要啟用巢狀虛擬化功能,請停用 Disable VM nested virtualization 布林限制的強制執行,如要停用巢狀虛擬化功能,請啟用布林限制的強制執行。
前往 Google Cloud 控制台的「Organization policies」(機構政策)頁面。
在機構、資料夾和專案選取器中,選取要編輯機構政策的實體。
選取「停用 VM 巢狀虛擬化」限制條件,開啟「政策詳細資料」頁面。
按一下「編輯」,然後選取「自訂」。
在「Enforcement」下方,選取「Disable VM nested virtualization」布林限制的下列強制執行選項:
- 開啟:啟用強制執行設定並停用巢狀虛擬化
- 關閉:停用強制執行設定並啟用巢狀虛擬化功能
按一下 [儲存]。
gcloud
使用 gcloud resource-manager org-policies
指令啟用或停用 compute.disableNestedVirtualization
機構政策布林限制的強制執行功能。
如果您使用 disable-enforce
指令停用 compute.disableNestedVirtualization
限制,就可以建立已啟用巢狀虛擬化的 VM。
如果您使用 enable-enforce
指令啟用限制條件,就無法建立已啟用巢狀虛擬化的 VM。
gcloud resource-manager org-policies \ ( disable-enforce | enable-enforce ) compute.disableNestedVirtualization \ (--organization=ORGANIZATION_ID | --folder=FOLDER_ID | --project=PROJECT_ID)
請更換下列任一項目:
ORGANIZATION_ID
:要修改限制值的機構 ID。如需可存取的機構清單及其 ID,請執行gcloud organizations list
指令。FOLDER_ID
:要修改限制值的資料夾 ID。如要查看可存取的資料夾清單及其 ID,請執行gcloud resource-manager folders list
指令。PROJECT_ID
:要修改限制值的專案 ID。如要取得可存取專案和 ID 的清單,請執行gcloud projects list
指令。
REST
使用 REST 修改 compute.disableNestedVirtualization
布林限制的值,這項值會決定您是否可以在機構、資料夾或專案中建立巢狀 VM。
POST https://cloudresourcemanager.googleapis.com/v1/RESOURCE/RESOURCE_ID:setOrgPolicy { "policy": { "booleanPolicy": { "enforced": ENFORCE }, "constraint": "constraints/compute.disableNestedVirtualization" } }
更改下列內容:
RESOURCE
:要修改機構政策的資源。將此值設為下列其中一個:organizations
:呼叫organizations.setOrgPolicy
方法folders
:呼叫folders.setOrgPolicy
方法projects
:呼叫projects.setOrgPolicy
方法
RESOURCE_ID
:要檢查停用巢狀虛擬化限制條件狀態的機構、資料夾或專案ENFORCE
:判斷組織政策是否會強制執行compute.disableNestedVirtualization
布林值限制。請將其設為下列其中一個值:true
:強制執行限制條件。使用這項設定時,您無法建立已啟用巢狀虛擬化的 VM。false
:不強制執行限制條件。您可以使用這項設定,建立已啟用巢狀虛擬化的 VM。