예제 #1
0
 def on_done(self, pod, vifs):
     pod_name = utils.get_pod_unique_name(pod)
     vif_dict = {
         ifname: vif.obj_to_primitive() for
         ifname, vif in vifs.items()
     }
     # NOTE(dulek): We need a lock when modifying shared self.registry dict
     #              to prevent race conditions with other processes/threads.
     with lockutils.lock(pod_name, external=True):
         if pod_name not in self.registry:
             self.registry[pod_name] = {'pod': pod, 'vifs': vif_dict,
                                        'containerid': None,
                                        'vif_unplugged': False,
                                        'del_received': False}
         else:
             # NOTE(dulek): Only update vif if its status changed, we don't
             #              need to care about other changes now.
             old_vifs = {
                 ifname:
                     base.VersionedObject.obj_from_primitive(vif_obj) for
                     ifname, vif_obj in (
                         self.registry[pod_name]['vifs'].items())
             }
             for iface in vifs:
                 if old_vifs[iface].active != vifs[iface].active:
                     pod_dict = self.registry[pod_name]
                     pod_dict['vifs'] = vif_dict
                     self.registry[pod_name] = pod_dict
예제 #2
0
 def on_deleted(self, pod):
     pod_name = utils.get_pod_unique_name(pod)
     try:
         if pod_name in self.registry:
             # NOTE(dulek): del on dict is atomic as long as we use standard
             #              types as keys. This is the case, so we don't
             #              need to lock here.
             del self.registry[pod_name]
     except KeyError:
         # This means someone else removed it. It's odd but safe to ignore.
         pass
예제 #3
0
 def on_done(self, pod, vif):
     pod_name = utils.get_pod_unique_name(pod)
     vif_dict = vif.obj_to_primitive()
     # NOTE(dulek): We need a lock when modifying shared self.registry dict
     #              to prevent race conditions with other processes/threads.
     with lockutils.lock(pod_name, external=True):
         if pod_name not in self.registry:
             self.registry[pod_name] = {'pod': pod, 'vif': vif_dict,
                                        'containerid': None}
         else:
             # NOTE(dulek): Only update vif if its status changed, we don't
             #              need to care about other changes now.
             old_vif = base.VersionedObject.obj_from_primitive(
                 self.registry[pod_name]['vif'])
             if old_vif.active != vif.active:
                 pod_dict = self.registry[pod_name]
                 pod_dict['vif'] = vif_dict
                 self.registry[pod_name] = pod_dict
예제 #4
0
 def on_deleted(self, pod):
     pod_name = utils.get_pod_unique_name(pod)
     try:
         if pod_name in self.registry:
             # NOTE(ndesh): We need to lock here to avoid race condition
             #              with the deletion code for CNI DEL so that
             #              we delete the registry entry exactly once
             with lockutils.lock(pod_name, external=True):
                 if self.registry[pod_name]['vif_unplugged']:
                     del self.registry[pod_name]
                 else:
                     pod_dict = self.registry[pod_name]
                     pod_dict['del_received'] = True
                     self.registry[pod_name] = pod_dict
     except KeyError:
         # This means someone else removed it. It's odd but safe to ignore.
         LOG.debug('Pod %s entry already removed from registry while '
                   'handling DELETED event. Ignoring.', pod_name)
         pass