12. IBM Cloud: VMware as a Service（VMWaaS) - VMWaaS APIの実行例

# 1. はじめに

今まで色々な作業をVMware Console（VMware Cloud Director)を使って操作してきましたが、作業内容によってはAPIを使った自動化作業を実施したいということもあるでしょう。今回は、VMware as a ServiceのAPIを呼び出す方法を紹介したいと思います。

過去の記事はこちら。

- [01. IBM Cloud: VMware as a Service（VMWaaS)の概要](https://qiita.com/testnin2/items/d39ba856f70fc14ea719) 
- [02. IBM Cloud: VMware as a Service（VMWaaS) - VDCの注文](https://qiita.com/testnin2/items/a3630d5a532a6ce48720)
- [03. IBM Cloud: VMware as a Service（VMWaaS) - VDCの追加注文](https://qiita.com/testnin2/items/666a8a03db85f983f56a) 
- [04. IBM Cloud: VMware as a Service（VMWaaS) - 外部接続のためのネットワークとNAT/Firewallを構成する](https://qiita.com/testnin2/items/3575b27c2ec2b6242ee6) 
- [05. IBM Cloud: VMware as a Service（VMWaaS) - RHELをプロビジョニングして疎通確認を行う](https://qiita.com/testnin2/items/56901ef332ee060fcf2f) 
- [06. IBM Cloud: VMware as a Service（VMWaaS) - 検証: IBM Cloud private networkへの通信におけるSNATの必要性](https://qiita.com/testnin2/items/5add312256d1e264e31f)
- [07. IBM Cloud: VMware as a Service（VMWaaS) - 検証: isolated networkとの通信](https://qiita.com/testnin2/items/9bc1b57b9636071b7239)
- [08. IBM Cloud: VMware as a Service（VMWaaS) - 検証: routed network間の通信](https://qiita.com/testnin2/items/fa9426df262368ddc2ef) 
- [09. IBM Cloud: VMware as a Service（VMWaaS) - Data Center Groupの構成](https://qiita.com/testnin2/items/f940550d7564db526531) 
- [10. IBM Cloud: VMware as a Service（VMWaaS) - Distributed Firewallの構成](https://qiita.com/testnin2/items/26dd06d28effbd83ff9e) 
- [11. IBM Cloud: VMware as a Service（VMWaaS) - VDC間のVM/vApp Migration](https://qiita.com/testnin2/items/381c5e6db4fdd7ed64d6)
- [12. IBM Cloud: VMware as a Service（VMWaaS) - VMWaaS APIの実行例](https://qiita.com/testnin2/items/3e0e86a25bfd06a165bf)
- [13. IBM Cloud: VMware as a Service（VMWaaS) - VMware Cloud Director OpenAPIの実行例](https://qiita.com/testnin2/items/420e55a06255d626a471) 
- [14. IBM Cloud: VMware as a Service（VMWaaS) - 検証: VIP切り替えによる高可用性構成の確認（手動切替）](https://qiita.com/testnin2/items/fead2339a999242ecae9) 
- [15. IBM Cloud: VMware as a Service（VMWaaS) - 検証: VIP切り替えによる高可用性構成の確認（keepalived）](https://qiita.com/testnin2/items/2a5c9660ccfab74faa49) 
- [16. IBM Cloud: VMware as a Service（VMWaaS) - Transit Gateway接続](https://qiita.com/testnin2/items/1ec6223b6713eb58e156) 
- [17. IBM Cloud: VMware as a Service（VMWaaS) - Veeam Backup and Replication service連携](https://qiita.com/testnin2/items/69fd29db9f8cc313e353) 


# 2. 実行例

- VMware as a ServiceにはCLIが存在しないので、直接APIを呼び出す必要がある。
- VMware as a ServiceのAPI Referenceは[こちら](https://cloud.ibm.com/apidocs/vmware-service)
- IBM Cloud のIAM tokenの取得方法は[こちら](https://qiita.com/testnin2/items/3a4ca8a1a2b79b713c48)を参照。

```txt:IAM tokenの取得方法
$ APIKEY=xxxxxx
$ iam_token=`curl -sX POST \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=${APIKEY}" \
  https://iam.cloud.ibm.com/identity/token | jq -r '.access_token' `
$ echo ${iam_token}
```

```txt:VMWaaS APIの実行例
$ curl -X GET 'https://api.us-south.vmware.cloud.ibm.com/v1/director_sites' -H "authorization: Bearer ${iam_token}" -H 'Content-Type:application/json'
{
  "director_sites": [
    {
      "crn": "crn:v1:bluemix:public:vmware:us-south:a/f7ae49cc04f348edb34ac01af90ee00e::directorsite:40e701cd-ef86-4d5e-a847-e7c336f11f27",
      "enable_vcda": true,
      "href": "https://api.us-south.vmware.cloud.ibm.com/director_sites/40e701cd-ef86-4d5e-a847-e7c336f11f27",
      "id": "40e701cd-ef86-4d5e-a847-e7c336f11f27",
      "ip_allow_list": [],
      "name": "IBM VMwaaS Multitenant - DAL",
      "ordered_at": "2023-08-30T21:06:09.100407+00:00",
      "private_only": false,
      "provisioned_at": "2023-09-08T21:19:36.140204+00:00",
      "pvdcs": [
        {
          "data_center_name": "dal10",
          "href": "https://api.us-south.vmware.cloud.ibm.com/director_sites/40e701cd-ef86-4d5e-a847-e7c336f11f27/pvdcs/f864f016-2c34-4658-95e7-dd3363408d76",
          "id": "f864f016-2c34-4658-95e7-dd3363408d76",
          "name": "DAL10",
          "private_only": false,
          "provider_types": [
            {
              "name": "on_demand"
            },
            {
              "name": "reserved"
            }
          ],
          "provisioned_at": "2023-09-27T17:59:35.433022+00:00"
        },
        {
          "data_center_name": "dal12",
          "href": "https://api.us-south.vmware.cloud.ibm.com/director_sites/40e701cd-ef86-4d5e-a847-e7c336f11f27/pvdcs/5b4af31c-383b-422b-b297-0ea6ed8af479",
          "id": "5b4af31c-383b-422b-b297-0ea6ed8af479",
          "name": "DAL12",
          "private_only": false,
          "provider_types": [
            {
              "name": "on_demand"
            },
            {
              "name": "reserved"
            }
          ],
          "provisioned_at": "2023-08-30T21:06:09.117160+00:00"
        }
      ],
      "resource_group": {
        "crn": "crn:v1:bluemix:public:resource-controller::a/f7ae49cc04f348edb34ac01af90ee00e::resource-group:224c64825a154252a864241890de793e",
        "id": "224c64825a154252a864241890de793e",
        "name": "Dallas MZR"
      },
      "rhel_vm_activation_key": "ic4v_vmwaas_8ed285a1-b804-4f6c-bad7-783b25605194",
      "services": [],
      "status": "ready_to_use",
      "type": "multitenant"
    }
  ]
}
```