--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<workflow xmlns="http://vmware.com/vco/workflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://vmware.com/vco/workflow http://vmware.com/vco/workflow/Workflow-v4.xsd" root-name="item1" object-name="workflow:name=generic" id="a5c7285f-1b6c-45e6-a4cb-3b2881b54cb0" version="0.0.8" api-version="3.1.0" allowed-operations="fve" restartMode="1" resumeFromFailedMode="0">
+ <display-name>get_project</display-name>
+
+ <description>Small flow used to get ldapPath for AD object. Also returns project name.</description>
+
+ <position x="100.0" y="50.0"/>
+
+ <input>
+ <param name="computerName" type="string"/>
+ </input>
+
+ <output>
+ <param name="project" type="string"/>
+ <param name="ldapPath" type="string"/>
+ </output>
+
+ <attrib name="errorCode" type="string" read-only="false">
+ <value encoded="n">Computer not defined in correct AD path</value>
+ </attrib>
+
+ <workflow-item name="item0" type="end" end-mode="0">
+ <position x="384.5" y="45.40909090909091"/>
+ </workflow-item>
+
+ <workflow-item name="item1" out-name="item0" throw-bind-name="errorCode" type="task">
+ <display-name>Scriptable task</display-name>
+
+ <script encoded="false">
+var vmname=computerName.replace(/\..*/,"");
+
+function get_computers (vmname) {
+ var computers = ActiveDirectory.getComputerADRecursively(vmname);
+
+ for each (var mpc in computers){
+ //System.log("Checking computer: "+pc.name);
+
+ if (vmname.toLowerCase() == mpc.name.toLowerCase()){
+ System.log("Found Computer: "+mpc.name);
+ var ff=mpc.allAttributes;
+ return mpc;
+ }
+ }
+}
+
+computer=get_computers(vmname);
+if (!computer) {
+ System.log("Not able to find "+computerName+" in AD");
+ System.throw("Error");
+}
+
+ldapPath=computer.distinguishedName;
+
+var ous=ldapPath.split(',');
+ous.shift();
+ldapPath=ous.toString();
+
+if (ous[1] == "OU=lost and found hosts") {
+ System.trow("VM er i lost and found");
+}
+
+var reverse=ous.reverse();
+//System.log(reverse);
+
+if (reverse[3] != "OU=projects") {
+ if (reverse[3] == "OU=usit") {
+ System.log(reverse[4]);
+ project="usit";
+ } else {
+ project="autoprovisioned";
+ }
+} else {
+ project=reverse[4].split('=')[1];
+}
+ </script>
+
+ <in-binding>
+ <bind name="computerName" type="string" export-name="computerName"/>
+ </in-binding>
+
+ <out-binding>
+ <bind name="project" type="string" export-name="project"/>
+ <bind name="ldapPath" type="string" export-name="ldapPath"/>
+ </out-binding>
+
+ <position x="204.5" y="55.40909090909091"/>
+ </workflow-item>
+
+ <presentation>
+ <p-param name="computerName">
+ <desc>computerName</desc>
+ </p-param>
+ </presentation>
+</workflow>