Thursday, February 18, 2010

Get VM disks across datastores

I find myself often having to move VMs around onto different datastores (due to upgrades and hardware migrations). I have found the best way to do this is to determine what VM is on what datastore and plan out where I want it to move to. This gets somewhat tedious if you have dozens (or hundreds) of small datastores. Below are 2 powershell scripts I cam across that gather VM/datastore information and outputs it in a fashion easily usable in Excel.

Option 1: (from http://communities.vmware.com/thread/135266)
This is a quick little script that gets all the hosts and the datastores it is on. It runs fairly fast and exports to a CSV file.
get-cluster | %{$cluster = $_; get-vm -Location $_ | %{$vm = $_; $ds = get-datastore -vm $_; echo "$cluster,$vm.name,$ds" >> c:\$cluster.csv ; write-host -NoNewline . }}

Option 2: (from http://doitsmarter.blogspot.com/2008/10/list-vm-usage-and-assosiated-datastore.html)
This is a more invovled script that takes much longer to run. The benefit of this script is that it will include the disk size along with the VM and datastore. This can be very useful when planning migrations because you can easily identify how much space will be needed on the target datastore. NOTE: This only reports the disk capacity, not how much is actually allocated
$datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}
$diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}
get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property Datastore,"Total Disk"

Monday, February 15, 2010

Changing VMware advanced settings via Powershell

I am in progress of adding more NFS datastores to my VMware cluster and realized that there is a max of 8 mounts in the default configuration. The blog http://blog.scottlowe.org/2010/01/31/emc-celerra-optimizations-for-vmware-on-nfs/ describes additional settings that should be changed when updating the number of VM mounts as well.

So, how do you change some discrete settings on dozens of ESX hosts without dedicating and entire day to it? How do you inventory those settings to ensure you got everything done? Thankfully there is powershell.

Inventorying the NFS and NET advanced settings
foreach ($ESXHost in get-cluster Cluster_01 | get-vmhost)
{
Get-VMHostAdvancedConfiguration -VMHost $ESXHost -Name NFS.MaxVolumes
Get-VMHostAdvancedConfiguration -VMHost $ESXHost -Name Net.TcpipHeap*
}


Updating NFS and NET advanced settings
foreach ($ESXHost in get-cluster Cluster_01 | get-vmhost)
{
set-VMHostAdvancedConfiguration -VMHost $ESXHost -Name NFS.MaxVolumes -Value 32
set-VMHostAdvancedConfiguration -VMHost $ESXHost -Name Net.TcpipHeapSize -Value 30
set-VMHostAdvancedConfiguration -VMHost $ESXHost -Name Net.TcpipHeapMax -Value 120
}

Wednesday, February 10, 2010

Custom Roku channels

I just learned today that you can create custom channels for your Roku to stream your own content. Tonight I will be rebuilding my powered off Linux server and setting up the Roku SDK to try and stream video from my server to my desktop

http://thinkcreatecomplete.blogspot.com/2009/12/stream-media-using-app-built-with-roku.html

Tuesday, February 09, 2010

VMware maintenance mode from command line

From http://xtravirt.com/xd10051:

To enter Maintenance Mode, at the ESX console type:

vimsh -n -e /hostsvc/maintenance_mode_enter

To exit Maintenance Mode type:

vimsh -n -e /hostsvc/maintenance_mode_exit

To display whether the ESX Server is currently in maintenance mode or not type:

vimsh -n -e"hostsvc/hostsummary" | grep inMaintenanceMode

Friday, February 05, 2010

Creating and assigning EMC storage via CLI

If your anything like me, you hate doing mind numing work. One of the tasks I have to do regularly is provision storage from our EMC array for VMware. I found the NaviCLI reference doc and identified the commands to provision and present the storage.

Storage configuration:
To balance the need for performance, size, and rebuild time we will be creating multiple RAID5 arrays and metalun between them. For simplicity, we will limit activity into a single physical tray of disks
3* RAID5 (4+1) arrays
Each array will have 7* 150GB LUNs
The 21 LUNs will be combined into 7 metaluns (1 LUN from each array)

STEP 1: Create the Raid Group
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 createrg 60 1_3_0 1_3_1 1_3_2 1_3_3 1_3_4 -raidtype r5
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 createrg 61 1_3_5 1_3_6 1_3_7 1_3_8 1_3_9 -raidtype r5
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 createrg 62 1_3_10 1_3_11 1_3_12 1_3_13 1_3_14 -raidtype r5


STEP 2: Create the LUNs
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 601 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 602 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 603 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 604 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 605 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 606 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 607 -rg 60 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 611 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 612 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 613 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 614 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 615 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 616 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 617 -rg 61 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 621 -rg 62 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 622 -rg 62 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 623 -rg 62 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 624 -rg 62 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 625 -rg 62 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 626 -rg 62 -cap 150
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 bind r5 627 -rg 62 -cap 150


STEP 3: Create the MetaLUNs
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 601 -lus 611 -lus 621 -autoassign 1 -o
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 602 -lus 612 -lus 622 -autoassign 1 -o
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 603 -lus 613 -lus 623 -autoassign 1 -o
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 604 -lus 614 -lus 624 -autoassign 1 -o
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 605 -lus 615 -lus 625 -autoassign 1 -o
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 606 -lus 616 -lus 626 -autoassign 1 -o
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 metalun -expand -base 607 -lus 617 -lus 627 -autoassign 1 -o



STEP 4: Assign MetaLUNs to Storage Group
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 601 -hlu 0
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 602 -hlu 1
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 603 -hlu 2
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 604 -hlu 3
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 605 -hlu 4
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 606 -hlu 5
naviseccli -user emc -password emc -scope 0 -h tkj2506ds01 storagegroup -addhlu -gname VMware -alu 607 -hlu 6