propagate caller when a method calls another method
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 30 Nov 2010 17:51:19 +0000 (18:51 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 30 Nov 2010 17:51:19 +0000 (18:51 +0100)
PLC/Method.py
PLC/Methods/GetBootMedium.py
PLC/Methods/GetNodeFlavour.py
PLC/Methods/GetSliceFamily.py
PLC/Methods/GetSliceTicket.py
PLC/Methods/GetSlivers.py

index 275316f..783bc5d 100644 (file)
@@ -59,13 +59,18 @@ class Method (object):
 
         return True
 
-    def __init__(self, api):
+    def __init__(self, api,caller=None):
         self.name = self.__class__.__name__
         self.api = api
 
-        # Auth may set this to a Person instance (if an anonymous
-        # method, will remain None).
-        self.caller = None
+        if caller: 
+            # let a method call another one by propagating its caller
+            self.caller=caller
+        else:
+            # Auth may set this to a Person instance (if an anonymous
+            # method, will remain None).
+            self.caller = None
+        
 
         # API may set this to a (addr, port) tuple if known
         self.source = None
index 53f68a1..8248409 100644 (file)
@@ -1,5 +1,3 @@
-# $Id$
-# $URL$
 import random
 import base64
 import os
@@ -264,13 +262,13 @@ class GetBootMedium(Method):
         node_id=node['node_id']
 
         # no support for deployment-based BootCD's, use kvariants instead
-        node_pldistro = GetNodePldistro (self.api).call(auth, node_id)
+        node_pldistro = GetNodePldistro (self.api,self.caller).call(auth, node_id)
         if node_pldistro: pldistro = node_pldistro
 
-        node_fcdistro = GetNodeFcdistro (self.api).call(auth, node_id)
+        node_fcdistro = GetNodeFcdistro (self.api,self.caller).call(auth, node_id)
         if node_fcdistro: fcdistro = node_fcdistro
 
-        node_arch = GetNodeArch (self.api).call(auth,node_id)
+        node_arch = GetNodeArch (self.api,self.caller).call(auth,node_id)
         if node_arch: arch = node_arch
 
         return (pldistro,fcdistro,arch)
index 1b622e3..a9d6817 100644 (file)
@@ -40,10 +40,10 @@ class GetNodeFlavour(Method):
         # the deployment tag, if set, wins
         # xxx Thierry: this probably is wrong; we need fcdistro to be set anyway
         # for generating the proper yum config....
-        deployment = GetNodeDeployment (self.api).call(auth,node_id)
+        deployment = GetNodeDeployment (self.api,self.caller).call(auth,node_id)
         if deployment: return deployment
 
-        pldistro = GetNodePldistro (self.api).call(auth, node_id)
+        pldistro = GetNodePldistro (self.api,self.caller).call(auth, node_id)
         if not pldistro:
             pldistro = self.api.config.PLC_FLAVOUR_NODE_PLDISTRO
             SetNodePldistro(self.api).call(auth,node_id,pldistro)
@@ -53,12 +53,12 @@ class GetNodeFlavour(Method):
 
     def extensions (self, auth, node_id, fcdistro, arch):
         try:
-            return [ "%s-%s-%s"%(e,fcdistro,arch) for e in GetNodeExtensions(self.api).call(auth,node_id).split() ]
+            return [ "%s-%s-%s"%(e,fcdistro,arch) for e in GetNodeExtensions(self.api,self.caller).call(auth,node_id).split() ]
         except:
             return []
 
     def plain (self, auth, node_id):
-        return not not GetNodePlainBootstrapfs(self.api).call(auth,node_id)
+        return not not GetNodePlainBootstrapfs(self.api,self.caller).call(auth,node_id)
 
     def call(self, auth, node_id_or_name):
         # Get node information
@@ -68,13 +68,13 @@ class GetNodeFlavour(Method):
         node = nodes[0]
         node_id = node['node_id']
 
-        arch = GetNodeArch (self.api).call(auth,node_id)
+        arch = GetNodeArch (self.api,self.caller).call(auth,node_id)
         # if not set, use the global default and tag the node, in case the global default changes later on
         if not arch:
             arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
             SetNodeArch (self.api).call(auth,node_id,arch)
 
-        fcdistro = GetNodeFcdistro (self.api).call(auth, node_id)
+        fcdistro = GetNodeFcdistro (self.api,self.caller).call(auth, node_id)
         if not fcdistro:
             fcdistro = self.api.config.PLC_FLAVOUR_NODE_FCDISTRO
             SetNodeFcdistro (self.api).call (auth, node_id, fcdistro)
index 5e9ae6a..48b3f22 100644 (file)
@@ -1,5 +1,3 @@
-# $Id$
-# $URL$
 from PLC.Method import Method
 from PLC.Auth import Auth
 from PLC.Faults import *
@@ -39,21 +37,21 @@ class GetSliceFamily(Method):
         slice = slices[0]
         slice_id = slice['slice_id']
 
-        arch = GetSliceArch (self.api).call(auth,slice_id)
+        arch = GetSliceArch (self.api,self.caller).call(auth,slice_id)
         if not arch: arch = self.api.config.PLC_FLAVOUR_SLICE_ARCH
 
-        pldistro = GetSlicePldistro (self.api).call(auth, slice_id)
+        pldistro = GetSlicePldistro (self.api,self.caller).call(auth, slice_id)
         if not pldistro: pldistro = self.api.config.PLC_FLAVOUR_SLICE_PLDISTRO
 
-        fcdistro = GetSliceFcdistro (self.api).call(auth, slice_id)
+        fcdistro = GetSliceFcdistro (self.api,self.caller).call(auth, slice_id)
         if not fcdistro: fcdistro = self.api.config.PLC_FLAVOUR_SLICE_FCDISTRO
 
         # the vref tag, if set, wins over pldistro
-        vref = GetSliceVref (self.api).call(auth,slice_id)
+        vref = GetSliceVref (self.api,self.caller).call(auth,slice_id)
 
         # omf-control'ed slivers need the omf vserver reference image
         # this is to avoid asking users to set both tags 'omf_control' and 'vref'
-        if not vref and GetSliceOmfControl(self.api).call(auth,slice_id):
+        if not vref and GetSliceOmfControl(self.api,self.caller).call(auth,slice_id):
             SetSliceVref (self.api) (auth,slice_id,'omf')
             vref='omf'
 
index 90c0f63..fecf9ac 100644 (file)
@@ -63,7 +63,7 @@ class GetSliceTicket(Method):
         data = {
             'timestamp': int(time.time()),
             'initscripts': initscripts,
-            'slivers': get_slivers(self.api, auth, [slice['slice_id']]),
+            'slivers': get_slivers(self.api, self.caller, auth, [slice['slice_id']]),
             }
 
         # Sign ticket
index d54784d..745b0fc 100644 (file)
@@ -1,5 +1,3 @@
-# $Id$
-# $URL$
 import time
 
 from PLC.Faults import *
@@ -28,7 +26,7 @@ from PLC.Accessors.Accessors_standard import *
 MAXINT =  2L**31-1
 
 # slice_filter essentially contains the slice_ids for the relevant slices (on the node + system & delegated slices)
-def get_slivers(api, auth, slice_filter, node = None):
+def get_slivers(api, caller, auth, slice_filter, node = None):
     # Get slice information
     slices = Slices(api, slice_filter, ['slice_id', 'name', 'instantiation', 'expires', 'person_ids', 'slice_tag_ids'])
 
@@ -109,7 +107,7 @@ def get_slivers(api, auth, slice_filter, node = None):
         if slice['expires'] > MAXINT:  slice['expires']= MAXINT
 
         # expose the slice vref as computed by GetSliceFamily
-        family = GetSliceFamily (api).call(auth, slice['slice_id'])
+        family = GetSliceFamily (api,caller).call(auth, slice['slice_id'])
 
         slivers.append({
             'name': slice['name'],
@@ -272,7 +270,7 @@ class GetSlivers(Method):
         controller_and_delegated_slice_ids = controller_and_delegated_slices.keys()
         slice_ids = system_slice_ids + controller_and_delegated_slice_ids + node['slice_ids']
 
-        slivers = get_slivers(self.api, auth, slice_ids, node)
+        slivers = get_slivers(self.api, self.caller, auth, slice_ids, node)
 
         # get the special accounts and keys needed for the node
         # root
@@ -314,7 +312,7 @@ class GetSlivers(Method):
         personsitekeys=get_all_admin_keys(self.api)
         accounts.append({'name':'root','keys':personsitekeys})
 
-        hrn = GetNodeHrn(self.api).call(auth,node['node_id'])
+        hrn = GetNodeHrn(self.api,self.caller).call(auth,node['node_id'])
 
         # XMPP config for omf federation
         try: