Monday, February 27, 2012

Get all VMs and the MAC address, Duplicate IPs

1. ESXi with
Get-VMHostNetworkAdapter | select VMhost, Name, Mac,Ip
Get-VMHost|Get-VMHostNetworkAdapter
Get-VMHost|Get-VirtualSwitch


2. Get-VM | `Select-Object -Property Name,@{N="MacAdresses";E={$_.NetworkAdapters | ForEach-Object {$_.MacAddress}}},VMHost`


3. Connect-VIServer -Server vSphereServer

$match_address = "172......3"

Get-VM | %{
$vmIPs = $_.Guest.IPAddress
foreach($ip in $vmIPs) {
if ($ip -eq $match_address) {
"Found VM with matching address: {0}" -f $_.Name
}
}
}


4. Get-VMHost |Get-VMHostNetworkAdapter | Where-Object {$_.Mac -eq "00:25:90:2a:6a:a2"}


5.Get-VM -Location Proteus-Cluster | where {$_.'PowerState' -eq "PoweredOn"} | `Select-Object VMHost,Name`

( Verified the number of powered on VMs are the same - 41)
172.16.13.1 Jenkins-Dogfood-Proteus
172.16.13.1 build-amazon-vm-0
172.16.13.1 steve-windows

Thursday, February 23, 2012

Top in Batch Mode, and Expect Script to monitor ESX logs

Unix Top:

0,15,30,45 * * * * /home/nutanix/serviceability/top_pprof.sh > /dev/null 2>&1

nutanix@NTNX-Ctrl-VM-3-NTNX:~$ more serviceability/top_pprof.sh
#!/bin/sh
if [ ! -d /home/nutanix/data/logs/top ]; then
mkdir /home/nutanix/data/logs/top
fi
m=`date "+%d%m"`
dod=`date "+%H%M"`
if [ ! -d /home/nutanix/data/logs/top/$m ]; then
mkdir /home/nutanix/data/logs/top/$m
fi
top -b -n1 > /home/nutanix/data/logs/top/$m/$dod.top
#TOP IN BATCH MODE
mem=`grep stargate /home/nutanix/data/logs/top/$m/$dod.top | awk '{print $10}'|sort -r | head -1| cut -d"." -f1`
if [ ${mem} -gt 55 ]; then
# IF MEM USAGE is more than 55.
curl http://localhost:2009 2>/dev/null |html2text -ascii -width 600 >/home/nutanix/data/logs/top/$m/$dod.stargatepage
curl http://localhost:2009/h/pprof/growth >/home/nutanix/data/logs/top/$m/$dod.pprof 2>/dev/null
curl http://localhost:2009/h/pprof/heapstats >/home/nutanix/data/logs/top/$m/$dod.pprof.heap 2>/dev/null
/home/nutanix/toolchain/x86_64-unknown-linux-gnu/1.1/bin/pprof -pdf /home/nutanix/bin/stargate http://localhost:2009/h/pprof/growth > /home/nutanix/data/logs/top/$m/$dod.pprof.pdf 2>/dev/null
fi

Monitor ESX logs from webpage:
ns:~/public_html/ATLAS$ ~/scripts/check_vcenter_disconnect.sh >> ~/public_html/ATLAS/index.html &

nutanix@uranus:~/public_html/ATLAS$ cat /data/home/nutanix/scripts/check_vcenter_disconnect.sh
#!/bin/sh
while true
do
dddd=`date -u +%Y-%m-%dT%H`
echo $dddd
for seq in `seq 1 4`
do
echo "atlas$seq"
~/scripts/atlas$seq |grep $dddd
done
sleep 1800 <<<< I did not use Cron, because we might forget to turn it off, altleast here when uranus rebooted, it is gone.
done

I could have create single expect script..
nutanix@uranus:~/public_html/ATLAS$ cat /data/home/nutanix/scripts/atlas*
#!/usr/bin/expect
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@172.
expect "word:"
send "a\r"
expect "#"
send "gunzip /var/run/log/vpxa*.gz\r"
expect "#"
send "egrep stolen /var/run/log/vpxa*\r"
expect "#"
send "egrep -i dropping /var/run/log/vpx*\r"
expect "#"
send "exit\r"

atlas2:
#!/usr/bin/expect
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@172
expect "word:"
send "\r"
expect "#"
send "gunzip /var/run/log/vpxa*.gz\r"
expect "#"
send "egrep stolen /var/run/log/vpxa*\r"
expect "#"
send "egrep -i dropping /var/run/log/vpx*\r"
expect "#"
send "exit\r"

atlas3:
#!/usr/bin/expect
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@172.
expect "word:"
send "a\r"
expect "#"
send "gunzip /var/run/log/vpxa*.gz\r"
expect "#"
send "egrep stolen /var/run/log/vpxa*\r"
expect "#"
send "egrep -i dropping /var/run/log/vpx*\r"
expect "#"

atlas4:
send "exit\r"
#!/usr/bin/expect
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@17
expect "word:"
send "apple4u2$\r"
expect "#"
send "gunzip /var/run/log/vpxa*.gz\r"
expect "#"
send "egrep stolen /var/run/log/vpxa*\r"
expect "#"
send "egrep -i dropping /var/run/log/vpx*\r"
expect "#"

Saturday, February 11, 2012

Create VMs from Template - PowerCLI

add-pssnapin VMware.VimAutomation.Core
Connect-VIServer 1751 -User administrator -Password Password
$global:location = "Atlas-Cluster"
$global:datastore = "Atlas-NTNX-datastore"
$global:sourceVM = @("Atlas_Windows_Template")
$global:testIterations = 10
for($i=1; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas$i -VMhost 170 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
$global:testIterations = 20
for($i=11; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas31$i -VMhost 171 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
$global:testIterations = 30
for($i=21; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas31$i -VMhost 172 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
$global:testIterations = 40
for($i=31; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas31$i -VMhost 173 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
get-VM WinDows*|Start-VM

get-VMHost ip_Addr|  get-VM Windows7-*| where {$_.'PowerState' -eq "PoweredOff"} | Start-VM -RunAsync
 get-VM Windows7-*| where {$_.'PowerState' -eq "Suspended"} |Start-VM -RunAsync -Confirm:$false

Wednesday, February 1, 2012

Troubleshooting storage issues with ESXi5.0

~ # vmkload_mod -l|grep vmfs3
vmfs3 2 316

~ # vmkiscsi-tool -D -l vmhba37

=========Discovery Properties for Adapter vmhba37=========
iSnsDiscoverySettable : 0
iSnsDiscoveryEnabled : 0
iSnsDiscoveryMethod : 0
iSnsHost.ipAddress : ::
staticDiscoverySettable : 0
staticDiscoveryEnabled : 1
sendTargetsDiscoverySettable : 0
sendTargetsDiscoveryEnabled : 1
slpDiscoverySettable : 0
DISCOVERY ADDRESS : 192.168.5.2
STATIC DISCOVERY TARGET
NAME : iqn.2010-06.com.nutanix:shared_data1-516ad8b0
ADDRESS : 192.168.5.2:62000
BOOT : No
LAST ERR : LOGIN: No Errors
STATIC DISCOVERY TARGET
NAME : iqn.2010-06.com.nutanix:shared_data2-3ae58737
ADDRESS : 192.168.5.2:62001
BOOT : No
LAST ERR : LOGIN: No Errors
STATIC DISCOVERY TARGET
NAME : iqn.2010-06.com.nutanix:shared_data4-8d6bc1cd
ADDRESS : 192.168.5.2:62003
BOOT : No
LAST ERR : LOGIN: No Errors
STATIC DISCOVERY TARGET
NAME : iqn.2010-06.com.nutanix:shared_data3-cbdfce84
ADDRESS : 192.168.5.2:62002
BOOT : No
LAST ERR : LOGIN: No Errors
/dev/disks # esxcli storage core path list | egrep "Target Ident|vmhba37"
Runtime Name: vmhba37:C0:T3:L0
Adapter: vmhba37
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data3-cbdfce84,t,1
Target Identifier: sata.0:0
Runtime Name: vmhba37:C0:T2:L0
Adapter: vmhba37
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data4-8d6bc1cd,t,1
Target Identifier: sata.0:0
Target Identifier: sata.0:0
Runtime Name: vmhba37:C0:T1:L0
Adapter: vmhba37
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data2-3ae58737,t,1
Target Identifier: sata.0:0
Runtime Name: vmhba37:C0:T0:L0
Adapter: vmhba37
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data1-516ad8b0,t,1
Target Identifier: sata.0:0
Target Identifier: sata.0:0

/dev/disks # esxcli storage core path list | egrep "Target Identifier|Runtime|naa|Device:"|grep -B1 -A1 NUTAN
Runtime Name: vmhba37:C0:T3:L0
Device: t10.NUTANIX_shared_data3_852409da74945ca63d601382a1db06b2c8f6de10
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data3-cbdfce84,t,1
--
Runtime Name: vmhba37:C0:T2:L0
Device: t10.NUTANIX_shared_data4_7ffbcad0adc23e030f69935fe1c0dd5c4a18d187
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data4-8d6bc1cd,t,1
--
Runtime Name: vmhba37:C0:T1:L0
Device: t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data2-3ae58737,t,1
--
Runtime Name: vmhba37:C0:T0:L0
Device: t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data1-516ad8b0,t,1
/dev/disks # esxcli storage core path list -d t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7
iqn.1998-01.com.vmware:ntnx-4-0eaa89c5-00023d000001,iqn.2010-06.com.nutanix:shared_data1-516ad8b0,t,1-t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7
UID: iqn.1998-01.com.vmware:ntnx-4-0eaa89c5-00023d000001,iqn.2010-06.com.nutanix:shared_data1-516ad8b0,t,1-t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7
Runtime Name: vmhba37:C0:T0:L0
Device: t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7
Device Display Name: NUTANIX iSCSI Disk (t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7)
Adapter: vmhba37
Channel: 0
Target: 0
LUN: 0
Plugin: NMP
State: active
Transport: iscsi
Adapter Identifier: iqn.1998-01.com.vmware:ntnx-4-0eaa89c5
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data1-516ad8b0,t,1
Adapter Transport Details: iqn.1998-01.com.vmware:ntnx-4-0eaa89c5
Target Transport Details: IQN=iqn.2010-06.com.nutanix:shared_data1-516ad8b0 Alias= Session=00023d000001 PortalTag=1
/dev/disks # esxcli storage core path list -d t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d
iqn.1998-01.com.vmware:ntnx-4-0eaa89c5-00023d000001,iqn.2010-06.com.nutanix:shared_data2-3ae58737,t,1-t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d
UID: iqn.1998-01.com.vmware:ntnx-4-0eaa89c5-00023d000001,iqn.2010-06.com.nutanix:shared_data2-3ae58737,t,1-t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d
Runtime Name: vmhba37:C0:T1:L0
Device: t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d
Device Display Name: NUTANIX iSCSI Disk (t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d)
Adapter: vmhba37
Channel: 0
Target: 1
LUN: 0
Plugin: NMP
State: active
Transport: iscsi
Adapter Identifier: iqn.1998-01.com.vmware:ntnx-4-0eaa89c5
Target Identifier: 00023d000001,iqn.2010-06.com.nutanix:shared_data2-3ae58737,t,1
Adapter Transport Details: iqn.1998-01.com.vmware:ntnx-4-0eaa89c5
Target Transport Details: IQN=iqn.2010-06.com.nutanix:shared_data2-3ae58737 Alias= Session=00023d000001 PortalTag=1

~ # esxcfg-scsidevs -A

vmhba37 t10.NUTANIX_shared_data4_7ffbcad0adc23e030f69935fe1c0dd5c4a18d187
vmhba37 t10.NUTANIX_shared_data3_852409da74945ca63d601382a1db06b2c8f6de10
vmhba37 t10.NUTANIX_shared_data2_e6c1a2244603b85e94955787f6862d54a277290d
vmhba37 t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7

But
~ # esxcfg-scsidevs -m

t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7:1 /vmfs/devices/disks/t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7:1 4f

/dev/disks # esxcli storage vmfs extent list
Volume Name VMFS UUID Extent Number Device Name Partition
-------------------- ----------------------------------- ------------- ------------------------------------------------------------------------ ---------
NTNX-4-local-ds-NTNX 4f1748db-b24ddb90-00b1-0025904b0c90 0 t10.ATA_____INTEL_SSDSA2CW300G3_____________________CVPR133400KE300EGN__ 3
NTNX_datastore_1 4f1de5c4-8b7c3ecc-a9ed-0025904b0c98 0 t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7 1


/dev/disks # ls
vml.0100000000435650523133333430304b4533303045474e2020494e54454c20:8
t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7 vml.01000000007368617265645f64617461315f66316630366138383434656161303330303835613161623562564449534b20
t10.NUTANIX_shared_data1_f1f06a8844eaa030085a1ab5bbd6575daa0ea3b7:1 vml.01000000007368617265645f64617461315f66316630366138383434656161303330303835613161623562564449534b20:1

/dev/disks # esxcli storage filesystem list
Mount Point Volume Name UUID Mounted Type Size Free
------------------------------------------------- -------------------- ----------------------------------- ------- ------ ------------- -------------
/vmfs/volumes/4f1748db-b24ddb90-00b1-0025904b0c90 NTNX-4-local-ds-NTNX 4f1748db-b24ddb90-00b1-0025904b0c90 true VMFS-5 294742130688 54638149632
/vmfs/volumes/4f1de5c4-8b7c3ecc-a9ed-0025904b0c98 NTNX_datastore_1 4f1de5c4-8b7c3ecc-a9ed-0025904b0c98 true VMFS-3 2195533594624 1080925618176
/vmfs/volumes/4ee7c1ed-df35b248-89f3-0025902ef1c9 4ee7c1ed-df35b248-89f3-0025902ef1c9 true vfat 4293591040 4278583296
/vmfs/volumes/0663f37a-83c2d90f-7056-e4ffaac98b5b 0663f37a-83c2d90f-7056-e4ffaac98b5b true vfat 261853184 114044928
/vmfs/volumes/ec72867e-e39b1732-b736-44c76538fffd ec72867e-e39b1732-b736-44c76538fffd true vfat 261853184 114515968
/vmfs/volumes/4ee7c1e5-15813146-c506-0025902ef1c9 4ee7c1e5-15813146-c506-0025902ef1c9 true vfat 299712512 114843648



Resolution Was:
Connect Vcenter, click on Devices in Storage Config, right click on unmounted disk
and then attach it.
Then Rescan VMFS volumes will be in unmounted state, right click and mount it.

VMNIC0 Failures.

tail vmkernel.log
2012-02-01T20:03:32.032Z cpu0:4780)<6>e1000e: vmnic0 NIC Link is Down

/var/log # esxcfg-vswitch -l
Switch Name Num Ports Used Ports Configured Ports MTU Uplinks
vSwitch0 128 7 128 1500 vmnic3.p1,vmnic0,vmnic1

PortGroup Name VLAN ID Used Ports Uplinks
VM Network 0 2 vmnic3.p1,vmnic0,vmnic1
Management Network 0 1 vmnic1,vmnic3.p1,vmnic0


Try to remove vmnic0 from vswitch
esxcfg-vswitch -U vmnic0 vSwitch0

fix the link and add it again
esxcfg-vswitch -L vmnic0 vSwitch0

/var/log # esxcli network vswitch standard list
vSwitch0
Name: vSwitch0
Class: etherswitch
Num Ports: 128
Used Ports: 7
Configured Ports: 128
MTU: 1500
CDP Status: listen
Beacon Enabled: false
Beacon Interval: 1
Beacon Threshold: 3
Beacon Required By:
Uplinks: vmnic0, vmnic3.p1, vmnic1
Portgroups: VM Network, Management Network


To check override.
/var/log # esxcli network vswitch standard portgroup policy failover get -p "Management Network"
Load Balancing: srcport
Network Failure Detection: link
Notify Switches: true
Failback: true
Active Adapters: vmnic1
Standby Adapters: vmnic3.p1, vmnic0
Unused Adapters:
Override Vswitch Load Balancing: false
Override Vswitch Network Failure Detection: false
Override Vswitch Notify Switches: false
Override Vswitch Failback: false
Override Vswitch Uplinks: true