removed the 'append' option to Allocate in the PL driver;
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 3 Jun 2015 15:54:17 +0000 (17:54 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 3 Jun 2015 15:54:17 +0000 (17:54 +0200)
replaced with the 'pltags' option that can be either 'ignore' (default), 'append' (only add the provided tags if not yet present) or anything else (try to do the magic, which is known to be a little fragile)

sfa/methods/Allocate.py
sfa/planetlab/pldriver.py
sfa/planetlab/plslices.py

index e136766..5d0c8d2 100644 (file)
@@ -25,11 +25,21 @@ class Allocate(Method):
     @param rspec (string) rspec to allocate
     @param options (dict)
 
-    The PL driver implements here an important option named
-    'append' that affects the management of slice tags. 
-    It is recommended to set this option to True, and to not pass
-    any slice tag in the incoming rspec, in which case
-    you are guaranteed to leave slice tags alone.
+    As of 3.1.16, the PL driver implements here an important option named
+    'pltags' that affects the management of slice tags.
+
+    This option can take 3 values
+      (*) options['pltags'] == 'ignore' (default)
+          This is the recommended mode; in this mode all slice tags passed 
+          here are ignore, which correspond to the <planetlab:attribute> XML tags in 
+          the <sliver_type> areas of incoming rspec to Allocate.
+          In other words you are guaranteed to leave slice tags alone.
+      (*) options['pltags'] == 'append'
+          All incoming slice tags are added to corresponding slivers, 
+          unless an exact match can be found in the PLC db
+      (*) options['pltags'] == 'match'
+          The historical mode, that attempts to leave the PLC db in a state
+          that matches the ones specified in incoming rspec.
 
     See also http://svn.planet-lab.org/wiki/SFASliceTags
 
index 8473ee4..36d8bd0 100644 (file)
@@ -680,7 +680,7 @@ class PlDriver (Driver):
         # ensure person records exists
         persons = slices.verify_persons(xrn.hrn, slice, users, sfa_peer, options=options)
         # ensure slice attributes exists
-        slices.verify_slice_attributes(slice, requested_attributes, options=options)
+        slices.verify_slice_tags(slice, requested_attributes, options=options)
        
         # add/remove slice from nodes
         request_nodes = rspec.version.get_nodes_with_slivers()
index 68681ca..bacba0f 100644 (file)
@@ -321,8 +321,7 @@ class PlSlices:
                 slice_tags.append({'name': 'vini_topo', 'value': 'manual', 'node_id': node_id})
                 #self.driver.shell.AddSliceTag(slice['name'], 'topo_rspec', str([topo_rspec]), node_id) 
 
-        self.verify_slice_attributes(slice, slice_tags, {'append': True}, admin=True)
-                        
+        self.verify_slice_tags(slice, slice_tags, {'pltags':'append'}, admin=True)
         
 
     def verify_site(self, slice_xrn, slice_record=None, sfa_peer=None, options=None):
@@ -557,15 +556,29 @@ class PlSlices:
                   self.driver.shell.AddPersonKey(int(person_id), key)
 
 
-    # incoming data (attributes) have a (name, value) pair
-    # while PLC data (tags) have a (tagname, value) pair
-    # we must be careful not to mix these up
-    def verify_slice_attributes(self, slice, requested_slice_attributes, options=None, admin=False):
+    def verify_slice_tags(self, slice, requested_slice_attributes, options=None, admin=False):
+        """
+        This function deals with slice tags, and supports 3 modes described
+        in the 'pltags' option that can be either
+        (*) 'ignore' (default) - do nothing
+        (*) 'append' - only add incoming tags, that do not match an existing tag
+        (*) anything else - tries to do the plain wholesale thing, 
+            i.e. to leave the db in sync with incoming tags
+        """
         if options is None: options={}
-        append = options.get('append', True)
-        logger.debug("verify_slice_attributes, append mode: {}".format(append))
-        for requested_slice_attribute in requested_slice_attributes:
-            logger.debug("verify_slice_attributes, incoming req : {}".format(requested_slice_attribute))
+
+        # lookup 'pltags' in options to find out which mode is requested here
+        # make sure the default is 'ignore' 
+        pltags = options.get('pltags', 'ignore') or 'ignore'
+
+        if pltags == 'ignore':
+            logger.info('verify_slice_tags in ignore mode - leaving slice tags as-is')
+            return
+        
+        # incoming data (attributes) have a (name, value) pair
+        # while PLC data (tags) have a (tagname, value) pair
+        # we must be careful not to mix these up
+
         # get list of tags users are able to manage - based on category
         filter = {'category': '*slice*'}
         if not admin:
@@ -597,8 +610,8 @@ class PlSlices:
                        requested_attribute['value'] == slice_tag['value']:
                         tag_found = True
                         break
-            # preserve missing tags in append mode
-            if not tag_found and not append:
+            # remove tags only if not in append mode
+            if not tag_found and pltags != 'append':
                 slice_tags_to_remove.append(slice_tag)
 
         # get tags that should be added: