vmware / vsphere-automation-sdk-java

Java samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
MIT License
209 stars 133 forks source link

Feature Request Example Docu for simple print network details with version 8.0.1 of JAVA SDK #185

Closed GVLLIFESTYLE closed 1 year ago

GVLLIFESTYLE commented 1 year ago

This documentation does not work anymore, could you provide an valid example for the latest api?

https://developer.vmware.com/samples/7909/print-vm-network-details?h=network

if possible please incluse connecting, ....

aagrawal3 commented 1 year ago

Please include more details about the issue. Environment details, error stack-trace and steps to reproduce.

GVLLIFESTYLE commented 1 year ago

well it is not even possible to execute the example, as most of the classes simply don't exist anymore. References from the example cannot be loaded from the sdk, methods don't exist anymore or have different parameters,... Moreover if I build the SDK and add it as external jar to maven, I have no sources from most of the classes. Is there a way to get the sources for debugging?

GVLLIFESTYLE commented 1 year ago

For example these can't be resolved:

import com.vmware.vim25.mo.InventoryNavigator; import com.vmware.vim25.mo.ServiceInstance; import com.vmware.vim25.mo.VirtualMachine;

aagrawal3 commented 1 year ago

Hi @MrLoverLoverMMMM Looks like you have used a sample which is dependent on third party libraries that are not supported by VMware. https://mvnrepository.com/artifact/com.vmware/vijava/5.1 https://vijava.sourceforge.net/

The packages mentioned in https://github.com/vmware/vsphere-automation-sdk-java/issues/185#issuecomment-1530917891 are not part of our official vim25 jar.

GVLLIFESTYLE commented 1 year ago

OK, could you then please point me to a version of the example which is working officially with the vmware sdk? We bought vmware and we would like to switch from RHV to vmware. Therefore we need that example. As the sources of the SDK are not shipped I have no idea how to proceed.

aagrawal3 commented 1 year ago

Can you please help with following details

Please note that vsphere-automation-sdk-java is part of our automation suite of SDKs. The sources for vim25.jar (which is part of our management SDK are not published here). You can refer to our management SDK here

For vsphere-automation-sdk-java, please refer to: samples sources Docs quick start guide

GVLLIFESTYLE commented 1 year ago

OK Other question. Which SDKs and Examples fit best for my usecases:

We are using the on-prem solution of vmware. The latest version.

GVLLIFESTYLE commented 1 year ago

I tried and it failed: the classes used in the example are also not in the built of vim25 of the current version of the management sdk

kunal-pmj commented 1 year ago

The references from the example you are referring to are not part of the vim25. @aagrawal3 updated earlier that these packages, "com.vmware.vim25.mo.*" are part of 3rd party library and not managed by VMware.

Is there some kind of maven repository for all of your sdks, that would make everything much more easy?

No, at this point SDKs are not present in public repositories. We will have this concern addressed soon.

How can I build the management sdk for java ?

Kindly download the management SDK from https://developer.vmware.com/web/sdk/8.0/vsphere-management and follow the developer setup and programming guide to get started with your use case. The SDK also contains samples/examples to showcase VM operations like Clone, Create, Power, Reconfigure etc.

Let us know if you face issues working with management SDK samples.

Is it possible to get the sources for eclipse for auto completion somewhere? (if I build the sdk according to the manual, they aren't included)

The vim25 source code in not included with the SDK. Since, the vim25 source and jar are built using tools shipped with the SDK. You can chose to retain the java source when you build the management SDK. However, If auto completion is your only concern then check the eclipse build class path for vim25.jar it should address the autocompletion issues related to vim25 APIs.

Thanks Kunal

GVLLIFESTYLE commented 1 year ago

Thank you very much for the detailed answer. Now I've got only 1 questions left. If that example I found in within your example search is not supported. Do you guys have somewhere an example for getting network info and status of an running vm and could you point me to it?

aagrawal3 commented 1 year ago

Which SDKs and Examples fit best for my usecases.

Our vSphere Management SDK covers the legacy VIM APIs which are exposed over SOAP such as VM, Host while our vSphere Automation SDK covers the APIs which are relatively new and are exposed over REST protocol. Ex: Content Library, Tagging Features. There are some APIs which are available in both the SDKs. For the APIs you mentioned, you may use either one of our SDKs.

Do you guys have somewhere an example for getting network info and status of an running vm and could you point me to it?

We do not have samples covering all our APIs. Please refer to our existing samples in SDKs to draw out a coding pattern and utilise the API docs, programming guide to write code for your use cases. We highly appreciate and request sample contributions from community.

For this particular use case, if you are using automation SDK, you can try guest networking API -> https://developer.vmware.com/apis/vsphere-automation/v8.0.0/vcenter/api/vcenter/vm/vm/guest/networking/get/ To get the ID of VM, you may use list VM sample These VM related samples for Automation SDK may be of help to you.

GVLLIFESTYLE commented 1 year ago

Is there a java SDK for the guest networking api? I think its not best practrise if all is coded beautifully with the SDK and for the network I need the rest interface...

GVLLIFESTYLE commented 1 year ago

I want to do something like this. Is this not possible??

ManagedObjectReference vmRef= vmWareConnection.findObject("VirtualMachine", vmName); vmWareConnection= getConnectionToVMware(); ManagedObjectReference loadTask= vmWareConnection.getVimPort().getNetworkDetails(vmRef); .... Or how can I get the IP from a virtual machien by a managedobjectreference?

GVLLIFESTYLE commented 1 year ago

@kunal-pmj from which external library are thos?

import com.vmware.vim25.mo.InventoryNavigator; import com.vmware.vim25.mo.ServiceInstance; import com.vmware.vim25.mo.VirtualMachine;

??

I tried . It was not sufficient.

I was able to implement nearly all usecases.

Now I hava only this 1 usecase left.

Get the ip of an running vm by the vmname. That should be as easy as possible. Can anyone please advice?

GVLLIFESTYLE commented 1 year ago

@aagrawal3 : Your example (listVMs) does not work. It uses a vapiAuthHelper which comes from somewhere? No initialization, nothing... Where can I find out from where it comes from?

I need at least any kind of example which is working or a list of all example i need to get 1 example to work...

aagrawal3 commented 1 year ago

Hi @MrLoverLoverMMMM It looks like you wish to use vim25 jar from our Management SDK for your use case. -> https://developer.vmware.com/web/sdk/8.0/vsphere-management As mentioned earlier, the examples I shared work with Automation SDK. -> https://github.com/vmware/vsphere-automation-sdk-java Please open a service request (SR). It will be convenient for both sides to discuss things over call.

GVLLIFESTYLE commented 1 year ago

I have those 3 jars refered at my project. Your example still does not work. Neither the one about network nor the one from list vms.

vsphere-management-sdk vim25 vmGuestSDK

It seems the examples are not complete or use imports which are not avialable anymore.

GVLLIFESTYLE commented 1 year ago

I highlighted the things not clear and add comments

` /*


import java.util.Arrays; import java.util.Collections; import java.util.List;

import org.apache.commons.cli.Option;

import com.vmware.vcenter.VM; import com.vmware.vcenter.VMTypes.Summary; import com.vmware.vcenter.VMTypes.FilterSpec.Builder; import vmware.samples.common.SamplesAbstractBase; import vmware.samples.vcenter.helpers.ClusterHelper; import vmware.samples.vcenter.helpers.DatacenterHelper; import vmware.samples.vcenter.helpers.FolderHelper;

/**

kunal-pmj commented 1 year ago

//where is this vapiAuthHelper comming from?, How to initialize the connetion? //What is the sessionStubConfig, how to create it?

vapiAuthHelper is a utility class available with this SDK.

Kindly follow the README to build and run the sample

$java -ea -cp target/vsphere-samples-8.0.0.1.jar vmware.samples.vcenter.vm.list.ListVMs --server --username --password --skip-server-verification

GVLLIFESTYLE commented 1 year ago

I was already building the sdk obviously... Which one of the two I should use in my java and do i have to add the lib-jars from the folder lib additionally? I would like to have an entire bundle of everything as 1 jar.

How can I build 1 jar containing all inclusive sources to add as external repo to maven?

GVLLIFESTYLE commented 1 year ago

I have those currently Which one contains all, or can i simply bundle all them up into 1 jar? image

kunal-pmj commented 1 year ago

vsphere-samples-8.0.0.1.jar has all the samples, utilities and dependencies. Include it

GVLLIFESTYLE commented 1 year ago

OK, I will try.

GVLLIFESTYLE commented 1 year ago

Where can I open a service request (SR) for assistence to receive the exact quote for what we need?

GVLLIFESTYLE commented 1 year ago

I added the jar combining all, but source / autocompletion in my ide is for most classes not avialable. I would just like to get the list of ips of a running vm by vmname. Can that be that dificult? Is there somewhere an working example for loading network ips of an running vm? I already where able to load the id of the vm by name.

kunal-pmj commented 1 year ago

Where can I open a service request (SR) for assistence to receive the exact quote for what we need?

https://www.vmware.com/web/vmware/login

To get the VM Identity use this API https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/index.html Here is the REST API Reference for the API https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/api/vcenter/vm/vm/guest/identity/get/

GVLLIFESTYLE commented 1 year ago

@kunal-pmj : I already have the vms id with the list example you shared beforehand. How do I get the network-ip of the vm? is appliance used synonym to vm in your documentation?

kunal-pmj commented 1 year ago

@MrLoverLoverMMMM did you look at the API?

https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/Identity.html

It returns the Guest Identity which includes IP, hostname etc.

You need to pass the VM ids to this API to get guest Info

GVLLIFESTYLE commented 1 year ago

So from where can I get then, which endpoint do I need to use?

kunal-pmj commented 1 year ago

Updated the right API bindings Link

GVLLIFESTYLE commented 1 year ago

@MrLoverLoverMMMM did you look at the API?

https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/Identity.html

It returns the Guest Identity which includes IP, hostname etc.

You need to pass the VM ids to this API to get guest Info

I use the java-sdk, not the api directly

GVLLIFESTYLE commented 1 year ago

I need the ip-address of the running vm. This seems to also not be possible with the identiy endpoint. Which one should I use?

kunal-pmj commented 1 year ago

This conversation is going all over the place. Kindly share you official email address to discuss further

GVLLIFESTYLE commented 1 year ago

OK. You should have received an e-mail from our side.

GVLLIFESTYLE commented 1 year ago

I have sent it to singhk@vmware.com

kunal-pmj commented 1 year ago

You can refer to this SDK sample which uses the VM Guest Identity API(https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/Identity.html)

Sample : https://github.com/vmware/vsphere-automation-sdk-java/blob/master/src/main/java/vmware/samples/vcenter/vm/guest/GuestInfo.java#L87

GVLLIFESTYLE commented 1 year ago

But there is also no method to get the interfaces / ip of the vm.

kunal-pmj commented 1 year ago

I seem have shared a wrong link earlier

https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/guest/IdentityTypes.Info.html

GVLLIFESTYLE commented 1 year ago

thanks, what actually if there is multiple ips / nics on 1 vm? This method returns only 1 string.

kunal-pmj commented 1 year ago

The REST API does not have the capability to return multiple VM IPs. You can use the SOAP SDK to get multiple nics/IPs

GVLLIFESTYLE commented 1 year ago

2 things: Could you add the support for multiple ips as feature request? 2nd: How does the api currently handly 2 ips? Will there be both in 1 string or just nothing returned or how does it work?

kunal-pmj commented 1 year ago

Could you add the support for multiple ips as feature request?

Yes, an enhancement request can be taken up

2nd: How does the api currently handly 2 ips? Will there be both in 1 string or just nothing returned or how does it work?

The first IP from NIC0 will be returned by the API

GVLLIFESTYLE commented 1 year ago

perfect, thanks :) Please add me to the list of notifications about this feature request. We do need this function.

lemke1458 commented 1 year ago

APIs to expose full guest networking have existed for a while (7.0.x I think?)

Look under https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/guest/networking/package-tree.html for them.

Specifically https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/guest/networking/Interfaces.html

for full guest NIC info.

kunal-pmj commented 1 year ago

Thanks @lemke1458

@MrLoverLoverMMMM here is the for REST API reference https://developer.vmware.com/apis/vsphere-automation/v8.0.0/vcenter/api/vcenter/vm/vm/guest/networking/interfaces/get/ I am closing the Issue.

GVLLIFESTYLE commented 1 year ago

I need the java sdk. You got a bundle where this is fixed? I dont wanna use the api directly!

Am 19. Mai 2023, 08:32, um 08:32, Kunal Singh @.***> schrieb:

Thanks @lemke1458

@MrLoverLoverMMMM here is the for REST API reference https://developer.vmware.com/apis/vsphere-automation/v8.0.0/vcenter/api/vcenter/vm/vm/guest/networking/interfaces/get/ I am closing the Issue.

-- Reply to this email directly or view it on GitHub: https://github.com/vmware/vsphere-automation-sdk-java/issues/185#issuecomment-1554075214 You are receiving this because you were mentioned.

Message ID: @.***>

kunal-pmj commented 1 year ago

The API bindings are present in the SDK.

Kindly refer to @lemke1458 's update

https://vmware.github.io/vsphere-automation-sdk-java/vsphere/8.0.1.0/vcenter-bindings/com/vmware/vcenter/vm/guest/networking/Interfaces.html

com.vmware.vcenter.vm.guest.networking.Interfaces.list(java.lang.String vm)

Returns information about the networking interfaces in the guest operating system.

GVLLIFESTYLE commented 1 year ago

Thanks, I'll try that. I have 1 question. If the current interface is only ipv6 what does getIpv4().getAddress() return in this case?

GVLLIFESTYLE commented 1 year ago

OK, I tried but it won't work I get unauthorized for the following code:

Interfaces interfacesService = vmwareConnection.getVapiAuthHelper().getStubFactory().createStub(
                     Interfaces.class,
                     vmwareConnection.getSessionStubConfig());

             List<InterfaceInfo> interfaceInfo = interfacesService.list();

Other code such as the following works without issues

 Power vmPowerService = vmwareConnection.getVapiAuthHelper().getStubFactory().createStub(Power.class, vmwareConnection.getSessionStubConfig());
                 Identity identityService=vmwareConnection.getVapiAuthHelper().getStubFactory().createStub(Identity.class, vmwareConnection.getSessionStubConfig());

Can you help me out why?

kunal-pmj commented 1 year ago

can you share your snippet and console log