Commit a82e4ef2 authored by Leigh Stoller's avatar Leigh Stoller

Add routine to get node attributes (node_attributes table).

parent 29109c53
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005-2007 University of Utah and the Flux Group.
# Copyright (c) 2005-2008 University of Utah and the Flux Group.
# All rights reserved.
#
package Node;
......@@ -89,6 +89,7 @@ sub Lookup($$)
$self->{"DBROW"} = $query_result->fetchrow_hashref();
$self->{"RSRV"} = undef;
$self->{"TYPEINFO"} = undef;
$self->{"ATTRS"} = undef;
bless($self, $class);
# Add to cache.
......@@ -254,6 +255,7 @@ sub Refresh($)
# Force reload
$self->{"RSRV"} = undef;
$self->{"TYPEINFO"} = undef;
$self->{"ATTRS"} = undef;
return 0;
}
......@@ -706,6 +708,47 @@ sub vname($)
return $self->{"RSRV"}->{'vname'};
}
#
# Lookup a specific attribute in the node_attributes table,
#
sub NodeAttribute($$$;$)
{
my ($self, $attrkey, $pattrvalue, $pattrtype) = @_;
return -1
if (!ref($self));
my $node_id = $self->node_id();
if (!defined($self->{"ATTRS"})) {
my $query_result =
DBQueryWarn("select * from node_attributes ".
"where node_id='$node_id'");
return -1
if (!defined($query_result));
$self->{"ATTRS"} = {};
while (my $row = $query_result->fetchrow_hashref()) {
my $key = $row->{'attrkey'};
$self->{"ATTRS"}->{$key} = $row;
}
}
if (!exists($self->{"ATTRS"}->{$attrkey})) {
$$pattrvalue = undef;
return 0;
}
my $ref = $self->{"ATTRS"}->{$attrkey};
$$pattrvalue = $ref->{'attrvalue'};
$$pattrtype = $ref->{'attrtype'}
if (defined($pattrtype));
return 0;
}
#
# Return type info. We cache this in the instance since node_type stuff
# does not change much.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment