def do_sites(self, args): """List available cloud sites""" result = getVMTypes() print(result) siteDict = result["Value"] records = [] for site in siteDict: ceStart = True for ce in siteDict[site]: vmStart = True for vmType in siteDict[site][ce]["VMTypes"]: flavor = siteDict[site][ce]["VMTypes"][vmType].get( "FlavorName", "Unknown") image = siteDict[site][ce]["VMTypes"][vmType].get( "Image", siteDict[site][ce]["VMTypes"][vmType].get( "ImageID", "Unknown")) if ceStart and vmStart: records.append([site, ce, vmType, flavor, image]) elif ceStart: records.append(["", "", vmType, flavor, image]) else: records.append(["", ce, vmType, flavor, image]) vmStart = False ceStart = False fields = ["Site", "Endpoint", "VM Type", "Flavor", "Image"] printTable(fields, records)
def getCEInstances(cls, siteList=None, ceList=None, vo=None): result = getVMTypes(siteList=siteList, ceList=ceList, vo=vo) if not result["OK"]: return result imageDict = result["Value"] ceList = [] for site in imageDict: for ce in imageDict[site]: result = EndpointFactory().getCE(site, ce) if not result["OK"]: continue ceList.append((site, ce, result["Value"])) nodeDict = {} for site, ceName, ce in ceList: result = ce.getVMNodes() if not result["OK"]: continue for node in result["Value"]: if not node.name.startswith("DIRAC"): continue ip = node.public_ips[0] if node.public_ips else "None" nodeState = ( node.state.upper() if not isinstance(node.state, six.integer_types) else STATE_MAP[node.state] ) nodeDict[node.id] = { "Site": site, "CEName": ceName, "NodeName": node.name, "PublicIP": ip, "State": nodeState, } return S_OK(nodeDict)
def beginExecution(self): # The Director is for a particular user community self.vo = self.am_getOption("VO", "") if not self.vo: self.vo = CSGlobals.getVO() # The SiteDirector is for a particular user group self.group = self.am_getOption("Group", "") # Choose the group for which clouds will be submitted. This is a hack until # we will be able to match clouds to VOs. if not self.group: if self.vo: result = Registry.getGroupsForVO(self.vo) if not result["OK"]: return result self.voGroups = [] for group in result["Value"]: if "NormalUser" in Registry.getPropertiesForGroup(group): self.voGroups.append(group) else: self.voGroups = [self.group] result = findGenericCloudCredentials(vo=self.vo) if not result["OK"]: return result self.cloudDN, self.cloudGroup = result["Value"] self.maxVMsToSubmit = self.am_getOption("MaxVMsToSubmit", 1) self.runningPod = self.am_getOption("RunningPod", self.vo) # Get the site description dictionary siteNames = None if not self.am_getOption("Site", "Any").lower() == "any": siteNames = self.am_getOption("Site", []) if not siteNames: siteNames = None ces = None if not self.am_getOption("CEs", "Any").lower() == "any": ces = self.am_getOption("CEs", []) if not ces: ces = None result = getVMTypes(vo=self.vo, siteList=siteNames) if not result["OK"]: return result resourceDict = result["Value"] result = self.getEndpoints(resourceDict) if not result["OK"]: return result # if not siteNames: # siteName = gConfig.getValue( '/DIRAC/Site', 'Unknown' ) # if siteName == 'Unknown': # return S_OK( 'No site specified for the SiteDirector' ) # else: # siteNames = [siteName] # self.siteNames = siteNames self.log.always("Sites:", siteNames) self.log.always("CEs:", ces) self.log.always("CloudDN:", self.cloudDN) self.log.always("CloudGroup:", self.cloudGroup) self.localhost = socket.getfqdn() self.proxy = "" if self.firstPass: if self.vmTypeDict: self.log.always("Agent will serve VM types:") for vmType in self.vmTypeDict: self.log.always( "Site: %s, CE: %s, VMType: %s" % (self.vmTypeDict[vmType]["Site"], self.vmTypeDict[vmType]["CEName"], vmType) ) self.firstPass = False return S_OK()