From 85d05682d47a6a15421a18c6835461b3c44baf35 Mon Sep 17 00:00:00 2001 From: bybai Date: Mon, 8 Aug 2016 04:47:54 -0400 Subject: [PATCH] add list_netip rest api --- xCAT-server/lib/xcat/plugins/localrest.pm | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/localrest.pm b/xCAT-server/lib/xcat/plugins/localrest.pm index 8474acad3..6c3b2ccdb 100644 --- a/xCAT-server/lib/xcat/plugins/localrest.pm +++ b/xCAT-server/lib/xcat/plugins/localrest.pm @@ -161,6 +161,36 @@ sub list_adapter { return $result; } +#------------------------------------------------------- + +=head3 handler to list network adapter first ip + + Subroutine to handle rest request + GET /localres/netip/ + + Usage example: + This function is called from handle_rest_request, + do not call it directly. +=cut + +#------------------------------------------------------- +sub list_netip { + my @params = @_; + my ($rsp, $result, $iface, $cmd); + if (!@params) { + $rsp->{data}->[0] = "Argmument error."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + return 1; + } + $iface = shift @params; + $cmd = "ip addr show dev $iface |grep inet|head -1|awk '{print \$2}'|awk -F/ '{print \$1}'"; + + $result->[ 0 ] = xCAT::Utils->runcmd("$cmd", -1); + + return $result; +} + + #------------------------------------------------------- =head3 handler to download credential files