#!/usr/bin/perl

# USAGE: getObjects <object_list>

use strict;
use warnings;

use lib "/opt/sarch/common/lib"; # service API
use lib "/opt/sarch/om/bin/perl/OMIface";
use lib "/opt/sarch/imp/lib/perl"; # thrift api

use ObjectManagementService;
use NextCAM::Servicing::Client;
use Data::Dumper;

my $service_client = NextCAM::Servicing::Client->new("s_master", 10000);
my $om_client = ObjectManagementServiceClient->new($service_client->getProtocol("skm.om"));

sub getObjects {
    my @objref_list = ();
    push(@objref_list, new ObjectRef({objid => $_})) foreach (@_);
    
    my $res;
    my $objlist = {objectListFilter => \@objref_list};

    my $o = { includeMethods => 1,
	      includeProperties => 1
    		  #properties => ['health']
    };
    
    eval {
	$res = $om_client->getObjects(new Filter($objlist), new OutputOptions ($o));
    };
    if ($@)
    {
	die "FwIface::FwException: ". $@->{errorId}.": ".$@->{what}. "\n" if $@->UNIVERSAL::isa("OMIface::FwException");
        die "Bad: $@\n"; 
    }
    else
    {
      print("Action performed successfully: \n");
    }
    return $res;
}

die "Usage: getObjects <object_list>\n" unless @ARGV;
print Dumper(getObjects(@ARGV));
