vCO – Another way of getting Distributed Virtual Switches

Well this is my very first blog ever.  Actually  this is a reply to a blog on the mighty virtualization blog from   on

http://mighty-virtualization.blogspot.com/2011/01/vco-get-all-distributed-virtual.html

Blogspot for some reason did not let me post this code as a reply but I thought I do not want to leave my talent wasted (cough!) and post it as a new blog.  Maybe a start for something great.  Well here it is, another code for VMware vCenter Orchestrator on how to get all Distributed Virtual Switches.  In this case the name of it.

dc by the way is a VcDatacenter object.  An input parameter if you will

var dcNetworkFolder = VcPlugin.convertToVimManagedObject( dc, dc.networkFolder.childEntity );
for each (var netItem in dcNetworkFolder)
{
	if (netItem instanceof VcVmwareDistributedVirtualSwitch)
	{
		System.log( "DVS Name: " + netItem.name);
	}
}

Today I actually noticed that you could create a network folder put a dvs switch in there and the code above then would not find it as it only runs through the root network folder. So if you are actually using network folders then you need to run through all network folders. But I don’t leave you alone with that. Below you find a code that does that. However you will get all dvs switches and not just the ones that belong to a specific datacenter.

var allNetFolder = sdkConnection.getAllNetworkFolders();
for each (var netFolder in allNetFolder)
{
	var dcNetworkFolder = VcPlugin.convertToVimManagedObject( netFolder, netFolder.childEntity );
	for each (var netItem in dcNetworkFolder)
	{
		if (netItem instanceof VcVmwareDistributedVirtualSwitch)
		{
			System.log( "DVS Name: " + netItem.name);
		}
	}
}

Published by txusa

VMware Certified Design Expert - VCDX 92. VMware Architect, automation enthusiast.

One thought on “vCO – Another way of getting Distributed Virtual Switches

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: