2017-07-13 127 views
0

我有一個VCenter服務器版本5.5。我嘗試使用下面的命令生成一個會話ID來驗證REST API請求:無法創建虛擬機會話ID

curl -kv -X POST -H 'Accept: application/json' --basic -u [email protected]:myPass! $VCENTER/rest/com/vmware/cis/session 

其中$ VCENTER = https://vc

這裏的輸出我得到

* Hostname was NOT found in DNS cache 
* Trying 1.2.3.4... 
* Connected to vc (1.2.3.4) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: none 
    CApath: /etc/ssl/certs 
* SSLv3, TLS handshake, Client hello (1): 
* SSLv3, TLS handshake, Server hello (2): 
* SSLv3, TLS handshake, CERT (11): 
* SSLv3, TLS handshake, Server finished (14): 
* SSLv3, TLS handshake, Client key exchange (16): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSL connection using AES256-SHA 
* Server certificate: 
*  subject: O=VMware, Inc.; OU=vCenterServer_2014.12.24_203443; CN=VMware default certificate; [email protected] 
*  start date: 2014-12-24 04:44:30 GMT 
*  expire date: 2024-12-22 04:44:32 GMT 
*  issuer: O=VMware, Inc.; OU=vCenterServer_2014.12.24_203443; CN=VC.xyz.co.in; [email protected] 
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway. 
* Server auth using Basic with user '[email protected]' 
> POST /rest/com/vmware/cis/session HTTP/1.1 
> Authorization: Basic YWthbmtzaGFfamFpbkBwZXJzaXN0ZW50LmNvLmluOmFra2FTZXAyMDE3IQ== 
> User-Agent: curl/7.35.0 
> Host: pt-vc 
> Accept: application/json 
> 
< HTTP/1.1 400 Bad Request 
< Date: Thu, 13 Jul 2017 09:33:40 GMT 
< Connection: close 
< Content-Type: text; charset=plain 
< Content-Length: 0 
< 
* Closing connection 0 
* SSLv3, TLS alert, Client hello (1): 

看着輸出結果我不確定發生了什麼問題以及在哪裏。這是因爲我的密碼有!需要轉換成其十六進制等效?

回答

1

感嘆號應該可以作爲密碼傳遞。

問題可能是由於vCenter 5.5沒有任何可用的RESTful端點。這是在vSphere/vCenter 6.0中引入的。

你的輸出會看起來更接近,如果你是在6.0或6.5的環境下:

curl -kv -X POST -H 'Accept: application/json' --basic -u [email protected]:VMware1! https://vcsa01.domain.lab/rest/com/vmware/cis/session 
* Trying 10.159.13.52... 
* Connected to vcsa01.domain.lab (10.159.13.52) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 
* Server certificate: VCSA01 
* Server auth using Basic with user '[email protected]' 
> POST /rest/com/vmware/cis/session HTTP/1.1 
> Host: vcsa01.domain.lab 
> Authorization: Basic ZWNrQGNwYnUubGFiOlZNd2FyZTEh 
> User-Agent: curl/7.43.0 
> Accept: application/json 
> 
< HTTP/1.1 200 OK 
< Date: Thu, 13 Jul 2017 18:47:18 GMT 
< Set-Cookie: vmware-api-session-id=37e6921e6a3905b47ba356aaad19d3d6;Path=/rest;Secure;HttpOnly 
< Expires: Thu, 01 Jan 1970 00:00:00 GMT 
< Content-Type: application/json 
< Transfer-Encoding: chunked 
< 
* Connection #0 to host vcsa01.domain.lab left intact 
{"value":"37e6921e6a3905b47ba356aaad19d3d6"}