VMware Cloud Community
MyMoore
Contributor
Contributor
Jump to solution

Shutdown & Restart VMs from remote server

I need to shut-down VMs running under ESX 4(1) hosts from a remote server (IBM System i).

The remote server actually controlls the storage used by the ESX and VM OS's, so I'll have scripts running on the remote server that:

Shuts-down the VM's

Performs maintenance

Restarts the VM's

I've tried to comprehend the big picture here reading discussions, but I'm still confused.

Is vMA provide the best means for shutting-down VMs from a script running on a remote server?

Do the scripts need to use SSH to connect to the vSphere environment to run scripts or issue command?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

vCLI ( really its vSphere SDK for Perl ), PowerCLI, VI Java, etc are all vSphere SDK's to be correct and they are client side bindings to the various scripting and programming languages that bind to the vSphere API. So when I say "API", I mean using any of these SDK's you'll be using the vSphere API to perform the work.

The SDK's are initiated on remote server, this can be windows, linux, etc. so long as it supports one of those toolkits. In general, for admins, you'll be using either vCLI (vSphere SDK for Perl) which supports Linux and Windows or if you're more windows oriented, you can use PowerCLI.

All the documentation was referenced in my first post, please take some time go over the documents as they provide much more detail about the use cases for each + lots of examples with the commands. Again, there's no SSH involved if you're using the vSphere APIs. As I've said, vMA is a virtual appliance you can download and start using if you don't want to install vCLI or PowerCLI on a remote system, this is assuming you're comfortable in a Linux environment. If you're not, then I would highly recommend using PowerCLI which will require a Windows remote server.

Here's a few additional getting started resources:

vSphere SDK for Perl + vMA:

PowerCLI:

http://www.vmware.com/support/developer/windowstoolkit/

http://www.virtu-al.net/2009/11/10/powercli-where-do-i-start/

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

0 Kudos
15 Replies
lamw
Community Manager
Community Manager
Jump to solution

vMA is a VMware virtual appliance that aids administrators in managing and configuring your VMware infrastructure, it's an environment that provides a similar interface such as the Service Console for classic ESX hosts. The neat thing about vMA is, you can centralize all your management and configuration within this appliance and it uses vSphere API (not SSH) to communicate with both your ESX/ESXi and vCenter hosts. This is just one of many toolkits in VI admins arsenal to manage and configure your infrastructure, generally geared towards those that are familiar with the Service Console, there are "remote" CLI tools called vCLI that have the familiar esxcfg-* commands at your disposal.

I would highly recommend you taking a look at the following documentation to get a feel for what's available:

Starting with vMA documentation - http://www.vmware.com/support/developer/vima/

vCLI documentation (all included in vMA appliance) - http://www.vmware.com/support/developer/vcli/

Additional Utility scripts included in vMA appliance - http://www.vmware.com/support/developer/viperltoolkit/viperl40/doc/vsperl_util_index.html

For simple power operations for both VMs/host, you can take a look at vmcontrol.pl and hostops.pl which are part of the vSphere SDK for Perl Utilities (3rd link)

If you're much comfortable in a Windows environment, you may want to take a look at PowerCLI, it's pretty easy to get started with, especially those new to using VMware's SDK's.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Sreejesh_D
Virtuoso
Virtuoso
Jump to solution

This can be achived by running vmware-vmd command through trusted ssh connection.

1. Establish a trusted ssh connection between ESX 4(1) host and remote server (IBM System i). The following link has the detail on setting up trusted connection.

http://www.notesbit.com/index.php/scripts-unix/how-to-create-ssh-trust-connection-between-servers-or...

2. executed the following commands.

To list the registered VMs:

  1. ssh remotehost 'vmware-cmd -l'

/vmfs/volumes/<uuid>/test.vmx

To get the status of the VM:

  1. ssh remotehost 'vmware-cmd /vmfs/volumes/<uuid>/test.vmx getstate'

To start the VM:

  1. ssh remotehost 'vmware-cmd /vmfs/volumes/<uuid>/test.vmx start'

To shutdown the GOS:

  1. ssh remotehost 'vmware-cmd /vmfs/volumes/<uuid>/test.vmx

stop soft'

To restart the GOS:

  1. ssh remotehost 'vmware-cmd /vmfs/volumes/<uuid>/test.vmx reset soft'

Note: vmware tools should be running on the GOS for shutting down and restarting the VM.

VCP3, VCP4, RHCE, EMCPA

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful

MyMoore
Contributor
Contributor
Jump to solution

Thanks.

So, based on your comments and the content referenced, vMA is likley over-kill for what I need?

0 Kudos
MyMoore
Contributor
Contributor
Jump to solution

Thanks, yezdi.

Your suggestion is that I can initiate each operation from individually commands in the script running on the remote server - - rather than calling a script on the ESX host that initiates all the operations?

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Not necessarily overkill, just depends on your comfort level. Tell you truth, I don't use shell scripts or Service Console for automation anymore. It's too much of a hack to do certain operations based on the native toolset, the APIs are much more richer and when you start to manage a large infrastructure, you're not updating/configuring few hosts, it's a few hundred hosts. To really perform the day to day operations that's required such as monitoring or changes to the environment, the API's are really the way to go and it's the direction of VMware as you can see with the transition away from ESX with the Service Console, ESXi has no such console, you'll need to learn to use vCLI, PowerCLI, etc. ... if not now, you eventually will. This is a great opportunity to start learning about these new CLI's that are much more powerful.

I agree, if you need to perform specific changes such as updating your syslog configuration, you may need to rely on shell scripts, but majority of the configuration or operations can be performed using the API and the operations you've mentioned are perfect with the APIs.

It was mentioned in reply by the other user to use "vmware-cmd", yes you can use this on the Service Console, but this also exists as a remote CLI commandas part of the vCLI toolkit.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
MyMoore
Contributor
Contributor
Jump to solution

Thanks, William.

Please elaborate - so I'm sure I understand your recommendations.

You suggest using "the API's" rather than shell scripts or Service Console.

Are "vCLI, PowerCLI, etc." the same as "the APIs?"

Where do I learn how to initiate the APIs (in my case to shut-down and start VM's) from a remote server? Is this still done using SSH?

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

vCLI ( really its vSphere SDK for Perl ), PowerCLI, VI Java, etc are all vSphere SDK's to be correct and they are client side bindings to the various scripting and programming languages that bind to the vSphere API. So when I say "API", I mean using any of these SDK's you'll be using the vSphere API to perform the work.

The SDK's are initiated on remote server, this can be windows, linux, etc. so long as it supports one of those toolkits. In general, for admins, you'll be using either vCLI (vSphere SDK for Perl) which supports Linux and Windows or if you're more windows oriented, you can use PowerCLI.

All the documentation was referenced in my first post, please take some time go over the documents as they provide much more detail about the use cases for each + lots of examples with the commands. Again, there's no SSH involved if you're using the vSphere APIs. As I've said, vMA is a virtual appliance you can download and start using if you don't want to install vCLI or PowerCLI on a remote system, this is assuming you're comfortable in a Linux environment. If you're not, then I would highly recommend using PowerCLI which will require a Windows remote server.

Here's a few additional getting started resources:

vSphere SDK for Perl + vMA:

PowerCLI:

http://www.vmware.com/support/developer/windowstoolkit/

http://www.virtu-al.net/2009/11/10/powercli-where-do-i-start/

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
MyMoore
Contributor
Contributor
Jump to solution

Please help me comprehend the "remote syste" issue here...

I've installed, configured, and tested vMA.

Now, to end VM's on ESX hosts in the same management network from a remote server... does vSphere CLI, vSphere SDK for Perl, or PowerCLI need to be instaled on that remote server?

The remote server is not Windows or Linux - it's IBM i5/OS, which has an Unix (AIX) runtime environment.

Thanks.

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

okay, apparently you've not looked at any of the documentation I've referenced?

pg 7 shows the supported OSes for installing the vCLI and AIX is not one of the supported OSes.

PowerCLI is for Windows, so again you did not clearly read through what I've written in the previous replies.

You might be able to compile vSphere SDK for Perl from source but it may be a hack and may or may not work and definitely won't be supported from VMware. I would recommend you download vMA and use that, that way the environment is all setup and you can start using the utilities. Please spend some time going over the documentation, as most of your general questions will probably be answered through that.

If you still have further questions after going through the documents, I would be more than welcome to help answer them.

Thanks

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
MyMoore
Contributor
Contributor
Jump to solution

Sorry for implying I hadn't read the referenced material: I had.

In fact it was based on my assilimation of your comments and referenced sources that I inquired about initiating the shutdown and restart of vm's from an OS (IBM AIX) on which the SDK is not supported. I created a vMA vm, and tested with supported OS's.

Is there a way to initiate these operations (via API/SDK) on a vm from an OS other than Windows or Linux?

If not, is using SSH to connect to the vMA appliance recommended?

Thanks for you time and valuable contribution to this community!

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

So I would recommend you try to use the SDK's, which ever one makes sense and since it sounds like your in UNIX/Linux shop, vMA and vCLI is your best bet. You can issue SSH connection to vMA, it's just a RHEL5 system and SSH is indeed available but it sounds like you'll need to use it as a proxy? Do you have to run the commands from your IBM system? Can you run the scripts on vMA host and contact the IBM system for data? I guess it can go either way, but you're adding a level of complexity into your environment by doing this hop.

What you probably can do is have the scripts setup in vMA, maybe have a script that basically waits for a call from our IBM system and based on certain input, it would execute. I'll leave it to you to figure out the integration pieces between your internal system to vMA. It's definitely doable, but if you can perform it from vMA, that would be the most ideal. You could also see if you can get vCLI compiled on AIX, it's worth a shot but remember not all feature of vMA will be in vCLI, primarily vi-fastpass and vi-logger

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
MyMoore
Contributor
Contributor
Jump to solution

Thanks, William.

I don't think it will have to be a proxy: the IBM server can, as an SSH client, connect directly to the vMA. (Is that what you meant about "proxy?")

The IBM server needs to initiate the shut-down and restart of the vm's because the ESX hosts are dependent on it; the IBM server manages the SAN, tape drives, etc. Anytime the IBM server shuts-down, the entire VMware environment needs to be gracefully ended first.

Running the scripts on vMA sounds good: can scripts that leverage the vMA features be run on vMA - and be called from a remote server?

So, when the IBM server needs to shut-down a VM (i. e. for backup), it calls an existing script on vMA that ends a vm with:

"vmware-cmd "

Is that doable?

Would this method be using the APIs - not shell scripts - as you previously encouraged?

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Yes, you can do that. I don't know to the extent of your automation, but yes you can remotely call the scripts from another system. vmware-cmd is one of the many scripts that leverages the vSphere API, you don't necessary have to call those scripts directly, you can even wrap them in a external Perl or shell script. There's quite a bit of flexibility, but at the end of the day, the actual scripts executing the operations should be those vCLI or any custom scripts you've written against the vSphere SDK for Perl.

e.g.

You should be able to do something like this from your IBM box:

ssh vi-admin@vma-host vmware-cmd <vm-path> stop <powerop_mode>

Just remember, that the vm-path probably should be queried before performing the operations, so perhaps you'll want to create a local script on vMA that queries for all the VMs you want to perform the operation, do a for loop and perform whatever power operation you need and then just call this "wrapper" script from your IBM system.

Hopefully this makes sense, it'll be a fun exercise Smiley Wink

Happy scripting

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
MyMoore
Contributor
Contributor
Jump to solution

Yes, it will be very fun!

Thanks for getting me started.

0 Kudos
knarayana
Contributor
Contributor
Jump to solution

Hi,

I am looking for an api that I can use to shut down and restart vms from within a vm. But I do not want to install vmtools. Is there an api that allows me to to a shutdown of vms from within a vm. Assume all the vms are on the same host machine and one esxi server managing them. I don't want to install vmtools in my vm. Without that, I want to perform shutdown operation.

\...kt

0 Kudos