+ my $domname = shift;
+
+ my $cmd = "virt-tools-get-transport";
+ $cmd .= " -v" if $verbose;
+ # XXX quoting
+ $cmd .= " -c '$uri'" if $uri;
+ $cmd .= " '$domname'";
+
+ print STDERR "$cmd\n" if $verbose;
+
+ open PIPE, "$cmd |" or die "$cmd: $!";
+ my $line = <PIPE>;
+ die __"no response from virt-tools-get-transport\n" unless $line;
+ chomp $line;
+ close PIPE;
+
+ $line
+}
+
+=head2 SNMP QUERIES
+
+Standard SNMP queries are used between the host and guest.
+
+SNMP already supports many of the features we are trying to query
+(eg. the UCD SNMP MIB provides a way to query the process list of a
+machine in a form which is a de facto standard).
+
+To determine what precise queries are sent, run the tools in verbose
+mode or examine the source.
+
+=cut
+
+sub get_snmp_session
+{
+ my $key = shift;
+ my $transport = shift;
+
+ my ($hostname, $port, $domain);
+ if ($transport =~ /^udp:(.*):(.*)/) {
+ $domain = "udp";
+ $hostname = $1;
+ $port = $2;
+ } elsif ($transport =~ /^tcp:(.*):(.*)/) {
+ $domain = "tcp";
+ $hostname = $1;
+ $port = $2;
+ } else {
+ die __x("unknown transport type: {t}", t => $transport);
+ }
+
+ if ($verbose) {
+ print STDERR "creating Net::SNMP session to $domain:$hostname:$port with key $key\n"
+ }
+
+ my ($session, $error) = Net::SNMP->session (
+ -version => 3,
+ -username => "virttools",
+ -authpassword => $key,
+ -authprotocol => "sha",
+ -privpassword => $key,
+ -privprotocol => "aes",
+ -hostname => $hostname,
+ -port => $port,
+ -domain => $domain,
+ );
+ die __x("SNMP failure: {e}", e => $error) unless $session;
+
+ $session;