Sunday, May 24, 2015

Mass creation of vDS portgroups using PowerCLI

There’s a potential project going on to migrate off of the Nexus 1000v distributed switch. One of the things that will be needed, is to create portgroups for all the existing Nexus port profiles.

Following is a simple PowerCLI script put together to help with this. It simply creates the port groups from entries in a .csv file. Nothing else is done with respect to the migration.

It’s a practical, functional script. It’s not fully featured or doing anything clever. In essence, it’s what I tend to use Powershell and PowerCLI for, getting tedious things done quickly. It’s missing the “correct” way to do things, but took 10 minutes to put together - which shows.

The core of the script is basically a couple of lines. Fleshed out with some comments, and an initial check on whether a connection has been made to the vCenter before running the script. Typically in my everyday work, I have PowerCLI connections made to the VC’s, so don’t like scripts to nag me to connect. But I’ve added a rudimentary check for this. If already connected, you’ll carry on as normal, if not connected, you’ll be prompted for the VC and the script will disconnect you at the end.

The other assumption here is that all the portgroups are going to be of type VLAN - ie, we’ve got trunked NICs, so each portgroup will need a VLAN ID set.

The script uses a .csv file that you will need to generate - this is my typical approach on these things, as I just find it easy to work with. The layout of the .csv file (ie the column name that you will need) is :

vDS - name of vDS that we want to create the portgroup on
pgName - name of the portgroup to create
NumPorts - number of ports for the portgroup
vlanID - vlanID.

Once it’s created the portgroups, it will just print out the name, number of ports, port binding and vlan configuration for every portgroup on the dVS for confirmation.


# Check if already connected to VC or not. If not, prompt to.
if ($ -eq $null) {
	$vc = Read-Host "Enter the VC to connect to"
	Connect-VIServer $vc

	Write-Host "Now connected to " -ForegroundColor Magenta

	# $wasConnected set to no - this will be used at the end to prompt 
	# whether to disconnect the session.
	$wasConnected = "no"
else {
	# There was already a session connected - display it and continue.
	Write-Host "Currently connected to " -ForegroundColor Magenta

# Read in the .csv file with all the details that we'll need
# Layout (ie, column names) of the .csv is  :
# vDS - name of vDS that we want to create the portgroup on
# pgName - name of the portgroup to create
# NumPorts - number of ports for the portgroup
# vlanID - vlanID - assumption here is we've got a trunk, and each portgroup needs 
# it's own vlan ID to identify the tag
$srcFile = Read-Host "Enter the name of the .csv file to work with"
$vdsPortgroup = Import-Csv $srcFile
foreach ($portgroup in $vdsPortgroup){
	Get-VDSwitch $portgroup.vDS | New-VDPortgroup -name $portgroup.pgName -NumPorts $portgroup.numports -VlanId $portgroup.vlanID

Write-Host "`nPortgroups created. Now confirming settings" -ForegroundColor Cyan

Get-VDSwitch $portgroup.vDS | Get-VDPortgroup | select name, numports, portbinding, vlanconfiguration
# If a connection was needed to the VC at the start of the script, then prompt
# to confirm whether to disconnect the session.
if ($wasConnected -eq "no")
	Disconnect-VIServer $vc -confirm:$true

Sample output :

Currently connected to

Enter the name of the .csv file to work with: dvs-test.csv

Name NumPorts PortBinding
—- ——– ———–
scriptpg1 100 Static
scriptpg2 150 Static
scriptpg3 100 Static
scriptpg4 200 Static
scriptpg5 125 Static

Portgroups created. Now confirming settings

Name : scriptpg1
NumPorts : 100
PortBinding : Static
VlanConfiguration : VLAN 500

Name : scriptpg5
NumPorts : 125
PortBinding : Static
VlanConfiguration : VLAN 504

Name : scriptpg2
NumPorts : 150
PortBinding : Static
VlanConfiguration : VLAN 501

Name : scriptpg4
NumPorts : 200
PortBinding : Static
VlanConfiguration : VLAN 503

Name : scriptpg3
NumPorts : 100
PortBinding : Static
VlanConfiguration : VLAN 502

Name : dvPortGroup
NumPorts : 128
PortBinding : Static
VlanConfiguration :

Name : CloudMgmt-vDS-DVUplinks-888
NumPorts : 2
PortBinding : Static
VlanConfiguration : VLAN Trunk [0-4094]

Saturday, January 10, 2015

VCPVCD510 exam passed - VMware Infrastructure as a Service (VCP Cloud)

Today I managed to pass the VMware Certified Professional Cloud exam - Infrastructure as a Service VCPVCD510 . So, the obligatory post follows …

Exam was tough in my opinion. It’s a “standard” VCP exam as the blueprint points out - 85 questions, 90 minutes, multiple choice. It was tough for me for a few reasons. One is that it had some of the question types that I dislike, and to be honest, I ended up guessing for in some cases. I don’t like these because in the real world, I don’t memorise certain things, I just do it - which is why the VCAP was in a sense better. But also, because in the real world, if I’m wrong the system will tell me. The kind of thing I mean is :

On a Windows server, how would you find the IP address
A) ipconfig -all
B) ifconfig -all
C) ipconfig /all
D) ifconfig /all

Obviously that isn’t a question from the exam, but it illustrates the type of thing I mean (especially if the question relates to “which menu option” type of question). In reality, I “just know”, and if I did get it wrong (perhaps had just been working on a Linux box instead) then the system will effectively tell me and I’ll “d’oh of course” and fix it. So I struggle to motivate myself to learn this kind of thing or way for exams, and that can make them harder.

The other reason I found it tough is in a sense due to the reason I took the exam. I worked on a POC vCloud Director setup in work a bit last year, but that was basically canned as the focus is on a different Cloud management platform. This was a bit annoying, but hey, not my call so unfortunately not much I can do about that. But I didn’t want to waste the time I’d put in, so I made the choice to try and carry on working at home on it, and schedule the exam.

But, the VCAP was more important to me, and so took the majority of my time. Therefore I scheduled this exam only after passing the VCAP (if I’d failed, I wouldn’t have done this, I would have focused on studying to resit the VCAP instead). So I left myself with about 4-6 weeks preparation time at home and well, I soon realised how much I’d forgotten since the work POC was canned, and also how hard I find the network aspect of VCD. And in a home setup, my network configuration is extremely limited, so can’t practice as much as I’d like (plus no chargeback or connector setup at home). So the preparation wasn’t ideal and this is more a case of trying to pass the exam because it would be nice, as opposed to working with it everyday and using the exam to validate that. Is that a valid reason for doing an exam - dunno, I tend to get mixed feelings about it.

So, as mentioned, this meant I guessed a few answers (obviously I don’t know if I did this correctly), albeit trying to narrow it down and rule out what I think were obvious wrong answers. The time on the exam meant there was time for this, as some questions did seem “easy” - as in, as soon as you read it, you know what (you think) the answer is, and if you see that answer, select and move on. But again, should I really be guessing - the way I was taught in school was to always have a go (you won’t get any marks if you don’t try etc), but guessing just feels a wrong if you are trying to validate what you (believe) you know. But that’s probably as much to do with my mixed views on IT certification, and would probably be the subject for a separate post.

Preparation and materials used:

Blueprint - same for any VMware exam. The blueprint is your friend, and you pay heed to it.

Documentation - blueprint points to the documentation, so you should read it. Some of it’s dry, and makes little sense to me without actually doing it.

Lab - built a small nested lab again at home. As mentioned, there’s no bells and whistles - no Chargeback or vCloud Connector, and the networking is limited. It’s more for trying to get familiar/remember some of the processes etc (and learn the interface, but hey, that just doesn’t work for me!)

VMware Private Cloud Computing with vCloud Director by Simon Gallagher et al - bought a Kindle copy of this (afraid I never buy physical tech books these days, all on kindle/iPad) and have a copy on my “bookshelf” on my Safari subscription.

VCP-Cloud official book - again via my Safari subscription.

A few of the Packt vCloud Director books on the Safari subscription, but those were more cursory glances, and there’s not a specific one that I would recommend.

Hopefully this clears the deck a little for me now just in case VMware release anything new in the next few months to focus on …

Sunday, November 30, 2014

VCAP-DCA 550 passed

So I took the VCAP-DCA550 exam the other day, and passed (just, but a pass is a pass). Awaiting the details to be updated to my Transcript, so kind of feel it’s always a little premature until this is complete, but in time honoured fashion, here’s the obligatory “What I did, and what I used” post.

Thoughts on the exam :
Fair - it’s actually not that difficult a set of questions, but as almost everyone else has said, time is your challenge. The setup I had to use was a 20” (I think) monitor. The actual booth I was in didn’t really have elbow space, so I had to put the marker boards you are given in front of the keyboard, not to the side. So it was cramped in that sense, and the use of a single monitor for flicking between question and RDP session is ok, but not ideal.

This actually impacts on the time factor (coupled with if you need to look something up in the documentation, this is where the latency hits home a bit). I’m of the view that if you had say a dual monitor setup with elbow space, so you could see the questions/documentation on one monitor, and RDP on another, then it would actually save you say 5-10 minutes of flicking back and forth. I ended the exam with 35 seconds left, so that 5/10 minutes actually would make a reasonable difference.

So as I mentioned, I think the exam is fair. The questions aren’t that difficult, but you need to get on and do them, not think too much about them. If you’ve got a few that you think you can get done quickly, then do it, as clearing those out of the way will give you a bit of thinking time on the questions you are a bit wary of. Don’t focus on what you can’t do, focus on what you CAN.

I started a marking scheme on my marker board which indicated confidence level in the question :-
C1 - confident,
C2 - yeah, think this will be ok,
C3 - ah, bugger, I knew I should have looked more at that :-)

This worked to an extent. There were some questions that initially fell into the C3 category, but when I re-read them, they weren’t that bad - a combination of them probably actually got me over the line in the overall score.

So don’t let yourself get downhearted if you see something you think you can’t do or are not confident on. Deep breath, relax and think logically - chances are you can figure it out, and it may make the difference between passing and failing. If you’ve reached the point where you felt you wanted and were ready to take this exam, you probably can do it - you just need to be relaxed and confident enough in yourself.

Work through the questions as you need to, it’s not necessarily a sequential exam. If you can do some later question before an earlier one, or while waiting on a task from another question, then do that. Be aware of what’s being asked - a question may require you to do something without explicitly stating it - no trickery involved, just read and think logically.

Try and pick up the points where you’re confident and come back to the others. I left one question completely (which really annoyed me as it was some area I’d been specifically practicing, but it was subtly different to what I’d practiced). I reckoned I knew it - I marked it as a C2, and would come back to it. I came back to it, and my mind was a total blank. I’m still as annoyed with myself for that one, (and one other question that was easy and I know I messed up), as I am pleased with passing.

One other looking back for me, is planning on when you’re going to do the exam - day and time. I booked the exam for early(ish) morning. In order to get a slot around the date I wanted, I had to go “out of town”, which meant a 90 minute drive, so I booked a hotel for the evening before to avoid the drive to the testing center on the day of the exam. I also knew that for me, it would have to be an early time - I prefer to get going early in the day, and I also knew if I waited towards the end of the day, I’d kind of be fretting all day, so better to get on and get it done, than hang around and letting the mind play tricks. But one thing I probably overlooked, is that I booked the exam for a Friday. This may have been a mistake, as it meant I spent the final week during work thinking/fretting about it, and as I’m in work, I can’t really do anything about this like practicing etc. So for me personally, I think booking for first thing on a Monday may have been a better plan - I would still have being thinking about things on the weekend prior to it, but I could’ve spent the time working on it and trying to practice. But that’s just me. The main thing is to know yourself - know how you work, how you react, how you prepare. And so then arrange things in a way that works for you.

Material used and preparation
VMware vSphere 5.5
Yeah, I know it’s obvious. Nothing here that everyone else hasn’t said, you need to be hands on in your practice. I work with VMware everyday - it’s my job, so I use it every day. However, we don’t use every feature. We have ways to do some things, I’ve written scripts to do some stuff, so my practice had to focus more on the things I don’t do/know well, and the alternative ways to do things.

I set up a nested environment at home and tried to practice scenarios and configurations - the official study guide (details below) helped here, in that it had some suggestions and “example scenarios”. Trying these and variations on the theme helped me. I also wrote a “task sheet” document - 1 task per page, just how to do some things in a manner that made sense to me. I did this partly as I often find writing stuff down helps me in learning/remembering, and partly so that I would then use those sheets as part of my practice.

Ultimately, I booked the exam 6 weeks before taking it - full of good intentions for my preparations (and because I read that there was a 20% off discount announced at VMworld Europe - hey, don’t judge me!). Unfortunately work got busier and more stressful, and firing up the lab each evening became harder to do, so that most of of the preparation work took place on the weekends instead. The final week before the exam, I did feel like cancelling, and my preparation wasn’t as good as it should be. But that’s entirely my fault - plus I’ve always hated and always will hate exams, so this was a bit par for the course :-)

Oh, and although the sheet tells you that it may take 15 days to receive your result, I had mine when I checked e-mail 2 hours later after driving home. Actually the e-mail itself arrived about 15 minutes after leaving the exam center, so the wait may not be as stressful as you think.

In supporting the practice, I used the following :

Documentation - All documentation on my iPad and Kindle - would read some on the train on the way home every day.

VCAP-DCA Official guide by Steve Baca and John A Davies, which I have as part of my Safari subscription. Again, I had a copy of this on the kindle and would read a bit every day on the way home from work.

Unofficial guide by Jason Langer and Josh Coen

CLI guide

Chris Wahl’s study sheet (5.5 edition) - although I didn’t fill this in, this is especially useful for checking/forcing yourself to do things in different ways to what you perhaps do every day. This sheet helped focus that I may need to confirm that I could complete tasks in multiple ways as opposed to just “yeah, I can do that”.

I also used resources from the VCP exam - the Safari library has pretty much all the VMware Press books available, along with other publishers, meaning there was a good selection available for checking different bits, and coming up with ideas on what to practice. But the resources listed above were the main basis, and just practice, practice and worry.

Ultimately, if you feel this is the exam for you, go for it. Sure, my passing score wasn’t great, but I do think that if you prepare well and show the exam the respect it deserves, then there’s a good chance you’ll be successful.

Then you continue learning …

Tuesday, October 16, 2012

Quick check on number of VMs powered on and off in multiple VCs

Recently there was a need to quickly report the number of VMs in all VCs, ideally with numbers for powered on and powered off VMs. We have multiple VCs (10 plus), not in linked mode, so it meant connecting to each and counting or exporting the information.

It’s fairly easy to get this information, but figured a script may be in order, in case the request was made again in the future, so this is what I came up with. It’s rough and ready, but did what I needed it to do. And yes, there are other scripts and tools (RVTools, PowerGUI with the VMware powerpack etc) that can do it, but this is partly an exercise in trying to get to grips with Powershell and PowerCLI.

It also spits out a couple of CSV files with a basic host report and VM report per VC in files named per VC. Assumes credentials are sorted in some way for conveniance - ie, credentials store.

The VCs to check are listed in the vclist.txt file

$currVC = Get-Content "vclist.txt"
foreach ($targetVC in $currVC) {
        Connect-VIServer $targetVC
        $hostCount = Get-VMhost
        write-host "Total number of hosts in $targetVC :" ($hostCount).count
# VM's, powered on and memory count
        Write-Host "Collecting VM information"
        $OutputFile = $targetVC + ".csv"
        $totalvms = get-vm | where{$_.powerstate -eq "PoweredOn" } |`
                select name, powerstate, numcpu, memorymb | `
                export-csv -NoTypeInformation $outputFile | out-null
        $pvms = Get-VM
        write-host "Powered on: " ($pvms | where {$_.PowerState -eq "PoweredOn"}
        write-host "Powered off: " ($pvms | where {$_.PowerState -eq "PoweredOff

# VMhost details
        Write-Host "Collecting host information"
        $HostOutputFile = $targetVC + "-vmhost.csv"
        $totalHosts = get-vmhost | select name, numcpu, CPUTotalMHz, MemoryTotal
MB, MemoryUsageMB, Parent |`
                Export-Csv -NoTypeInformation  $HostOutputFile | out-null
Disconnect-VIServer -Confirm:$false

Monday, October 15, 2012

Using PowerCLI to retrieve IP from VM annotations

In our environment, we have a lot of VMs on NAT’d addresses. On occassion, I need acccess to their public IP - eg, for pinging to verify guests are still running if we put a host into maintenance mode. Grabbing the address from the internal system for each VM is time consuming and somewhat annoying. vSphere reports the private IP in the GUI which isn’t what I want. You can extract the info from the VM with PowerCLI, but again, it’s a little awkward (for my skill level). And we don’t label the VMs by their DNS name, it’s more an internal system, which again, makes identifying a particular machine harder than I would like, but that’s the way the system is.

Luckily, when we create VMs, we add annotations. One of which contains the public IP (or it should if people fill in the details :-)

That allows a way to grab the public IP with a one liner (here the assumption is the annotation field is called Public IP).

For VM called “foo” :

get-vm  foo|  get-annotation | where-object {$ -eq "Public IP"}

For all VMs in a VC :

get-vm | get-annotation | where-object {$ -eq "Public IP"}

Or, if we want just the powered on VMs :

get-vm | where-object {$_.powerstate -eq "PoweredOn"} | get-annotation | where-object {$ -eq "Public IP"}

I export them to .csv, and now have a more manageable way of quickly being able to call upon the relevant IPs