Vcloud API 整理

環境Vcloud

賬戶:iaasadmin 密碼:passwd 租戶:vsphere.local

1,獲取token

curl --insecure -H "Accept: application/json" -H 'Content-Type: application/json' --data '{"username":"[email protected]","password":"passwd","tenant":"vsphere.local"}' https://vra.cloud.local/identity/api/tokens

2,列出虛擬機,page指定頁數,limit顯示多少臺,orderby以什麼排序|dateCreated|id|name|status

curl --insecure -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://$vRA/catalog-service/api/consumer/resources/?page=1&limit=n&$orderby=name

3,獲取所有藍圖/查看所有目錄項

curl --insecure -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://$vRA/catalog-service/api/consumer/entitledCatalogItemViews|python3 -m json.tool

4,查看某個藍圖詳細信息

curl --insecure -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://vra.cloud.local/catalog-service/api/consumer/entitledCatalogItems/528c19ab-f9b1-4c71-ad68-cab37e8cbd6d/requests/template

5,查看某臺機器的 請求的詳細信息

curl --insecure -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://$vRA/catalog-service/api/consumer/requests/dc9262db-29c6-4fea-ba03-b31b5fa2c34f

6,查看某臺機器的詳細信息(包含其他請求連接)*

curl --insecure -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://$vRA/catalog-service/api/consumer/requests/499760da-efea-46f6-ac4d-e0e9fd81fc21/resourceViews

7,重新配置已有虛擬機 先獲取虛擬機的Reconfigure重新配置模板json ,再攜帶模板json去請求重新配置

8,生成模板json文件

curl --insecure -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://vra.cloud.local/catalog-service/api/consumer/entitledCatalogItems/528c19ab-f9b1-4c71-ad68-cab37e8cbd6d/requests/template|python -m json.tool >Centos7_VLAN39.json

創建虛擬機

curl --insecure -H "Content-Type: application/json" -H "Authorization: Bearer $token"https://vra.cloud.local/catalog-service/api/consumer/entitledCatalogItems/528c19ab-f9b1-4c71-ad68-cab37e8cbd6d/requests --data @Centos7_VLAN39.json

檢查請求狀態 URL: https://<vrafqdn/catalog-service/api/consumer/requests/{requestid}

curl --insecure -H "Content-Type: application/json" -H "Authorization: Bearer $token"https://vra.cloud.local/catalog-service/api/consumer/requests/dabca9e4-42cf-466c-a497-ad8edb93d1d5

驗證token狀態碼

    204 NO CONTENT        ##請求成功了。
    401未經授權        ##您必須具有身份驗證憑據才能訪問該資源。所有請求都必須經過身份驗證。
    403 FORBIDDEN            ##您的身份驗證憑據無法提供對資源的足夠訪問權限。
    404未找到        ##無法根據指定的URI找到資源。
    405方法不允許        ##資源不支持HEAD方法。
    500 SERVER ERROR    ##由於內部服務器錯誤,無法創建或更新資源。

官方文檔:https://docs.vmware.com/en/vRealize-Automation/7.3/com.vmware.vra.programming.doc/GUID-A83C30BB-3EDD-439B-B369-A92B4992EEDD.html 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章