def initialize(self):

        self.am_disableMonitoring()
        # Init vars
        self.runningPod = gConfig.getValue('/LocalSite/RunningPod')
        self.log.info("Running pod name of the image is %s" % self.runningPod)
        self.vmID = gConfig.getValue('/LocalSite/VMID')

        self.__loadHistory = []
        self.vmMinWorkingLoad = None
        self.vmLoadAvgTimespan = None
        self.vmJobWrappersLocation = None
        self.haltPeriod = None
        self.haltBeforeMargin = None
        self.heartBeatPeriod = None
        self.am_setOption("MaxCycles", 0)
        self.am_setOption("PollingTime", 60)

        # Discover net address
        self.ipAddress = None
        netData = Network.discoverInterfaces()
        for iface in sorted(netData):
            # Warning! On different clouds interface name may be different(eth, ens, ...)
            if "eth" in iface or "ens" in iface:
                self.ipAddress = netData[iface]['ip']
                self.log.info("IP Address is %s" % self.ipAddress)
                break

        # getting the stop policy
        self.op = Operations.Operations()
        self.vmStopPolicy = self.op.getValue("Cloud/%s/VMStopPolicy",
                                             'elastic')
        self.log.info("vmStopPolicy is %s" % self.vmStopPolicy)

        # Declare instance running
        self.uniqueID = ''
        result = virtualMachineDB.getUniqueIDByName(self.vmID)
        if result['OK']:
            self.uniqueID = result['Value']
        result = self.__declareInstanceRunning()
        if not result['OK']:
            self.log.error("Could not declare instance running",
                           result['Message'])
            self.__haltInstance()
            return S_ERROR("Halting!")

        self.__instanceInfo = result['Value']

        # Get the cs config
        result = self.__getCSConfig()
        if not result['OK']:
            return result

        return S_OK()
示例#2
0
def getGenericVMId():
  fd = open( "/proc/stat" )
  lines = fd.readlines()
  fd.close()
  btime = False
  for line in lines:
    fields = List.fromChar( line, " " )
    if fields[0] == "btime":
      btime = fields[1]
      break
  if not btime:
    return S_ERROR( "Could not find btime in /proc/stat" )
  md5Hash = md5()
  md5Hash.update( btime )
  netData = Network.discoverInterfaces()
  for iface in sorted( netData ):
    if iface == "lo":
      continue
    md5Hash.update( netData[ iface ][ 'mac' ] )
  return S_OK( md5Hash.hexdigest() )
示例#3
0
 def getVMIP(self):
     netData = Network.discoverInterfaces()
     ip = netData['eth0']['ip']
     return ip