From: Alex Brett Date: Wed, 18 Nov 2015 12:51:57 +0000 (+0000) Subject: Add getByName method to fetch a blueprint by name X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8ead7f1a094d75cc55c402b298acbc9afb38a8d5;p=xenrt-citrix%2Fxenrt.git Add getByName method to fetch a blueprint by name --- diff --git a/exec/testcases/scalextreme/poc.py b/exec/testcases/scalextreme/poc.py index 53413c6f4..85d547e71 100644 --- a/exec/testcases/scalextreme/poc.py +++ b/exec/testcases/scalextreme/poc.py @@ -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() diff --git a/exec/xenrt/lib/scalextreme/sxprocess.py b/exec/xenrt/lib/scalextreme/sxprocess.py index 1886fdaa6..31cdf3f98 100644 --- a/exec/xenrt/lib/scalextreme/sxprocess.py +++ b/exec/xenrt/lib/scalextreme/sxprocess.py @@ -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