vCenter REST API 사용 방법

3801 단어 vCentervmwareREST-API
개인 비망록
vSphere Client 버전 6.7.0.20000

apiexplorer


  • VMware의 apiexplorer에 액세스하면 REST API 참조를 볼 수 있습니다.
  • URL: https://<vCenter IP or FQDN>/apiexplorer/

  • 예를 들어 VM 정보를 GET하는 API는 다음과 같이 확인할 수 있다.

  • TRY IT OUT!를 클릭하면 실제로 vCenter에서 API를 실행해 볼 수 있습니다.


  • ※ 상기는 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

    호스트

    inventory/datastore

    inventory/network

    iso/image

    네트워크

    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

    좋은 웹페이지 즐겨찾기