]> xenbits.xensource.com Git - xenrt-citrix/xenrt.git/commitdiff
Add getByName method to fetch a blueprint by name
authorAlex Brett <alex.brett@citrix.com>
Wed, 18 Nov 2015 12:51:57 +0000 (12:51 +0000)
committerAlex Brett <alex.brett@citrix.com>
Wed, 18 Nov 2015 12:51:57 +0000 (12:51 +0000)
exec/testcases/scalextreme/poc.py
exec/xenrt/lib/scalextreme/sxprocess.py

index 53413c6f44afc3e969ff066168da4744d59e52c1..85d547e71356baf0b394324716770a3cd9ef422e 100644 (file)
@@ -24,7 +24,8 @@ class XDPoc(xenrt.TestCase):
         # Find the Windows template
         template = self.getGuest("Windows Server 2012 R2")
         host = template.getHost()
-        sxp = SXProcess("58687", "2", "2937")
+        sxp = SXProcess.getByName("XenApp and XenDesktop Proof of Concept (25)", templateDeploymentProfile="xenrt-template")
+        # sxp = SXProcess("58687", "2", "2937")
 
         # Find our providerId (TODO: we should store this in the registry)
         providerName = "xenrt-%d" % xenrt.GEC().jobid()
index 1886fdaa667e1220d7fd96e62f80204f81436ac3..31cdf3f987552b469fb75ad40093d6cce5da4eb9 100644 (file)
@@ -17,6 +17,32 @@ class SXProcess(object):
         self.__credential = xenrt.TEC().lookup("SXA_CREDENTIAL", None)
         self.__api = None
 
+    @staticmethod
+    def getByName(name, version=None, templateDeploymentProfile=None):
+        """Creates an SXProcess object for the named blueprint"""
+        # First instantiate an 'empty' object which we can fill in
+        p = SXProcess(None, version)
+        api = p.apiHandler
+        blueprints = api.execute(category="process", method="GET", params={"type":"purchased"})
+        matchedBlueprints = filter(lambda b: b['processName'] == name, blueprints)
+        if len(matchedBlueprints) != 1:
+            raise xenrt.XRTError("Found %d matching blueprints (expected 1)" % len(matchedBlueprints))
+        b = matchedBlueprints[0]
+        p.__processId = b['processId']
+        if not version:
+            # Find the latest version
+            versions = api.execute(category="process", command="versions", method="GET")
+            p.__processVersion = max(map(lambda v: int(v['version']), versions))
+        if templateDeploymentProfile:
+            # Find the id of this profile
+            profiles = api.execute(category="deploymentprofile", command="list", method="POST", params={"processId": b['processId'], "processVersion": b['processVersion']})
+            matchedProfiles = filter(lambda dp: dp['deploymentProfileName'] == templateDeploymentProfile, profiles)
+            if len(matchedProfiles) != 1:
+                raise xenrt.XRTError("Found %d matching deployment profiles (expected 1)" % len(matchedProfiles))
+            p.__templateDeploymentProfileId = matchedProfiles[0]['deploymentProfileId']
+
+        return p
+
     @property
     def processId(self):
         return self.__processId