Thanks for the comments. See inline below for comments on the comments.

/ Johan

-----Original Message-----
From: Srikanth Revanuru [mailto:[email protected]] 
Sent: den 13 augusti 2015 11:25
To: Johan Mårtensson O
Cc: Hung Nguyen D; [email protected]; [email protected]; 
[email protected]
Subject: Re: [PATCH 3 of 5] pyosaf: Add --snapshot and --listen arguments to 
the CLM listener and extend CLM utils to support this [#1441]

Johan,

 Comments inline.
 Ack for the other 4 patches.

----- [email protected] wrote:

> python/pyosaf/utils/clm/__init__.py |  43
> ++++++++++++++++++++++++++++++++++++-
>  python/samples/clm-listener         |  39
> ++++++++++++++++++++++++++++++---
>  2 files changed, 77 insertions(+), 5 deletions(-)
> 
> 
> Extend the clm-listener sample application with --snapshot and 
> --listen arguments to show how to get the current members and how to 
> track membership. Also extend the clm utils to support this. Verify 
> like this:
> 
> ./clm-listener --snapshot #Lists the current nodes
> 
> ./clm-listener --listen   #Blocks and prints any changes to the
> cluster membership list
> 
> diff --git a/python/pyosaf/utils/clm/__init__.py
> b/python/pyosaf/utils/clm/__init__.py
> --- a/python/pyosaf/utils/clm/__init__.py
> +++ b/python/pyosaf/utils/clm/__init__.py
> @@ -81,6 +81,23 @@ def track_callback(c_notification_buffer
>  def node_get_callback(*args):
>      pass
>  
> +class ClusterNode:
> +
> +    def __init__(self, node_id, node_address, node_name,
> execution_environment,
> +                 member,
> +                 boot_timestamp,
> +                 initial_view_number):
> +
> +        self.node_id               = node_id
> +        self.node_address_value    = node_address.value
> +        self.node_address_family   = node_address.family
> +        self.node_name             = node_name.value
> +        self.execution_environment = execution_environment
> +        self.member                = member
> +        self.boot_timestamp        = boot_timestamp
> +        self.initial_view_number   = initial_view_number
> +
> +
>  def initialize(track_fn=None):
>  
>      global track_function
> @@ -100,4 +117,28 @@ def initialize(track_fn=None):
>      saClmInitialize_4(HANDLE, callbacks, version)
>  
>  def track(flags=saAis.saAis.SA_TRACK_CHANGES_ONLY):
> -    saClm.saClmClusterTrackCallbackT_4(HANDLE, flags, None)
> +    saClmClusterTrack_4(HANDLE, flags, None)
> +
> +def get_members():
> +    notification_buffer = saClm.SaClmClusterNotificationBufferT_4()
> +
> +    saClmClusterTrack_4(HANDLE, saAis.saAis.SA_TRACK_CURRENT, 
> +                        notification_buffer)
> +
> +    cluster_nodes = []
> +
> +    for i in range(notification_buffer.numberOfItems):
> +        notification = notification_buffer.notification[i]
> +        clusterNode  = notification.clusterNode
> +
> +        node = ClusterNode(node_id=clusterNode.nodeId,
> +                           node_address=clusterNode.nodeAddress,
> +                           node_name=clusterNode.nodeName,
> +                          
> execution_environment=clusterNode.executionEnvironment,
> +                           member=clusterNode.member,
> +                           boot_timestamp=clusterNode.bootTimestamp,
> +                          
> initial_view_number=clusterNode.initialViewNumber)
> +
> +    cluster_nodes.append(node)

[Srikanth] : Appending a node to the list should be pushed inside the for loop.
             Otherwise last node is only added to the list.
Johan: I got tripped up by the indentation. :-/ Good catch! 

> +
> +    return cluster_nodes
> diff --git a/python/samples/clm-listener b/python/samples/clm-listener 
> old mode 100644 new mode 100755
> --- a/python/samples/clm-listener
> +++ b/python/samples/clm-listener
> @@ -1,5 +1,8 @@
>  #!/usr/bin/env python
>  
> +import argparse
> +import sys
> +
>  from subprocess import Popen, PIPE
>  
>  from pyosaf import saAis, saClm, saImm @@ -9,6 +12,15 @@ from 
> pyosaf.utils import immoi, clm  def dn_to_vm_name(vm_dn):
>      return vm_dn.split(',')[0].split('=')[1]
>  
> +def print_members(members):
> +
> +    for node in members:
> +        if node.member:
> +            vm_name    = dn_to_vm_name(node.node_name)
> +            ip_address = node.node_address_value
> +
> +            print "  - %s  %s" % (vm_name, ip_address)
> +
>  def membership_change(all, added, removed, changed):
>      print "Info: Received cluster membership update"
>  
> @@ -18,21 +30,40 @@ def membership_change(all, added, remove
>          print "INFO: % joined the cluster" % vm_name
>  
>      for vm_dn in removed:
> -        vm_name = dn_to_vm_name(vm_dn):
> +        vm_name = dn_to_vm_name(vm_dn)
>  
>          print "INFO: %s left the cluster" % vm_name
>  
>  
>  if __name__ == "__main__":
>  
> +    # Parse command line arguments
> +    parser = argparse.ArgumentParser(
> +        description='Listens to changes to objects of the given
> classes')
> +
> +    group = parser.add_mutually_exclusive_group(required=True)
> +
> +    group.add_argument('--snapshot', action="store_true",
> +                        help='shows a snapshot of the current
> membership list')
> +    group.add_argument('--listen', action="store_true", help='listens
> to changes to all classes')
> +
> +    args = parser.parse_args()
> +
>      # Initialize the CLM service
>      clm.initialize(track_fn=membership_change)
>  
> +    if args.snapshot:
> +        print "-" * 10 + " Members " + "-"*10
> +
> +        members = clm.get_members()
> +
> +        print_members(members)
> +
> +        sys.exit(0)
> +
>      # Start tracking
>      clm.track()
>  
> -    print "INFO: Initialized CLM and started tracking"
> -
>      # Do dispatch forever
>      while True:
> -        clm.saClmDispatch(handle,
> saAis.eSaDispatchFlagsT.SA_DISPATCH_BLOCKING)
> +        clm.saClmDispatch(clm.HANDLE,
> saAis.eSaDispatchFlagsT.SA_DISPATCH_BLOCKING)


[ Srikanth ] : I don't think there is a need for while loop to the dispatch api
               with SA_DISPATCH_BLOCKING as argument. 
Johan: I need this to keep getting tracking callbacks for the "--listen" 
argument.

Thanks,
Srikanth
------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to