VMware Cloud Community
jarhorn
Contributor
Contributor
Jump to solution

Get User reference from VcloudClient vCloud 1.5 Java SDK ?

How can I get the ReferenceType for me after I have logged in?  Assume that I am here:

VcloudClient.setLogLevel(Level.OFF);

VcloudClient client = VcloudClient.login(username, password);

What I would like is to get either the UUID or a reference for my user.  Something that I could use for this code:

User me = User.getUserById(client, userId);

or

User me = User.getUserByReference(client, userRef);

I see no methods on VcloudClient that can get me there...  Any help would be greatly appreciated!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

Yes, these methods are available in SDK 5.1

Regards,

Rajesh Kamal.

View solution in original post

0 Kudos
28 Replies
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

Once you login, the VcloudClient contains the orgname and the username with which one has logged in. Using that information you can get the user reference from the AdminOrganization.

Something like this,

      client.login(adminUsername, adminPassword);
      String userName = client.getUserName();
      String orgName = client.getOrgName();
      AdminOrganization adminOrg = AdminOrganization.getAdminOrgByReference(client, client.getVcloudAdmin().getAdminOrgRefByName(orgName));
      ReferenceType userRef = adminOrg.getUserRefByName(userName);
      User user = User.getUserByReference(client, userRef);

Regards,

Rajesh Kamal.

0 Kudos
jarhorn
Contributor
Contributor
Jump to solution

Thanks for your quick reply, but I don't have those methods ("client.getUserName()" & "client.getOrgName()")available.

Are those perhaps a 5.1 feature?  We haven't upgraded yet, sorry.

I have attached the VcloudClient.class file from my IDE.

Thanks,

jason

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

Yes, these methods are available in SDK 5.1

Regards,

Rajesh Kamal.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

can you guys help me out with vcloud api 5.1 ?? when i use https://example.vcloud.com/api, Im not getting any respose. Is there anything to setup before we use APIs? Can you please guide me ?

Thanks in advance.

Madhu 

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

How are you talking to the vCloud API's.

Are you using the SDK's/REST API tools etc.

Regards,

Rajesh Kamal.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

Actually, My developer wants to use these APS's. As he told me, He wrote me some script for login purpose and he tried to call that script to vcloud director but he doesnt get anything reply back, And i tried that in url which is https://ip-address/api/login not working in the browser as well. Im not sure this is the right way to use API's. Is there anything we need to set up in the vcloud director to use APIs?

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

vCD 5.1 API's has dropped support for the 1.0 API's. 1.0 API's contained the api/login.

1.5 and 5.1 API's have the POST - api/sessions login mechanism.

Use the api/sessions instead of the api/login.

Regards,

Rajesh Kamal.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

how can we call any oraganization? like /api/org-name?? its not working like this

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

Does https://ip-address/api/sessions supoosed to work in the url??  Its not working in browser

But when i use https://ip-address/api/versions , I get some xml response

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

The REST API's are not supported in the browser.

You have to use some tools(http://code.google.com/p/rest-client/ or CURL)/SDKs(Java/.NET/PHP) to access them.

Regards,

Rajesh Kamal.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

So we dont need to set up anything in vcloud right? Just directly access them using SDK/REST API tools ?

My developer Using PHP/SDK, but he is saying he doesnt get any response.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

I have downloaded REST client and sent request for https://ip-address/api, saying not authenticated

here is the respose

peer not authenticated
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.wiztools.restclient.HTTPClientRequestExecuter.execute(HTTPClientRequestExecuter.java:387)
at org.wiztools.restclient.ui.RESTViewImpl$2.run(RESTViewImpl.java:320)

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

When i selected   trust self-signed certificate checkmark, hostnaem verifier allow all,

I get this response, No valid API version can be selected

0000: 4E 6F 20 76  61 6C 69 64  20 41 50 49  20 76 65 72  | No valid API ver |
0010: 73 69 6F 6E  20 63 61 6E  20 62 65 20  73 65 6C 65  | sion can be sele |
0020: 63 74 65 64                                                                                cted             |

0 Kudos
jarhorn
Contributor
Contributor
Jump to solution

Madhu,

This is a completely different thread / discussion.  Please create a new discussion to satisfy your request.

Here is a guide that can help you get started with the vCloud API:

VMware: VMware vSphere Blog: Exploring the vCloud REST API Part 1

It gives a very good introduction to how and what you can do with the API...  This thread is concerning the Java SDK, which is an SDK built for Java based on the Schema of the SDK.  (a layer higher than what you are inquiring about).

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

PHP SDK 5.1.1 patch works against vCD 5.1 and vCD 1.5 API's.

Using RESTClient against vCloud API's

Regards,

Rajesh Kamal.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

How about PHP SDK 5.1.0 for vCloud API 5.1?? 

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

PHP SDK 5.1.0 works against vCD 5.1.

To make it work against vCD 1.5.X we released a PHP SDK 5.1.1 patch. Just a minor change in the login method.

Regards,

Rajesh Kamal.

0 Kudos
MadhuVMwarevClo
Contributor
Contributor
Jump to solution

Its not working for me SDK PHP 5.1.0 against vCD 5.1

Should i use SDK PHP 5.1.0 patch? against vCD5.1

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

Its not working for me SDK PHP 5.1.0 against vCD 5.1

    [Rajesh] This should work, what is not working. Can you elaborate.

Should i use SDK PHP 5.1.0 patch? against vCD 5.1

    [Rajesh] This should work against vCD 5.1 and vCD 1.5.X

Regards,

Rajesh Kamal.

0 Kudos