The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 09:42:56 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: sort of contrib - start VMWare session with C#  (Read 4536 times)
stefan
n00b
*
Offline Offline

Posts: 8


View Profile
« on: November 07, 2007, 01:12:41 PM »

EDIT: wrong forum. New here...Shoudl have been in C# code repository - sorry, Please move it fellows...

This is a very sloppy contribution, I guess I could have given you more exact info on the sdks - but I am so busy coding these days...

not sure if this is "too" basic for this rather impressive forum either but here I go

I have VMWare server setup - one one of those virtual boxes I run Tor/Privoxy. On the host I have a few apps running at occasions. However, automation is king, so I want those apps to check if that VMWare virtual machine isn't running I need the app to start it up automagically.

1. I use C#

2. There is a SDK API for VMWare. Active X controls. To be honest I am not sure (was a month ago or so) if I did download something from
http://www.vmware.com/download/sdk/
or of files are always there after installing VMWare server:
C:\Program files\VMware\VMware VmCOM Scripting API\VmCOM.dll is the file you should reference

3. I have created a VM called TorPrivoxy which is what we want to check if running - and if not, then fire it up

4. Now for the code
Code:
using System;
using System.Collections.Generic;
using System.Text;
using VMCOMLib;

namespace ControlPanelJobs
{
    public class EnsureProxy
    {
        public static void Ensure()
        {
            VmConnectParams vmConn = new VmConnectParams();

            vmConn.Hostname = "localhost";
            vmConn.Username = "administrator";
            vmConn.Password = "foobaradminpassword";



            VmServerCtl vmSrvCtl;

            vmSrvCtl = new VmServerCtl();
            vmSrvCtl.Connect(vmConn);
            foreach (string s in vmSrvCtl.RegisteredVmNames)
            {
                if (s.IndexOf("TorPrivoxy")>= 0 )
                {
                    VmCtl vm = new VmCtl();
                    vm.Connect(vmConn, s);
                    if (vm.ExecutionState != VmExecutionState.vmExecutionState_On)
                    {
                        vm.Start(VmPowerOpMode.vmPowerOpMode_TrySoft);
                        System.Threading.Thread.Sleep(60 * 1000);
                    }

                }
            }


        }



    }
}




I am not sure if it's possible to check when it's up - I guess one single way is just check if the proxy is indeed available , but this one is easy - waiting 60 seconds IS enough and I have no hurry in these cases.
You need to change the admin name and password of course.

For non C#ers - there ARE Perl API:s as well.

The main reason for me needing this is I have found myself - when disturbed by a customer on phone etc - I sometimes (without knowing it) click around my open windows - and it has happened I closed the whole virtual machine down...
 
« Last Edit: November 07, 2007, 01:14:55 PM by stefan » Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!