In my last Post I covered manual steps of vCloud Usage Meter deployment & configuration. In this post I will show how we can leverage Usage Meter API’s to perform end to end configuration.
Usage Meter Deployment: There is no API for UM deployment and we have to stick to ovftool method for this step.
1 |
ovftool --name=Usage-Meter --X:injectOvfEnv --X:logFile=ovftool.log --allowExtraConfig --datastore=vsanDatastore --network=VM_MGMT --acceptAllEulas --noSSLVerify --diskMode=thin --powerOn --prop:varoot-password=VMware123! --prop:vausagemeter-password=VMware123! --prop:vami.gateway.vCloud_Usage_Meter=x.x.x.x --prop:vami.domain.vCloud_Usage_Meter=mgmt.vmw --prop:vami.searchpath.vCloud_Usage_Meter=mgmt.vmw --prop:vami.DNS.vCloud_Usage_Meter=x.x.x.x --prop:vami.ip0.vCloud_Usage_Meter=x.x.x.x --prop:vami.netmask0.vCloud_Usage_Meter=x.x.x.x C:\Users\Administrator\Downloads\Usage_Meter_Agent-4.1.0.1-15426816_OVF10.ova vi://root@esxmb1.mgmt.vmw/ |
Once Usage meter boots up, we can leverage below API calls to perform end to end configuration.
1: Get Authentication Token
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
1: Get Auth Token Method: POST URL: https://<usage-meter-fqdn>:8443/api/v1/login Headers: Content-Type: application\json Payload: { "user":"usagemeter", "password":"UM-Password" } |
Response Output: We need to grab value of “sessionid” from output response. Further API calls will be authenticated using sessionid.
1 2 3 4 5 6 |
{ "data_usage_acceptance":true, "http_proxy":true, "alert_email":false, "sessionid":"UmSID3c46SdhYG7GGCe/npvNJNeMzU2Z84SRWWzkx737zPDg" } |
2: Accept Data Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Method: POST URL: https://<usage-meter-fqdn>:8443/api/v1/data_usage_acceptance Headers: sessionId: {{session_id}} Content-Type: application\json Payload: { "accepted":true } |
3: Network Connection Configuration: In this step we are configuring direct internet access to usage meter. If in your environment, internet connectivity is via proxy, your payload will change accordingly.
1 2 3 4 5 6 7 8 9 10 |
Method: PUT URL: https://<usage-meter-fqdn>:8443/api/v1/test_proxy Payload: { "type":"none", "host":"direct" } |
4: Grab Usage Meter UUID for Registration
Cat /opt/vmware/cloudusagemetering/resources/ro.txt
1 2 3 |
cat /opt/vmware/cloudusagemetering/resources/ro.txt | grep UUID UUID = 576d9a23-7718-425f-804e-55ca64d85840 |
5: Register UM UUID with Commerce Portal
5a: Get Commerce Portal Auth Token
1 2 3 4 5 6 7 8 9 10 |
Method: POST URL: https://vcp.vmware.com/api/session Payload: { "username":"username", "password":"password" } |
Response Output: We have to grab “XSRF-TOKEN” value from response output. In Postman client you can see this under cookies.
5b: List Contracts
1 2 3 4 5 6 7 |
Method: GET URL: https://vcp.vmware.com/api/contracts Headers: X-XSRF-TOKEN: {{Token-Value}} |
Response Output: We need to find id associated with a contract#
1 2 3 4 5 6 7 8 9 |
{ "createdTime":"2019-12-26T10:08:17Z", "createdBy":"system", "lastModifiedTime":"2019-12-26T10:08:17Z", "lastModifiedBy":"system", "id":"ad4be2b4-7872-4646-80df-635a8e2b630b", "group":"ENG-MaaS", "code":"VSPP3-360-PSSS-C" } |
5c: Get List of instance registered with a given contract
1 2 3 4 5 6 7 |
Method: GET URL: https://vcp.vmware.com/api/contracts/<id>/usageMeters Headers: X-XSRF-TOKEN: {{Token-Value}} |
Sample Output (Trimmed):
1 2 3 4 5 6 7 8 9 10 11 |
{ "createdTime":"2020-03-22T06:06:06Z", "createdBy":"system", "lastModifiedTime":"2020-03-22T06:06:06Z", "lastModifiedBy":"system", "id":"1e690da9-cbad-4a84-ad3e-4017f46bd642", "name":"Manish-UM-4.2", "instanceId":"57926a17-5cba-40ff-aeca-3e0f4e2e3f07", "version":"v4_x", "mode":"TEST" } |
5d: Add a new UM Instance to an existing contract
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Method: POST URL: https://vcp.vmware.com/api/contracts/<id>/usageMeters Headers: Content-Type: application\json X-XSRF-TOKEN {{Token-Value}} Payload: { "name":"Manish-New-UM", "instanceId":"57926a17-5cba-40ff-aeca-3e0f4e2e3f07", "version":"v4_x", "mode":"TEST" } |
6: Register vCenter with Usage Meter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Method: POST URL: https://<usage-meter-fqdn>:8443/api/v1/product Payload: { "productType":"vCenter", "externalSSO":false, "user":"administrator@vsphere.local", "password":"VMware123!", "vcfManaged":false, "host":"vcenter.mgmt.vmw", "port":443 } |
Response Output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "externalSSO":false, "extSSOport":0, "lastChanged":1584891747649, "active":true, "fullName":null, "vcfManaged":false, "version":null, "extSSOhost":null, "port":443, "host":"vcenter.mgmt.vmw", "instanceUUID":null, "metered":false, "id":1, "vcfEdition":null, "user":"administrator@vsphere.local", "productType":"vCenter", "status":{ "code":"Info", "lastChanged":1584891747744, "text":"Getting certificates" } } |
I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing 🙂