[Users] [rhevm-api] Need help to Start and Stop VM using Java SDK

Juan Hernandez jhernand at redhat.com
Tue Feb 11 10:31:12 EST 2014


On 02/11/2014 04:16 PM, Itamar Heim wrote:
> On 02/11/2014 04:55 PM, Tejesh M wrote:
>> Thanks for your fast response.
>>
>> But intelli sense is not listing vm.*start *function
>>

This is because you are using the VM class from the
org.ovirt.engine.sdk.entities package, instead of from the
org.ovirt.engine.sdk.decorators package.

The entities package contains classes that plain containers for the data
that is sent to and received from the server.

The decorators package contains classes that extend those plain
containers adding functionality like the action methods.

>> I'm using rhevm-sdk-java-1.0.0.29-1.jar
>>
>> _*code:*_
>>
>> import org.ovirt.engine.sdk.Api;
>> import org.ovirt.engine.sdk.common.*;
>> import org.ovirt.engine.sdk.decorators.VMDisk;
>> import org.ovirt.engine.sdk.entities.*;
>> import org.apache.commons.beanutils.*;
>>
>>
>> public class rhvm {
>>      static Api api;
>>      public static void callAPI()
>>      {
>>          try{
>>
>>          api = new Api("https://rhevm:443/api", "admin at internal",
>> "password");
>>
>>
>>          org.ovirt.engine.sdk.entities.VM vm =
>> api.getVMs().get("testVM3"); //get VM

If you want to be able to use the "start" method you will need something
like this:

org.ovirt.engine.sdk.decorators.VM vm = api.getVMs().get("testVM3");

Then your IDE will show you the additional methods in the decorator,
including the "start" method.

>>          vm.setDescription("java_sdk");
>>
>>          System.out.print("VM ID:" + vm.getStatus().getState());
>>          System.out.print("VM ID:" + vm.getId());
>>
>>
>>          }
>>          catch(Exception e)
>>          {
>>              System.out.print(e);
>>          }
>>          finally {
>>               api.shutdown();
>>           }
>>      }
>> public static void main(String a[]) throws Exception
>> {
>>      //rhvm obj = new rhvm();
>>      callAPI();
>>      System.out.println("\ncompleted");
>> }
>> }
>>
>>
>>
>>
>> On Tue, Feb 11, 2014 at 8:08 PM, Ewoud Kohl van Wijngaarden
>> <ewoud+rhevm-api at kohlvanwijngaarden.nl
>> <mailto:ewoud+rhevm-api at kohlvanwijngaarden.nl>> wrote:
>>
>>     On Tue, Feb 11, 2014 at 08:00:57PM +0530, Tejesh M wrote:
>>      > Can anyone share sample on how to Start & Stop VM using Java SDK? I
>>      > couldn't find any document on JAVA SDK for RHEVM.
>>
>>     While this list hasn't been in use for some time, I hope I can still
>>     point you
>>     in the right direction. http://www.ovirt.org/Java-sdk#Examples has the
>>     following examples:
>>
>>     // -- Create proxy
>>
>>     // #1 - import
>>     import org.ovirt.engine.sdk.Api;
>>
>>     // #2 - create proxy
>>     Api api = new Api("http://localhost:8080/api", "user at domain",
>>     "password");
>>
>>     // -- perform an action on resource
>>
>>     // #1 - fetch resource
>>     VM vm = api.getVMs().get("test");
>>
>>     // #2 - create params + perform an action
>>     Action res = vm.start(new Action() {
>>              {
>>                      setVm(new org.ovirt.engine.sdk.entities.VM());
>>              }
>>     });
>>
>>     I'd guess vm.stop is exactly the same as vm.start.
>>     _______________________________________________
>>     rhevm-api mailing list
>>     rhevm-api at lists.fedorahosted.org
>>     <mailto:rhevm-api at lists.fedorahosted.org>
>>     https://lists.fedorahosted.org/mailman/listinfo/rhevm-api
>>
>>
>>
>>
>> --
>> Thanks & Regards
>> Tejesh
>>
>>
>> _______________________________________________
>> rhevm-api mailing list
>> rhevm-api at lists.fedorahosted.org
>> https://lists.fedorahosted.org/mailman/listinfo/rhevm-api
>>
> 
> moving to users at ovirt.org...
> 
> thanks,
>     Itamar
> _______________________________________________
> Users mailing list
> Users at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users
> 


-- 
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.


More information about the Users mailing list