Hi Johan, Reviewed and tested the patch. Ack from me.
BR, Hung Nguyen - DEK Technologies -------------------------------------------------------------------------------- From: Johan Martensson [email protected] Sent: Monday, November 09, 2015 1:30PM To: Hans 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: pyosaf: Update sample applications to use immom utils instead of direct bindings [#1451] python/samples/immadm | 58 ++++++++++++++++--------------------------------- python/samples/immlist | 47 +++++++++++++++------------------------- 2 files changed, 37 insertions(+), 68 deletions(-) Update the IMM Python sample applications to use immom utils instead of the direct bindings. 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, 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] + ptype = saImm.eSaImmValueTypeT.lookup[type] params.append( - SaImmAdminOperationParamsT_2(name, ptype, val)) - 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) + saImm.SaImmAdminOperationParamsT_2(name, ptype, val)) + + 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) ------------------------------------------------------------------------------ Presto, an open source distributed SQL query engine for big data, initially developed by Facebook, enables you to easily query your data on Hadoop in a more interactive manner. Teradata is also now providing full enterprise support for Presto. Download a free open source copy now. http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140 _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
