Thursday 20 May 2010

PowerShell is Powerful

A pretty obvious thing to say I'm sure you'll agree, but for the sysadmin it is an incredibly useful link between the old WSH scripting world and full on object based C# or similar. I've been working with Windows Server for many years, and I'm struggling to come up with another administrative advancement which brings as much to the table as PowerShell.
Anyway, after that generic praise, let's get down to the real topic for this post. I have formed close allegiance with several Windows HPC Server PS commandlets over the past few years, so I thought I'd write about some of my favourites. Apologies to those left out, but I know they'll be waiting for me to come their way in the future despite not being given love here :)

Deployment
When you're building out multiple clusters, creating a PowerShell script which removes the need to manually work through the cluster configuration wizard is a sweet deal. As you're probably aware the cluster set up wizard runs through he following steps:


See the nice green checks? All achieved using PS commandlets. Let's break it down a bit...
Configure your network. Could be quite complicated as it takes into account various disconnected options such as network topology, subnet details, firewall settings, DHCP and NAT. But this can all be set up using Set-HpcNetwork As an example, say you want to create a Topology 1 setup, using NAT, firewall on for the Enterprise network, off for the private network, public address = currently assigned to NIC, private address = 192.168.1.253 private range 192.168.1.235 - 8.250, DHCP on for the private network, Headnode to provide NAT function. Check this out...

Set-HpcNetwork -topology private -enterprise 'NICName' -EnterpriseFirewall $True -private 'NICName2' -PrivateIpAddress 192.168.1.253 -PrivateSubnetMask 255.255.255.0 -PrivateDHCP $true -PrivateDhcpStartAddress 192.168.1.235 -PrivateDhcpEndAddress 192.168.1.250 -privateDHCPGateway 192.168.1.253 -PrivateDHCPDns 192.168.1.253 -PrivateNat $True -PrivateFirewall $False

Sweet!
Now then, provide installation credentials. Want to add domain\nodebuild as the node installation account?

Set-HpcClusterProperty -InstallCredential DOMAIN\nodebuild

Configure the naming of new nodes. Let's say you fancy naming the nodes after the cluster, so something like CLUSTER-CN001 onwards. The commandlet your looking for here is

Set-HpcClusterProperty -NodeNamingSeries

but you need to find the cluster name first. I use PS to grab the CCP_SCHEDULER environment variable.

Create a node Template? Simple, knock up a template with the appropriate steps, then export it. If your template has an image associated with it get that ready than import the image using

Add-HpcImage -Path

Now import your node template (which should reference your image if applicable)

Import-HpcNodeTemplate -Path

All done right? Well you may need to import drivers for he deployment process etc:

Add-HpcDriver -Path

You're all set, and of course by using a scripted method this is all nicely documented and repeatable.

Node Management

How do you control node group membership? I used to use the UI to manually add nodes to groups, which was a little bit painful so another delve into PS gave me a better way. I use Get-HpcNode in conjunction with Add-HpcGroup like this


Example - if you populate the node description with the software it has installed (softwarepackage2):

Get-HpcNode|where {$_.description -eq "softwarepackage2"}|Add-HpcGroup -name SoftwarePackage2Group

Example - if you want to add a node to a group based on it's config e.g. installed memory

Get-HpcNode|where {$_.Memory -ge "8000"}|Add-HpcGroup -name Over8GBGroup

Keeping an Eye on Business


The Operation log contains many juicy bits of info which are sometimes easy to miss. I tend to run up a monthly report which includes details of recent warnings and errors in the log.  PS again comes to my assistance, with the help of the Select-Object commandlet to hit the last 500 entries (appropriate for my needs).

Get-HpcOperation -State committed | Select-Object -Last 500 | Get-HpcOperationLog -Severity  Error,Warning

Also in the report is output of failed / failed to run diagnostics. I have an Ops Manager environment in place which of course provides overall management and reporting, but it also periodically runs diagnostic jobs. These are useful, and I grab the results like this:

Get-HpcTestResult -teststate -LastRunTime (get-date).AddMonths(-1)

So, to sum up, PowerShell is awesome! 

No comments:

Post a Comment