VMware Cloud Community
MariusRoma
Expert
Expert

Scripting ovftool

I need to write a script to remotely shotdown a guest VM, export it to .ova format an restart it.

Is there any sample I can start from?

Regards

marius

Tags (1)
0 Kudos
5 Replies
nicolapavlov
Contributor
Contributor

Hello Marius,

I want to do the same thing? I want to write a batch script on windows.

Did you succeed?

Thanks,

Nicola.

0 Kudos
eumoremar
Contributor
Contributor

Hello Marius,

In windows you can try this:

c:>ovftool --powerOffSource --overwrite vi://user:password@your_server/your_pool/your_machine destination_file.ova

c:>plink -ssh -pw password -2 user@your_server vim-cmd vmsvc/power.on your_machine_id   --> You need the putty command for ssh (plink).

To know your_machine_id, you must run this commans in your ESXi host:

#vim-cmd vmsvc/getallvms

In linux, at first you must solve the ssh authentication with this:


#ssh -keygen

#ssh-copy-id -i ~/.ssh/id_rsa.pub root@your_server

And then:

#ovftool --powerOffSource --overwrite vi://user:password@your_server/your_pool/your_machine destination_file.ova

#ssh user@your_server vim-cmd vmsvc/power.on your_machine_id

Best regards.

0 Kudos
nicolapavlov
Contributor
Contributor

Hello,

Thank you for the post.

I have run the following command under Windows in order to export a VM in ovf format:

     ovftool --powerOffSource vi://my_username:my_password@my_host/test C:\Users\Administrator\Desktop\nicola.ovf

The export process finishes smoothly but the VM stays down. Is there a way to get it up without having to import it again?

I tried the following:

     ovftool --powerOffSource --powerOn vi://my_username:my_password@my_host/test C:\Users\Administrator\Desktop\nicola.ovf

with no luck.

Only this works but it means to deploy again:

     ovftool --name=test --overwrite --powerOn C:\Users\Administrator\Desktop\nicola.ovf vi://my_username:my_password@my_host/test

Is there a way to get up a VM after export without deploying?

Thanks,

Nicola.

0 Kudos
eumoremar
Contributor
Contributor

Hello Nicola,

Effectively, I tried the “—powerOn” option with no luck too. The only way that I have found to run it successfully has been a direct call to the ESXi command vim-cmd via ssh.


In Windows:


c:>plink -ssh -pw password -2 user@your_server vim-cmd vmsvc/power.on your_machine_id


In Linux:


#ssh user@your_server vim-cmd vmsvc/power.on your_machine_id


Best regards.

0 Kudos
nicolapavlov
Contributor
Contributor

Thanks a lot.

This seems to fix it.

Regards,

Nicola.

0 Kudos