Help us understand the problem. What is going on with this article?

vCenterのREST API使用方法

個人的備忘録
vSphere Client バージョン 6.7.0.20000

apiexplorer

  • VMwareのapiexplorerにアクセスすることで、REST APIのリファレンスを確認することができる。
    • URL: https://<vCenter IP or FQDN>/apiexplorer/
  • 例えばVM情報をGETするAPIは以下のように確認することができる。 image.png
  • TRY IT OUT!をクリックすることで、実際にvCenterに対してAPIの実行を試すことができる。 image.png

※上記はheader内のsession-idがnullになっているため、認証エラーとなる。

curlによるAPI実行

  • vCenterとIPリーチャブルなマシンにログインする。
  • 事前にsession-idを取得する。
$ curl --insecure -X POST -u <your-id>:<your-password> \
 https://<vCenter IP or FQDN>/rest/com/vmware/cis/session
{"value":"d8da17d7cba6677d67a271873666eecf"}
  • session-idをheaderに追加して、任意のRESTリクエストを実行する。
$ curl -X GET --header "Accept: application/json" --header \
 "vmware-api-session-id: d8da17d7cba6677d67a271873666eecf" \
 "https://<vCenter IP or FQDN>/rest/vcenter/vm" -k
  • ちなみにsession-idを環境変数にして実行すると便利。
    • もちろんjqでも可。
$ export session_id=`curl --insecure -X POST -u 'user:pass' https://<vCenter IP or FQDN>/rest/com/vmware/cis/session | python3 -c "import sys, json; print(json.load(sys.stdin)['value'])"`
$ curl -k -X GET --header "Accept: application/json" --header "vmware-api-session-id: $session_id" "https://<vCenter IP or FQDN>/rest/vcenter/vm" | python3 -m json.tool 

参考:vCenter REST-API一覧

  • apiexplorerに記載されているAPIの一覧
rest-api
cluster
datacenter
datastore
datastore/default_policy
deployment
deployment/import_history
deployment/install
deployment/install/initial_config/remote_psc/thumbprint
deployment/install/psc/replicated
deployment/install/psc/standalone
deployment/install/remote_psc
deployment/question
deployment/upgrade
folder
guest/customization_specs
host
inventory/datastore
inventory/network
iso/image
network
ovf/capability
ovf/export_flag
ovf/import_flag
ovf/library_item
resource_pool
services/service
storage/policies
storage/policies/compliance
storage/policies/compliance/VM
storage/policies/VM
system_config/deployment_type
system_config/psc_registration
vcha/capabilities
vcha/cluster
vcha/cluster/active
vcha/cluster/deployment_type
vcha/cluster/mode
vcha/cluster/passive
vcha/cluster/witness
vcha/operations
vcha/vc_credentials
VM
vm_template/library_items
vm/guest/identity
vm/guest/local_filesystem
vm/guest/power
vm/hardware
vm/hardware/adapter/sata
vm/hardware/adapter/scsi
vm/hardware/boot
vm/hardware/boot/device
vm/hardware/cdrom
vm/hardware/cpu
vm/hardware/disk
vm/hardware/ethernet
vm/hardware/floppy
vm/hardware/memory
vm/hardware/parallel
vm/hardware/serial
vm/power
vm/storage/policy
vm/storage/policy/compliance
hmtk715
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした