<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UML Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/uml/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/uml/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 10:24:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.10</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>UML Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/uml/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>UML diagram your VM, vdisks and snapshots</title>
		<link>https://www.lucd.info/2010/03/31/uml-diagram-your-vm-vdisks-and-snapshots/</link>
					<comments>https://www.lucd.info/2010/03/31/uml-diagram-your-vm-vdisks-and-snapshots/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Wed, 31 Mar 2010 19:18:05 +0000</pubDate>
				<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[UML]]></category>
		<category><![CDATA[vSphere]]></category>
		<guid isPermaLink="false">http://lucd.info/?p=1984</guid>

					<description><![CDATA[After my yadr – A vdisk reporter post I received an email from [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>After my <a href="https://lucd.info/?p=1935" target="_blank" rel="noopener noreferrer">yadr – A vdisk reporter</a> post I received an email from <a href="https://twitter.com/vmachine" target="_blank" rel="noopener noreferrer">Dennis Zimmer</a>, known from <a href="http://www.vmachine.de" target="_blank" rel="noopener noreferrer">VMachine</a> blog and as the IcomaSoft CTO. He pointed me to the <a href="https://yuml.me/" target="_blank" rel="noopener noreferrer">yUML</a> website and suggested that I could perhaps use part of the <strong>yadr</strong> script to produce an UML diagram.</p>
<p>As it happended there were already some <strong>PowerShell</strong> scripts that used the functionality offered by the <a href="https://yuml.me/" target="_blank" rel="noopener noreferrer">yUML</a> website to produce <strong>UML diagrams</strong>. Have a look for example at <a href="https://dougfinke.com/blog/index.php/2009/05/06/use-powershell-and-yuml-to-create-diagrams/" target="_blank" rel="noopener noreferrer">Use PowerShell and yUML to Create Diagrams</a> by <a href="https://twitter.com/dfinke" target="_blank" rel="noopener noreferrer">Doug Finke</a> and <a href="https://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!434.entry" target="_blank" rel="noopener noreferrer">Create Database Diagrams with Powershell + yUML</a> by <a href="https://twitter.com/cmille19" target="_blank" rel="noopener noreferrer">Chad Miller</a>.</p>
<p>As you probably guessed by now I was sold to the idea.</p>
<h2><span id="more-1984"></span>The script</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">function Get-UMLDiagram{
	param($vmName)

	function Set-ULMFromTo{
		param($from, $to, $attrib)

		$result = &quot;[&quot; + $from + &quot;]-&gt;[&quot; + $to
		if($attrib){
			$result += &quot;|&quot;
			$attrib | %{
				$result += ([string]$_ + &quot;;&quot;)
			}
			$result = $result.TrimEnd(&quot;;&quot;)
		}
		$result += &quot;],`n&quot;
		$result
	}

	filter Get-SnapHash{
		param($parent)

		$snapHash[$_.Snapshot.Value] = @($_.Name,$parent)
		if($_.ChildSnapshotList){
			$newparent = $_
			$_.ChildSnapShotList | Get-SnapHash $newparent
		}
	}

	$vms = Get-View -ViewType VirtualMachine -Filter @{&quot;Name&quot;=$vmName}

	$snapHash = @{}

	$vms | %{
		$ulmStr = &quot;&quot;
		$vm = $_

		if($vm.Snapshot){
			$vm.Snapshot.RootSnapshotList | Get-SnapHash $vm
		}
		$firstHD = $true
		$_.Config.Hardware.Device | where {$_.DeviceInfo.Label -like &quot;Hard disk *&quot;} | %{
			$hd = $_
			$hdNr = $hd.DeviceInfo.Label.Split(&quot; &quot;)[-1]
			$exDisk = $vm.LayoutEx.Disk | where {$_.Key -eq $hd.Key}
			$diskFiles = @()
			$exDisk.Chain | %{$_.FileKey} | %{$diskFiles += $_}
			$totalDiskAllocated = 0
			$vm.LayoutEx.File | where {$diskFiles -contains $_.Key} | %{
				$totalDiskAllocated += $_.Size
			}
			$hdProp = @()
			if($hd.Backing.ThinProvisioned){
				$hdProp += &quot;Thin&quot;
				$hdProp += (&quot;AllocatedGB=&quot; + (&quot;{0:N0} GB&quot; -f ($totalDiskAllocated / 1GB)))
				$hdProp += (&quot;Used=&quot; + (&quot;{0:P0}&quot; -f ($totalDiskAllocated / 1KB /$hd.CapacityInKB)))
			}
			elseif($hd.Backing.GetType().Name.Contains(&quot;RawDisk&quot;)){
				$hdProp += &quot;RDM&quot;
			}
			else{
				$hdProp += &quot;Thick&quot;
				$hdProp += (&quot;Allocated=&quot; + (&quot;{0:N0} GB&quot; -f ($totalDiskAllocated / 1GB)))
			}
			$ulmStr += (Set-ULMFromTo ($vm.Name + &quot;{bg:orange}&quot;)  ($hd.DeviceInfo.Label) $hdProp)

			$exDisk.Chain[0].FileKey | %{
				$ulmStr += (Set-ULMFromTo ($hd.DeviceInfo.Label + &quot;{bg:green}&quot;) $vm.LayoutEx.File[$_].Name.Split(&quot;/&quot;)[-1] $vm.LayoutEx.File[$_].Size)
			}
			$snapHash.GetEnumerator() | %{
				$key = $_.Key
				$value = $_.Value
				$vm.LayoutEx.Snapshot | where {$_.Key.Value -eq $key} | %{
					$vmsnId = $_.DataKey
					$_.Disk | where{$_.Key -eq $hd.Key} | %{
						if($diskFiles -notcontains $_.Chain[-1].FileKey[0] -and $diskFiles -notcontains $_.Chain[-1].FileKey[1]){
							$chain = $_.Chain[-1]
						}
						else{
							$preSnapFiles = $_.Chain | %{$_.FileKey} | %{$_}
							$vm.layoutEx.Disk | where {$_.Key -eq $hd.Key} | %{
								foreach($chain in $_.Chain){
									if($preSnapFiles -notcontains $chain.FileKey[0] -and $preSnapFiles -notcontains $chain.FileKey[1]){
										break
									}
								}
							}
						}
						if($firstHD){
							$ulmStr += (Set-ULMFromTo ($value[1].Name + &quot;{bg:yellow}&quot;) ($value[0] + &quot;{bg:yellow}&quot;))
							$ulmStr += (Set-ULMFromTo $value[0] $vm.LayoutEx.File[$vmsnId].Name.Split(&quot;/&quot;)[-1] $vm.LayoutEx.File[$vmsnId].Size)
						}
						$ulmStr += (Set-ULMFromTo $value[0] ($value[0] + &quot;-HD&quot; + $hdNr + &quot;{bg:blue}&quot;))
						$chain.FileKey | %{
							$ulmStr += (Set-ULMFromTo ($value[0] + &quot;-HD&quot; + $hdNr) $vm.LayoutEx.File[$_].Name.Split(&quot;/&quot;)[-1] $vm.LayoutEx.File[$_].Size)
						}
					}
				}
			}
			$firstHD = $false
		}
		$ulmStr.TrimEnd(&quot;,`n&quot;)
	}
}

# Based on Doug Finke's original Get-yUMLDiagram function.
# See: https://dougfinke.com/blog/index.php/2009/05/06/use-powershell-and-yuml-to-create-diagrams/
# Added the &quot;scruffy&quot; switch and rearranged some of the lines
#
function Get-yUMLDiagram {
    param(
        $yUML,
        $diagramFileName = &quot;C:\yUML.jpg&quot;,
        [switch]$show,
        [switch]$pdf,
		[switch]$scruffy
    )

	$scruffyPath = &quot;&quot;
	if($scruffy){
		$scruffyPath = &quot;scruffy/&quot;
	}
    $base = &quot;https://yuml.me/diagram/&quot; + $scruffyPath + &quot;class/&quot;
    $address = $base + $yUML

	$wc = New-Object Net.WebClient
	if($pdf){
		$diagramFileName = $diagramFileName.Replace($diagramFileName.Split(&quot;.&quot;)[-1],&quot;pdf&quot;)
		$address += &quot;.pdf&quot;
	}
    $wc.DownloadFile($address, $diagramFileName)
    if($show) {
        Invoke-Item $diagramFileName
	}
}

$vmName = &quot;MyVM1&quot;
$diagram = Get-UMLDiagram $vmName

Get-yUMLDiagram $diagram &quot;D:\yULM.jpg&quot; -show</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 1</strong>: The <strong>Get-UMLDiagram</strong> function does the hard work of analysing the data in the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.FileLayoutEx.html" target="_blank" rel="noopener noreferrer">VirtualMachineFileLayoutEx</a> object. The <strong>LayoutEx</strong> property in each <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html" target="_blank" rel="noopener noreferrer">VirtualMachine</a> object points to this <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.FileLayoutEx.html" target="_blank" rel="noopener noreferrer">VirtualMachineFileLayoutEx</a><strong></strong> object. The function takes one parameter, the name of the virtual machine for which you want to produce the UML diagram.<br />
<strong>Line 4-17</strong>: The <strong>Set-ULMFromTo</strong> is an <strong>internal</strong> function that produces the correct text to draw a box-to-box diagram.</p>
<p><strong>Line 19-27</strong>: This internal filter stores how the snapshots are related in a hash table. The filter has been expanded with extra data compared to the filter with the same name in the <strong>yadr</strong> script.</p>
<p><strong>Line 33</strong>: The main loop of the <strong>Get-ULMDiagram</strong> function.</p>
<p><strong>Line 34</strong>: The text that is passed to the <a href="https://yuml.me/" target="_blank" rel="noopener noreferrer">yUML</a> website is collected in this variable.</p>
<p><strong>Line 37-39</strong>: Read the snapshot tree and store it in a hash table.</p>
<p><strong>Line 41</strong>: Loop through all the virtual machine&#8217;s devices but only take the hard disks for further processing.</p>
<p><strong>Line 44</strong>: Get the correct hard disk, if there are more than one.</p>
<p><strong>Line 48-50</strong>: Calculate the total storage allocated to this hard disk. This will be displayed as an attribute in the UML diagram.</p>
<p><strong>Line 52-63</strong>: Determine what type of hard disk we are dealing with. The script can distinguish Thick, Thin and RDM disks.</p>
<p><strong>Line 69</strong>: If there are snapshots, this is the loop through all them. The script will extract the information for the c urrent hard disk.</p>
<p><strong>Line 88</strong>: To avoid double lines in the UML diagram when we have more than one hard disk, I use the switch $firstHD. The lines between the snapshots are only drawn for the first hard disk.</p>
<p><strong>Line 109-134</strong>: The Get-yUMLDiagram function was originally written by <a href="https://twitter.com/dfinke" target="_blank" rel="noopener noreferrer">Doug Finke</a>. I expanded it to support the &#8220;scruffy&#8221; option.</p>
<h2>Usage</h2>
<p>The function, called <strong>Get-yUMLDiagram</strong>, does the actual call to the <a href="https://yuml.me/" target="_blank" rel="noopener noreferrer">yUML</a> website and receives the requested output.</p>
<p>This function&#8217;s parameters allow you to select which type of output you want, the style of the diagram and if the diagram should be displayed on screen.</p>
<table border="0">
<tbody>
<tr>
<td>yUML</td>
<td>A string containing the text that the yUML site will convert into a diagram</td>
</tr>
<tr>
<td>diagramFileName</td>
<td>The name of the file into which the diagram will be saved</td>
</tr>
<tr>
<td>show</td>
<td>A switch where you can specify if the script should show the diagram</td>
</tr>
<tr>
<td>pdf</td>
<td>A switch where you can specify if the yUML website should produce a PDF file instead of a JPG file</td>
</tr>
<tr>
<td>scruffy</td>
<td>A switch where you can specify if the diagram should be produced in a less formal style</td>
</tr>
</tbody>
</table>
<h2>Samples</h2>
<h3>VM with 1 hard disk</h3>
<p><a href="https://lucd.info/wp-content/uploads/2010/03/UML-MyVM12.png"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1999" title="UML-MyVM1" src="https://lucd.info/wp-content/uploads/2010/03/UML-MyVM12.png" alt="" width="392" height="403" srcset="https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM12.png 490w, https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM12-291x300.png 291w" sizes="(max-width: 392px) 100vw, 392px" /></a></p>
<p>Notice the attributes for <strong>Hard disk 1</strong>. It&#8217;s a <strong>Thick</strong> provisioned disk and <strong>8 Gb</strong> have been allocated.</p>
<p>The Hard disk 1 box points to the two actual files on the datastore. They each have as attribute the size (in bytes) of the file.</p>
<h3>VM with 3 hard disks</h3>
<p><a href="https://lucd.info/wp-content/uploads/2010/03/UML-MyVM2.png"><img decoding="async" class="alignnone size-full wp-image-2001" title="UML-MyVM2" src="https://lucd.info/wp-content/uploads/2010/03/UML-MyVM2.png" alt="" width="918" height="393" srcset="https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM2.png 1275w, https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM2-300x128.png 300w, https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM2-1024x438.png 1024w" sizes="(max-width: 918px) 100vw, 918px" /></a></p>
<p>Notice that Hard disk 1 is a Thin provisioned disk.</p>
<h3>VM with 1 hard disk and 1 snapshot</h3>
<p><a href="https://lucd.info/wp-content/uploads/2010/03/UML-MyVM3.png"><img decoding="async" class="alignnone size-full wp-image-2002" title="UML-MyVM3" src="https://lucd.info/wp-content/uploads/2010/03/UML-MyVM3.png" alt="" width="891" height="542" srcset="https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM3.png 1114w, https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM3-300x182.png 300w, https://www.lucd.info/wp-content/uploads/2010/03/UML-MyVM3-1024x623.png 1024w" sizes="(max-width: 891px) 100vw, 891px" /></a></p>
<p>The Snapshot1 branch connects to the <strong>.vmsn</strong> file and the files for <strong>Hard disk 1</strong> that were created due to the snapshot.</p>
<h3>Extravaganza</h3>
<p>This is something you probably shouldn&#8217;t see in real life <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>But I included it to show you how the snapshot tree is represented in the UML diagram.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/03/yULM.jpg"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2003" title="yULM" src="https://lucd.info/wp-content/uploads/2010/03/yULM.jpg" alt="" width="1154" height="286" srcset="https://www.lucd.info/wp-content/uploads/2010/03/yULM.jpg 4009w, https://www.lucd.info/wp-content/uploads/2010/03/yULM-300x74.jpg 300w, https://www.lucd.info/wp-content/uploads/2010/03/yULM-1024x254.jpg 1024w" sizes="auto, (max-width: 1154px) 100vw, 1154px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2010/03/31/uml-diagram-your-vm-vdisks-and-snapshots/feed/</wfw:commentRss>
			<slash:comments>26</slash:comments>
		
		
			</item>
	</channel>
</rss>
