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 

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