Ejemplo n.º 1
0
int MAcctToXML(

    mgcred_t *A, mxml_t **EP, int *SAList)

{
    int DAList[] = {mcaID, -1};

    int aindex;

    int *AList;

    char tmpString[MAX_MLINE];

    if ((A == NULL) || (EP == NULL)) return (FAILURE);

    if (SAList != NULL)
        AList = SAList;
    else
        AList = DAList;

    MXMLCreateE(EP, (char *)MXO[mxoAcct]);

    for (aindex = 0; AList[aindex] != -1; aindex++) {
        if ((MCredAToString((void *)A, mxoAcct, AList[aindex], tmpString, 0) ==
             FAILURE) ||
            (tmpString[0] == '\0')) {
            continue;
        }

        MXMLSetAttr(*EP, (char *)MCredAttr[AList[aindex]], tmpString,
                    mdfString);
    } /* END for (aindex) */

    return (SUCCESS);
} /* END MAcctToXML() */
Ejemplo n.º 2
0
int MXMLAppendAttr(

  mxml_t *E,      /* I root element */
  char   *AName,  /* I */
  char   *AVal,   /* I */
  char    Delim)  /* I */

  {
  int   ATok;
  int   len;

  char  VBuf[MMAX_LINE];

  if ((E == NULL) || (AName == NULL) || (AVal == NULL))
    {
    return(FAILURE);
    }

  ATok = -1;

  if (MXMLGetAttr(E,AName,&ATok,VBuf,sizeof(VBuf)) == SUCCESS)
    {
    char DString[2];

    char *tmpAVal;

    len = strlen(E->AVal[ATok]) + strlen(AVal) + 2;

    tmpAVal = realloc(
      E->AVal[ATok],
      len);

    if (tmpAVal == NULL)
      {
      return(FAILURE);
      }

    E->AVal[ATok] = tmpAVal;

    DString[0] = Delim;

    DString[1] = '\0';

    /* just allocated adequate space, should not be able to overflow */

    strcat(E->AVal[ATok], DString);

    strcat(E->AVal[ATok], AVal);
    }
  else if (MXMLSetAttr(E, AName, AVal, mdfString) == FAILURE)
    {
    return(FAILURE);
    }

  return(SUCCESS);
  }  /* END MXMLAppendAttr() */
Ejemplo n.º 3
0
int MRMAddLangToXML(
  
  mxml_t *E)  /* I/O (modified) */

  {
  char Languages[MMAX_LINE];
  char tmpName[MMAX_NAME];
  mrm_t *R;
  int rmindex;

  if (E == NULL)
    {
    return(FAILURE);
    }

  /* add languages that this virtual node supports */

  Languages[0] = '\0';

  for (rmindex = 0;rmindex < MSched.M[mxoRM];rmindex++)
    {
    R = &MRM[rmindex];

    if (R->Name[0] == '\0')
      break;

    if (MRMIsReal(R) == FALSE)
      continue;

    if (MRMFunc[R->Type].JobSubmit == NULL)
      continue;

    snprintf(tmpName,sizeof(tmpName),"%s%s%s,",
      MRMType[R->Type],
      (R->SubType != mrmstNONE) ? ":" : "",
      (R->SubType != mrmstNONE) ? MRMSubType[R->SubType] : "");

    /* make sure we don't already have this subtype */

    if (strstr(Languages,tmpName) != NULL)
      {
      continue;
      }

    MUStrCat(Languages,tmpName,sizeof(Languages));
    }  /* END for (rmindex) */

  if (MXMLSetAttr(E,"rmlanguages",(void **)&Languages,mdfString) == FAILURE)
    {
    return(FAILURE);
    }

  return(SUCCESS);
  }  /* END MRMAddLangToXML() */
Ejemplo n.º 4
0
int MVMCRToXML(

  mvm_req_create_t *VMCR, /* I */
  mxml_t          **VEP)  /* O */

  {
  mxml_t *VE = NULL;

  if (VMCR == NULL)
    return(FAILURE);

  if (*VEP == NULL)
    {
    if (MXMLCreateE(VEP,(char *)MXO[mxoxVMCR]) == FAILURE)
      {
      MDB(3,fCKPT) MLog("INFO:     failed to create xml for VMCR for '%s'\n",
        VMCR->VMID);

      return(FAILURE);
      }
    }

  VE = *VEP;

  if (VMCR->VMID[0] != '\0')
    {
    MXMLSetAttr(VE,"ID",(void *)VMCR->VMID,mdfString);
    }

  if (VMCR->Vars[0] != '\0')
    {
    MXMLSetAttr(VE,"VARS",(void *)VMCR->Vars,mdfString);
    }

  if (VMCR->Storage[0] != '\0')
    {
    MXMLSetAttr(VE,"STORAGE",(void *)VMCR->Storage,mdfString);
    }

  if (VMCR->Aliases[0] != '\0')
    {
    MXMLSetAttr(VE,"ALIAS",(void *)VMCR->Aliases,mdfString);
    }

  if (VMCR->Triggers[0] != '\0')
    {
    MXMLSetAttr(VE,"TRIGGER",(void *)VMCR->Triggers,mdfString);
    }

  if (VMCR->N != NULL)
    {
    MXMLSetAttr(VE,"HYPERVISOR",(void *)VMCR->N->Name,mdfString);
    }

  if (VMCR->JT != NULL)
    {
    MXMLSetAttr(VE,"TEMPLATE",(void *)VMCR->JT->Name,mdfString);
    }

  if (VMCR->OwnerJob != NULL)
    {
    MXMLSetAttr(VE,"OWNERJOB",(void *)VMCR->OwnerJob->Name,mdfString);
    }

  if (VMCR->OSIndex != 0)
    {
    /* Set to string so that OS loading order doesn't matter */

    MXMLSetAttr(VE,"IMAGE",(void *)MAList[meOpsys][VMCR->OSIndex],mdfString);
    }

  if (VMCR->TrackingJ[0] != '\0')
    MXMLSetAttr(VE,"TRACKINGJ",(void *)VMCR->TrackingJ,mdfString);

  MXMLSetAttr(VE,"WALLTIME",(void *)&VMCR->Walltime,mdfLong);
  MXMLSetAttr(VE,"SOVEREIGN",(void *)MBool[VMCR->IsSovereign],mdfString);
  MXMLSetAttr(VE,"ISONETIMEUSE",(void *)MBool[VMCR->IsOneTimeUse],mdfString);

  /* CRes info */

  MXMLSetAttr(VE,"DISK",(void *)&VMCR->CRes.Disk,mdfInt); 
  MXMLSetAttr(VE,"MEM",(void *)&VMCR->CRes.Mem,mdfInt); 
  MXMLSetAttr(VE,"PROCS",(void *)&VMCR->CRes.Procs,mdfInt);

  return(SUCCESS);
  } /* END MVMCRToXML() */
Ejemplo n.º 5
0
int MXMLFromString(

  mxml_t **EP,        /* O (populate or create) */
  char    *XMLString, /* I */
  char   **Tail,      /* O (optional) */
  char    *EMsg,      /* O (optional) */
  int      emsg_size) /* I */

  {
  mxml_t  *E;
  char    *ptr;

  char    *tail;

  int      index;

  mbool_t  ElementIsClosed = FALSE;

  mbool_t  DoAppend = FALSE;

  char tmpNLine[MMAX_LINE + 1];
  char tmpVLine[MMAX_XBUFFER + 1];

  if (EP != NULL)
    *EP = NULL;

  if (EMsg != NULL)
    EMsg[0] = '\0';

  if ((XMLString == NULL) || (EP == NULL))
    {
    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "invalid arguments");

    return(FAILURE);
    }

  if ((ptr = strchr(XMLString, '<')) == NULL)
    {
    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "no XML in string");

    return(FAILURE);
    }

  if (ptr[1] == '/')
    {
    /* located tail marker */

    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "premature termination marker");

    return(FAILURE);
    }

  /* NOTE:  should support append/overlay parameter (NYI) */

  /* ignore 'meta' elements */

  while ((ptr[1] == '?') || (ptr[1] == '!'))
    {
    ptr++;

    /* ignore 'meta' elements */

    if (*ptr == '?')
      {
      ptr++;

      if ((ptr = strstr(ptr, "?>")) == NULL)
        {
        /* cannot locate end of meta element */

        return(FAILURE);
        }

      if ((ptr = strchr(ptr, '<')) == NULL)
        {
        /* cannot locate next element */

        if (EMsg != NULL)
          snprintf(EMsg, emsg_size, "cannot locate post-meta XML");

        return(FAILURE);
        }
      }    /* END if (*ptr == '?') */

    /* ignore 'comment' element */

    if (!strncmp(ptr, "!--", 3))
      {
      ptr += 3;

      if ((ptr = strstr(ptr, "-->")) == NULL)
        {
        /* cannot locate end of comment element */

        if (EMsg != NULL)
          snprintf(EMsg, emsg_size, "cannot locate comment termination marker");

        return(FAILURE);
        }

      if ((ptr = strchr(ptr, '<')) == NULL)
        {
        /* cannot locate next element */

        if (EMsg != NULL)
          snprintf(EMsg, emsg_size, "cannot locate post-comment XML");

        return(FAILURE);
        }
      }    /* END if (!strncmp(ptr,"!--",3)) */
    }      /* END while ((ptr[1] == '?') || (ptr[1] == '!')) */

  /* remove whitespace */

  while (isspace(*ptr))
    ptr++;

  /* extract root element */

  if (*ptr != '<')
    {
    /* cannot located start of element */

    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "cannot locate start of root element");

    return(FAILURE);
    }

  ptr++;  /* ignore '<' */

  index = 0;

  while ((*ptr != ' ') && (*ptr != '>'))
    {
    if ((ptr[0] == '/') && (ptr[1] == '>'))
      {
      ElementIsClosed = TRUE;

      break;
      }

    tmpNLine[index++] = *(ptr++);

    if ((index >= MMAX_LINE) || (ptr[0] == '\0'))
      {
      if (EMsg != NULL)
        snprintf(EMsg, emsg_size, "element name is too long - %.10s", tmpNLine);

      return(FAILURE);
      }
    }

  tmpNLine[index] = '\0';

  if ((*EP == NULL) && (MXMLCreateE(EP, tmpNLine) == FAILURE))
    {
    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "cannot create XML element '%s'", tmpNLine);

    return(FAILURE);
    }

  E = *EP;

  if ((E->ACount > 0) || (E->CCount > 0))
    {
    DoAppend = TRUE;
    }

  if (ElementIsClosed == TRUE)
    {
    ptr += 2; /* skip '/>' */

    if (Tail != NULL)
      *Tail = ptr;

    return(SUCCESS);
    }

  while (*ptr == ' ')
    ptr++;

  while (*ptr != '>')
    {
    /* extract attributes */

    /* FORMAT:  <ATTR>="<VAL>" */

    index = 0;

    while ((*ptr != '=') && (*ptr != '\0'))
      {
      tmpNLine[index++] = *(ptr++);

      if (index >= MMAX_LINE)
        break;
      }

    tmpNLine[index] = '\0';

    if (*ptr != '\0')
      ptr++;  /* skip '=' */

    if (*ptr != '\0')
      ptr++;  /* skip '"' */

    if (*ptr == '\0')
      {
      if (EMsg != NULL)
        snprintf(EMsg, emsg_size, "string is corrupt - early termination");

      return(FAILURE);
      }

    index = 0;

    while ((*ptr != '"') ||
           ((ptr > XMLString) && (*(ptr - 1) == '\\')))
      {
      tmpVLine[index++] = *(ptr++);

      if ((index >= MMAX_XBUFFER) || (*ptr == '\0'))
        {
        MXMLDestroyE(EP);

        /* locate tail */

        if (Tail != NULL)
          *Tail = ptr + strlen(ptr);

        if (EMsg != NULL)
          {
          snprintf(EMsg, emsg_size, "attribute name is too long - %.10s", tmpVLine);
          }

        return(FAILURE);
        }
      }

    tmpVLine[index] = '\0';

    MXMLSetAttr(E,tmpNLine,(void *)tmpVLine,mdfString);

    ptr++; /* ignore '"' */

    while (*ptr == ' ')
      ptr++;

    if ((ptr[0] == '/') && (ptr[1] == '>'))
      {
      /* element terminator reached */

      ptr += 2; /* skip '/>' */

      if (Tail != NULL)
        *Tail = ptr;

      return(SUCCESS);
      }
    }  /* END while (*ptr != '>') */

  ptr++; /* ignore '>' */

  /* skip whitespace */

  while (isspace(*ptr))
    ptr++;

  /* extract value */

  if (*ptr != '<')
    {
    char *ptr2;

    index = 0;

    while (*ptr != '<')
      {
      tmpVLine[index++] = *(ptr++);

      if (index >= MMAX_XBUFFER)
        break;
      }

    tmpVLine[index] = '\0';

    E->Val = strdup(tmpVLine);

    if (E->Val == NULL)
      {
      if (EMsg != NULL)
        {
        snprintf(EMsg, emsg_size, "cannot alloc memory for value - %.10s", tmpVLine);
        }

      return(FAILURE);
      }

    /* restore '<' symbols */

    for (ptr2 = strchr(E->Val,(char)14);ptr2 != NULL;ptr2 = strchr(ptr2,(char)14))
      *ptr2 = '<';
    }  /* END if (*ptr != '<') */

  /* extract children */

  while (ptr[1] != '/')
    {
    mxml_t *C;

    C = NULL;

    if (DoAppend == TRUE)
      {
      char *ptr2;
      char  tmpCName[MMAX_NAME];

      int   index;

      /* FORMAT:  <NAME>... */

      /* locate name */

      ptr2 = ptr + 1;  /* ignore '<' */

      index = 0;

      while ((*ptr2 != ' ') && (*ptr2 != '>'))
        {
        if ((ptr2[0] == '/') && (ptr2[1] == '>'))
          {
          break;
          }

        tmpCName[index++] = *(ptr2++);

        if ((index >= MMAX_LINE) || (ptr2[0] == '\0'))
          {
          if (EMsg != NULL)
            {
            snprintf(EMsg, emsg_size, "element name is too long - %.10s", tmpCName);
            }
 
          return(FAILURE);
          }
        }

      tmpCName[index] = '\0';

      MXMLGetChild(E, tmpCName, NULL, &C);
      }

    if ((MXMLFromString(&C, ptr, &tail, EMsg, emsg_size) == FAILURE) ||
        (MXMLAddE(E, C) == FAILURE))
      {
      break;
      }

    ptr = tail;

    if ((ptr == NULL) || (ptr[0] == '\0'))
      {
      /* XML is corrupt */

      if (Tail != NULL)
        *Tail = ptr;

      if ((EMsg != NULL) && (EMsg[0] == '\0'))
        snprintf(EMsg, emsg_size, "cannot extract child");

      return(FAILURE);
      }
    }  /* END while (ptr[1] != '/') */

  /* ignore whitespace */

  while (isspace(*ptr))
    ptr++;

  /* process tail */

  if (*ptr == '/')
    {
    /* process '/>' */

    ptr++; /* ignore '/' */
    }
  else
    {
    ptr++; /* ignore '<' */

    ptr++; /* ignore '/' */

    ptr += strlen(E->Name);
    }

  ptr++; /* ignore '>' */

  if (Tail != NULL)
    *Tail = ptr;

  return(SUCCESS);
  }  /* END MXMLFromString() */
Ejemplo n.º 6
0
int MVCToXML(
  mvc_t  *VC,
  mxml_t *VE,
  enum MVCAttrEnum *SAList,
  mbool_t FullXML)

  {
  const enum MVCAttrEnum DAList[] = {
    mvcaACL,         /* ACL */
    mvcaCreateTime,  /* time VC was created */
    mvcaCreator,     /* creator */
    mvcaDescription, /* description */
    mvcaFlags,       /* flags (from MVCFlagEnum) */
    mvcaJobs,        /* names of jobs in VC */
    mvcaMessages,    /* VC messages */
    mvcaName,        /* VC name */
    mvcaNodes,       /* names of nodes in VC */
    mvcaOwner,       /* VC owner */
    mvcaParentVCs,   /* names of parent VCs */
    mvcaReqStartTime,/* requested start time for guaranteed start time */
    mvcaRsvs,        /* names of rsvs in VC */
    mvcaVariables,   /* VC vars */
    mvcaVCs,         /* sub-VCs */
    mvcaVMs,         /* names of VMs in VC */
    mvcaThrottlePolicies, /* throttling policies attached to VC via mvcctl */
    mvcaNONE };

  int aindex;

  enum MVCAttrEnum *AList;
  mbool_t PrintACL = FALSE;

  if ((VC == NULL) || (VE == NULL))
    {
    return(FAILURE);
    }

  if (SAList != NULL)
    AList = SAList;
  else
    AList = (enum MVCAttrEnum *)DAList;

  mstring_t tmpBuf(MMAX_LINE);

  for (aindex = 0;AList[aindex] != mvcaNONE;aindex++)
    {
    if (AList[aindex] == mvcaACL)
      {
      PrintACL = TRUE;

      continue;
      }

    if ((FullXML == TRUE) && 
         ((AList[aindex] == mvcaJobs) ||
          (AList[aindex] == mvcaNodes) ||
          (AList[aindex] == mvcaRsvs) ||
          (AList[aindex] == mvcaVMs) ||
          (AList[aindex] == mvcaVCs) ||
          (AList[aindex] == mvcaParentVCs)))
      continue;

    if (AList[aindex] == mvcaVariables)
      {
      MUAddVarsToXML(VE,&VC->Variables);

      continue;
      }
    else if ((AList[aindex] == mvcaMessages) &&
              (VC->MB != NULL))
      {
      /* Use the already existing MMB to XML functionality */

      mxml_t *ME = NULL;

      MXMLCreateE(&ME,(char *)MVCAttr[mvcaMessages]);

      MMBPrintMessages(VC->MB,mfmXML,TRUE,-1,(char *)ME,0);

      MXMLAddE(VE,ME);

      continue;
      }

    MVCAToMString(VC,AList[aindex],&tmpBuf);

    if (!tmpBuf.empty())
      {
      MXMLSetAttr(VE,(char *)MVCAttr[AList[aindex]],tmpBuf.c_str(),mdfString);
      }
    }  /* END for (aindex) */

  if (FullXML)
    {
    /* If you specify FullXML, you get all of the children.  Don't check AList */

    mln_t *tmpL;
    mxml_t *CE;

    if (VC->Jobs != NULL)
      {
      mjob_t *J;

      enum MJobAttrEnum JAList[] = {
        mjaJobID,
        mjaAccount,
        mjaArgs,
        mjaClass,
        mjaCmdFile,
        mjaDescription,
        mjaFlags,
        mjaGroup,
        mjaPAL,
        mjaQOS,
        mjaRCL,
        mjaReqAWDuration,
        mjaReqHostList,    /**< requested hosts */
        mjaReqNodes,
        mjaReqReservation,
        mjaRM,
        mjaStatPSDed,
        mjaSysPrio,
        mjaTemplateFlags,
        mjaTrigger,
        mjaUser,
        mjaVMUsagePolicy,
        mjaNONE };

      for (tmpL = VC->Jobs;tmpL != NULL;tmpL = tmpL->Next)
        {
        CE = NULL;
        J = (mjob_t *)tmpL->Ptr;

        MJobToXML(J,&CE,JAList,NULL,NULL,FALSE,FALSE);

        MXMLAddE(VE,CE);
        }
      }  /* END if (VC->Jobs != NULL) */

    if (VC->Nodes != NULL)
      {
      mnode_t *N;

      enum MNodeAttrEnum NAList[] = {
        mnaNodeID,
        mnaArch,
        mnaAvlGRes,
        mnaCfgGRes,
        mnaAvlTime,      
        mnaFeatures,
        mnaHopCount,
        mnaLoad,
        mnaNodeState,
        mnaOS,
        mnaOSList,
        mnaProcSpeed,
        mnaRADisk,
        mnaRAMem,
        mnaRAProc,
        mnaRASwap,
        mnaRCDisk,
        mnaRCMem,
        mnaRCProc,
        mnaRCSwap,
        mnaSpeed,
        mnaVMOSList,
        mnaNONE };

      for (tmpL = VC->Nodes;tmpL != NULL;tmpL = tmpL->Next)
        {
        CE = NULL;
        N = (mnode_t *)tmpL->Ptr;

        MXMLCreateE(&CE,(char *)MXO[mxoNode]);
        MNodeToXML(N,CE,NAList,0,FALSE,FALSE,NULL,NULL);

        MXMLAddE(VE,CE);
        }
      }  /* END if (VC->Nodes != NULL) */

    if (VC->Rsvs != NULL)
      {
      mrsv_t *R;

      for (tmpL = VC->Rsvs;tmpL != NULL;tmpL = tmpL->Next)
        {
        CE = NULL;
        R = (mrsv_t *)tmpL->Ptr;

        MRsvToXML(R,&CE,NULL,NULL,FALSE,mcmNONE);

        MXMLAddE(VE,CE);
        }
      }  /* END if (VC->Rsvs != NULL) */

    if (VC->VMs != NULL)
      {
      mvm_t *V;

      for (tmpL = VC->VMs;tmpL != NULL;tmpL = tmpL->Next)
        {
        CE = NULL;
        V = (mvm_t *)tmpL->Ptr;

        MXMLCreateE(&CE,(char *)MXO[mxoxVM]);
        MVMToXML(V,CE,NULL);

        MXMLAddE(VE,CE);
        }
      }  /* END if (VC->VMs != NULL) */

    if (VC->VCs != NULL)
      {
      mvc_t *V;

      for (tmpL = VC->VCs;tmpL != NULL;tmpL = tmpL->Next)
        {
        CE = NULL;
        V = (mvc_t *)tmpL->Ptr;

        MXMLCreateE(&CE,(char *)MXO[mxoxVC]);
        MVCToXML(V,CE,SAList,FullXML);

        MXMLAddE(VE,CE);
        }
      }  /* END if (VC->VCs != NULL) */
    }  /* END if (FullXML) */

  if ((PrintACL == TRUE) && (!MACLIsEmpty(VC->ACL)))
    {
    macl_t *tACL;
    mxml_t *AE = NULL;

    for (tACL = VC->ACL;tACL != NULL;tACL = tACL->Next)
      {
      AE = NULL;

      MACLToXML(tACL,&AE,NULL,FALSE);

      MXMLAddE(VE,AE);
      }
    }  /* END if ((PrintACL == TRUE) && (!MACLIsEmpty(VC->ACL))) */

  return(SUCCESS);
  }  /* END MVCToXML() */
Ejemplo n.º 7
0
Archivo: MMB.c Proyecto: dhh1128/cbase
char *MMBPrintMessages(

  mmb_t               *Head,        /* I (optional) */
  enum MFormatModeEnum DFormat,     /* I */
  mbool_t              ShowVerbose, /* I */
  int                  MinPrio,     /* I (only display messages of this priority or higher) */
  char                *Buf,         /* O (optional,char * or mxml_t *) */
  int                  BufSize)     /* I */

  {
  mmb_t *mptr;

  char *BPtr = NULL;
  int   BSpace;

  char *hptr = NULL;

  static char tmpMBuf[MMAX_BUFFER];

  char  tmpLine[MMAX_LINE << 2];
  char  tmpLine2[MMAX_LINE << 2];

  if (Buf != NULL)
    {
    BPtr = Buf;
    BSpace = BufSize;
    }
  else
    {
    BPtr = tmpMBuf;
    BSpace = sizeof(tmpMBuf);
    }

  hptr = BPtr;

  switch (DFormat)
    {
    case mfmXML:
    case mfmAVP:  /* KLUDGE - use AVP to create packed XML data */

      {
      mxml_t *DE;
      mxml_t *CE;
      mxml_t *UE;

      int     count = 0;

      DE = (mxml_t *)Buf;

      if (DE == NULL)
        break;

      if (Head == NULL)
        {
        /* header not required in XML */

        break;
        }  /* END if (Head == NULL) */

      if (DFormat == mfmAVP)
        {
        /* initialize temporary parent XML element */

        UE = NULL;
        }
    
      for (mptr = Head;mptr != NULL;mptr = mptr->Next)
        {
        if (mptr->Priority < MinPrio)
          continue;

        CE = NULL;

        MXMLCreateE(&CE,"message");

        MXMLSetAttr(CE,"index",(void *)&count,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaCTime],(void *)&mptr->CTime,mdfLong);

        if (mptr->Owner != NULL)
          MXMLSetAttr(CE,(char *)MMBAttr[mmbaOwner],(void *)mptr->Owner,mdfString);

        MXMLSetAttr(CE,(char *)MMBAttr[mmbaPriority],(void *)&mptr->Priority,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaCount],(void *)&mptr->Count,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaExpireTime],(void *)&mptr->ExpireTime,mdfLong);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaType],(void *)MMBType[mptr->Type],mdfString);

        if (mptr->Data != NULL)
          {
          if (strchr(mptr->Data,'\n') != NULL)
            {
            char tmpData[MMAX_BUFFER];

            MUStrCpy(tmpData,mptr->Data,sizeof(tmpData));

            MUStrReplaceChar(tmpData,'\n',' ',FALSE);

            MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)tmpData,mdfString);
            }
          else
            { 
            MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)mptr->Data,mdfString);
            }
          }

        if (mptr->Label != NULL)
          MXMLSetAttr(CE,(char *)MMBAttr[mmbaLabel],(void *)mptr->Label,mdfString);

        if (DFormat == mfmAVP)
          {
          /* create/update temporary XML */

          if (UE == NULL)
            MXMLCreateE(&UE,(char*) MSON[msonData]);

          MXMLAddE(UE,CE);
          }
        else
          {
          MXMLAddE(DE,CE);
          }

        count++;
        }  /* END for (mptr) */

      if ((DFormat == mfmAVP) && (UE != NULL))
        {
        /* NOTE:  Buf is mxml_t *, do not populate */

        MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf));

        hptr = BPtr;

        MXMLToString(UE,tmpLine,sizeof(tmpLine),NULL,TRUE);

        MXMLDestroyE(&UE);

        MUStringPack(tmpLine,tmpLine2,sizeof(tmpLine2));

        MUSNCat(&BPtr,&BSpace,tmpLine2);
        }
      }    /* END BLOCK */

      break;

    case mfmHuman:
    default:

      {
      int count = 0;

      char tmpBuf[MMAX_NAME];
      char label[MMAX_NAME];

      if (Buf != NULL)
        MUSNInit(&BPtr,&BSpace,Buf,BufSize);
      else
        MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf));

      hptr = BPtr;

      if (Head == NULL)
        {
        if (ShowVerbose == TRUE)
          {
          MUSNPrintF(&BPtr,&BSpace,"%-7s %10s %10s %8.8s %4.4s %3.3s %s\n",
            "Label",
            "CreateTime",
            "ExpireTime",
            "Owner",
            "Prio",
            "Num",
            "Message");
          }

        break;
        }  /* END if (Head == NULL) */

      for (mptr = Head;mptr != NULL;mptr = mptr->Next)
        {
        if (mptr->Priority < MinPrio)
          continue;

        if (mptr->Label != NULL)
          {
          strncpy(label,mptr->Label,sizeof(label));
          }
        else
          {
          sprintf(label,"%d",
            count);
          }

        count++;

        if (ShowVerbose == TRUE)
          {
          char TString[MMAX_LINE];
          /* display w/relative time */

          MULToTString(mptr->CTime - MSched.Time,TString);

          strcpy(tmpBuf,TString);

          MULToTString(mptr->ExpireTime - MSched.Time,TString);

          MUSNPrintF(&BPtr,&BSpace,"%-8.8s %10s %10s %8.8s %4d %3d %s\n",
            label,
            tmpBuf,
            TString,
            (mptr->Owner != NULL) ? mptr->Owner : "N/A",
            mptr->Priority,
            mptr->Count,
            (mptr->Data != NULL) ? mptr->Data : "-");
          }
        else
          {
          if (mptr->Source != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] (from %s) %s\n",
              label,
              mptr->Source,
              (mptr->Data != NULL) ? mptr->Data : "-");
            }
          else
            {
            MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] %s\n",
              label,
              (mptr->Data != NULL) ? mptr->Data : "-");
            }
          }
        }  /* END for (mptr) */
      }    /* END BLOCK (case mfmHuman) */

      break;
    }  /* END switch (DFormat) */

  return(hptr);
  }  /* END MMBPrintMessages() */
Ejemplo n.º 8
0
int MVMToPendingActionXML(

  mvm_t   *V,    /* I */
  mxml_t **VEP)  /* O (alloc) */

  {
  char tmpLine[MMAX_LINE];

  mxml_t  *PE;
  mxml_t  *CE;
  mulong JDuration = 0;
  mbool_t  GEventsSpecified = FALSE;

  enum MSystemJobTypeEnum PendingActionType = msjtNONE;
  char PendingActionTypeStr[MMAX_LINE];

  if (VEP == NULL)
    {
    return(FAILURE);
    }

  *VEP = NULL;

  if (V == NULL)
    {
    return(FAILURE);
    }

  PE = NULL;

  /* See if there are any GEvents */

  if (MGEventGetItemCount(&V->GEventsList) > 0)
    {
    GEventsSpecified = TRUE;
    }

  /* NOTE:  do not change pending actions strings w/o coordinating with MCM 
            team */

  if ((V->NextOS != 0) &&
      (V->NextOS != V->ActiveOS))
    {
    PendingActionType = msjtOSProvision;
    MUStrCpy(PendingActionTypeStr,(char *)MPendingActionType[mpatVMOSProvision],sizeof(PendingActionTypeStr));
    }
  else if (((V->PowerSelectState == mpowOn) || (V->PowerSelectState == mpowOff)) &&
            (V->PowerState != V->PowerSelectState) &&
            (MSched.Time - V->PowerMTime < MCONST_HOURLEN))
    {
    if (V->PowerSelectState == mpowOn)
      {
      PendingActionType = msjtPowerOn;
      MUStrCpy(PendingActionTypeStr,(char *)MPendingActionType[mpatVMPowerOn],sizeof(PendingActionTypeStr));
      }
    else if (V->PowerSelectState == mpowOff)
      {
      PendingActionType = msjtPowerOff;
      MUStrCpy(PendingActionTypeStr,(char *)MPendingActionType[mpatVMPowerOff],sizeof(PendingActionTypeStr));
      }
    }
  else
    {
    PendingActionType = msjtNONE;
    }

  if (PendingActionType == msjtNONE)
    {
    /* has no action on it to report as a pending action */

    return(FAILURE);
    }

    /* create common elements */

  if (MXMLCreateE(&PE,(char *)MXO[mxoxPendingAction]) == FAILURE)
    {
    return(FAILURE);
    }

  snprintf(tmpLine,sizeof(tmpLine),"%s-%ld",
    V->VMID,
    V->LastOSModRequestTime);

  MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaPendingActionID],(void *)tmpLine,mdfString);
  MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaSched],(void *)MSched.Name,mdfString);

  if (PendingActionType != msjtNONE)
    {
    MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaType],(void *)PendingActionTypeStr,mdfString);

    if (V->LastOSModRequestTime > 0)
      {
      /* Viewpoint only wants positive starttimes reported */

      MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaStartTime],(void *)&V->LastOSModRequestTime,mdfLong);
      }

    if (MSched.DefProvDuration > 0)
      JDuration = MSched.DefProvDuration;
    else
      JDuration = MDEF_PROVDURATION;

    MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaMaxDuration],(void *)&JDuration,mdfLong);

    if (V->N != NULL)
      MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaHostlist],(void *)V->N->Name,mdfString);

    MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaState],(void *)MJobState[mjsRunning],mdfString);

    if (V->LastSubState != NULL)
      {
      MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaSubState],(void *)V->LastSubState,mdfString);
      }

    /* now set action specific data */
  
    switch (PendingActionType)
      {
      case msjtOSProvision:
  
        /* handle re-provisioning of VM's */
  
        MXMLAddChild(PE,PendingActionTypeStr,NULL,&CE);
        MXMLSetAttr(CE,(char *)MPendingActionAttr[mpaaVMID],(void *)V->VMID,mdfString);
        MXMLSetAttr(CE,(char *)MPendingActionAttr[mpaaTargetOS],(void *)MAList[meOpsys][V->NextOS],mdfString);
  
        break;
  
      case msjtPowerOn:
      case msjtPowerOff:
  
        /* handle start/stop */
  
        MXMLAddChild(PE,PendingActionTypeStr,NULL,&CE);
        MXMLSetAttr(CE,(char *)MPendingActionAttr[mpaaVMID],(void *)V->VMID,mdfString);
  
        break;
  
      default:
  
        /* NO-OP */
  
        break;
      }  /* END switch (PendingActionType) */
    } /* END if (PendingActionType != msjtNONE) */

  if (GEventsSpecified != FALSE)
    {
    mxml_t *GEE;

    if (MVMFailuresToXML(V,NULL,&GEE) == SUCCESS)
      MXMLAddE(PE,GEE);
    } /* END if (GEventsSpecified != FALSE) */

  *VEP = PE;

  return(SUCCESS);
  }  /* END MVMToPendingActionXML() */
Ejemplo n.º 9
0
int MVMToXML(

  mvm_t            *V,      /* I */
  mxml_t           *VE,     /* I/O (modified,alloc) */
  enum MVMAttrEnum *SAList) /* I (optional,terminated w/mvmaLAST) */

  {
  char tmpString[MMAX_LINE];

  enum MVMAttrEnum *AList;  /**< VM attribute list */

  int aindex;

  mbitmap_t BM;

  const enum MVMAttrEnum DAList[] = {
    mvmaActiveOS,
    mvmaADisk,
    mvmaAlias,
    mvmaAMem,
    mvmaAProcs,
    mvmaCDisk,
    mvmaCMem,
    mvmaCProcs,
    mvmaCPULoad,
    mvmaContainerNode,
    mvmaDDisk,
    mvmaDMem,
    mvmaDProcs,
    mvmaDescription,
    mvmaEffectiveTTL,
    mvmaFlags,
    mvmaGMetric,
    mvmaID,
    mvmaJobID,
    mvmaLastMigrateTime,
    mvmaLastSubState,
    mvmaLastSubStateMTime,
    mvmaLastUpdateTime,
    mvmaMigrateCount,
    mvmaNetAddr,
    mvmaNextOS,
    mvmaOSList,
    mvmaPowerIsEnabled,
    mvmaPowerState,
    mvmaProvData,
    mvmaRackIndex,
    mvmaSlotIndex,
    mvmaSovereign,
    mvmaSpecifiedTTL,
    mvmaStartTime,
    mvmaState,
    mvmaSubState,
    mvmaStorageRsvNames,
    mvmaVariables,
    mvmaLAST };

  if ((V == NULL) || (VE == NULL))
    {
    return(FAILURE);
    }
 
  if (SAList != NULL)
    AList = SAList;
  else
    AList = (enum MVMAttrEnum *)DAList;

  bmset(&BM,mcmXML);

  for (aindex = 0;AList[aindex] != mvmaLAST;aindex++)
    {
    if ((MVMAToString(V,NULL,AList[aindex],tmpString,sizeof(tmpString),&BM) == FAILURE) ||
        (tmpString[0] == '\0'))
      {
      continue;
      }

    if (AList[aindex] == mvmaVariables)
      {
      MUAddVarsToXML(VE,&V->Variables);

      continue;
      }

    MXMLSetAttr(VE,(char *)MVMAttr[AList[aindex]],tmpString,mdfString);
    }  /* END for (aindex) */

  /* Set GEvents */

  MGEventListToXML(VE,&V->GEventsList);

  MVMStorageMountsToXML(VE,V);

  /* Triggers */

  if (V->T != NULL)
    {
    mtrig_t *T;

    int tindex;
    mxml_t *TE = NULL;

    for (tindex = 0;tindex < V->T->NumItems;tindex++)
      {
      T = (mtrig_t *)MUArrayListGetPtr(V->T,tindex);

      if (MTrigIsReal(T) == FALSE)
        continue;

      TE = NULL;

      MXMLCreateE(&TE,(char *)MXO[mxoTrig]);

      MTrigToXML(T,TE,NULL);

      MXMLAddE(VE,TE);
      }
    } /* END if (V->T != NULL) */

  if (V->Action != NULL)
    {
    mln_t  *tmpL = NULL;
    mjob_t *J;

    mxml_t *AE;

    /* report pending actions */

    for (tmpL = V->Action;tmpL != NULL;tmpL = tmpL->Next)
      {
      if ((MJobFind(tmpL->Name,&J,mjsmExtended) == FAILURE) ||
          (J->System == NULL))
        {
        continue;
        }

      AE = NULL;

      MXMLCreateE(&AE,"action");

      MXMLSetAttr(AE,"id",(void **)tmpL->Name,mdfString);

      MXMLSetAttr(AE,"type",(void **)MSysJobType[J->System->JobType],mdfString);

      if (MJOBISACTIVE(J) == TRUE)
        MXMLSetAttr(AE,"starttime",(void **)&J->StartTime,mdfLong);
      else if (J->Rsv != NULL)
        MXMLSetAttr(AE,"starttime",(void **)&J->Rsv->StartTime,mdfLong);

      MXMLSetAttr(AE,"duration",(void **)&J->SpecWCLimit[0],mdfLong);

      switch (J->System->JobType)
        {
        case msjtVMMigrate:

          if (!MNLIsEmpty(&J->Req[0]->NodeList))
            {
            MXMLSetAttr(AE,"destination",(void **)MNLGetNodeName(&J->Req[0]->NodeList,0,NULL),mdfString);
            }
          
          break;

        case msjtOSProvision:

          MXMLSetAttr(AE,"os",(void **)MAList[meOpsys][J->System->ICPVar1],mdfString);

          break;

#if 0
        case msjtVMCreate:

          if (J->System->Action != NULL) 
            {
            char *ptr;

            if ((ptr = strstr(J->System->Action,"create:")) != NULL)
              {
              /* report new VM configuration */

              ptr += strlen("create:");

              MXMLSetAttr(AE,"config",(void **)ptr,mdfString);
              }
            }

          break;
#endif

        default:

          /* NO-OP */

          break;
        }  /* END switch (J->System->JobType) */

      MXMLAddE(VE,AE);
      }  /* END for (tmpL = V->Action) */
    }    /* END if ((V->Action != NULL) && (V->Action[0] != NULL)) */

  /* VMTracking job */

  if (V->TrackingJ != NULL)
    {
    MXMLSetAttr(VE,"TrackingJob",(void **)V->TrackingJ->Name,mdfString);
    }

  return(SUCCESS);
  }  /* END MVMToXML() */
Ejemplo n.º 10
0
int MRMToXML(

  mrm_t             *R,      /* I */
  mxml_t           **RMEP,   /* O */
  enum MRMAttrEnum  *SAList) /* I (optional) */

  {
  enum MRMAttrEnum DAList[] = {
    mrmaAuthType,
    mrmaAuthAList,
    mrmaAuthCList,
    mrmaAuthGList,
    mrmaAuthQList,
    mrmaAuthUList,
    mrmaCheckpointSig,
    mrmaCheckpointTimeout,
    mrmaClusterQueryURL,
    mrmaConfigFile,
    mrmaCredCtlURL,
    mrmaCSAlgo,
    mrmaDataRM,
    mrmaDefDStageInTime,
    mrmaDefHighSpeedAdapter,
    mrmaDataRM,
    mrmaEPort,
    mrmaFlags,
    mrmaHost,
    mrmaJobCount,
    mrmaJobCounter,
    mrmaJobStartCount,
    mrmaLocalDiskFS,
    /* mrmaMessages, - msgs are currently not safe for XML (need to update like job msgs) */
    mrmaMinETime,
    mrmaName,
    mrmaNC,
    mrmaNMPort,
    mrmaNMServer,
    mrmaNodeFailureRsvProfile,
    mrmaNodeList,
    mrmaOMap,
    mrmaPartition,
    mrmaPort,
    mrmaProcs,
    mrmaProfile,
    mrmaResourceType,
    mrmaSocketProtocol,
    mrmaSQLData,
    mrmaState,
    mrmaStats,
    mrmaSubmitCmd,
    mrmaSuspendSig,
    mrmaTargetUsage,
    mrmaTimeout,
    mrmaType,
    mrmaUpdateTime,
    mrmaVersion,
    mrmaVMOwnerRM,
    mrmaWireProtocol,
    mrmaWorkloadQueryURL,
    mrmaNONE };

  int  aindex;
  int  pindex;

  enum MRMAttrEnum *AList;

  char tmpBuffer[MMAX_BUFFER];

  mxml_t *RME;

  if ((R == NULL) || (RMEP == NULL))
    {
    return(FAILURE);
    }

  if ((*RMEP == NULL) && (MXMLCreateE(RMEP,(char *)MXO[mxoRM]) == FAILURE))
    {
    return(FAILURE);
    }

  RME = *RMEP;

  if (SAList != NULL)
    AList = SAList;
  else
    AList = DAList;

  for (aindex = 0;AList[aindex] != mrmaNONE;aindex++)
    {
    if ((MRMAToString(R,AList[aindex],tmpBuffer,sizeof(tmpBuffer),0) == FAILURE) ||
        (tmpBuffer[0] == '\0'))
      {
      continue;
      }

    MXMLSetAttr(
      RME,
      (char *)MRMAttr[AList[aindex]],
      (void *)tmpBuffer,
      mdfString);
    }  /* END for (aindex) */

  /* checkpoint local queue information */

  if (bmisset(&R->IFlags,mrmifLocalQueue) &&
      (MSched.LoadAllJobCP == FALSE) &&
      (MUHTIsInitialized(&R->U.S3.JobListIndex) == SUCCESS))
    {
    char *tmpBuf;
    int   tmpBufLen;

    mhashiter_t JobListIter;
    char *JobName = NULL;

    mjob_t *J;

    mxml_t *QE = NULL;

    MUHTIterInit(&JobListIter);

    MXMLCreateE(&QE,(char *)MXO[mxoQueue]);

    tmpBuf = NULL;
    tmpBufLen = 0;

    while (MUHTIterate(&R->U.S3.JobListIndex,&JobName,NULL,NULL,&JobListIter) == SUCCESS)
      {
      if (MJobFind(JobName,&J,mjsmBasic) == SUCCESS)
        {
        if (MJobShouldCheckpoint(J,R) == FALSE)
          continue;
        }

      MUStrAppend(&tmpBuf,&tmpBufLen,JobName,',');  /* consider using MUSNXPrintF to decrease heap fragmentation */
      }

    MXMLSetAttr(QE,(char *)MXO[mxoJob],tmpBuf,mdfString);

    MXMLAddE(RME,QE);

    MUFree(&tmpBuf);
    }  /* END if ((bmisset(&R->IFlags,mrmifLocalQueue)) && ...) */

  /* create peer interface child */

  for (pindex = 0;pindex < MMAX_RMSUBTYPE;pindex++)
    {
    mxml_t *PE;

    if (bmisset(&R->RTypes,mrmrtLicense) ||
        bmisset(&R->RTypes,mrmrtNetwork) ||
        bmisset(&R->RTypes,mrmrtProvisioning) ||
        bmisset(&R->RTypes,mrmrtStorage))
      {
      /* non-compute RM's may not have interface type specified since they
         may route directly through file or CLI interfaces */

      if (R->P[pindex].RespTotalCount[0] <= 0)
        continue;
      }
    else
      { 
      if (R->P[pindex].Type == mpstNONE)
        continue;
      }

    PE = NULL;

    MXMLCreateE(&PE,"psi");

    MPSIToXML(&R->P[pindex],PE);

    MXMLAddE(RME,PE);
    }  /* END for (pindex) */

  if (bmisset(&R->RTypes,mrmrtLicense))
    {
    int rindex;
    int IC;

    double tmpD;

    double totalCfg;
    double totalDed;

    mxml_t *GRE;

    IC = MAX(1,R->U.Nat.ICount);

    totalCfg = 0.0;
    totalDed = 0.0;

    for (rindex = 0;rindex < MSched.M[mxoxGRes];rindex++)
      {
      if ((R->U.Nat.ResName == NULL) ||
          (R->U.Nat.ResName[rindex][0] == '\0'))
        break;

      /* Only include license information that applies to this resource manager */

      if (MSNLGetIndexCount(&R->U.Nat.ResConfigCount,rindex) == 0)
        continue;

      GRE = NULL;

      MXMLCreateE(&GRE,"license");

      MXMLSetAttr(GRE,"name",(void *)R->U.Nat.ResName[rindex],mdfString);

      MXMLSetAttr(GRE,"ic",(void *)&IC,mdfInt);

      tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResAvailCount,rindex)) / IC;

      MXMLSetAttr(GRE,"averageAvail",(void *)&tmpD,mdfDouble);

      tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResConfigCount,rindex)) / IC;

      MXMLSetAttr(GRE,"averageConfig",(void *)&tmpD,mdfDouble);

      /* NOTE: percentages below are over all iterations since Moab started */

      tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResFreeICount,rindex)) / IC;

      MXMLSetAttr(GRE,"percentIdle",(void *)&tmpD,mdfDouble);

      tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResAvailICount,rindex) - MSNLGetIndexCount(&R->U.Nat.ResFreeICount,rindex)) / IC;

      MXMLSetAttr(GRE,"percentActive",(void *)&tmpD,mdfDouble);

      tmpD = (double)(R->U.Nat.ICount - MSNLGetIndexCount(&R->U.Nat.ResAvailICount,rindex)) / IC;

      MXMLSetAttr(GRE,"percentBusy",(void *)&tmpD,mdfDouble);

      if (R->U.Nat.N != NULL)
        {
        mnode_t *GN;

        GN = (mnode_t *)R->U.Nat.N;
          
        tmpD = (double)(MSNLGetIndexCount(&GN->CRes.GenericRes,rindex));

        MXMLSetAttr(GRE,"currentConfig",(void *)&tmpD,mdfDouble);

        tmpD = (double)(MSNLGetIndexCount(&GN->ARes.GenericRes,rindex));

        totalCfg += tmpD;

        MXMLSetAttr(GRE,"currentAvail",(void *)&tmpD,mdfDouble);

        tmpD = (double)(MSNLGetIndexCount(&GN->DRes.GenericRes,rindex));

        MXMLSetAttr(GRE,"currentDedicated",(void *)&tmpD,mdfDouble);

        tmpD = (double)(MSNLGetIndexCount(&GN->DRes.GenericRes,rindex));

        totalDed += tmpD;
        }

      MXMLAddE(RME,GRE);
      }  /* END for (rindex) */

    tmpD = totalDed / MAX(1.0,totalCfg);

    MXMLSetAttr(RME,"LOAD",(void *)&tmpD,mdfDouble);
    }    /* END if (bmisset(&R->RTypes,mrmrtLicense)) */

  if (bmisset(&R->RTypes,mrmrtNetwork))
    {
    if (!MNLIsEmpty(&R->NL))
      {
      double   tmpD;
      mnode_t *N;
      int      gindex;

      MNLGetNodeAtIndex(&R->NL,0,&N);

      gindex = MUMAGetIndex(
        meGRes,
        "bandwidth",
        mVerify);

      if (gindex > 0)
        {
        tmpD = MSNLGetIndexCount(&N->ARes.GenericRes,gindex) / MAX(1.0,MSNLGetIndexCount(&N->CRes.GenericRes,gindex));

        tmpD = 1.0 - tmpD;

        MXMLSetAttr(RME,"LOAD",(void *)&tmpD,mdfDouble);
        } 
      }
    }    /* END if (bmisset(&R->RTypes,mrmrtNetwork)) */

  if (bmisset(&R->RTypes,mrmrtProvisioning))
    {
    /* report ratio of I/O (ie, install) capacity currently in use */

    /* NYI */
    }

  if (bmisset(&R->RTypes,mrmrtStorage))
    {
    if (!MNLIsEmpty(&R->NL))
      {
      double   tmpD;
      mnode_t *N;

      MNLGetNodeAtIndex(&R->NL,0,&N);

      tmpD = N->ARes.Disk / MAX(1.0,N->CRes.Disk);

      tmpD = 1.0 - tmpD;

      MXMLSetAttr(RME,"LOAD",(void *)&tmpD,mdfDouble);
      }  /* END if (bmisset(&R->RTypes,mrmrtStorage)) */
    }

  return(SUCCESS);
  }  /* END MRMToXML() */
Ejemplo n.º 11
0
int __MSysTestXML(
 
  char *XMLString)  /* I */

  {
  char *tail;

  FILE *fp;

  mxml_t *E = NULL;

  char EMsg[MMAX_LINE];

  char buffer[MMAX_BUFFER << 3];

  if ((XMLString != NULL) && (XMLString[0] != '\0'))
    {
    if (XMLString[0] == '/')
      {
      int rc;

      fp = fopen(XMLString,"r");

      rc = fread((void *)buffer,sizeof(buffer),1,fp);

      XMLString = buffer;

      fprintf(stdout,"read in %d\n",rc);
      }

    fprintf(stdout,"XMLString: '%s'\n\n",
      XMLString);
  
    if (MXMLFromString(&E,XMLString,&tail,EMsg) == FAILURE)
      {
      fprintf(stderr,"ERROR: '%s'\n",
        EMsg);
  
      exit(1);
      }
  
    if (tail != NULL)
      {
      fprintf(stdout,"tail: '%s'\n\n",
        XMLString);
      }

    exit(0);
    }

  MXMLCreateE(&E,"Data");
  MXMLSetAttr(E,"Value",(void *)"this >> that",mdfString);

  MXMLToString(E,EMsg,sizeof(EMsg),NULL,TRUE);

  fprintf(stdout,"XML = '%s'\n\n",
    EMsg);

  MXMLDestroyE(&E);

  MXMLFromString(&E,EMsg,NULL,NULL);

  fprintf(stdout,"After MXMLFromString: <Data %s=\"%s\"></Data>\n\n",
    E->AName[0],
    E->AVal[0]);

  EMsg[0] = '\0';

  MXMLToString(E,EMsg,sizeof(EMsg),NULL,TRUE);

  fprintf(stdout,"XML = '%s'\n\n",
    EMsg);

  exit(1);

  /* NOTREACHED */

  return(SUCCESS);
  }  /* END __MSysTestXML() */
Ejemplo n.º 12
0
int MVMTransitionToXML(

  mtransvm_t       *V,
  mxml_t          **VEP,
  enum MVMAttrEnum *SAList)

  {
  char tmpString[MMAX_LINE];

  mxml_t *VE;     /* element for the VM */

  enum MVMAttrEnum *AList;  /**< VM attribute list */

  int aindex;

  const enum MVMAttrEnum DAList[] = {
    mvmaActiveOS,
    mvmaADisk,
    mvmaAlias,
    mvmaAMem,
    mvmaAProcs,
    mvmaCDisk,
    mvmaCMem,
    mvmaCProcs,
    mvmaCPULoad,
    mvmaContainerNode,
    mvmaDDisk,
    mvmaDMem,
    mvmaDProcs,
    mvmaDescription,
    mvmaEffectiveTTL,
    mvmaFlags,
    mvmaGMetric,
    mvmaID,
    mvmaJobID,
    mvmaLastMigrateTime,
    mvmaLastSubState,
    mvmaLastSubStateMTime,
    mvmaLastUpdateTime,
    mvmaMigrateCount,
    mvmaNetAddr,
    mvmaNextOS,
    mvmaOSList,
    mvmaPowerIsEnabled,
    mvmaPowerState,
    mvmaProvData,
    mvmaRackIndex,
    mvmaSlotIndex,
    mvmaSovereign,
    mvmaSpecifiedTTL,
    mvmaStartTime,
    mvmaState,
    mvmaSubState,
    mvmaStorageRsvNames,
    mvmaTrackingJob,
    mvmaVariables,
    mvmaLAST };

  *VEP = NULL;

  if ((V == NULL) || (VEP == NULL))
    {
    return(FAILURE);
    }

  if (MXMLCreateE(VEP,(char *)MXO[mxoxVM]) == FAILURE)
    {
    return(FAILURE);
    }

  VE = *VEP;
 
  if (SAList != NULL)
    AList = SAList;
  else
    AList = (enum MVMAttrEnum *)DAList;

  for (aindex = 0;AList[aindex] != mvmaLAST;aindex++)
    {
    if (AList[aindex] == mvmaVariables)
      {
      mxml_t *VarE = NULL;

      MXMLDupE(V->Variables,&VarE);

      MXMLAddE(VE,VarE);

      continue;
      }

    if ((MVMTransitionAToString(V,AList[aindex],tmpString,sizeof(tmpString)) == FAILURE) ||
        (tmpString[0] == '\0'))
      {
      continue;
      }

    MXMLSetAttr(VE,(char *)MVMAttr[AList[aindex]],tmpString,mdfString);
    }  /* END for (aindex) */

  return(SUCCESS);
  }  /* END MVMTransitionToXML() */