Hi Hung, Thanks, I had missed that it's possible to pass several parameters with the same name. I'll include the changes below in the next changeset to fix this.
/ Johan diff --git a/python/pyosaf/utils/immoi/implementer.py b/python/pyosaf/utils/immoi/implementer.py --- a/python/pyosaf/utils/immoi/implementer.py +++ b/python/pyosaf/utils/immoi/implementer.py @@ -159,6 +159,18 @@ def _collect_full_transaction(ccb_id): return out + +class AdminOperationParameter: + ''' This class represents an admin operation parameter ''' + + def __init__(self, name, param_type, value): + ''' Creates an instance of an admin operation parameter ''' + + self.name = name + self.type = param_type + self.value = value + + # Set up callbacks def admin_operation(oi_handle, c_invocation_id, c_name, c_operation_id, c_params): ''' Callback for administrative operations ''' @@ -178,7 +190,9 @@ def admin_operation(oi_handle, c_invocat value = saImm.unmarshalSaImmValue(paramBuffer, paramType) - params.append(value) + parameter = AdminOperationParameter(paramName, paramType, value) + + params.append(parameter) # Invoke the operation result = implementer_instance.admin_operation(operation_id, name, params) @@ -569,7 +589,6 @@ class Constraints: current_children = get_children_with_classname(parent_name, all_instances, mo.class_name) - # Validate the number of children of the specific class to the given parent lower, upper = self.cardinality[(parent_class, mo.class_name)] diff --git a/python/samples/interface-handler-inheritance-version b/python/samples/interface-handler-inheritance-version --- a/python/samples/interface-handler-inheritance-version +++ b/python/samples/interface-handler-inheritance-version @@ -92,7 +92,7 @@ class InterfaceImplementer(Implementer): pass # Go through existing objects - for mo in InstanceIterator('InterfaceRO'): + for mo in InstanceIterator('InterfaceRO01'): interface_name = self.get_interface_name_from_dn(mo.dn) # Remove objects for deleted interfaces diff --git a/python/samples/ping-pong b/python/samples/ping-pong --- a/python/samples/ping-pong +++ b/python/samples/ping-pong @@ -14,13 +14,24 @@ class_name = "PingPong" dn = "pingPongId=1" +def print_admin_operation_info(dn, arguments): + print "INFO: I am %s" % dn + + if arguments: + print "INFO: Received arguments" + + for argument in arguments: + print " - %s: %s (%s)" % \ + (argument.name, argument.value, argument.type) + + def ping(dn, arguments): print print print "Pong!" print - print "INFO: I am %s, received arguments %s" % (dn, arguments) + print_admin_operation_info(dn, arguments) return eSaAisErrorT.SA_AIS_OK @@ -31,7 +42,7 @@ def pong(dn, arguments): print "Ping!" print - print "INFO: I am %s, received arguments %s" % (dn, arguments) + print_admin_operation_info(dn, arguments) return eSaAisErrorT.SA_AIS_OK diff --git a/python/samples/ping-pong-inheritance-impl b/python/samples/ping-pong-inheritance-impl --- a/python/samples/ping-pong-inheritance-impl +++ b/python/samples/ping-pong-inheritance-impl @@ -24,7 +24,8 @@ class PingPong(Implementer): print print "Pong!" print - print "INFO: I am %s, received arguments %s" % (dn, arguments) + + self.print_admin_operation_info(dn, arguments) @AdminOperation(class_name, 1) def pong(self, dn, arguments): @@ -32,8 +33,18 @@ class PingPong(Implementer): print print "Ping!" print - print "INFO: I am %s, received arguments %s" % (dn, arguments) + self.print_admin_operation_info(dn, arguments) + + def print_admin_operation_info(self, dn, arguments): + print "INFO: I am %s" % dn + + if arguments: + print "INFO: Received arguments" + + for argument in arguments: + print " - %s: %s (%s)" % \ + (argument.name, argument.value, argument.type) if __name__ == '__main__': On 09/15/2015 09:57 AM, Hung Nguyen wrote: > Hi Johan, > > 'interface-handler-inheritance-version' still has that 'InterfaceRO' > problem :) > for mo in InstanceIterator('InterfaceRO'): > > > > One more thing about the ping-pong application. > I see that only a list of values of the parameters is passed to the > application. > > root@SC1:~# immadm -o 0 -p paramName:SA_STRING_T:paramValue pingPongId=1 > > Pong! > > INFO: I am pingPongId=1, received arguments ['paramValue'] > > > I think paramName and paramType should also be passed to application. > IMM services supports multiple parameters for admin-operation, those > parameters can even have the same paramName. > > > Best Regards, > Hùng Nguyễn - DEK Technologies > > > > ------------------------------------------------------------------------ > > *From:* Johan Martensson > *Sent:* Monday, September 14, 2015 9:31PM > *To:* Hans Nordeback, Mathivanan Naickan, Hung Nguyen, Srikanth > Revanuru (srikanth.revan...@oracle.com) > *Cc:* Opensaf-devel > *Subject:* [PATCH 15 of 15] pyosaf: Correct sample applications and > add help text [#1406] > > python/samples/caps | 9 +++++++++ > python/samples/caps-inheritance-impl | 9 +++++++++ > python/samples/interface-handler | 16 ++++++++++++---- > python/samples/interface-handler-inheritance-version | 13 ++++++++++--- > python/samples/ping-pong | 8 ++++++++ > python/samples/ping-pong-inheritance-impl | 8 ++++++++ > python/samples/time-reporter | 12 ++++++++++-- > python/samples/time-reporter-inheritance-impl | 14 +++++++++++--- > python/samples/users | 11 ++++++++++- > python/samples/users-inheritance-impl | 11 ++++++++++- > 10 files changed, 97 insertions(+), 14 deletions(-) > > > Correct mistakes in the sample applications and add proper help text to all. > > diff --git a/python/samples/caps b/python/samples/caps > --- a/python/samples/caps > +++ b/python/samples/caps > @@ -1,6 +1,7 @@ > #!/usr/bin/env python > > import itertools > +import argparse > > from pyosaf.saAis import eSaAisErrorT > > @@ -31,6 +32,14 @@ def handle_validate(all_instances, updat > > if __name__ == "__main__": > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Validates that the lowerCaps and upperCaps attributes > +of instances of the CapsSample class can only contain > +lower case and upper case text respectively.') > + > + parser.parse_args() > + > # Create the implementer > classes = [caps_class_name] > > diff --git a/python/samples/caps-inheritance-impl > b/python/samples/caps-inheritance-impl > --- a/python/samples/caps-inheritance-impl > +++ b/python/samples/caps-inheritance-impl > @@ -1,6 +1,7 @@ > #!/usr/bin/env python > > import itertools > +import argparse > > from pyosaf.saAis import eSaAisErrorT > > @@ -42,6 +43,14 @@ class Caps(Implementer): > > if __name__ == "__main__": > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Validates that the lowerCaps and upperCaps attributes > +of instances of the CapsSample class can only contain > +lower case and upper case text respectively.') > + > + parser.parse_args() > + > # Create the implementer > caps_implementer = Caps() > > diff --git a/python/samples/interface-handler > b/python/samples/interface-handler > --- a/python/samples/interface-handler > +++ b/python/samples/interface-handler > @@ -61,7 +61,7 @@ def create_rt_object_for_interface(imple > implementer.create(mo) > > def select_loop(implementer): > - > + print 'select loop' > # Get selection object for the implementer > selection_object = implementer.get_selection_object() > > @@ -82,16 +82,18 @@ def select_loop(implementer): > > # Add objects for new interfaces > for interface in interfaces: > - if not immoi.get_object_no_runtime('interfaceId=%s' % > interface, > - > class_name=interface_class_name): > + > + try: > create_rt_object_for_interface(implementer, interface) > + except Exception as err: > + pass > > # Go through existing objects > for mo in InstanceIterator('InterfaceRO01'): > interface_name = get_interface_name_from_dn(mo.dn) > > # Remove objects for deleted interfaces > - if not mo.dn in interfaces: > + if not mo.interfaceId.split('=')[1] in interfaces: > implementer.delete(mo.dn) > > continue > @@ -115,6 +117,12 @@ def select_loop(implementer): > > if __name__ == "__main__": > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Creates a runtime object per network interface on the > machine and populates the ipv4Addresses and ipv6Addresses attributes.') > + > + parser.parse_args() > + > # Create the implementer instance > interface_implementer = Implementer(name="InterfaceImplementer") > > diff --git a/python/samples/interface-handler-inheritance-version > b/python/samples/interface-handler-inheritance-version > --- a/python/samples/interface-handler-inheritance-version > +++ b/python/samples/interface-handler-inheritance-version > @@ -86,16 +86,17 @@ class InterfaceImplementer(Implementer): > > # Add objects for new interfaces > for interface in interfaces: > - if not immoi.get_object_no_runtime('interfaceId=%s' % > interface, > - > class_name=interface_class_name): > + try: > self.create_rt_object_for_interface(interface) > + except Exception as err: > + pass > > # Go through existing objects > for mo in InstanceIterator('InterfaceRO'): > interface_name = self.get_interface_name_from_dn(mo.dn) > > # Remove objects for deleted interfaces > - if not mo.dn in interfaces: > + if not mo.interfaceId.split('=')[1] in interfaces: > self.delete(mo.dn) > > continue > @@ -119,6 +120,12 @@ class InterfaceImplementer(Implementer): > > if __name__ == "__main__": > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Creates a runtime object per network interface on the > machine and populates the ipv4Addresses and ipv6Addresses attributes.') > + > + parser.parse_args() > + > # Create the implementer > interface_implementer = InterfaceImplementer() > > diff --git a/python/samples/ping-pong b/python/samples/ping-pong > --- a/python/samples/ping-pong > +++ b/python/samples/ping-pong > @@ -1,6 +1,7 @@ > #!/usr/bin/env python > > import select > +import argparse > > from pyosaf.saAis import eSaAisErrorT > > @@ -37,6 +38,13 @@ def pong(dn, arguments): > > if __name__ == '__main__': > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Logs and replies to admin operations 0 and 1 towards > %s,' > + ' and replies' % dn) > + > + parser.parse_args() > + > # Create the ping-pong instance if it doesn't exist > if not immom.get(dn): > > diff --git a/python/samples/ping-pong-inheritance-impl > b/python/samples/ping-pong-inheritance-impl > --- a/python/samples/ping-pong-inheritance-impl > +++ b/python/samples/ping-pong-inheritance-impl > @@ -1,6 +1,7 @@ > #!/usr/bin/env python > > import select > +import argparse > > from pyosaf.saAis import eSaAisErrorT > > @@ -36,6 +37,13 @@ class PingPong(Implementer): > > if __name__ == '__main__': > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Logs and replies to admin operations 0 and 1 towards > %s,' > + ' and replies' % dn) > + > + parser.parse_args() > + > # Create the ping-pong instance if it doesn't exist > if not immom.get(dn): > > diff --git a/python/samples/time-reporter b/python/samples/time-reporter > --- a/python/samples/time-reporter > +++ b/python/samples/time-reporter > @@ -2,6 +2,7 @@ > > import select > import datetime > +import argparse > > from pyosaf.utils import immom, immoi > from pyosaf.utils.immoi.implementer import Implementer > @@ -45,6 +46,12 @@ def select_loop(implementer): > > if __name__ == '__main__': > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Keeps the %s object updated with the current time' % dn) > + > + parser.parse_args() > + > # Create the implementer instance > time_implementer = Implementer(name="TimeReporter") > > @@ -52,8 +59,7 @@ if __name__ == '__main__': > (hours, minutes, seconds) = get_time() > > # Create the time instance if it doesn't exist > - if not immoi.get_object_no_runtime(dn): > - > + try: > obj = ImmObject(class_name=class_name, dn=dn) > > obj.hours = hours > @@ -62,6 +68,8 @@ if __name__ == '__main__': > obj.timeId = "timeId=1" > > time_implementer.create(obj) > + except Exception as err: > + pass > > # Start dispatch and time update loop > select_loop(time_implementer) > diff --git a/python/samples/time-reporter-inheritance-impl > b/python/samples/time-reporter-inheritance-impl > --- a/python/samples/time-reporter-inheritance-impl > +++ b/python/samples/time-reporter-inheritance-impl > @@ -2,6 +2,7 @@ > > import select > import datetime > +import argparse > > from pyosaf.utils import immom, immoi > from pyosaf.utils.immoi.implementer import Implementer > @@ -28,8 +29,7 @@ class TimeReporter(Implementer): > # Create the time instance if it doesn't exist > dn = "timeId=%s" % self.time_id > > - if not immoi.get_object_no_runtime(dn): > - > + try: > now = datetime.datetime.now() > > obj = ImmObject(class_name=class_name, dn=dn) > @@ -39,7 +39,9 @@ class TimeReporter(Implementer): > obj.seconds = now.second > obj.timeId = "timeId=%" % self.time_id > > - time_implementer.create(obj) > + self.create(obj) > + except Exception as err: > + pass > > def enter_dispatch_loop(self): > ''' > @@ -74,6 +76,12 @@ class TimeReporter(Implementer): > > if __name__ == '__main__': > > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Keeps the %s object updated with the current time' % dn) > + > + parser.parse_args() > + > # Create the implementer instance > time_implementer = TimeReporter(time_id=1) > > diff --git a/python/samples/users b/python/samples/users > --- a/python/samples/users > +++ b/python/samples/users > @@ -6,6 +6,7 @@ from pyosaf.utils.immom.object import Im > from pyosaf.utils.immoi.implementer import Implementer > > import psutil > +import argparse > > class_name='UsersSampleClass' > > @@ -13,7 +14,15 @@ def on_attribute_update(*args): > return list(set(map(lambda x: x.name, psutil.get_users()))) > > if __name__ == '__main__': > - > + > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Creates the usersId=1 object and updates its users ' > + 'attribute with the current list of logged in users when it\' read ' > + 'in IMM.') > + > + parser.parse_args() > + > users_implementer = > Implementer(on_runtime_values_get=on_attribute_update, > name='UsersImplementer') > > diff --git a/python/samples/users-inheritance-impl > b/python/samples/users-inheritance-impl > --- a/python/samples/users-inheritance-impl > +++ b/python/samples/users-inheritance-impl > @@ -6,6 +6,7 @@ from pyosaf.utils.immom.object import Im > from pyosaf.utils.immoi.implementer import Implementer > > import psutil > +import argparse > > class_name='UsersSampleClass' > > @@ -18,7 +19,15 @@ class UsersImplementer(Implementer): > return list(set(map(lambda x: x.name, psutil.get_users()))) > > if __name__ == '__main__': > - > + > + # Parse command line arguments > + parser = argparse.ArgumentParser( > + description='Creates the usersId=1 object and updates its users ' > + 'attribute with the current list of logged in users when it\' read ' > + 'in IMM.') > + > + parser.parse_args() > + > users_implementer = UsersImplementer() > > try: > ------------------------------------------------------------------------------ _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel