static void Main(string[] args) { string vmName = args[0]; Console.WriteLine("ReImaging VM " + vmName); Console.WriteLine("Hit ENTER to roll back VM to the Service snapshot."); Console.ReadLine(); NetworkCredential mNetworkCredentials = new NetworkCredential("user", "password"); Console.WriteLine("Rolling VM back to the Service snapshot..."); // First step: roll back to service PowerCLI.Instance(mNetworkCredentials).RollbackVM(vmName, "Service", null); Console.WriteLine("Rolled back VM to snapshot Service."); Console.WriteLine("Hit ENTER to remove the Service snapshot."); Console.ReadLine(); Console.WriteLine("Removing snapshot Service..."); PowerCLI.Instance(mNetworkCredentials).RemoveSnapshot(vmName, "Service", null); Console.WriteLine("Removed snapshot Service from VM " + vmName); Console.WriteLine("Hit ENTER to create a new Service snapshot."); Console.ReadLine(); Console.WriteLine("Creating new snapshot Service..."); PowerCLI.Instance(mNetworkCredentials).CreateSnapshot(vmName, "Service", null); Console.WriteLine("Removed snapshot Service from VM " + vmName); Console.WriteLine("All done."); }
private bool CreateSnapshot(string snapshot) { if (snapshot.ToLower() == "service") { Log("Not allowed to create Service snapshot.", true); return(false); } bool result = true; if (mTesting == false) { Log("Creating snapshot " + snapshot, true); StopHeartbeatTimer(); PowerCLI powerCLI = PowerCLI.Instance(mNetworkCredentials); result = powerCLI.CreateSnapshot(mData.VMName, snapshot, mLogFile); if (result == false) { DatabaseLog.Insert("CreateSnapshot failed on VM " + mData.VMName, "There might be an issue with PowerCLI. Please check the logs.", 1); } StartHeartbeatTimer(); } return(result); }
private bool Initialize(string snapshot) { bool result = true; if (mTesting == false) { mBusy = true; // Refresh data in case the VM name has changed..... mData = VMInstanceData.SelectByIP(mData.IPAddress); // Stop the heartbeat timer because rolling it back might cause it to actually miss a heartbeat. StopHeartbeatTimer(); PowerCLI powerCLI = PowerCLI.Instance(mNetworkCredentials); result = powerCLI.RollbackVM(mData.VMName, snapshot, mLogFile); if (result == false) { DatabaseLog.Insert("Rollback failed on VM " + mData.VMName, "There might be an issue with PowerCLI. Please check the logs.", 1); } StartHeartbeatTimer(); mBusy = false; } return(result); }
private bool RemoveSnapshot(string snapshot) { if (mTesting == false) { mBusy = true; Log("Removing snapshot " + snapshot); StopHeartbeatTimer(); PowerCLI powerCLI = PowerCLI.Instance(mNetworkCredentials); powerCLI.RemoveSnapshot(mData.VMName, snapshot, mLogFile); StartHeartbeatTimer(); mBusy = false; } return(true); }
private bool RebootVM() { bool result = true; if (mTesting == false) { // Refresh data in case the VM name has changed..... mData = VMInstanceData.SelectByIP(mData.IPAddress); Log("Rebooting VM " + mData.VMName); StopHeartbeatTimer(); PowerCLI powerCLI = PowerCLI.Instance(mNetworkCredentials); result = powerCLI.Reboot(mData.VMName, mLogFile); if (result == false) { DatabaseLog.Insert("Rebooting failed for VM " + mData.VMName, "There might be an issue with PowerCLI. Please check the logs.", 1); } StartHeartbeatTimer(); } return(result); }