Monday 16 September 2013

One way to re-IP your NFS array with VMware

Recently I have been working on a project to replace an old FAS2040 NetApp array with a newer FAS2240. The old FC disk shelves from the 2040 will be re-purposed in the 2240, so will be physically moved to the new array complete with all of the existing VMs in the farm.

This poses an interesting problem though, the existing filers with their current IP's will disappear and the new filer will have a different hostname and IP. This change will cause all of the VMs to go grey because they cannot reach their disks. With a little googleing you can find a couple of scripts that are able to re-register VMs, these can be modified to fix this issue.

To add to the interest in this environment we have VMs with multiple disks on different NFS mounts, so we need to fix the vmx files so they point to the new datastores on the new filer.

So whats the plan then??

  1. Get the names of all your templates
    Get-Template | Select-Object Name | Export-Csv -NoTypeInformation -Path ./templates.csv
  2. Convert all templates to VMs
    Set-Template -ToVM * -Confirm:$false
  3. Run this command to collect the necessary information
    get-view -viewtype virtualmachine -property name, config.files.vmpathname, parent, Runtime.Host | select name, @{n="vmxFilePath"; e={$_.config.files.vmpathname}}, parent, @{n="host"; e={$_.runtime.host}} | Export-Clixml -Path ./vms.xml
  4. Remove all VMs from the inventory
    Get-Datastore <regex to get all affected DS> | Get-VM | Remove-VM -Confirm:$false
  5. Enable SSH on a host
    Get-VMHost <hostname> | Foreach-Object {  Start-VMHostService -Confirm:$False -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
  6. Get the datastore locations
    SSH to your host > enter  ls -l /vmfs/volumes/ 

    Save this info for later
  7. Unmount affected Datastores
    Get-Datastore <regex to match all affected DS> | foreach {Remove-Datastore -Confirm:$false -Datastore $_ -VMHost (Get-VMHost <regex to get all affected hosts>)}
  8. Mount your new datastores, since there are heaps of ways to do this I'll leave it to you
  9. Get the new datastore locations
    Just re-do point 6 above
  10. Copy this sh script over to your host, make sure you replace OLD-DATASTORE and NEW-DATASTORE with the correct UID's from point 6 and 9.#!/bin/sh
         find /vmfs/volumes/ -name '*.vmx' -maxdepth 3 | while read fl; do
         echo $fl
         mv "$fl" "$fl.old"
         sed 's/OLD-DATASTORE/NEW-DATASTORE/g;s/OLD-DAASTORE/NEW_DATASTORE/g' "$fl.old" > "$fl"
         chmod 755 "$fl"
         done
    You can add as many datastores to rename as you like, just use separate them with ; the example above does 2 datastores.
  11. Disable SSH
    Get-VMHost <hostname> | Foreach-Object {  Stop-VMHostService -Confirm:$False -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
  12. Register all your VMs
    Import-Clixml .\vms.xml | foreach { New-VM -VMFilePath $_.vmxfilepath -VMHost (Get-VIObjectByVIView $_.host.toString()) -Location (Get-VIObjectByVIView $_.parent.toString()) -RunAsync}
  13. Convert your templates back to templates
    Import-Csv -Path ./templates.csv | foreach {Set-VM -ToTemplate -VM $_.name -Confirm:$false}
With a little luck you should be all done! :)

Sunday 15 September 2013

Cable Modems and DHCP

Fun fact- many new cable modems strictly adhere to DHCP standards.  We found this out the hard way when trying to set up our Comcast cable internet connection with our new refurbished Cisco Linksys Router.  Setting up our connection was not painless, in part as a result of my own fault.  To begin, looking for a deal, I purchased a refurbished Motorola Surfboard modem on Ebay, since like many other cable providers, Comcast charges an arm and a leg to lease a modem.

The modem I purchased was explicitly listed as Comcast compatible, however upon initial installation I couldn't "activate" the device using Comcast's online tool.  I found this incredibly frustrating because on initial connection, I could resolve and ping external web sites thus proving the cable modem worked, however due to the nature of the Cable internet-provider business, all http traffic is proxied prior to activation (which as I understand it, is just the cable provider sending down a small config file to the modem which sets transfer rates and ensures proper billing).   After failed "automated" activation, I had to call customer service where I was directed to a call center in the Philippines.  While the call representative was nice, she basically ran through her script, which took about 30 minutes, before finally forwarding me on to an on-shore representative who quickly concluded that because my modem was using the deprecated DOCSIS 2.0 standard, Comcast would not send down a configuration file. Sigh.

I could've waited and just ordered another DOCSIS 3.0 modem online, but wanting an internet connection that day, I hopped in the car and dropped by Best Buy where I picked up a NetGear CMD31T modem.  Upon returning home, I hooked up the new modem and was able to get an internet connection directly connecting my laptop to the modem within minutes.  Next came time to hook up our new Cisco Linksys wireless router to the modem.  The first thing I noticed was that the "1G ETH" light turned from green, when plugged into my laptop, to orange when plugged into the router.



In addition to that, the router would not pull down the IP from the modem.  After a bit of head scratching, I decided to try updating the Cisco firmware on the device, to no avail.  Then, in a fit of increasing frustration, I tried flashing DD-WRT on to the router (which is one reason why I chose the router in the first place- due to the DD-WRT support).  Still no love.  Now at this point, I began my cursing tirade against Cisco selling "refurbished" products that don't work.  After letting a friend and colleague visiting from Australia to have a shot of changing the WAN port configuration within DD-WRT, we all but surrendered and I almost ran back to Best Buy to over pay for another modem.  Then at the suggestion of my friend, we tried rebooting the modem to see if it would issue a new DHCP lease. Up to this point, we were hesitant to power down the modem out of fear of losing the connection form Comcast.  Sure enough, rebooting the modem worked the trick, the router obtained the external WAN IP, and we were up and running!

As it turns out, it looks like newer cable modems more closely adhere to DHCP standards and once an IP is allocated from the modem to the downstream device (be it a router or a laptop), it won't allocate another address until either:

A.) The IP address is released by the client device
B.) The modem is rebooted

Effectively a simple problem, but it took us the better part of an hour to figure it out.  Also, as an aside, I ended up having to flash the Cisco firmware back onto the device, as DD-WRT was providing high latency ping responses.  Additionally, DD-WRT does not support the two-antennas as of yet on the router.

Finally, we are once again bathed in beautiful wifi internets!