Showing posts with label Cluster. Show all posts
Showing posts with label Cluster. Show all posts

Tuesday, June 23, 2015

Simply log what VM is running and where.

We have an issue where randomly a node in our Hyper-V cluster will fail.  We know it is related to an iSCSI event, but we cannot reproduce the error.  Since we don't know what is running when it happens, I thought we could simply log what VMs are running, and on what hosts.
I looked around the internets (or BinGled so to speak) and didn't see anyone who was simply listing the Hyper-V virtual machines running on a host. (Some folks were doing it for Citrix for VMware, but not Hyper-V.)
So I wrote a simple script that will display it on the screen, along with writing it to a file (as we plan on running this script every 24 hours or so, waiting for a crash).



####################################################################################
####################################################################################

<#.Synopsis 
    List all VMs running in the cluster, along with what host it is running on and writes them to a location of your choosing.

.Description 
     List all VMs running in the cluster, along with what host it is running on and writes them to a location of your choosing.

.Parameter  filetowrite
            Path and file name to write the output to.
    

.Parameter clustergroupname
            Cluster name itself, Fully qualified recommended
         

.Example 
    .\List-Vms -filetowrite c:\temp\vmlist.txt -clustergroupname YOURCLUSTERNAMEHERE-FQDN

.Notes 
  Author: Bryan Loveless bryan.loveless@gmail.com
  Requires -Version 4.0 
   
 Version: 1.0
 Updated: 22.June.2015
   LEGAL: PUBLIC DOMAIN.  SCRIPT PROVIDED "AS IS" WITH NO WARRANTIES OR GUARANTEES OF 
          ANY KIND, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY AND/OR FITNESS FOR
          A PARTICULAR PURPOSE.  ALL RISKS OF DAMAGE REMAINS WITH THE USER, EVEN IF
          THE AUTHOR, SUPPLIER OR DISTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF
          ANY SUCH DAMAGE.  IF YOUR STATE DOES NOT PERMIT THE COMPLETE LIMITATION OF
          LIABILITY, THEN DELETE THIS FILE SINCE YOU ARE NOW PROHIBITED TO HAVE IT.

#>

Function List-VMs
{
[CmdletBinding()]
    Param (
        [Parameter(
            Position=1,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            #ValidateNotNullOrEmpty(),
            Mandatory=$true,
            HelpMessage="Filepath and name?"
            )
         ]
           [string]$filetowrite = ("c:\temp\VMlist.txt"),
       

        [Parameter(
            Position=2,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            #ValidateNotNullOrEmpty(),
            Mandatory=$true,
            HelpMessage="What is the name of the cluster?"
            )
         ]
            [string]$clustergroupname = ("YOURCLUSERNAMEHERE-FQDN")
     )  


    get-date | out-file $filetowrite -Append
    $OutArray = @()

    $clusterNodes = Get-ClusterNode -cluster $clustergroupname;
        ForEach($item in $clusterNodes)
            {
            write-host "RUNNING ON " ($item.name).ToString() ":" -foregroundcolor GREEN
            $item | out-file $filetowrite -Append
       
            $vms = Get-VM -ComputerName $item.Name
                ForEach($vm in $vms)
                {
                    write-host $vm.Name $vm.State "CPU used:" $vm.cpuusage "%" "Uptime:" $vm.uptime $vm.Status
                    $vm | Format-table name, state, cpuusage, memoryassigned, uptime, status | out-file $filetowrite -Append
                 }
                
            } 

}



#now to run it
List-VMs -filetowrite c:\temp\vmlist.txt -clustergroupname YOURCLUSTERNAMEHERE-FQDN

# FIN

Tuesday, June 26, 2012

Well, it could have been much worse.


I thought I would share a hyper-v war stor.

Yesterday someone from central IT called me, as he was going to update SCVMM to 2012.  I said, sounds great!  It wasn’t.

We believed that it shouldn’t bring anything down, as SCVMM mostly just monitors, so it shouldn’t be a big deal at all.  About 3 hours later, I get a call from my DBA.  Production SQL is down, along with a host of other VMs.  The dreaded “missing config file” error.  Now, I should mention that my vms are on a 3 node Win 2k8 R2 DC cluster.  Rebooting physical machines, and moving the drives around to “working” nodes didn’t work.  I could still browse to the VHDs and the config files.  Hyper-v then reported that there was a problem with a corrupted file.

So as we sitting around, thinking about backup tapes and considering how to update our resume, I remembered that once I just had rebuilt the config file for a machine that did this in the past.  Now this current machine that was failing to start had several pass through disks, memory settings, various NIC configurations that I didn’t want to have to recreate.  I decided to look into the XML config file.  Sure enough, it ended with :
“<settings>
    <global>
      <logical_id type="string">78F….D-4FC2-someotherGUIDdigitshereFB</logical_id>
    </global>
    <memory>
      <bank>
        <limit type="integer">12288</limit>
        <reservation type="integer">12288</reservation>
        <size type="integer">12288</size>
      </bank>
    </memory>
    <processors>
      <count type="integer">4</count>
      <features>
        <limit type="bool">True</limit>
      </features>
      <limit type="integer">100000</limit>
      <limit_cpuid type="bool">False</limit_cpuid>
      <reservation type="integer">0</reservation>
      <weight type="integer">200</weight>
    </processors>
    <stopped_at_host_shutdown type="bool">False</stopped_at_host_shutdo
“

Now I am no programming wiz, but I know that you at least have to close XML tags, or computers get angry.  Some quick googlin’ turned up:


So I made a backup copy of the current broken XML doc, then properly ended the XML tags that were missing.  I then crossed some fingers, right clicked “bring online” and POOF! It worked.
My heart started beating again, and my cell phone quit vibrating.