Пример #1
0
 def submitInstance( self, imageName, workDir ):
   """
   """
   self.log.info( 'Submitting', imageName )
   if imageName not in self.images:
     return DIRAC.S_ERROR( 'Unknown Image: %s' % imageName )
   retDict = virtualMachineDB.insertInstance( imageName, imageName )
   if not retDict['OK']:
     return retDict
   instanceID = retDict['Value']
   retDict = self._submitInstance( imageName, workDir )
   if not retDict['OK']:
     return retDict
   uniqueID = retDict[ 'Value' ]
   retDict = virtualMachineDB.setInstanceUniqueID( instanceID, uniqueID )
   if not retDict['OK']:
     return retDict
   retDict = virtualMachineDB.declareInstanceSubmitted( uniqueID )
   if not retDict['OK']:
     return retDict
   return DIRAC.S_OK( imageName )
Пример #2
0
  def submitInstance( self, imageName, endpoint, numVMsToSubmit, runningPodName ):
    """
    """
    # warning: instanceID is the DIRAC instance id, while uniqueID is unique for a particular endpoint
    self.log.info( '*** Preparing to submitting VM of image: ', imageName )
    self.log.info( '******* num of VMs to sumbit: ', numVMsToSubmit )
    self.log.info( '******* of running pod: ', runningPodName )
    self.log.info( '******* destination: ', endpoint )
    if runningPodName not in self.runningPods:
      return S_ERROR( 'Unknown Running Pod: %s' % runningPodName )

    for numVM in range(1,numVMsToSubmit+1):
      self.log.info( '********** Preparing to submitting VM number %s of %s VMs' % ( numVM, numVMsToSubmit ) )

      dictVMSubmitted = {}
      dictVMDBrecord = {}

      # FIRST, insert the instance into the DB !
      newInstance = virtualMachineDB.insertInstance( imageName, imageName, endpoint, runningPodName )
      if not newInstance[ 'OK' ]:
        return newInstance
      instanceID = newInstance[ 'Value' ]

      runningRequirementsDict = self.runningPods[runningPodName]['Requirements']
      cpuTime = runningRequirementsDict['CPUTime']
      if not cpuTime:
        return S_ERROR( 'Unknown CPUTime in Requirements of the RunningPod %s' % runningPodName )

      submitPool = runningRequirementsDict['SubmitPool']
      if not submitPool:
        return S_ERROR( 'Unknown submitPool in Requirements of the RunningPod %s' % runningPodName )

      dictVMSubmitted = self._submitInstance( imageName, endpoint, instanceID, runningRequirementsDict )
      if not dictVMSubmitted[ 'OK' ]:
        return dictVMSubmitted

      #########CloudStack2 adn CloudStack3 drivers have the bug of a single VM creation produces two VMs
      #########To deal with this CloudStack preaty feature we first startNewInstance inside 
      #########VMDIRECTOR._submitInstance, and second we declare two VMs 
      #########CloudStack check to preaty feature
      driver = gConfig.getValue( "/Resources/VirtualMachines/CloudEndpoints/%s/%s" % ( endpoint, "cloudDriver" ) )
      if driver == "CloudStack":
        virtualMachineDB.insertInstance( imageName, imageName, endpoint, runningPodName )

      if driver == "nova-1.1" or driver =="rocci-1.1":
        ( uniqueID, publicIP ) = dictVMSubmitted['Value']
        dictVMDBrecord = virtualMachineDB.setPublicIP( instanceID, publicIP )
        if not dictVMDBrecord['OK']:
          return dictVMDBrecord
      else: 
        uniqueID = dictVMSubmitted['Value']


      dictVMDBrecord = virtualMachineDB.setInstanceUniqueID( instanceID, uniqueID )
      if not dictVMDBrecord['OK']:
        return dictVMDBrecord

      #########CloudStack check to preaty feature
      if driver == "CloudStack":
        virtualMachineDB.setInstanceUniqueID( str( int( instanceID ) + 1 ), str( int( uniqueID ) - 1 ) )

      # check contextMethod and update status if need ssh contextualization:
      contextMethod = gConfig.getValue( "/Resources/VirtualMachines/Images/%s/%s" % ( imageName, "contextMethod" ) )
      if contextMethod == 'ssh':
        dictVMDBrecord = virtualMachineDB.declareInstanceWait_ssh_context( uniqueID )
        if not dictVMDBrecord['OK']:
          return dictVMDBrecord
      else:
        dictVMDBrecord = virtualMachineDB.declareInstanceSubmitted( uniqueID )
        if not dictVMDBrecord['OK']:
          return dictVMDBrecord

      #########CloudStack check to preaty feature
      if driver == "CloudStack":
        dictVMDBrecord = virtualMachineDB.declareInstanceSubmitted( str( int( uniqueID ) - 1 ) )

    return S_OK( imageName )