Thanks! I will fix and send an updated version. / Johan
On 11/04/2015 08:29 AM, Hung Nguyen wrote: > Hi Johan, > > Reviewed and tested the patch. > Ack from me with some minor comments. Please see them inline. > > BR, > Hung Nguyen - DEK Technologies > > -------------------------------------------------------------------------------- > From: Johan [email protected] > Sent: Wednesday, November 04, 2015 2:18PM > To: Ans Nordeback, Mathivanan Naickan, Hung Nguyen, Srikanth Revanuru > > [email protected],[email protected],[email protected],[email protected] > Cc: Opensaf-devel > [email protected] > Subject: [PATCH 1 of 1] pyosaf: Update sample applications to use immom utils > instead of direct bindings [#1451] > > > python/pyosaf/utils/immom/__init__.py | 4 ++ > python/samples/immadm | 54 > +++++++++++----------------------- > python/samples/immlist | 47 +++++++++++------------------ > 3 files changed, 39 insertions(+), 66 deletions(-) > > > Update the python sample applications to use immom utils instead of the > direct IMM OM bindings. > > Also fix immom.get() because the updates uncovered a fault when it's used to > request only specific attributes. If the attributes requested don't include > SaImmAttrClassName the function will fail since it's used to determine the > class of the object. > > diff --git a/python/pyosaf/utils/immom/__init__.py > b/python/pyosaf/utils/immom/__init__.py > --- a/python/pyosaf/utils/immom/__init__.py > +++ b/python/pyosaf/utils/immom/__init__.py > @@ -83,6 +83,10 @@ def _initialize(): > def get(object_name, attr_name_list=None): > ''' obtain values of some attributes of the specified object ''' > > + # Always request the SaImmAttrClassName attribute > + if attr_name_list and not 'SaImmAttrClassName' in attr_name_list: > + attr_name_list.append('SaImmAttrClassName') > + > attrib_names = [SaImmAttrNameT(a) for a in attr_name_list]\ > if attr_name_list else None > > diff --git a/python/samples/immadm b/python/samples/immadm > --- a/python/samples/immadm > +++ b/python/samples/immadm > @@ -18,10 +18,10 @@ > > from optparse import OptionParser > from pyosaf import saImm > -from pyosaf.saImmOm import * > +from pyosaf.utils import immom > *[Hung] Missing SafException* > > > from socket import gethostname > from os import getpid > -from immbase import * > +from pyosaf.saAis import eSaAisErrorT, SaAisErrorT > import json > import sys > > @@ -46,66 +46,46 @@ def parseArgs(cmd=sys.argv[1:]): > help='turn off pretty printing.', > action='store_true', default=False) > (options, args) = parser.parse_args(cmd) > + > if len(args) < 2: > parser.print_help() > sys.exit() > + > return options, args > > def immadm(options, args): > + > if len(args) < 2: > raise SafException(eSaAisErrorT.SA_AIS_ERR_INIT) > - opId = SaImmAdminOperationIdT(int(args[0])) > - dn = SaNameT(args[1]) > - retVal = SaAisErrorT(eSaAisErrorT.SA_AIS_ERR_NOT_EXIST) > + > + op_id = int(args[0]) > + dn = args[1] > + retVal = SaAisErrorT(eSaAisErrorT.SA_AIS_OK) > > try: > - immHandle = SaImmHandleT() > - rc = saImmOmInitialize(immHandle, None, IMM_VERSION) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > - > - ownerName = SaImmAdminOwnerNameT(options.adminOwner) > - ownerHandle = SaImmAdminOwnerHandleT() > - rc = saImmOmAdminOwnerInitialize(immHandle, > - ownerName, eSaBoolT.SA_TRUE, ownerHandle) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > - > - rc = saImmOmAdminOwnerSet(ownerHandle, > - [dn], saImm.eSaImmScopeT.SA_IMM_ONE) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > - > params = [] > for p in options.params: > (name, type, val) = p.split(':', 2) > ptype = eSaImmValueTypeT.lookup[type] > *[Hung] Missing saImm module. Should be saImm.eSaImmValueTypeT* > > params.append( > SaImmAdminOperationParamsT_2(name, ptype, val)) > **[Hung] Missing saImm module. Should be > *saImm.SaImmAdminOperationParamsT_2* > > - contId = SaImmContinuationIdT() > - rc = saImmOmAdminOperationInvoke_2(ownerHandle, > - dn, contId, opId, params, retVal, > - saAis.SA_TIME_ONE_SECOND*5) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > + > + immom.admin_op_invoke(dn, op_id, params=params) > + > except SafException, e: > if e.value != eSaAisErrorT.SA_AIS_ERR_NOT_EXIST: > raise e > - finally: > - saImmOmAdminOwnerRelease(ownerHandle, > - [dn], saImm.eSaImmScopeT.SA_IMM_ONE) > - saImmOmAdminOwnerFinalize(ownerHandle) > - saImmOmFinalize(immHandle) > > - return {'opId': opId.value, > - 'dname': args[1], > - 'owner': options.adminOwner, > + return {'opId': op_id, > + 'dname': args[1], > + 'owner': options.adminOwner, > 'params': options.params, > - 'rc': eSaAisErrorT.whatis(retVal.value)} > + 'rc': eSaAisErrorT.whatis(retVal.value)} > > if __name__ == '__main__': > (options, args) = parseArgs() > result = immadm(options, args) > logger = SafLogger(result['owner']) > logger.log('ADMIN_CMD: OP_ID %(opId)s %(dname)s: %(rc)s' % result) > + > print json.dumps(result, indent=None if options.ugly else 4) > diff --git a/python/samples/immlist b/python/samples/immlist > --- a/python/samples/immlist > +++ b/python/samples/immlist > @@ -16,8 +16,9 @@ > # > ############################################################################ > > +from pyosaf import saImm > +from pyosaf.utils import immom > from optparse import OptionParser > -from immbase import * > import json > import sys > > @@ -42,36 +43,24 @@ class ListOptions(object): > self.ugly = False > > def immlist(options, args): > - try: > - immHandle = SaImmHandleT() > - rc = saImmOmInitialize(immHandle, None, IMM_VERSION) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > + objects = {} > > - accessorHandle = SaImmAccessorHandleT() > - rc = saImmOmAccessorInitialize(immHandle, accessorHandle) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > + for dn in args: > + obj = immom.get(dn, attr_name_list=options.attr) > > - objects = {} > - attribNames = [SaImmAttrNameT(a) for a in options.attr]\ > - if options.attr else None > - attribs = pointer(pointer(SaImmAttrValuesT_2())) > - for dn in args: > - rc = saImmOmAccessorGet_2(accessorHandle, > - SaNameT(dn), attribNames, attribs) > - if rc == eSaAisErrorT.SA_AIS_ERR_NOT_EXIST: > - continue; > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > - objects[dn] = SafObject(dn, attribs, options.numeric) > - finally: > - saImmOmAccessorFinalize(accessorHandle) > - saImmOmFinalize(immHandle) > - return objects > + if obj: > + attributes = {} > + for name, value_pair in obj.attrs.iteritems(): > + type_str = > saImm.eSaImmValueTypeT.whatis(value_pair[0]) > + value = value_pair[1] > + > + attributes[name] = [type_str, value] > + > + objects[dn] = attributes > + > + return objects > > if __name__ == '__main__': > (options, args) = parseArgs() > - print json.dumps(immlist(options, args), > - default=SafObject.serialize, > - indent=None if options.ugly else 4) > + print json.dumps(immlist(options, args), > + indent=None if options.ugly else 4) > ------------------------------------------------------------------------------ _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
