Exemple #1
0
def stopInstance(site, endpoint, nodeID):

    result = getVMTypeConfig(site, endpoint)
    if not result['OK']:
        return result
    ceParams = result['Value']
    ceFactory = EndpointFactory()
    result = ceFactory.getCEObject(parameters=ceParams)
    if not result['OK']:
        return result

    ce = result['Value']
    result = ce.stopVM(nodeID)
    return result
Exemple #2
0
def createEndpoint(uniqueID):

    result = gVirtualMachineDB.getEndpointFromInstance(uniqueID)
    if not result['OK']:
        return result
    site, endpoint = result['Value'].split('::')

    result = getVMTypeConfig(site, endpoint)
    if not result['OK']:
        return result
    ceParams = result['Value']
    ceFactory = EndpointFactory()
    result = ceFactory.getCEObject(parameters=ceParams)
    return result
Exemple #3
0
    def getEndpoints(self, resourceDict):
        """ Get the list of relevant CEs and their descriptions
    """

        self.vmTypeDict = {}
        ceFactory = EndpointFactory()

        result = getPilotBootstrapParameters(vo=self.vo,
                                             runningPod=self.runningPod)
        if not result['OK']:
            return result
        opParameters = result['Value']

        for site in resourceDict:
            for ce in resourceDict[site]:
                ceDict = resourceDict[site][ce]
                ceTags = ceDict.get('Tag', [])
                if isinstance(ceTags, basestring):
                    ceTags = fromChar(ceTags)
                ceMaxRAM = ceDict.get('MaxRAM', None)
                qDict = ceDict.pop('VMTypes')
                for vmType in qDict:
                    vmTypeName = '%s_%s' % (ce, vmType)
                    self.vmTypeDict[vmTypeName] = {}
                    self.vmTypeDict[vmTypeName]['ParametersDict'] = qDict[
                        vmType]
                    self.vmTypeDict[vmTypeName]['ParametersDict'][
                        'VMType'] = vmType
                    self.vmTypeDict[vmTypeName]['ParametersDict'][
                        'Site'] = site
                    self.vmTypeDict[vmTypeName]['ParametersDict'][
                        'Setup'] = gConfig.getValue('/DIRAC/Setup', 'unknown')
                    self.vmTypeDict[vmTypeName]['ParametersDict'][
                        'CPUTime'] = 99999999

                    vmTypeTags = self.vmTypeDict[vmTypeName][
                        'ParametersDict'].get('Tag')
                    if vmTypeTags and isinstance(vmTypeTags, basestring):
                        vmTypeTags = fromChar(vmTypeTags)
                        self.vmTypeDict[vmTypeName]['ParametersDict'][
                            'Tag'] = vmTypeTags
                    if ceTags:
                        if vmTypeTags:
                            allTags = list(set(ceTags + vmTypeTags))
                            self.vmTypeDict[vmTypeName]['ParametersDict'][
                                'Tag'] = allTags
                        else:
                            self.vmTypeDict[vmTypeName]['ParametersDict'][
                                'Tag'] = ceTags

                    maxRAM = self.vmTypeDict[vmTypeName]['ParametersDict'].get(
                        'MaxRAM')
                    maxRAM = ceMaxRAM if not maxRAM else maxRAM
                    if maxRAM:
                        self.vmTypeDict[vmTypeName]['ParametersDict'][
                            'MaxRAM'] = maxRAM

                    ceWholeNode = ceDict.get('WholeNode', 'true')
                    wholeNode = self.vmTypeDict[vmTypeName][
                        'ParametersDict'].get('WholeNode', ceWholeNode)
                    if wholeNode.lower() in ('yes', 'true'):
                        self.vmTypeDict[vmTypeName][
                            'ParametersDict'].setdefault('Tag', [])
                        self.vmTypeDict[vmTypeName]['ParametersDict'][
                            'Tag'].append('WholeNode')

                    platform = ''
                    if "Platform" in self.vmTypeDict[vmTypeName][
                            'ParametersDict']:
                        platform = self.vmTypeDict[vmTypeName][
                            'ParametersDict']['Platform']
                    elif "Platform" in ceDict:
                        platform = ceDict['Platform']
                    if platform and platform not in self.platforms:
                        self.platforms.append(platform)

                    if "Platform" not in self.vmTypeDict[vmTypeName][
                            'ParametersDict'] and platform:
                        result = Resources.getDIRACPlatform(platform)
                        if result['OK']:
                            self.vmTypeDict[vmTypeName]['ParametersDict'][
                                'Platform'] = result['Value'][0]

                    ceVMTypeDict = dict(ceDict)
                    ceVMTypeDict['CEName'] = ce
                    ceVMTypeDict['VO'] = self.vo
                    ceVMTypeDict['VMType'] = vmType
                    ceVMTypeDict['RunningPod'] = self.runningPod
                    ceVMTypeDict['CSServers'] = gConfig.getValue(
                        "/DIRAC/Configuration/Servers", [])
                    ceVMTypeDict.update(
                        self.vmTypeDict[vmTypeName]['ParametersDict'])

                    # Allow a resource-specifc CAPath to be set (as some clouds have their own CAs)
                    # Otherwise fall back to the system-wide default(s)
                    if 'CAPath' not in ceVMTypeDict:
                        ceVMTypeDict['CAPath'] = gConfig.getValue(
                            '/DIRAC/Security/CAPath',
                            "/opt/dirac/etc/grid-security/certificates/cas.pem"
                        )

                    # Generate the CE object for the vmType or pick the already existing one
                    # if the vmType definition did not change
                    vmTypeHash = self.__generateVMTypeHash(ceVMTypeDict)
                    if vmTypeName in self.vmTypeCECache and self.vmTypeCECache[
                            vmTypeName]['Hash'] == vmTypeHash:
                        vmTypeCE = self.vmTypeCECache[vmTypeName]['CE']
                    else:
                        result = ceFactory.getCEObject(parameters=ceVMTypeDict)
                        if not result['OK']:
                            return result
                        self.vmTypeCECache.setdefault(vmTypeName, {})
                        self.vmTypeCECache[vmTypeName]['Hash'] = vmTypeHash
                        self.vmTypeCECache[vmTypeName]['CE'] = result['Value']
                        vmTypeCE = self.vmTypeCECache[vmTypeName]['CE']
                        vmTypeCE.setBootstrapParameters(opParameters)

                    self.vmTypeDict[vmTypeName]['CE'] = vmTypeCE
                    self.vmTypeDict[vmTypeName]['CEName'] = ce
                    self.vmTypeDict[vmTypeName]['CEType'] = ceDict['CEType']
                    self.vmTypeDict[vmTypeName]['Site'] = site
                    self.vmTypeDict[vmTypeName]['VMType'] = vmType
                    self.vmTypeDict[vmTypeName]['Platform'] = platform
                    self.vmTypeDict[vmTypeName]['MaxInstances'] = ceDict[
                        'MaxInstances']
                    if not self.vmTypeDict[vmTypeName]['CE'].isValid():
                        self.log.error(
                            'Failed to instantiate CloudEndpoint for %s' %
                            vmTypeName)
                        continue

                    if site not in self.sites:
                        self.sites.append(site)

        return S_OK()
    def getImages(self, resourceDict):
        """ Get the list of relevant CEs and their descriptions
    """

        self.imageDict = {}
        ceFactory = EndpointFactory()

        result = getPilotBootstrapParameters(vo=self.vo,
                                             runningPod=self.runningPod)
        if not result['OK']:
            return result
        opParameters = result['Value']

        for site in resourceDict:
            for ce in resourceDict[site]:
                ceDict = resourceDict[site][ce]
                ceTags = ceDict.get('Tag', [])
                if isinstance(ceTags, basestring):
                    ceTags = fromChar(ceTags)
                ceMaxRAM = ceDict.get('MaxRAM', None)
                qDict = ceDict.pop('Images')
                for image in qDict:
                    imageName = '%s_%s' % (ce, image)
                    self.imageDict[imageName] = {}
                    self.imageDict[imageName]['ParametersDict'] = qDict[image]
                    self.imageDict[imageName]['ParametersDict'][
                        'Image'] = image
                    self.imageDict[imageName]['ParametersDict']['Site'] = site
                    self.imageDict[imageName]['ParametersDict'][
                        'Setup'] = gConfig.getValue('/DIRAC/Setup', 'unknown')
                    self.imageDict[imageName]['ParametersDict'][
                        'CPUTime'] = 99999999
                    imageTags = self.imageDict[imageName][
                        'ParametersDict'].get('Tag')
                    if imageTags and isinstance(imageTags, basestring):
                        imageTags = fromChar(imageTags)
                        self.imageDict[imageName]['ParametersDict'][
                            'Tag'] = imageTags
                    if ceTags:
                        if imageTags:
                            allTags = list(set(ceTags + imageTags))
                            self.imageDict[imageName]['ParametersDict'][
                                'Tag'] = allTags
                        else:
                            self.imageDict[imageName]['ParametersDict'][
                                'Tag'] = ceTags

                    maxRAM = self.imageDict[imageName]['ParametersDict'].get(
                        'MaxRAM')
                    maxRAM = ceMaxRAM if not maxRAM else maxRAM
                    if maxRAM:
                        self.imageDict[imageName]['ParametersDict'][
                            'MaxRAM'] = maxRAM

                    platform = ''
                    if "Platform" in self.imageDict[imageName][
                            'ParametersDict']:
                        platform = self.imageDict[imageName]['ParametersDict'][
                            'Platform']
                    elif "Platform" in ceDict:
                        platform = ceDict['Platform']
                    if platform and not platform in self.platforms:
                        self.platforms.append(platform)

                    if not "Platform" in self.imageDict[imageName][
                            'ParametersDict'] and platform:
                        result = Resources.getDIRACPlatform(platform)
                        if result['OK']:
                            self.imageDict[imageName]['ParametersDict'][
                                'Platform'] = result['Value'][0]

                    ceImageDict = dict(ceDict)
                    ceImageDict['CEName'] = ce
                    ceImageDict['VO'] = self.vo
                    ceImageDict['Image'] = image
                    ceImageDict['RunningPod'] = self.runningPod
                    ceImageDict['CSServers'] = gConfig.getValue(
                        "/DIRAC/Configuration/Servers", [])
                    ceImageDict.update(
                        self.imageDict[imageName]['ParametersDict'])
                    ceImageDict.update(opParameters)

                    # Generate the CE object for the image or pick the already existing one
                    # if the image definition did not change
                    imageHash = self.__generateImageHash(ceImageDict)
                    if imageName in self.imageCECache and self.imageCECache[
                            imageName]['Hash'] == imageHash:
                        imageCE = self.imageCECache[imageName]['CE']
                    else:
                        result = ceFactory.getCEObject(parameters=ceImageDict)
                        if not result['OK']:
                            return result
                        self.imageCECache.setdefault(imageName, {})
                        self.imageCECache[imageName]['Hash'] = imageHash
                        self.imageCECache[imageName]['CE'] = result['Value']
                        imageCE = self.imageCECache[imageName]['CE']

                    self.imageDict[imageName]['CE'] = imageCE
                    self.imageDict[imageName]['CEName'] = ce
                    self.imageDict[imageName]['CEType'] = ceDict['CEType']
                    self.imageDict[imageName]['Site'] = site
                    self.imageDict[imageName]['ImageName'] = image
                    self.imageDict[imageName]['Platform'] = platform
                    self.imageDict[imageName]['MaxInstances'] = ceDict[
                        'MaxInstances']
                    if not self.imageDict[imageName]['CE'].isValid():
                        self.log.error(
                            'Failed to instantiate CloudEndpoint for %s' %
                            imageName)
                        continue

                    if site not in self.sites:
                        self.sites.append(site)

        return S_OK()