Automating the beast.. vrealize workflows

Okay so for years now I have played with vmware, vcloud and powercli. I always wanted to spend some time with orchestrator or vrealize as it is now known but never had the chance to dive in… That has changed of late and I have been having great fun building up some simple automation and learning javascript along the way.

Over the next few days I am doing to try and detail what I have done for everybody out there, they are rather simple workflows but very effective at reducing the time spent on your first level calls.

What will be covered.

  • Simple virtual machine build blueprint
  • Modify CPU (up or down whilst checking for hotplug)
  • Modify Memory (up or down whilst checking for hotplug)
  • Extend Disk
  • Rename Virtual Machine
  • Snapshot Virtual machine (with date to delete, asking for confirmation and an extend option)
  • Snapshot Report
  • Virtual Machine Detail Report

Simple virtual machine workflow and lessons learnt.

Originally I was trying to cram everything into the one workflow, operating system, datacenter design, tier 1 disk, tier 2 disk and on and on.. But quite frankly the workflow became unwieldy and complicated for the end users.. see screenshot below. Now it looks simple enough but the end user ended up with two pages of questions for the one workflow. Another approach to make it both easier and simpler for the end user needed to be found.

create-virtual-machine

So I decided to break it down to what we actually needed. In our environment we have three flavours* at the time of writing this. Microsoft 2012 R2, Redhat 7, Centos 7 and three datacenters. Therefore it is actually an easier approach to use the vcac blueprint style and show a OS-Datacenter model.

*flavours, being the main server OS built. Everything else is considered and exception and manual intervention at this stage is conducted.

  • Datacenter1-Windows 2012 R2
  • Datacenter1-Redhat 7 x64
  • Datacenter1-Centos 7 x64

Defaults to the datacenter, alllow automatically picking the host, datastore, cluster, OS, and due to pxe builds the starting vlan.

The end user is presented with one quick fill screen asking for the following.

  1. Virtual Machine Name
  2. Memory Size GB
  3. Cpu Number
  4. Size of Disk 1
  5. Size of Disk 2 (optional)
  6. Size of Disk 3 (optional)

Virtual machine name is converted to lowercase automatically, memory size in GB has a maximum set, cpu number has a maximum set.

The script at the beginning connects to Active Directory and grabs the users first name, last name and email address for a personal touch. Also means the user does not have to fiddle around putting in their contact details. And we end up with a very simple workflow, although it seems simple looking at the schema..

create-virtual-machine-blueprint

The main issue is that you will use the inbuilt workflow ‘Create Custom Virtual Machine’.. This calls on the actions;

  • createVirtualEthernetCardDvNetworkConfigSpec
    • not being vmxnet 3.. grrr
  • As well as only one choice of datastore
    • Now this is not normally an issue with auto-tiering SAN but in some workplaces SAN admins still prefer to run a manual tiering system.

I will continue on these and add some audio but here are some teasers..

Advertisements

vm unknown but what is it??

Ok so open up powercli and type in

get-vm unknown | fl *

Take note of the Id… VirtualMachine-vm-####

Now open up excel, click data, from other sources, SQL, type in your vcenter sql server and connect to [vcenter name] VCDB VPX_VM and find the id number..

To the right you will see the folder path and the name and location of the vmx to import. ds://vmfs/volumes/##############/vmname/vmname.vmx

linux admins worst nightmare

EVERYTHING IN UPPERCASE… grrrr..

okay so you have taken over a vmware environment and your ocd is burning out your eyeballs because the old naming convention contained uppercase characters.

for those not aware… When you do anything from the command line with linux it is case aware, so if I typed something like this on an esx(i) host.

I want to capture all network traffic going through an esx host and filter by a certain hostname.
So I run on a host using putty.

tcpdump-uw | grep hostname.whackddidy.com.au

But I get no results because some muppet has put the hostname as HostNamE so I need to type

tcpdump -uw | grep HostNamE.whackdiddy.com.au

grrr – does not sound frustrating but trust me when you are looking after a large environment and need to launch the viclient or powercli to get the correct mix of upper and lowercase it becomes frustrating.

So lets change all to lowercase shall we..

This is the magic bit here…

get-?? | ForEach { $_ | set-?? -Name ($_.Name).tolower()}

So as a few examples.

vm’s

get-vm | ForEach { $_ | set-vm -Name ($_.Name).tolower()}

dv-portgroups
note – when you change the port groups from upper to lower the vm’s will automatically adjust (tested on vsphere 5.5)

get-vdportgroup | ForEach { $_ | set-vdportgroup -Name ($_.Name).tolower()}

To hit just one port group for testing.

get-vdportgroup dv-wHaCkdiDdy | ForEach { $_ | set-vdportgroup -Name ($_.Name).tolower()}

folders.

Get-Folder | ForEach { $_ | set-Folder -Name ($_.Name).tolower()}

That should give you enough to continue with.

Apologies to the person I stole this initial bit of magic from that got me started..

Get-VM | Foreach { $_ | Set-VM -Name ($_.Name).tolower()}

A start for those wanting to learn powercli but were afraid to ask.

Why use powercli, you can do everything from the gui people say.
Yeah sure you can do everything from the gui, sort of.

Let’s say you have three vcenter servers and eighteen clusters and 17 thousand vms and want to find out.

  • Hosts in vcenter2 cluster 9
    • o  
      connect-viserver vcenter1,vcenter2,vcenter3 | get-cluster cluster9 | get-vmhosts | sort name 
  • vms running in cluster 9
    • o   
      get-cluster cluster9 | get-vm | sort name 
  • vms powered on in cluster9
    • get-cluster cluster9 | get-vm | where {$_.PowerState -eq "PoweredOn"}
  • vms powered on with 2 cpus on cluster9
    • o  
      get-cluster cluster9 | get-vm | where {$_.PowerState -eq "PoweredOn"} | where {$_.NumCpu -eq "2"}
  • vms powered on with a note containing the word whackdiddy
    • get-vm | where {$_.PowerState -eq "PoweredOn"} | where {$_.Notes -like "*whackdiddy*"}

To work out what you can filter by choose an existing guest and get full details like this..

get-vm guestname | fl

Where guestname is the name of one of your vm’s.

Once you have the basics you will find it much easier to get information with powercli than with the gui and so much quicker.

Checking vmware host vlan tagging

Checking network vlans.
Okay so I am use to being able to do a show run on the switching infrastructure attached to my virtual environment. However in my current position that ability has not been granted.

So I resorted to the following to test that trunking was setup correctly.

Create one guest (ubuntu live cd works great) on one host and another on another host.
Give these two guests an ip address on a range that is not within your companies / organisations ranges. For example if your company uses 19.20.21-31.0/24 then you could use 192.168.201.100-101/24. Now gateway needed, once the hosts are up and running with an ip address simply do a ping using terminal from one guest to the other.

ping -c 10 192.168.201.101

Okay so that is great if we want to check one vlan but what if we have multilple vlans.

Well in this case you can use this powercli to change the vlan on both guests with a pause and then change, this can flick through all your vlans.

Get-VM -Name pingt1 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName vlan1 -Confirm:$false
Get-VM -Name pingt2 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName vlan1 -Confirm:$false
sleep 7
Get-VM -Name pingt1 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName vlan2 -Confirm:$false
Get-VM -Name pingt2 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName vlan2 -Confirm:$false

Easy hey.

Now to aid in building the network jumper powercli you can run the following.
Get-VDPortgroup | Select Name,VlanConfiguration,Datacenter | ft -a
Paste into excel and you have your list of vlans.