python/samples/README | 9 ++++
python/samples/immoi/samples/interface-handler | 19
+++++----
python/samples/immoi/samples/interface-handler-inheritance-version | 17
++++----
3 files changed, 28 insertions(+), 17 deletions(-)
Correct the interface-handler according to review comments, move it to the
right directory, and add a description of it to the README.
diff --git a/python/samples/README b/python/samples/README
--- a/python/samples/README
+++ b/python/samples/README
@@ -65,6 +65,15 @@ users:
package psutil to fill in the list of logged in users. Run
'users --help' for specific options and arguments.
+interface-handler:
+ The Interface Handler OI demonstrates creation of runtime
+ objects and updates triggered by the OI as a timeout in its
+ select loop. It creates runtime objects for all detected
+ interfaces on the machine where it is running and lists all
+ available IPv4 and IPv6 addresses. It depends on the python
+ netifaces library to do so. Run 'interface-handler --help' for
+ specific options and arguments.
+
Logging for all apps/utils goes to /var/log/opensaf/saflog/saLogSystem*.log
The IMM OI samples use the classes defined in the classes.xml file. Load it
with immcfg -f classes.xml before trying them.
diff --git a/python/samples/immoi/samples/interface-handler
b/python/samples/interface-handler
copy from python/samples/immoi/samples/interface-handler
copy to python/samples/interface-handler
--- a/python/samples/immoi/samples/interface-handler
+++ b/python/samples/interface-handler
@@ -87,29 +87,30 @@ def select_loop(implementer):
create_rt_object_for_interface(implementer, interface)
# Go through existing objects
- for mo in InstanceIterator('InterfaceRO'):
+ 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:
implementer.delete(mo.dn)
+ continue
+
# Update interfaces
addresses = netifaces.ifaddresses(interface_name)
- ipv4 = None
- ipv6 = None
+ attributes = {}
if netifaces.AF_INET in addresses:
- ipv4 = [a['addr'] for a in addresses[netifaces.AF_INET]]
+ attributes['ipv4Addresses'] = \
+ [a['addr'] for a in addresses[netifaces.AF_INET]]
if netifaces.AF_INET6 in addresses:
- ipv6 = [a['addr'] for a in addresses[netifaces.AF_INET6]]
+ attributes['ipv6Addresses'] = \
+ [a['addr'] for a in addresses[netifaces.AF_INET6]]
- attributes = {'ipv4Addresses' : ipv4,
- 'ipv6Addresses' : ipv6}
-
- implementer.update_runtime_attributes(mo.dn, attributes)
+ if attributes:
+ implementer.update_runtime_attributes(mo.dn, attributes)
if __name__ == "__main__":
diff --git a/python/samples/immoi/samples/interface-handler-inheritance-version
b/python/samples/interface-handler-inheritance-version
copy from python/samples/immoi/samples/interface-handler-inheritance-version
copy to python/samples/interface-handler-inheritance-version
--- a/python/samples/immoi/samples/interface-handler-inheritance-version
+++ b/python/samples/interface-handler-inheritance-version
@@ -98,22 +98,23 @@ class InterfaceImplementer(Implementer):
if not mo.dn in interfaces:
self.delete(mo.dn)
+ continue
+
# Update interfaces
addresses = netifaces.ifaddresses(interface_name)
- ipv4 = None
- ipv6 = None
+ attributes = {}
if netifaces.AF_INET in addresses:
- ipv4 = [a['addr'] for a in
addresses[netifaces.AF_INET]]
+ attributes['ipv4Addresses'] = \
+ [a['addr'] for a in addresses[netifaces.AF_INET]]
if netifaces.AF_INET6 in addresses:
- ipv6 = [a['addr'] for a in
addresses[netifaces.AF_INET6]]
+ attributes['ipv6Addresses'] = \
+ [a['addr'] for a in addresses[netifaces.AF_INET6]]
- attributes = {'ipv4Addresses' : ipv4,
- 'ipv6Addresses' : ipv6}
-
- self.update_runtime_attributes(mo.dn, attributes)
+ if attributes:
+ self.update_runtime_attributes(mo.dn, attributes)
if __name__ == "__main__":
------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel