From 95051acb237ddbf6537660a5922d49e687fec6d5 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 26 Nov 2015 12:49:06 +0100 Subject: [PATCH] MT#16637 get_ngcp_type helper Detect NGCP installation using dpkg status Change-Id: I38e9e0d24eed3ecf12d9b95f65c13dacecccf8fa --- debian/control | 1 + lib/get_ngcp_type | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/get_ngcp_type diff --git a/debian/control b/debian/control index 426c34d6..cef44dcb 100644 --- a/debian/control +++ b/debian/control @@ -35,6 +35,7 @@ Depends: etckeeper, libdata-validate-ip-perl, libdbd-mysql-perl, libdbi-perl, + libdpkg-perl, libhash-merge-perl, libio-interface-perl, libipc-system-simple-perl, diff --git a/lib/get_ngcp_type b/lib/get_ngcp_type new file mode 100644 index 00000000..5671beca --- /dev/null +++ b/lib/get_ngcp_type @@ -0,0 +1,29 @@ +[% + # Returns the ngcp_type of the node calling this function. + # + # @return out one of ['spce', 'sppro', 'carrier'] +-%] +[% PERL -%] +use Dpkg; +use Dpkg::Index; +use Dpkg::Control::Types; + +my $status = Dpkg::Index->new(type => CTRL_INFO_PKG); +$status->load("$Dpkg::ADMINDIR/status"); + +my $pkg = $status->get_by_key('ngcp-ngcp-ce'); +if ($pkg->{Status} =~ m/\s+ok\s+installed$/) { + $stash->set(out => 'spce'); + return; +} +$pkg = $status->get_by_key('ngcp-ngcp-pro'); +if ($pkg->{Status} =~ m/\s+ok\s+installed$/) { + $stash->set(out => 'sppro'); + return; +} +$pkg = $status->get_by_key('ngcp-ngcp-carrier'); +if ($pkg->{Status} =~ m/\s+ok\s+installed$/) { + $stash->set(out => 'carrier'); + return; +} +[% END -%]