[torquedev] new node attribute: "note"
Marcus R. Epperson
mrepper at sandia.gov
Sun Mar 18 16:26:33 MDT 2007
Garrick Staples wrote:
> Hrm, wasn't 'pbsnodes -l -n' supposed to work as expected?
Not that I know of, but the attached patch should make it work (both "-l -n" and "-n -l"). (the way I would expect it to work, at least)
I would have included something like this with the original patch, but it wasn't clear to me how a user would query individual attributes in general. With pbsnodes you could either query all attributes (-a|-x) or a special case of the state attribute (-l).
-Marcus
-------------- next part --------------
--- pbsnodes.c-orig 2007-03-09 01:06:23.000000000 -0700
+++ pbsnodes.c 2007-03-18 15:13:32.000000000 -0600
@@ -124,6 +124,8 @@
#define DIAG 7
#define NOTE 8
+extern int optind, opterr, optopt;
+
int quiet = 0;
@@ -314,6 +316,26 @@ static int is_unknown(
+/* returns a pointer to the note if there is one, otherwise NULL */
+static char *has_note(
+
+ struct batch_status *pbs) /* I */
+
+ {
+ struct attrl *pat;
+
+ for (pat = pbs->attribs;pat != NULL;pat = pat->next)
+ {
+ if (strcmp(pat->name,ATTR_NODE_note) == 0)
+ {
+ return(pat->value);
+ }
+ }
+
+ return(NULL);
+ }
+
+
static int marknode(
@@ -395,7 +417,7 @@ int main(
int flag = ALLI;
char *note = NULL;
int note_flag = 0;
- int len;
+ char *node_spec = NULL;
/* get default server, may be changed by -s option */
@@ -404,7 +426,7 @@ int main(
if (def_server == NULL)
def_server = "";
- while ((i = getopt(argc,argv,"acdlopqrs:x-:n:")) != EOF)
+ while ((i = getopt(argc,argv,":acdlopqrs:x-:n:")) != EOF)
{
switch(i)
{
@@ -480,25 +502,37 @@ int main(
if ( flag == ALLI )
flag = NOTE;
+ /* don't set any notes if we're in LIST mode, instead
+ use optarg as the node name so we get expected behavior */
+ if ( flag == LIST )
+ {
+ node_spec = strdup(optarg);
+ break;
+ }
+
note = strdup(optarg);
if ( note != NULL )
{
- /* -n n is the same as -n "" -- it clears the note */
- if ( !strcmp(note,"n") )
- {
- *note = '\0';
- }
-
- len = strlen(note);
-
- if ( len > MAX_NOTE )
+ if ( strlen(note) > MAX_NOTE )
fprintf(stderr,"Warning: note exceeds length limit (%d) - server may reject it...\n",
MAX_NOTE);
if ( strchr(note,'\n') != NULL )
fprintf(stderr,"Warning: note contains a newline - server may reject it...\n");
+ /* -n n is the same as -n "" -- it clears the note */
+ if ( !strcmp(note,"n") )
+ *note = '\0';
+
+ /* -n -l is a special case for listing notes */
+ if ( !strcmp(note,"-l") )
+ {
+ flag = LIST;
+ free(note);
+ note = NULL;
+ }
+
}
break;
@@ -517,6 +551,27 @@ int main(
break;
+ case ':':
+ if (optopt == 'n')
+ {
+ if ( flag != LIST )
+ {
+ fprintf(stderr,"Error: -n with no argument must be preceded by -l\n");
+ exit(1);
+ }
+ else
+ {
+ note_flag = 1;
+ }
+ }
+ else
+ {
+ fprintf(stderr,"%s: option requires an argument -- %c\n", argv[0], optopt);
+ errflg = 1;
+ }
+
+ break;
+
case '?':
default:
@@ -563,8 +618,11 @@ int main(
{
/* allow node specification */
- if (argv[optind] != NULL)
- bstatus = pbs_statnode(con,argv[optind],NULL,NULL);
+ if (node_spec == NULL)
+ node_spec = argv[optind];
+
+ if (node_spec != NULL)
+ bstatus = pbs_statnode(con,node_spec,NULL,NULL);
else
bstatus = pbs_statnode(con,"",NULL,NULL);
}
@@ -607,7 +665,7 @@ int main(
} /* END if ((flag == ALLI) || (flag == DOWN) || (flag == LIST) || (flag == DIAG)) */
- if ( note_flag )
+ if ( note_flag && note )
{
/* set the note attrib string on specified nodes */
for (pa = argv + optind;*pa;pa++)
@@ -777,15 +835,34 @@ int main(
case LIST:
- /* list any node that is DOWN, OFFLINE, or UNKNOWN */
+ if (note_flag)
+ {
+ /* list any node that has a note */
- for (pbstat = bstatus; pbstat; pbstat = pbstat->next)
+ for (pbstat = bstatus; pbstat; pbstat = pbstat->next)
+ {
+ char *n = has_note(pbstat);
+
+ if (n)
+ {
+ printf("%-20.20s %s\n",
+ pbstat->name,
+ n);
+ }
+ }
+ }
+ else
{
- if (is_down(pbstat) || is_offline(pbstat) || is_unknown(pbstat))
+ /* list any node that is DOWN, OFFLINE, or UNKNOWN */
+
+ for (pbstat = bstatus; pbstat; pbstat = pbstat->next)
{
- printf("%-20.20s %s\n",
- pbstat->name,
- get_nstate(pbstat));
+ if (is_down(pbstat) || is_offline(pbstat) || is_unknown(pbstat))
+ {
+ printf("%-20.20s %s\n",
+ pbstat->name,
+ get_nstate(pbstat));
+ }
}
}
More information about the torquedev
mailing list