2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 09:36:41 +00:00

Merge pull request #3678 from immarvin/ondiscovery

notify the nodes which are sending findme requestd about the status of the processing
This commit is contained in:
zet809 2017-08-15 16:31:26 +08:00 committed by GitHub
commit c548d0bd77
4 changed files with 55 additions and 27 deletions

View File

@ -4903,4 +4903,39 @@ sub acquire_lock_imageop {
return (0,$lock);
}
#--------------------------------------------------------------------------------
=head3 send_tcp_msg
establish a tcp socket to the specified IP address and port, then send the specifid message via the socket
Arguments:
$destip : the destination IP address
$destport: the destination TCP port
$msg : the message to send
Returns:
0 on success, 1 on fail
=cut
#--------------------------------------------------------------------------------
sub send_tcp_msg {
my $self=shift;
my $destip=shift;
my $destport=shift;
my $msg=shift;
my $sock = new IO::Socket::INET(
PeerAddr => $destip,
PeerPort => $destport,
Timeout => '1',
Proto => 'tcp'
);
if ($sock) {
print $sock $msg;
close($sock);
return 0;
}else{
return 1;
}
}
1;

View File

@ -28,21 +28,6 @@ sub process_request {
}
my $client_ip = $req->{'_xcat_clientip'};
#now, notify the node that its findme request is under processing
xCAT::MsgUtils->message("S", "Notify $client_ip that its findme request is processing\n");
my $sock = new IO::Socket::INET(
PeerAddr => $client_ip,
PeerPort => '3001',
Timeout => '1',
Proto => 'tcp'
);
if ($sock) {
print $sock "processing";
close($sock);
}else{
xCAT::MsgUtils->message("S", "Failed to notify $client_ip that its findme request is processing.");
}
my $arptable;
if (-x "/usr/sbin/arp") {
$arptable = `/usr/sbin/arp -n`;

View File

@ -7,6 +7,8 @@ BEGIN
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use lib "$::XCATROOT/lib/perl";
use xCAT::Utils;
sub handled_commands {
return {
@ -28,18 +30,11 @@ sub process_request {
#now, notify the node that its findme request has been processed
my $client_ip = $req->{'_xcat_clientip'};
xCAT::MsgUtils->message("S","Notify $client_ip that its findme request has been processed");
my $sock = new IO::Socket::INET(
PeerAddr => $client_ip,
PeerPort => '3001',
Timeout => '1',
Proto => 'tcp'
);
if ($sock) {
print $sock "processed";
close($sock);
}else{
xCAT::MsgUtils->message("S", "Failed to notify $client_ip that its findme request has been processed");
xCAT::MsgUtils->message("S","xcat.discovery.zzzdiscovery: Notify $client_ip that its findme request has been processed");
#notify the client that its request is been processing
my $ret=xCAT::Utils->send_tcp_msg($client_ip,3001,"processed");
if($ret){
xCAT::MsgUtils->message("S", "xcat.discovery.zzzdiscovery: Failed to notify $client_ip that its findme request has been processed");
}
}else{
xCAT::MsgUtils->message("S", "xcat.discovery.zzzdiscovery: ($req->{_xcat_clientmac}->[0]) Successfully discovered the node using $req->{discoverymethod}->[0] discovery method.");

View File

@ -801,10 +801,23 @@ sub do_udp_service { # This function opens up a UDP port
foreach my $pkey (keys %packets) {
my $saddr = $packets{$pkey}->[0];
$data = $packets{$pkey}->[1];
my ($err, $srcip, $servicename) = Socket::getnameinfo($saddr,Socket::NI_NUMERICHOST,Socket::NIx_NOSERV);
if ($data =~ /^\037\213/) { # per rfc 1952, these two bytes are gzip, and they are invalid for
store_fd({ data => $data, sockaddr => $saddr }, $discoctl); # for now, punt the gunzip to the worker process
#notify the client that its request is been processing
my $ret=xCAT::Utils->send_tcp_msg($srcip,3001,"processing");
if($ret){
xCAT::MsgUtils->message("S", "INFO xcatd: fail to notify $srcip that its 'findme' request is been processing");
}
} elsif ($data =~ /^<xcat/) { # xml format
store_fd({ data => $data, sockaddr => $saddr }, $discoctl);
#notify the client that its request is been processing
my $ret=xCAT::Utils->send_tcp_msg($srcip,3001,"processing");
if($ret){
xCAT::MsgUtils->message("S", "INFO xcatd: fail to notify $srcip that its 'findme' request is been processing");
}
} else { # for *now*, we'll do a tiny YAML subset
if ($data =~ /^resourcerequest: xcatd$/) {
$socket->send("ackresourcerequest\n", 0, $packets{$pkey}->[0]);