.
[sfa.git] / sfa / senslab / slabslices.py
1 from sfa.util.xrn import get_authority, urn_to_hrn
2 from sfa.util.sfalogging import logger
3
4
5 MAXINT =  2L**31-1
6
7 class SlabSlices:
8
9     rspec_to_slice_tag = {'max_rate':'net_max_rate'}
10     
11     
12     def __init__(self, driver):
13         self.driver = driver
14         
15     ##Used in SFACE?    
16     #def get_slivers(self, xrn, node=None):
17         #hrn, hrn_type = urn_to_hrn(xrn)
18          
19         #slice_name = hrn_to_pl_slicename(hrn)
20         ## XX Should we just call PLCAPI.GetSliceTicket(slice_name) instead
21         ## of doing all of this?
22         ##return self.api.driver.GetSliceTicket(self.auth, slice_name) 
23         
24
25        
26         #sfa_slice = self.driver.GetSlices(slice_filter = slice_name, \
27         #                                   slice_filter_type = 'slice_hrn')
28  
29
30         ## Get user information
31         ##TODO
32         #alchemy_person = dbsession.query(RegRecord).filter_by(record_id = \
33                                         #sfa_slice['record_id_user']).first()
34
35         #slivers = []
36         #sliver_attributes = []
37             
38         #if sfa_slice['oar_job_id'] is not -1:
39             #nodes_all = self.driver.GetNodes({'hostname': \
40                                                     #sfa_slice['node_ids']},
41                             #['node_id', 'hostname','site','boot_state'])
42             #nodeall_byhostname = dict([(n['hostname'], n) for n in nodes_all])
43             #nodes = sfa_slice['node_ids']
44             
45             #for node in nodes:
46                 ##for sliver_attribute in filter(lambda a: a['node_id'] == \
47                                                 #node['node_id'], slice_tags):
48                 #sliver_attribute['tagname'] = 'slab-tag'
49                 #sliver_attribute['value'] = 'slab-value'
50                 #sliver_attributes.append(sliver_attribute['tagname'])
51                 #attributes.append({'tagname': sliver_attribute['tagname'],
52                                     #'value': sliver_attribute['value']})
53
54             ## set nodegroup slice attributes
55             #for slice_tag in filter(lambda a: a['nodegroup_id'] \
56                                         #in node['nodegroup_ids'], slice_tags):
57                 ## Do not set any nodegroup slice attributes for
58                 ## which there is at least one sliver attribute
59                 ## already set.
60                 #if slice_tag not in slice_tags:
61                     #attributes.append({'tagname': slice_tag['tagname'],
62                         #'value': slice_tag['value']})
63
64             #for slice_tag in filter(lambda a: a['node_id'] is None, \
65                                                             #slice_tags):
66                 ## Do not set any global slice attributes for
67                 ## which there is at least one sliver attribute
68                 ## already set.
69                 #if slice_tag['tagname'] not in sliver_attributes:
70                     #attributes.append({'tagname': slice_tag['tagname'],
71                                    #'value': slice_tag['value']})
72
73             ## XXX Sanity check; though technically this should 
74             ## be a system invariant
75             ## checked with an assertion
76             #if sfa_slice['expires'] > MAXINT:  sfa_slice['expires']= MAXINT
77             
78             #slivers.append({
79                 #'hrn': hrn,
80                 #'name': sfa_slice['name'],
81                 #'slice_id': sfa_slice['slice_id'],
82                 #'instantiation': sfa_slice['instantiation'],
83                 #'expires': sfa_slice['expires'],
84                 #'keys': keys,
85                 #'attributes': attributes
86             #})
87
88         #return slivers
89         
90         
91         
92
93
94         #return slivers
95     def get_peer(self, xrn):
96         hrn, hrn_type = urn_to_hrn(xrn)
97         #Does this slice belong to a local site or a peer senslab site?
98         peer = None
99         
100         # get this slice's authority (site)
101         slice_authority = get_authority(hrn)
102         site_authority = slice_authority
103         # get this site's authority (sfa root authority or sub authority)
104         #site_authority = get_authority(slice_authority).lower()
105         logger.debug("SLABSLICES \ get_peer slice_authority  %s \
106                     site_authority %s hrn %s" %(slice_authority, \
107                                         site_authority, hrn))
108         #This slice belongs to the current site
109         if site_authority == self.driver.root_auth :
110             return None
111         # check if we are already peered with this site_authority, if so
112         #peers = self.driver.GetPeers({})  
113         peers = self.driver.GetPeers(peer_filter = slice_authority)
114         for peer_record in peers:
115           
116             if site_authority == peer_record.hrn:
117                 peer = peer_record
118         logger.debug(" SLABSLICES \tget_peer peer  %s " %(peer))
119         return peer
120
121     def get_sfa_peer(self, xrn):
122         hrn, hrn_type = urn_to_hrn(xrn)
123
124         # return the authority for this hrn or None if we are the authority
125         sfa_peer = None
126         slice_authority = get_authority(hrn)
127         site_authority = get_authority(slice_authority)
128
129         if site_authority != self.driver.hrn:
130             sfa_peer = site_authority
131
132         return sfa_peer
133         
134         
135     def verify_slice_leases(self, sfa_slice, requested_jobs_dict, kept_leases, \
136         peer):
137
138        
139         #First get the list of current leases from OAR          
140         leases = self.driver.GetLeases({'name':sfa_slice['name']})
141         #leases = self.driver.GetLeases({'name':sfa_slice['name']},\
142                                      #['lease_id'])
143         if leases : 
144             current_leases = [lease['lease_id'] for lease in leases]
145             #Deleted leases are the ones with lease id not declared in the Rspec
146             deleted_leases = list(set(current_leases).difference(kept_leases))
147     
148             try:
149                 #if peer:
150                     #peer = RegAuyhority object is unsubscriptable
151                     #TODO :UnBindObjectFromPeer Quick and dirty 
152                     #auth='senslab2 SA 27/07/12
153                     
154                     #Commented out UnBindObjectFromPeer SA 09/10/12
155                     #self.driver.UnBindObjectFromPeer('senslab2', 'slice', \
156                                     #sfa_slice['record_id_slice'], peer.hrn)
157                 
158                 self.driver.DeleteLeases(deleted_leases, \
159                                         sfa_slice['name'])
160                
161             #TODO verify_slice_leases: catch other exception?
162             except KeyError: 
163                 logger.log_exc('Failed to remove slice leases')
164                 
165         #Add new leases        
166         for start_time in requested_jobs_dict:
167             job = requested_jobs_dict[start_time]
168             self.driver.AddLeases(job['hostname'], \
169                         sfa_slice, int(job['start_time']), \
170                         int(job['duration']))
171                         
172         return leases
173
174     def verify_slice_nodes(self, sfa_slice, requested_slivers, peer):
175         current_slivers = []
176         deleted_nodes = []
177         
178         if sfa_slice['node_ids']:
179             nodes = self.driver.GetNodes(sfa_slice['node_ids'], ['hostname'])
180             current_slivers = [node['hostname'] for node in nodes]
181     
182             # remove nodes not in rspec
183             deleted_nodes = list(set(current_slivers).\
184                                                 difference(requested_slivers))
185             # add nodes from rspec
186             #added_nodes = list(set(requested_slivers).\
187                                         #difference(current_slivers))
188
189             #Update the table with the nodes that populate the slice
190             logger.debug("SLABSLICES \tverify_slice_nodes slice %s\
191                                          \r\n \r\n deleted_nodes %s"\
192                                         %(sfa_slice,deleted_nodes))
193
194             if deleted_nodes:
195                 self.driver.DeleteSliceFromNodes(sfa_slice['name'], \
196                                                                 deleted_nodes)
197             return nodes
198
199             
200
201     def free_egre_key(self):
202         used = set()
203         for tag in self.driver.GetSliceTags({'tagname': 'egre_key'}):
204             used.add(int(tag['value']))
205
206         for i in range(1, 256):
207             if i not in used:
208                 key = i
209                 break
210         else:
211             raise KeyError("No more EGRE keys available")
212
213         return str(key)
214
215   
216        
217                         
218         
219
220     def handle_peer(self, site, sfa_slice, persons, peer):
221         if peer:
222             # bind site
223             try:
224                 if site:
225                     self.driver.BindObjectToPeer('site', site['site_id'], \
226                                         peer['shortname'], sfa_slice['site_id'])
227             except Exception, error:
228                 self.driver.DeleteSite(site['site_id'])
229                 raise error
230             
231             # bind slice
232             try:
233                 if sfa_slice:
234                     self.driver.BindObjectToPeer('slice', slice['slice_id'], \
235                                     peer['shortname'], sfa_slice['slice_id'])
236             except Exception, error:
237                 self.driver.DeleteSlice(sfa_slice['slice_id'])
238                 raise error 
239
240             # bind persons
241             for person in persons:
242                 try:
243                     self.driver.BindObjectToPeer('person', \
244                                     person['person_id'], peer['shortname'], \
245                                     person['peer_person_id'])
246
247                     for (key, remote_key_id) in zip(person['keys'], \
248                                                         person['key_ids']):
249                         try:
250                             self.driver.BindObjectToPeer( 'key', \
251                                             key['key_id'], peer['shortname'], \
252                                             remote_key_id)
253                         except:
254                             self.driver.DeleteKey(key['key_id'])
255                             logger.log_exc("failed to bind key: %s \
256                                             to peer: %s " % (key['key_id'], \
257                                             peer['shortname']))
258                 except Exception, error:
259                     self.driver.DeletePerson(person['person_id'])
260                     raise error       
261
262         return sfa_slice
263
264     #def verify_site(self, slice_xrn, slice_record={}, peer=None, \
265                                         #sfa_peer=None, options={}):
266         #(slice_hrn, type) = urn_to_hrn(slice_xrn)
267         #site_hrn = get_authority(slice_hrn)
268         ## login base can't be longer than 20 characters
269         ##slicename = hrn_to_pl_slicename(slice_hrn)
270         #authority_name = slice_hrn.split('.')[0]
271         #login_base = authority_name[:20]
272         #logger.debug(" SLABSLICES.PY \tverify_site authority_name %s  \
273                                         #login_base %s slice_hrn %s" \
274                                         #%(authority_name,login_base,slice_hrn)
275         
276         #sites = self.driver.GetSites(login_base)
277         #if not sites:
278             ## create new site record
279             #site = {'name': 'geni.%s' % authority_name,
280                     #'abbreviated_name': authority_name,
281                     #'login_base': login_base,
282                     #'max_slices': 100,
283                     #'max_slivers': 1000,
284                     #'enabled': True,
285                     #'peer_site_id': None}
286             #if peer:
287                 #site['peer_site_id'] = slice_record.get('site_id', None)
288             #site['site_id'] = self.driver.AddSite(site)
289             ## exempt federated sites from monitor policies
290             #self.driver.AddSiteTag(site['site_id'], 'exempt_site_until', \
291                                                                 #"20200101")
292             
293             ### is this still necessary?
294             ### add record to the local registry 
295             ##if sfa_peer and slice_record:
296                 ##peer_dict = {'type': 'authority', 'hrn': site_hrn, \
297                              ##'peer_authority': sfa_peer, 'pointer': \
298                                                         #site['site_id']}
299                 ##self.registry.register_peer_object(self.credential, peer_dict)
300         #else:
301             #site =  sites[0]
302             #if peer:
303                 ## unbind from peer so we can modify if necessary.
304                 ## Will bind back later
305                 #self.driver.UnBindObjectFromPeer('site', site['site_id'], \
306                                                             #peer['shortname']) 
307         
308         #return site        
309
310     def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer):
311
312         #login_base = slice_hrn.split(".")[0]
313         slicename = slice_hrn
314         slices_list = self.driver.GetSlices(slice_filter = slicename, \
315                                             slice_filter_type = 'slice_hrn') 
316         if slices_list:
317             for sl in slices_list:
318             
319                 logger.debug("SLABSLICE \tverify_slice slicename %s sl %s \
320                                     slice_record %s"%(slicename, sl, \
321                                                             slice_record))
322                 sfa_slice = sl
323                 sfa_slice.update(slice_record)
324                 #del slice['last_updated']
325                 #del slice['date_created']
326                 #if peer:
327                     #slice['peer_slice_id'] = slice_record.get('slice_id', None)
328                     ## unbind from peer so we can modify if necessary. 
329                     ## Will bind back later
330                     #self.driver.UnBindObjectFromPeer('slice', \
331                                                         #slice['slice_id'], \
332                                                             #peer['shortname'])
333                 #Update existing record (e.g. expires field) 
334                     #it with the latest info.
335                 ##if slice_record and slice['expires'] != slice_record['expires']:
336                     ##self.driver.UpdateSlice( slice['slice_id'], {'expires' : \
337                                                         #slice_record['expires']})
338         else:
339             logger.debug(" SLABSLICES \tverify_slice Oups \
340                         slice_record %s peer %s sfa_peer %s "\
341                         %(slice_record, peer,sfa_peer))
342             sfa_slice = {'slice_hrn': slicename,
343                      #'url': slice_record.get('url', slice_hrn), 
344                      #'description': slice_record.get('description', slice_hrn)
345                      'node_list' : [],
346                      'record_id_user' : slice_record['person_ids'][0],
347                      'record_id_slice': slice_record['record_id'],
348                      'peer_authority':str(peer.hrn)
349                     
350                      }
351             # add the slice  
352             self.driver.AddSlice(sfa_slice)                         
353             #slice['slice_id'] = self.driver.AddSlice(slice)
354             logger.debug("SLABSLICES \tverify_slice ADDSLICE OK") 
355             #slice['node_ids']=[]
356             #slice['person_ids'] = []
357             #if peer:
358                 #slice['peer_slice_id'] = slice_record.get('slice_id', None) 
359             # mark this slice as an sfa peer record
360             #if sfa_peer:
361                 #peer_dict = {'type': 'slice', 'hrn': slice_hrn, 
362                              #'peer_authority': sfa_peer, 'pointer': \
363                                                     #slice['slice_id']}
364                 #self.registry.register_peer_object(self.credential, peer_dict)
365             
366
367        
368         return sfa_slice
369
370
371     def verify_persons(self, slice_hrn, slice_record, users,  peer, sfa_peer, \
372                                                                 options={}):
373         """ 
374         users is a record list. Records can either be local records 
375         or users records from known and trusted federated sites. 
376         If the user is from another site that senslab doesn't trust yet,
377         then Resolve will raise an error before getting to create_sliver. 
378         """
379         #TODO SA 21/08/12 verify_persons Needs review 
380         
381         
382         users_by_id = {}  
383         users_by_hrn = {} 
384         #users_dict : dict whose keys can either be the user's hrn or its id.
385         #Values contains only id and hrn 
386         users_dict = {}
387         
388         #First create dicts by hrn and id for each user in the user record list:      
389         for user in users:
390             
391             if 'urn' in user and (not 'hrn' in user ) :
392                 user['hrn'], user['type'] = urn_to_hrn(user['urn'])
393                
394             if 'person_id' in user and 'hrn' in user:
395                 users_by_id[user['person_id']] = user
396                 users_dict[user['person_id']] = {'person_id':\
397                                         user['person_id'], 'hrn':user['hrn']}
398
399                 users_by_hrn[user['hrn']] = user
400                 users_dict[user['hrn']] = {'person_id':user['person_id'], \
401                                                         'hrn':user['hrn']}
402                 
403         
404         logger.debug( "SLABSLICE.PY \t verify_person  \
405                         users_dict %s \r\n user_by_hrn %s \r\n \
406                         \tusers_by_id %s " \
407                         %(users_dict,users_by_hrn, users_by_id))
408         
409         existing_user_ids = []
410         existing_user_hrns = []
411         existing_users = []
412         # Check if user is in Senslab LDAP using its hrn.
413         # Assuming Senslab is centralised :  one LDAP for all sites, 
414         # user_id unknown from LDAP
415         # LDAP does not provide users id, therefore we rely on hrns containing
416         # the login of the user.
417         # If the hrn is not a senslab hrn, the user may not be in LDAP.
418         if users_by_hrn:
419             #Construct the list of filters (list of dicts) for GetPersons
420             filter_user = []
421             for hrn in users_by_hrn:
422                 filter_user.append (users_by_hrn[hrn])
423             logger.debug(" SLABSLICE.PY \tverify_person  filter_user %s " \
424                                                     %(filter_user))
425             #Check user's in LDAP with GetPersons
426             #Needed because what if the user has been deleted in LDAP but 
427             #is still in SFA?
428             existing_users = self.driver.GetPersons(filter_user) 
429                            
430             #User's in senslab LDAP               
431             if existing_users:
432                 for user in existing_users :
433                     existing_user_hrns.append(users_dict[user['hrn']]['hrn'])
434                     existing_user_ids.\
435                                     append(users_dict[user['hrn']]['person_id'])
436          
437             # User from another known trusted federated site. Check 
438             # if a senslab account matching the email has already been created.
439             else: 
440                 req = 'mail='
441                 if isinstance(users, list):
442                     
443                     req += users[0]['email']  
444                 else:
445                     req += users['email']
446                     
447                 ldap_reslt = self.driver.ldap.LdapSearch(req)
448                 if ldap_reslt:
449                     logger.debug(" SLABSLICE.PY \tverify_person users \
450                                 USER already in Senslab \t ldap_reslt %s \
451                                 "%( ldap_reslt)) 
452                     existing_users.append(ldap_reslt[1])
453                  
454                 else:
455                     #User not existing in LDAP
456                     #TODO SA 21/08/12 raise smthg to add user or add it auto ?
457                     logger.debug(" SLABSLICE.PY \tverify_person users \
458                                 not in ldap ...NEW ACCOUNT NEEDED %s \r\n \t \
459                                 ldap_reslt %s "  %(users, ldap_reslt))
460    
461         requested_user_ids = users_by_id.keys() 
462         requested_user_hrns = users_by_hrn.keys()
463         logger.debug("SLABSLICE.PY \tverify_person requested_user_ids  %s \
464                         user_by_hrn %s " %(requested_user_ids, users_by_hrn)) 
465       
466    
467         #Check that the user of the slice in the slice record
468         #matches the existing users 
469         try:
470             if slice_record['record_id_user'] in requested_user_ids and \
471                                 slice_record['PI'][0] in requested_user_hrns:
472                 logger.debug(" SLABSLICE  \tverify_person  \
473                         requested_user_ids %s = \
474                         slice_record['record_id_user'] %s" \
475                         %(requested_user_ids,slice_record['record_id_user']))
476            
477         except KeyError:
478             pass
479             
480       
481         # users to be added, removed or updated
482         #One user in one senslab slice : there should be no need
483         #to remove/ add any user from/to a slice.
484         #However a user from SFA which is not registered in Senslab yet
485         #should be added to the LDAP.
486
487         added_user_hrns = set(requested_user_hrns).\
488                                             difference(set(existing_user_hrns))
489
490         #self.verify_keys(existing_slice_users, updated_users_list, \
491                                                             #peer, append)
492
493         added_persons = []
494         # add new users
495         for added_user_hrn in added_user_hrns:
496             added_user = users_dict[added_user_hrn]
497             #hrn, type = urn_to_hrn(added_user['urn'])  
498             person = {
499                 #'first_name': added_user.get('first_name', hrn),
500                 #'last_name': added_user.get('last_name', hrn),
501                 'first_name': added_user['first_name'],
502                 'last_name': added_user['last_name'],
503                 'person_id': added_user['person_id'],
504                 'peer_person_id': None,
505                 'keys': [],
506                 'key_ids': added_user.get('key_ids', []),
507                 
508             } 
509             person['person_id'] = self.driver.AddPerson(person)
510             if peer:
511                 person['peer_person_id'] = added_user['person_id']
512             added_persons.append(person)
513            
514             # enable the account 
515             self.driver.UpdatePerson(person['person_id'], {'enabled': True})
516             
517             # add person to site
518             #self.driver.AddPersonToSite(added_user_id, login_base)
519
520             #for key_string in added_user.get('keys', []):
521                 #key = {'key':key_string, 'key_type':'ssh'}
522                 #key['key_id'] = self.driver.AddPersonKey(person['person_id'], \
523                                                 #                       key)
524                 #person['keys'].append(key)
525
526             # add the registry record
527             #if sfa_peer:
528                 #peer_dict = {'type': 'user', 'hrn': hrn, 'peer_authority': \
529                                                 #sfa_peer, \
530                                                 #'pointer': person['person_id']}
531                 #self.registry.register_peer_object(self.credential, peer_dict)
532         #for added_slice_user_hrn in \
533                                 #added_slice_user_hrns.union(added_user_hrns):
534             #self.driver.AddPersonToSlice(added_slice_user_hrn, \
535                                                     #slice_record['name'])
536         #for added_slice_user_id in \
537                                     #added_slice_user_ids.union(added_user_ids):
538             # add person to the slice 
539             #self.driver.AddPersonToSlice(added_slice_user_id, \
540                                                 #slice_record['name'])
541             # if this is a peer record then it 
542             # should already be bound to a peer.
543             # no need to return worry about it getting bound later 
544
545         return added_persons
546             
547     #Unused
548     def verify_keys(self, persons, users, peer, options={}):
549         # existing keys 
550         key_ids = []
551         for person in persons:
552             key_ids.extend(person['key_ids'])
553         keylist = self.driver.GetKeys(key_ids, ['key_id', 'key'])
554         keydict = {}
555         for key in keylist:
556             keydict[key['key']] = key['key_id']     
557         existing_keys = keydict.keys()
558         persondict = {}
559         for person in persons:
560             persondict[person['email']] = person    
561     
562         # add new keys
563         requested_keys = []
564         updated_persons = []
565         for user in users:
566             user_keys = user.get('keys', [])
567             updated_persons.append(user)
568             for key_string in user_keys:
569                 requested_keys.append(key_string)
570                 if key_string not in existing_keys:
571                     key = {'key': key_string, 'key_type': 'ssh'}
572                     try:
573                         if peer:
574                             person = persondict[user['email']]
575                             self.driver.UnBindObjectFromPeer('person', \
576                                         person['person_id'], peer['shortname'])
577                         key['key_id'] = \
578                                 self.driver.AddPersonKey(user['email'], key)
579                         if peer:
580                             key_index = user_keys.index(key['key'])
581                             remote_key_id = user['key_ids'][key_index]
582                             self.driver.BindObjectToPeer('key', \
583                                             key['key_id'], peer['shortname'], \
584                                             remote_key_id)
585                             
586                     finally:
587                         if peer:
588                             self.driver.BindObjectToPeer('person', \
589                                     person['person_id'], peer['shortname'], \
590                                     user['person_id'])
591         
592         # remove old keys (only if we are not appending)
593         append = options.get('append', True)
594         if append == False: 
595             removed_keys = set(existing_keys).difference(requested_keys)
596             for existing_key_id in keydict:
597                 if keydict[existing_key_id] in removed_keys:
598
599                     if peer:
600                         self.driver.UnBindObjectFromPeer('key', \
601                                         existing_key_id, peer['shortname'])
602                     self.driver.DeleteKey(existing_key_id)
603  
604
605     #def verify_slice_attributes(self, slice, requested_slice_attributes, \
606                                             #append=False, admin=False):
607         ## get list of attributes users ar able to manage
608         #filter = {'category': '*slice*'}
609         #if not admin:
610             #filter['|roles'] = ['user']
611         #slice_attributes = self.driver.GetTagTypes(filter)
612         #valid_slice_attribute_names = [attribute['tagname'] \
613                                             #for attribute in slice_attributes]
614
615         ## get sliver attributes
616         #added_slice_attributes = []
617         #removed_slice_attributes = []
618         #ignored_slice_attribute_names = []
619         #existing_slice_attributes = self.driver.GetSliceTags({'slice_id': \
620                                                             #slice['slice_id']})
621
622         ## get attributes that should be removed
623         #for slice_tag in existing_slice_attributes:
624             #if slice_tag['tagname'] in ignored_slice_attribute_names:
625                 ## If a slice already has a admin only role 
626                 ## it was probably given to them by an
627                 ## admin, so we should ignore it.
628                 #ignored_slice_attribute_names.append(slice_tag['tagname'])
629             #else:
630                 ## If an existing slice attribute was not 
631                 ## found in the request it should
632                 ## be removed
633                 #attribute_found=False
634                 #for requested_attribute in requested_slice_attributes:
635                     #if requested_attribute['name'] == slice_tag['tagname'] \
636                         #and requested_attribute['value'] == slice_tag['value']:
637                         #attribute_found=True
638                         #break
639
640             #if not attribute_found and not append:
641                 #removed_slice_attributes.append(slice_tag)
642         
643         ## get attributes that should be added:
644         #for requested_attribute in requested_slice_attributes:
645             ## if the requested attribute wasn't found  we should add it
646             #if requested_attribute['name'] in valid_slice_attribute_names:
647                 #attribute_found = False
648                 #for existing_attribute in existing_slice_attributes:
649                     #if requested_attribute['name'] == \
650                         #existing_attribute['tagname'] and \
651                        #requested_attribute['value'] == \
652                        #existing_attribute['value']:
653                         #attribute_found=True
654                         #break
655                 #if not attribute_found:
656                     #added_slice_attributes.append(requested_attribute)
657
658
659         ## remove stale attributes
660         #for attribute in removed_slice_attributes:
661             #try:
662                 #self.driver.DeleteSliceTag(attribute['slice_tag_id'])
663             #except Exception, error:
664                 #self.logger.warn('Failed to remove sliver attribute. name: \
665                                 #%s, value: %s, node_id: %s\nCause:%s'\
666                                 #% (name, value,  node_id, str(error)))
667
668         ## add requested_attributes
669         #for attribute in added_slice_attributes:
670             #try:
671                 #self.driver.AddSliceTag(slice['name'], attribute['name'], \
672                             #attribute['value'], attribute.get('node_id', None))
673             #except Exception, error:
674                 #self.logger.warn('Failed to add sliver attribute. name: %s, \
675                                 #value: %s, node_id: %s\nCause:%s'\
676                                 #% (name, value,  node_id, str(error)))
677
678