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
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel