Welcome back to my learning vCO series of posts the posts will hopefully help to start to feel our way through vCO but to give base ideas that can be expanded on. Part 1 can be found here.
Today I thought how about we create a flow to create a windows Azure VM. Thought why not bring 2 virtualisation competitors and combine some technologies 🙂
There is a couple of pre reqs here.
1) You will need to have installed the powershell plugin into vCO, there are plenty of material out there on this.
2) you will need to run the “Add a powershell host” workflow to connect the “jumpbox” This requires winrm to be available.
2) you will need to have a “jump box” which will be your powershell plugins endpoint, this will allow us to run powershell commands remotely on this box. The Jump box will need the azure powershell modules installed which is extremely easy to install from by using the Web Platform Installer from MS.
3) Once done you will need to import your management cert onto the box navigate to https://windows.azure.com/download/publishprofile.aspx once you have entered your azure account login details will download a sub name.publishstettings file.
4) Once you have this file open powershell as administrator and use the Import-AzurePublishSettingsFile filepath name.publishsettings. This will connect this jump server to your windows azure account.
There is other ways to authenticate but I found this one less hassle and if you wanted to automate something like this on a larger scale you would have a dedicated endpoint like this.
Now time to get our flow on!!!
3) You will get prompted up the top to set up the workflows parameters, hit setup and change all the items to value or local variable. note the image below just shows the host as a value. I have pre-set this to our configured powershell endpoint, the rest should be set to value too.
4) Next up we need to drag a scriptible task element from the left and give it a good name, in this case we will be creating the powershell script to feed into the invoke powershell workflow.
you should now have something like the below image
5) Next up we hit the edit icon for the new script-able task and first up we need to create some parameters that we will want people to enter that will make up the script, So for starters lets just use VM name, Admin account for the VM, Admin pass for the VM and service name which is required to build an azure VM. These will all be created as a string. The below images show what you should now have.
7) Now onto the script where the magic happens, vCO uses java script so i need to create the powershell script I want to run line by line with while using the users inputed values. Here is the script that I whipped together for this post.
var tmpScript = ''; tmpScript +='import-module azure \n'; tmpScript +='$vmname= "' + vmName + '"\n'; tmpScript +='$instance ="Basic_A0" \n'; tmpScript +='$image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201406.01-en.us-127GB.vhd" \n'; tmpScript +='$adminName = "' + adminAccount + '"\n'; tmpScript +='$pass = "' + adminPass + '"\n'; tmpScript +='$group = "vmegroup" \n'; tmpScript +='$serviceName = "' + serviceName + '"\n'; tmpScript +='$vm1 = New-AzureVMConfig -Name $vmname -InstanceSize $instance -Image $image \n'; tmpScript +='$vm1 | Add-AzureProvisioningConfig -Windows -AdminUserName $adminName -Password $pass \n'; tmpScript +='$vm1 | New-AzureVM -ServiceName $serviceName -AffinityGroup "vmegroup" \n'; script = tmpScript; System.log(script);
The instance and image are what I am using in this demo but there is nothing stopping you adding more and having a drop down list, the instance is basically the size of the VM, while image is the build image you are using.
The Affinity group is something you setup within azure other wise location can be used which says which datacenter you building in.
The system logs are just so I can see what happening.
9) Now for this quick learning vCO post we will drag and drop another scriptible task out and call in debug output. but all I want to do here is print out the output. But taking this further you can manipulate the returned data and grab the dns name and port to rdp on etc to send back to the user. But for this we just want to see it.
So we add the input as the output and add one line in the script which is
Wooooo all good provisioned and working
Next time we might look at expanding what we did here or what we did in part 1
can download the workflow here