lingenavd

Deployment recommendations by VMTurbo (Part 3)

Blog Post created by lingenavd on May 22, 2015

Introduction:

In part 1 (https://greencircle.vmturbo.com/community/products/blog/2015/02/17/deployment-recommendations-by-vmturbo-part-1) of this series I described the advice offered by the VMTurbo Customer Success team regarding the creation of the necessary groups, templates and deployment profiles from the GUI needed to use the VMTurbo deployment recommendations for new VM’s on replicated or non-replicated datastores.

As a result we succeeded to get some recommendations from the Deploy Tab in the VMTurbo GUI.

 

In part 2 (https://greencircle.vmturbo.com/community/products/blog/2015/03/03/deployment-recommendations-by-vmturbo-part-2) of this series I described my efforts to automate the recommendations from Powershell scripting using the REST API services.

My starting point was the support article:

https://support.vmturbo.com/hc/en-us/articles/202387278-Deploy-VMs-Using-the-Rest-API\

For everything in that article that is done in the Bash command prompt, I wanted to be able to execute it with Powershell in combination with the REST API services.

 

In this part 3, I will describe a complete powershell script that will get the deployment recommendation based on input provided by a request form. This could be automated by any orchestration application, for example Microsoft System Center Orchestrator.

I am using the same groups, segments, templates and deployment profiles as described in part 1 and I will integrate some of the powershell snippets from part 2 into this article.

 

 

Let’s get started:

 

Note!:

  • This is successfully implemented on VMTurbo Operations Manager 5.1 and later versions
  • It may work (or not) on prior versions.
  • The credentials used in these API calls should have either Administrator or Automator permissions.

 

This tutorial provides an example of how to automate the creation or modification of the VMTurbo templates based on the required VM hardware configuration submitted by a requester and get first time right placement recommendations from VMTurbo.

 

The request form:

The server request form for a new virtual server contains numerous questions that need to be answered regarding hardware configuration, functionality, backup and network properties etc.

In our situation the server request form is hosted by Microsoft System Center Service Manager as a web portal.

 

fig1.png

Figure 1

 

The orchestration and automation:

All gathered information is stored in the database and eventually the information is submitted to Microsoft System Center Orchestrator to start a runbook to create the new virtual server.

 

fig2.png

Figure 2

 

The runbook shown in fig.2 is responsible for a lot of automated tasks like;

creating the servername, creating a CI in the CMDB, create the computer account in Active Directory, get the placement recommendation from VMTurbo, clone the VMware template and modify the VM hardware. Install software, create VMware custom attributes and tags and place the VM in the correct vCenter folder.

 

Not shown are the runbooks that are responsible for creating and closing RFC’s, cost calculations and billing, submitting requests for Firewall rules, DHCP request, backup scheduling and sending status updates to the requester.

 

Everything is orchestrated and automated from the user request to the final delivery of the virtual machine.

The end result is that a new virtual server is deployed with the requested hardware configuration. Standard applications like SCOM, SCCM, Anti-virus and backup software and the latest WSUS updates are automatically installed and configured. The server will be domain joined in the OU provided by the requester in the request portal, ready and waiting for the functional manager to login for the first time.

 

Now back to the subject, how to integrate VMTurbo in this server deployment process.

 

 

First time right placement recommendations from VMTurbo

Because the requester provides hardware configuration for the VM and can request up to three disks in the initial deployment it is necessary to have some intelligent mechanism to decide where the new VM should be placed in the virtual infrastructure.

A lot of vSphere hosts and datastores are available in the VMware clusters and these hosts and datastores are already utilized by existing VM’s.

So this is where the intelligent placement recommendations from VMTurbo kick in.

 

The script below is a slightly modified version of what we use in our deployment process.

It should give you, together with the previous articles, a general idea how you can use the different Web requests from VMTurbo’s API to get the recommendation from VMTurbo.

 

I have chosen to modify one specific VMTurbo template that is created solely for the deployment recommendation.

This template will be modified to reflect the hardware configuration chosen by the requester in the server request form.

Another way to go is to create a new template for every new deployment and delete it when the deployment is done.

 

The script

 

$cred = <a set of credentials that has the correct right on the VMTurbo appliance>

$VMTurbo = "10.10.10.10" #<Your VMTurbo appliance IP address or FQDN>

 

#Server OS

#Possible entries are "Windows Server 2012R2", "Windows Server 2008 R2 SP1 Standard" or "Windows Server 2008 R2 SP1 Enterprise"

$OS = "Windows Server 2012R2" #<variable, based on the input of the requester>

 

#Server profile

Possible entries are Bronze, Silver, Gold or Platinum)

$hardware_profiel = "Bronze" #<variable, based on the input of the requester>

 

 

If ($hardware_profiel –match “SQL”){

$SQL_Deployment = “yes”

}

Else{

$SQL_Deployment = "no"

}

 

switch ($hardware_profiel -replace "SQL") {

      "Bronze"$number_of_cpus = 1

                        $memory_in_mb = 1024}

      "Silver"$number_of_cpus = 1

                        $memory_in_mb = 4096}

      "Gold"   {  $number_of_cpus = 2

                        $memory_in_mb = 8192}

      "Platinum" {$number_of_cpus = 4

                $memory_in_mb = 16384}

}

 

switch($OS) {

      "Windows Server 2012R2"                   {$OS_disk_size = 60}

      "Windows Server 2008 R2 SP1 Standaard"    {$OS_disk_size = 40}

      "Windows Server 2008 R2 SP1 Enterprise"   {$OS_disk_size = 40}

}

 

$Extra_CPUs_by_requester = 1 #<variable, based on the input of the requester>

 

$Extra_Memory_by_requester_in_GB = 1 #<variable, based on the input of the requester>

 

 

$number_of_cpus = $number_of_cpus + $Extra_CPUs_by_requester

$memory_in_mb = $memory_in_mb + ($Extra_Memory_by_requester_in_GB * 1024)

 

#Normal server deployment

if ($SQL_Deployment -eq "no") {

      $Disk_size_extra_disk_1 = 300 #value is provided by requester

      $Disk_size_extra_disk_2 = 100 #value is provided by requester

      $Disk_size_extra_disk_3 = 0 #value is provided by requester

      $vmdisk_tot_size = $OS_disk_size + $Disk_size_extra_disk_1 + $Disk_size_extra_disk_2 + $Disk_size_extra_disk_3

}

 

 

#SQL server deployment

elseif ($SQL_Deployment -eq "yes") {

    $SQL_Disk_size_DATA_disk = 100 #value is provided by requester

    $SQL_Disk_size_BACKUP_disk = [Math]::Ceiling(($SQL_Disk_size_DATA_disk / 2) + 5)

    $SQL_Disk_size_LOG_disk = [Math]::Ceiling($SQL_Disk_size_DATA_disk / 3)

    $SQL_Disk_size_TEMPDB_disk = [Math]::Ceiling(($SQL_Disk_size_DATA_disk / 100) + 10)

    $SQL_Disk_size_PAGE_disk = ($memory_in_mb / 1024) + 4

      $vmdisk_tot_size = $OS_disk_size + $SQL_Disk_size_BACKUP_disk + $SQL_Disk_size_PAGE_disk

}

 

#Show temporary deployment template with virtual hardware config for placement recommendation VM (not necessary in you script, but is here to show you how the template looks after you created it manually)

$output_templates = Invoke-RestMethod -Credential $cred -Uri http://$VMTurbo/vmturbo/api/templates/VirtualMachine::AutoDeploy

$template_AutoDeploy_temp = $output_templates.TopologyElements.TopologyElement #| where {$_.description -imatch "AutoDeploy_temporary_tmpl"}

write-host "Template:"

$template_AutoDeploy_temp

 

 

<#

Template properties:

 

accessSpeedConsumed       : 0.0

cpuConsumedFactor         : 0.5

creationClassName         : VirtualMachineProfile

description               : AutoDeploy_temporary_tmpl

displayName               : AutoDeploy

ioThroughputConsumed      : 0.0

memConsumedFactor         : 0.75

model                     :

name                      : VirtualMachine::AutoDeploy

networkThroughputConsumed : 0.0

numVCPUs                  : 1

price                     : 0.0

services                  : _lFzk8J_xxxxxxxxxxx7Lsw

storageConsumedFactor     : 1.0

uuid                      : _LcCnYJ_xxxxxxxxxxx7Lsw

vMemSize                  : 1048576.0

vStorageSize              : 61440.0

vendor                    :

#>

 

 

 

#Modify temporary deployment template with virtual hardware config for placement recommendation VM

$templateUuid = "_LcCnYJ_xxxxxxxxxxx7Lsw"

$numVCPUs = $number_of_cpus

$vMemSize = $memory_in_mb

$vStorageSize = $vmdisk_tot_size

$networkThroughputConsumed = 0

$ioThroughputConsumed = 0

$accessSpeedConsumed = 0

$memConsumedFactor = 0.75

$cpuConsumedFactor = 0.5

$storageConsumedFactor = 1

$vendor = "AutoDeploy"

$model = "AutoDeploy_temporary_tmpl"

$price = 0

$desc = "AutoDeploy_temporary_tmpl"

 

 

$uri_mod_template = "http://$VMTurbo/vmturbo/api/templates/VirtualMachine::AutoDeploy?templateUuid=$templateUuid&numVCPUs=$numVCPUs&vMemSize=$vMemSize&vStorageSize=$vStorageSize&networkThroughputConsumed=$networkThroughputConsumed&ioThroughputConsumed=$ioThroughputConsumed&accessSpeedConsumed=$accessSpeedConsumed&memConsumedFactor=$memConsumedFactor&cpuConsumedFactor=$cpuConsumedFactor&storageConsumedFactor=$storageConsumedFactor&vendor=$vendor&model=$model&price=$price&desc=$desc"

 

 

 

#Create a reservation / placement recommendation

$reservationname = "NR_Deploy" #<variable, based on the input of the requester, it could be SR_Deploy for replicated datastores>

$count = 1

$templatename = $template_AutoDeploy_temp.uuid

$deploymentprofile = "_lFzk8J_xxxxxxxxxxx7Lsw"

$uri_create_res = "http://$VMTurbo/vmturbo/api/reservations?reservationName=$reservationname&count=$count&templateName=$templatename&deploymentProfile=$deploymentprofile"

 

$output_create_reservation_for_VM = Invoke-RestMethod -Credential $cred -Uri $uri_create_res -Method POST

 

write-host "Output Reservation:"

$output_create_reservation_for_VM

 

 

#wait about 20 seconds for VMTurbo to be able to calculate the best placement recommendation

sleep 20

 

 

#Show the placement recommendationby VMTurbo

$uri_res_result = "http://$VMTurbo/vmturbo/api/reservations/$output_create_reservation_for_VM"

$output_reservation_UUID = Invoke-RestMethod -Credential $cred -Uri $uri_res_result

Write-Host "Reservations:"

$output_reservation_UUID.VirtualMachines.ActionItem

$recommended_datastore = $output_reservation_UUID.VirtualMachines.ActionItem.datastore

$recommended_ESXHost = $output_reservation_UUID.VirtualMachines.ActionItem.host

write-host "VMTurbo recommended datastore for VM: $recommended_datastore"

write-host "VMTurbo recommended ESX Host for VM: $recommended_ESXHost"

 

 

The two variables $recommended_datastore and $recommended_ESXHost are published by the Orchestrator runbook so that they can be used in the next step to clone the VMware template.

To clone a VMware template you need to specify a datastore and vSphere ESX host. This is exactly what is provided by the above script.

 

 

I hope this can help you to automate deployment recommendations via Powershell scripting and use it in your automation process for deployment of virtual servers.

If you run into problems or need extra information I am happy to help you out.

 

 

With regards,

Andre van der Lingen

System Manager at SNS Bank

Outcomes