IBM Cloud for VMware Solutions APIの使用例

#1. はじめに
IBM Cloud for VMware SolutionsとしてVMware vCenter Server(VCS)というVMware製品および3rd Partyツールを自動的にプロビジョニング・管理してくれるソリューションがあります。VCS 2.9からAPIが公開されるようになったのですが、高価なサービスをわざわざAPIを使って注文しようとはなかなか思わないと思います。
とはいえ、ネットワーク構成情報など、１つ１つカスタマーポータルを見て情報を取得するよりAPIで一括で参照・取得できるのは便利なので、どういう情報が取得できるのか参照系を中心に試した結果を紹介したいと思います。

#2. 情報源

- IBM Cloud for VMware SolutionsのAPI docsは[こちら](https://cloud.ibm.com/apidocs/vmware-solutions)。
- APIを実行するためには認証をした後、Access Tokenを指定する必要があります。[こちら](https://qiita.com/testnin2/items/3a4ca8a1a2b79b713c48)をご参照ください。

#3. 使用例

##3.1 VCSインスタンスのリスト取得
```txt:"List&nbsp;all&nbsp;VMware&nbsp;vCenter&nbsp;Server&nbsp;instances"
# export ACCESS_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk '{print $4}'`
# curl -s -X GET https://api.vmware-solutions.cloud.ibm.com/v1/vcenters -H "authorization: Bearer $ACCESS_TOKEN" -H "Content-Type:application/json"
[
  {
    "created_time": 1562595707,
    "creator": "IBM1756623",
    "current_version": "3.1",
    "domain_type": "primary",
    "id": "702e2231-5325-4d03-88b4-1bae68644479",
    "initial_version": "3.1",
    "location": "tok05",
    "name": "vcs65",
    "status": "ReadyToUse"
  }
]
```

##3.2 VCSインスタンスの詳細情報
`702e2231-5325-4d03-88b4-1bae68644479`は3.1で取得したVCSインスタンスのIDです。

```txt:Retrieve&nbsp;the&nbsp;detailed&nbsp;information&nbsp;of&nbsp;a&nbsp;VMware&nbsp;vCenter&nbsp;Server&nbsp;instance
# export ACCESS_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk '{print $4}'`
# curl -s -X GET https://api.vmware-solutions.cloud.ibm.com/v1/vcenters/702e2231-5325-4d03-88b4-1bae68644479 -H "authorization: Bearer $ACCESS_TOKEN" -H "Content-Type:application/json"
{
  "created_time": 1562595707,
  "creator": "IBM1756623",
  "current_version": "3.1",
  "domain_type": "primary",
  "endpoints": [
    {
      "credentials": [
        {
          "password": "xxxxxxxxxxx",
          "type": "ADMIN",
          "user": "Administrator@vsphere.local"
        },
        {
          "password": "xxxxxxxxxxx",
          "type": "SSH",
          "user": "customerroot"
        }
      ],
      "fqdn": "vcenter-vcs65.vcs65.ibm.local",
      "ip_address": "10.193.73.2",
      "type": "vCenter/PSC",
      "version": "6.5"
    },
    {
      "credentials": [
        {
          "password": "xxxxxxxxxxx",
          "type": "HTTP",
          "user": "admin"
        }
      ],
      "edition": "base",
      "fqdn": "nsxmgr.vcs65.ibm.local",
      "ip_address": "10.193.73.3",
      "type": "NSX",
      "version": "6.4.4-11197766"
    },
    {
      "credentials": [
        {
          "password": "xxxxxxxxxxx",
          "type": "Remote Desktop",
          "user": "Administrator"
        }
      ],
      "deployment_type": "VSI",
      "fqdn": "ADNSvcs65.ibm.local",
      "ip_address": "10.193.72.205",
      "type": "AD_DNS",
      "version": 1.0
    }
  ],
  "host_prefix": "host",
  "id": "702e2231-5325-4d03-88b4-1bae68644479",
  "initial_version": "3.1",
  "location": "tok05",
  "name": "vcs65",
  "root_domain": "ibm.local",
  "status": "ReadyToUse",
  "subdomain": "vcs65"
}
```

##3.3 VCSインスタンスのClusterのリスト取得

以下の例では、Clusterが1つしかないため、id=0のClusterのみが表示されています。

```txt:List&nbsp;all&nbsp;the&nbsp;clusters&nbsp;for&nbsp;a&nbsp;specified&nbsp;VMware&nbsp;vCenter&nbsp;Server&nbsp;instance
# export ACCESS_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk '{print $4}'`
# curl -s -X GET https://api.vmware-solutions.cloud.ibm.com/v1/vcenters/702e2231-5325-4d03-88b4-1bae68644479/clusters -H "authorization: Bearer $ACCESS_TOKEN" -H "Content-Type:application/json"
[
  {
    "id": "0",
    "is_default_pod": true,
    "location": "tok05",
    "name": "cluster1",
    "num_hosts": 1,
    "status": "ReadyToUse"
  }
]
```

##3.3 VCSインスタンスのClusterの詳細情報

上記で取得したid=0のClusterの詳細情報を表示しています。

```txt:Retreive&nbsp;the&nbsp;detailed&nbsp;information&nbsp;of&nbsp;a&nbsp;cluster
# export ACCESS_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk '{print $4}'`
# curl -s -X GET https://api.vmware-solutions.cloud.ibm.com/v1/vcenters/702e2231-5325-4d03-88b4-1bae68644479/clusters/0 -H "authorization: Bearer $ACCESS_TOKEN" -H "Content-Type:application/json"
{
  "hosts": [
    {
      "customized_hardware": {
        "ram": "RAM_96_GB_DDR4_2133_ECC_REG",
        "server": "INTEL_INTEL_XEON_4110_2_10"
      },
      "domain": "vcs65.ibm.local",
      "hostname": "host0",
      "id": "init_1705285",
      "memory": 96,
      "os": "vSphere",
      "password": "xxxxxxxxxxx",
      "private_ip_address": "10.193.72.206",
      "processor": 16,
      "public_ip_address": "165.xx.xx.xx",
      "state": "ACTIVE",
      "template_id": "1",
      "user": "root",
      "vsphere_version": "6.5"
    }
  ],
  "id": "0",
  "is_default_pod": true,
  "location": "tok05",
  "name": "cluster1",
  "num_hosts": 1,
  "shared_storage": [
    {
      "datastore_name": "workload_share_bVI33",
      "file": "FILE_STORAGE_2",
      "iops": "READHEAVY_TIER",
      "nfs_type": "nfs",
      "size": "STORAGE_SPACE_FOR_2_IOPS_PER_GB",
      "status": "Added",
      "storage_id": "83594681",
      "type": "STORAGE_AS_A_SERVICE",
      "volume": 1000
    }
  ],
  "status": "ReadyToUse"
}
```

##3.4 VCSインスタンスのNW詳細情報

```txt:Retrieve&nbsp;the&nbsp;detailed&nbsp;network&nbsp;interface&nbsp;of&nbsp;a&nbsp;cluster
# export ACCESS_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk '{print $4}'`
# curl -s -X GET https://api.vmware-solutions.cloud.ibm.com/v1/vcenters/702e2231-5325-4d03-88b4-1bae68644479/clusters/0/vlans -H "authorization: Bearer $ACCESS_TOKEN" -H "Content-Type:application/json" 
[
  {
    "link": "https://cloud.ibm.com/classic/network/vlans/2657781",
    "location": "Tokyo 5",
    "name": "Private VLAN",
    "number": 2115,
    "primary_router": "bcr01a.tok05",
    "purpose": "Management VLAN",
    "subnets": [
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.0",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.1",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.63",
            "status": "Reserved"
          },
          {
            "desc": "vCenter Server",
            "ip_address": "10.193.73.2",
            "status": "Reserved"
          },
          {
            "desc": "NSX Manager",
            "ip_address": "10.193.73.3",
            "status": "Reserved"
          },
          {
            "desc": "NSX Controllers",
            "ip_address": "10.193.73.4",
            "status": "Reserved"
          },
          {
            "desc": "NSX Controllers",
            "ip_address": "10.193.73.5",
            "status": "Reserved"
          },
          {
            "desc": "NSX Controllers",
            "ip_address": "10.193.73.6",
            "status": "Reserved"
          },
          {
            "desc": "clouddriver",
            "ip_address": "10.193.73.7",
            "status": "Reserved"
          },
          {
            "desc": "Mgmt Edge Private Interface",
            "ip_address": "10.193.73.8",
            "status": "Reserved"
          },
          {
            "desc": "zerto mgmt portable ip",
            "ip_address": "10.193.73.9",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2149455",
        "network_identifier": "10.193.73.0/26",
        "purpose": "Infrastructure VMs: CD, NSX VMs, sddc manager...",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.128",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.129",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.255",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 1",
            "ip_address": "10.193.73.253",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 2",
            "ip_address": "10.193.73.254",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2149453",
        "network_identifier": "10.193.73.128/25",
        "purpose": "NSX traffic",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.64",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.65",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.73.127",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 1",
            "ip_address": "10.193.73.66",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 2",
            "ip_address": "10.193.73.67",
            "status": "Reserved"
          },
          {
            "desc": "Management workload edge primary address",
            "ip_address": "10.193.73.68",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2149457",
        "network_identifier": "10.193.73.64/26",
        "purpose": "Private subnet for customer workload edge",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "Network",
            "ip_address": "10.193.72.192",
            "status": "Reserved"
          },
          {
            "desc": "Gateway",
            "ip_address": "10.193.72.193",
            "status": "Reserved"
          },
          {
            "desc": "zerto.vcs65.ibm.local",
            "ip_address": "10.193.72.198",
            "status": "Active"
          },
          {
            "desc": "ADNSvcs65.ibm.local",
            "ip_address": "10.193.72.205",
            "status": "Active"
          },
          {
            "desc": "host0.vcs65.ibm.local",
            "ip_address": "10.193.72.206",
            "status": "Active"
          },
          {
            "desc": "host0.vcs65.ibm.local",
            "ip_address": "10.193.72.251",
            "status": "Active"
          },
          {
            "desc": "Broadcast",
            "ip_address": "10.193.72.255",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2148237",
        "network_identifier": "10.193.72.192/26",
        "purpose": "Hosts and virtual server instances",
        "subnet_type": "Primary"
      },
      {
        "ips": [
          {
            "desc": "host0.vcs65.ibm.local",
            "ip_address": "10.193.70.2",
            "status": "Reserved"
          },
          {
            "desc": "Gateway",
            "ip_address": "10.193.70.1",
            "status": "Reserved"
          },
          {
            "desc": "Broadcast",
            "ip_address": "10.193.70.63",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2148113",
        "network_identifier": "10.193.70.0/26",
        "purpose": "Zerto Private Subnet",
        "subnet_type": "Portable"
      }
    ]
  },
  {
    "link": "https://cloud.ibm.com/classic/network/vlans/2657793",
    "location": "Tokyo 5",
    "name": "Secondary Private VLAN",
    "number": 2116,
    "primary_router": "bcr01a.tok05",
    "purpose": "Private storage and vMotion VLAN",
    "subnets": [
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.0",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.1",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.63",
            "status": "Reserved"
          },
          {
            "desc": "vsan 10.193.72.206",
            "ip_address": "10.193.74.2",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2149467",
        "network_identifier": "10.193.74.0/26",
        "purpose": "Portable subnet for vSAN",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.64",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.65",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.127",
            "status": "Reserved"
          },
          {
            "desc": "mgmt share 10.193.72.206",
            "ip_address": "10.193.74.66",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2149469",
        "network_identifier": "10.193.74.64/26",
        "purpose": "Portable subnet for NAS",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.128",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.129",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "10.193.74.191",
            "status": "Reserved"
          },
          {
            "desc": "vmotion 10.193.72.206",
            "ip_address": "10.193.74.130",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2149471",
        "network_identifier": "10.193.74.128/26",
        "purpose": "vMotion traffic",
        "subnet_type": "Portable"
      }
    ]
  },
  {
    "link": "https://cloud.ibm.com/classic/network/vlans/2657795",
    "location": "Tokyo 5",
    "name": "Public VLAN",
    "number": 974,
    "primary_router": "fcr01a.tok05",
    "purpose": "Public VLAN",
    "subnets": [
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "165.xx.xx.64",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "165.xx.xx.65",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "165.xx.xx.79",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 1",
            "ip_address": "165.xx.xx.66",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 2",
            "ip_address": "165.xx.xx.67",
            "status": "Reserved"
          },
          {
            "desc": "mgmt-nsx-edge primary address",
            "ip_address": "165.xx.xx.68",
            "status": "Reserved"
          },
          {
            "desc": "mgmt-nsx-edge secondary address",
            "ip_address": "165.xx.xx.69",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2137317",
        "network_identifier": "165.xx.xx.64/28",
        "purpose": "Public subnet for management edge",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "SL Reserved",
            "ip_address": "165.xx.xx.64",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "165.xx.xx.65",
            "status": "Reserved"
          },
          {
            "desc": "SL Reserved",
            "ip_address": "165.xx.xx.79",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 1",
            "ip_address": "165.xx.xx.66",
            "status": "Reserved"
          },
          {
            "desc": "Potential HSRP block reserved 2",
            "ip_address": "165.xx.xx.67",
            "status": "Reserved"
          },
          {
            "desc": "customer-nsx-edge primary address",
            "ip_address": "165.xx.xx.68",
            "status": "Reserved"
          },
          {
            "desc": "Management workload edge secondary address",
            "ip_address": "165.xx.xx.69",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2135113",
        "network_identifier": "165.xx.xx.64/28",
        "purpose": "Public subnet for customer workload edge",
        "subnet_type": "Portable"
      },
      {
        "ips": [
          {
            "desc": "Network",
            "ip_address": "165.xx.xx.32",
            "status": "Reserved"
          },
          {
            "desc": "Gateway",
            "ip_address": "165.xx.xx.33",
            "status": "Reserved"
          },
          {
            "desc": "host0.vcs65.ibm.local",
            "ip_address": "165.xx.xx.35",
            "status": "Active"
          },
          {
            "desc": "Broadcast",
            "ip_address": "165.xx.xx.47",
            "status": "Reserved"
          }
        ],
        "link": "https://cloud.ibm.com/classic/network/subnets/2137371",
        "network_identifier": "165.xx.xx.32/28",
        "purpose": "Hosts and virtual server instances",
        "subnet_type": "Primary"
      }
    ]
  }
]
```