Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
a82e4ef2
Commit
a82e4ef2
authored
Feb 25, 2008
by
Leigh B. Stoller
Browse files
Add routine to get node attributes (node_attributes table).
parent
29109c53
Changes
1
Hide whitespace changes
Inline
Side-by-side
db/Node.pm.in
View file @
a82e4ef2
#
!/usr/bin/perl -wT
#
#
EMULAB
-
COPYRIGHT
#
Copyright
(
c
)
2005
-
200
7
University
of
Utah
and
the
Flux
Group
.
#
Copyright
(
c
)
2005
-
200
8
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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment