Hi Hung, Good comment, thanks. I will fix this and add support for the SA_IMM_CCB_ALLOW_NULL_OI flag as well in an updated patch.
/ Johan From: Hung Nguyen [mailto:[email protected]] Sent: den 15 juli 2015 10:58 To: Johan Mårtensson O; Hans Nordebäck; Anders Björnerstedt; [email protected] Cc: [email protected] Subject: Re: [PATCH 1 of 1] pyosaf: Add method to pyosaf.utils.immom.ccb.Ccb class to release admin owner for objects affected by the CCB [#1418] Hi Johan, For delete operation, you don't have to release admin owner for deleted objects. object_name should only be appended to objects_to_clear list when saImmOmCcbObjectDelete() failed. Best Regards, Hung Nguyen DEK Technologies ________________________________ From: Johan Mårtensson O Sent: Tuesday, July 14, 2015 4:46PM To: Hans Nordeback, Anders Bjornerstedt, Mathivanan Naickan, Hung Nguyen Cc: Opensaf-devel Subject: [PATCH 1 of 1] pyosaf: Add method to pyosaf.utils.immom.ccb.Ccb class to release admin owner for objects affected by the CCB [#1418] python/pyosaf/utils/immom/__init__.py | 43 +++++++++++++++++++++++++++++++++++ python/pyosaf/utils/immom/ccb.py | 23 ++++++++++++++++++ 2 files changed, 66 insertions(+), 0 deletions(-) Adds a method to they pyosaf.utils.immom.ccb.Ccb class to release the admin owner flag for any objects it has set the flag for during the CCB. Also creates support functions in the __init__.py file for the pyosaf.utils.immom module. Verify like this (assumming SampleClass1 and sampleClassId=1 exist): from pyosaf.utils.immom.ccb import Ccb from pyosaf.utils.immom.object import ImmObject from pyosaf.utils import immom ccb = Ccb() obj = ImmObject(class_name='SampleClass1', dn='sampleClassId=1,sampleClassId=1') obj.sampleClassId='sampleClassId=1' ccb.create(obj, 'sampleClassId=1') ccb.apply() print immom.get('sampleClassId=1').SaImmAttrAdminOwnerName ccb.release_admin_owner() print immom.get('sampleClassId=1').SaImmAttrAdminOwnerName diff --git a/python/pyosaf/utils/immom/__init__.py b/python/pyosaf/utils/immom/__init__.py --- a/python/pyosaf/utils/immom/__init__.py +++ b/python/pyosaf/utils/immom/__init__.py @@ -194,3 +194,46 @@ def admin_op_invoke(dn, op_id, params=No if error != eSaAisErrorT.SA_AIS_OK: print "saImmOmAdminOwnerFinalize: %s" % eSaAisErrorT.whatis(error) raise SafException(error) + + +def raise_saf_exception(function, error): + ''' Raises an exception for a given SAF function, based on + the given error code + ''' + + error_string = "%s: %s" % (function.__name__, eSaAisErrorT.whatis(error)) + + raise SafException(error, error_string) + + +def call_saf_function(function, *args): + ''' Calls a function, with the applied arguments, + with retries and sleep between each retry + ''' + + one_sec_sleeps = 0 + + error = function(*args) + + while error == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN: + if one_sec_sleeps == TRYAGAIN_CNT: + break; + time.sleep(1) + one_sec_sleeps += 1 + + error = function(*args) + + if error != eSaAisErrorT.SA_AIS_OK: + raise_saf_exception(function, error) + + return error + + +def release_admin_owner(dns, owner_handle): + ''' Releases admin owner for the given DNs ''' + + # Marshall the parameters + object_names = [SaNameT(dn) for dn in dns] + + call_saf_function(saImmOm.saImmOmAdminOwnerRelease, + owner_handle, object_names, eSaImmScopeT.SA_IMM_ONE) diff --git a/python/pyosaf/utils/immom/ccb.py b/python/pyosaf/utils/immom/ccb.py --- a/python/pyosaf/utils/immom/ccb.py +++ b/python/pyosaf/utils/immom/ccb.py @@ -76,6 +76,8 @@ class Ccb(object): def __init__(self, require_registered_oi=True): self.owner_handle = saImmOm.SaImmAdminOwnerHandleT() + self.objects_to_clear = [] + owner_name = saImmOm.SaImmAdminOwnerNameT("DummyName") one_sec_sleeps = 0 err = saImmOm.saImmOmAdminOwnerInitialize(pyosaf.utils.immom.HANDLE, owner_name, @@ -140,6 +142,9 @@ class Ccb(object): msg = "saImmOmAdminOwnerSet: %s - obj:%s" % \ (_parent_name, eSaAisErrorT.whatis(err)) raise SafException(err, msg) + + self.objects_to_clear.append(_parent_name) + else: parent_name = None @@ -175,6 +180,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (_object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(_object_name) + err = saImmOm.saImmOmCcbObjectDelete(self.ccb_handle, object_name) if err != eSaAisErrorT.SA_AIS_OK: raise SafException(err, "saImmOmCcbObjectDelete: %s - %s" % \ @@ -212,6 +219,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() @@ -263,6 +272,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() attr_mod.modType = \ @@ -313,6 +324,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() attr_mod.modType = \ @@ -346,6 +359,16 @@ class Ccb(object): if err != eSaAisErrorT.SA_AIS_OK: raise SafException(err) + def release_admin_owner(self): + ''' Removes the admin owner role for the objects + it has been set for during the CCB + ''' + + pyosaf.utils.immom.release_admin_owner(self.objects_to_clear, + self.owner_handle) + + self.objects_to_clear = [] + def test(): ccb = Ccb() ccb.modify("safAmfCluster=myAmfCluster", "saAmfClusterStartupTimeout", ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
