vROPS中获取虚拟机在VC中的UUID

vROPS中虚拟机对象的ID为resourceID,跟vCenter中虚拟机的UUID是不一致的,因此想要将vROPS中的虚拟机和vCenter中的虚拟机对应肯定不能靠虚拟机名称,而是一定要靠UUID。

下面的示例显示如何通过vROPS API获取虚拟机在vCenter中的UUID

步骤1,获取vROPS Token

URL: https://vrops.vmware.com/suite-api/api/auth/token/acquire
Method: POST
Content-Type: application/json
Accept: application/json
Body: {"username":"admin","password":"VMware1!"}
Response:
{
    "token": "4971b55f-68aa-47a0-a351-19fa751d59cb::5c1db8e3-90ec-44f4-87f7-ad986f358ca6",
    "validity": 1556219805813,
    "expiresAt": "Friday, April 26, 2019 3:16:45 AM CST",
    "roles": []
}

步骤2,获取虚拟机UUID

URL: https://vrops.dev-pso.com/suite-api/api/resources?name=000-001-OS-P003
Method: GET
Authorization: vRealizeOpsToken {{token}}
Accept: application/json
Response:
{
    "pageInfo": {
        "totalCount": 1,
        "page": 0,
        "pageSize": 1000
    },
    "links": [
        {
            "href": "/suite-api/api/resources?name=000-001-OS-P003&page=0&pageSize=1000",
            "rel": "SELF",
            "name": "current"
        },
        {
            "href": "/suite-api/api/resources?name=000-001-OS-P003&page=0&pageSize=1000",
            "rel": "RELATED",
            "name": "first"
        },
        {
            "href": "/suite-api/api/resources?name=000-001-OS-P003&page=0&pageSize=1000",
            "rel": "RELATED",
            "name": "last"
        }
    ],
    "resourceList": [
        {
            "creationTime": 1555486851466,
            "resourceKey": {
                "name": "000-001-OS-P003",
                "adapterKindKey": "VMWARE",
                "resourceKindKey": "VirtualMachine",
                "resourceIdentifiers": [
                    {
                        "identifierType": {
                            "name": "VMEntityInstanceUUID",
                            "dataType": "STRING",
                            "isPartOfUniqueness": false
                        },
                        "value": "50229f5c-74e6-9e0a-c3f4-a1d104e6fbe9"   // vmUUID, 和VC中VM的virtualMachine.ConfigInfo.instanceUUID是一致的
                    },
                    {
                        "identifierType": {
                            "name": "VMEntityName",
                            "dataType": "STRING",
                            "isPartOfUniqueness": false
                        },
                        "value": "000-001-OS-P003"
                    },
                    {
                        "identifierType": {
                            "name": "VMEntityObjectID",
                            "dataType": "STRING",
                            "isPartOfUniqueness": true
                        },
                        "value": "vm-601"
                    },
                    {
                        "identifierType": {
                            "name": "VMEntityVCID",
                            "dataType": "STRING",
                            "isPartOfUniqueness": true
                        },
                        "value": "e55e5bf7-06f7-4a77-9fb5-d16bcc4d5ecc"
                    }
                ]
            },
            "resourceStatusStates": [
                {
                    "adapterInstanceId": "e9e24f83-a735-4e8c-a974-0d01a2d9d681",
                    "resourceStatus": "DATA_RECEIVING",
                    "resourceState": "STARTED",
                    "statusMessage": ""
                }
            ],
            "resourceHealth": "RED",
            "resourceHealthValue": 25,
            "dtEnabled": true,
            "badges": [
                {
                    "type": "HEALTH",
                    "color": "RED",
                    "score": 25
                },
                {
                    "type": "CAPACITY_REMAINING",
                    "color": "GREEN",
                    "score": 66.13910915503129
                },
                {
                    "type": "COMPLIANCE",
                    "color": "GREY",
                    "score": -1
                },
                {
                    "type": "TIME_REMAINING",
                    "color": "GREEN",
                    "score": 366
                },
                {
                    "type": "RISK",
                    "color": "GREEN",
                    "score": 0
                },
                {
                    "type": "EFFICIENCY",
                    "color": "GREEN",
                    "score": 100
                },
                {
                    "type": "WORKLOAD",
                    "color": "GREEN",
                    "score": 33.4913158416748
                }
            ],
            "relatedResources": [],
            "links": [
                {
                    "href": "/suite-api/api/resources/40394dc8-2828-4277-85ef-15727e9c0e93",
                    "rel": "SELF",
                    "name": "linkToSelf"
                },
                {
                    "href": "/suite-api/api/resources/40394dc8-2828-4277-85ef-15727e9c0e93/relationships",
                    "rel": "RELATED",
                    "name": "relationsOfResource"
                },
                {
                    "href": "/suite-api/api/resources/40394dc8-2828-4277-85ef-15727e9c0e93/properties",
                    "rel": "RELATED",
                    "name": "propertiesOfResource"
                },
                {
                    "href": "/suite-api/api/alerts?resourceId=40394dc8-2828-4277-85ef-15727e9c0e93",
                    "rel": "RELATED",
                    "name": "alertsOfResource"
                },
                {
                    "href": "/suite-api/api/symptoms?resourceId=40394dc8-2828-4277-85ef-15727e9c0e93",
                    "rel": "RELATED",
                    "name": "symptomsOfResource"
                },
                {
                    "href": "/suite-api/api/resources/40394dc8-2828-4277-85ef-15727e9c0e93/statkeys",
                    "rel": "RELATED",
                    "name": "statKeysOfResource"
                },
                {
                    "href": "/suite-api/api/resources/40394dc8-2828-4277-85ef-15727e9c0e93/stats/latest",
                    "rel": "RELATED",
                    "name": "latestStatsOfResource"
                },
                {
                    "href": "/suite-api/api/resources/40394dc8-2828-4277-85ef-15727e9c0e93/properties",
                    "rel": "RELATED",
                    "name": "latestPropertiesOfResource"
                },
                {
                    "href": "/suite-api/api/credentials/",
                    "rel": "RELATED",
                    "name": "credentialsOfResource"
                }
            ],
            "identifier": "40394dc8-2828-4277-85ef-15727e9c0e93"
        }
    ]
}

 

上一篇:前端-html


下一篇:剑指offer--17.第一个只出现一次的字符