Take back the control of your Datacenter

Hi

TL;DR

The scripts are in my github repo. However, I encourage you to read the full post before using them.

As part of a project I was working on recently, I needed to create an automated way to bring the data center up and down

I wanted to share with you the scripts and concept I used to achieve that.

But before we dive into the weeds, it’s important to characterize the DC a bit, so you can understand the use case. I belive that once you get the use case I was facing, you can better understand the scripts and modify them to your needs

Datacenter Description

  • The DC is completely on-premise, no public cloud provider and actually, no internet connection exists. Completely isolated network.
  • The servers are all based on HP DL G9 series. All have the iLO module enabled. This is used in my script as I’m using HP iLO Powershell module
  • All servers are installed with either Windows Server 2012 R2 or VMware vSphere ESXi 6 OS
  • Client machines are running Windows 7 Professional SP1
  • The DC must be started and turned off in a specific order for the process to be successful. There are several dependencies in place that I took into consideration:

Startup Dependencies

  • Storage & Switches: I’m not turning on the storage and switches. Only the servers. The assumption is that both components – storage & switches – are already on and fully accessible before running the scripts
  • IT infrastructure services:
    • Turn on the first ESXi server. Then, turn on the following servers that should reside on it, in the following order:
      1. pdc – The primary domain controller
      2. deploysrv – deploysrv is a functional IT server performing many IT tasks in the environment. One of them is DHCP service and as such it needs to be up before all others to distribute IP to all other servers that boot (all servers are ip-reservation based in my scenario)
      3. vcenter – the vcenter is managing all VMware ESXi servers

Afterwards, it’s not really crucial what will come up. In my case I needed to start a few Windows servers (DB, etc.), then an ESXi, then the VMs on the ESXi, then another ESXi, then the machines on it, and so on…

Shutdown Dependencies

The order is pretty much reversed to the startup order, but there are some points to consider:

  • I am shutting down the storage in this scenario. Mind the note in the script regarding the SSH connection
  • I am shutting down Windows Client OS machines in addition to servers.
  • The vCenter, deploysrv and pdc are turned off in a reverse order to the boot

What else you should keep in mind

I know this use case is very specific and most of you might think they have no use for it….

But!

If you know your powershell, you should dive into the script and understand the concept.

I think that with minimal effort you can modify it to meet your needs and assist you in similar scenarios.

Basically, the scripts are based on a loop that reads lines from csv and executes commands against those lines. But there are a few nice concepts that I want to emphasize:

  • After turning on a server I’m verifying it’s on and only then move forward. This is due to the dependencies I mentioned
  • If the critical servers are not up the script will notify and abort
  • You need to have VMware PowerCli and HP iLO Powershell modules installed to run the scripts
  • You need to have PLINK.exe (part of putty.exe) installed
  • I’m utilizing a great function write-log from Jason Wasser (@wasserja) to produce a log of the operation to the console and a file for review
  • I broke the script to many small functions to try to keep it as reusable as possible. Take the time to look at the stop-machine, stop-windows & stop-ESX in the shutdown script as well as the start-machine, start-HPSrv & start-VMwareVM in the startup script. I think they can be re-used in many scenarios
  • The parameters used all come with default values. You can execute the scripts “as is” or use the parameters switches to add your own.

The scripts are located in my github repo, feel free to use, comment and contribute

Thanks, and good luck!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s