original_docstring: Find vhostuser connections with an attached VM
  
          The moment of VM attachment is useful, as it's one of the
          preconditions for notifying Nova a socket is ready.  Watching
          the vhostuser data inside VPP has a performance impact on
          forwarding, so instead we watch the kernel's idea of which
          vhostuser connections are properly opened.
  
          Having two open sockets is 99% ready - technically, the interface
          is ready when VPP has mapped its memory, but these two events are
          nearly contemporaenous, so this is good enough.
          
docstring: Find vhostuser connections with an attached VM
  The moment of VM attachment is useful, as it's one of the
  preconditions for notifying Nova a socket is ready.  Watching
  the vhostuser data inside VPP has a performance impact on
  forwarding, so instead we watch the kernel's idea of which
  vhostuser connections are properly opened.
  
  Having two open sockets is 99% ready - technically, the interface
  is ready when VPP has mapped its memory, but these two events are
  nearly contemporaenous, so this is good enough.
docstring_tokens: Find vhostuser connections with an attached VM The moment of VM attachment is useful as it ' s one of the preconditions for notifying Nova a socket is ready . Watching the vhostuser data inside VPP has a performance impact on forwarding so instead we watch the kernel ' s idea of which vhostuser connections are properly opened . Having two open sockets is 99% ready - technically the interface is ready when VPP has mapped its memory but these two events are nearly contemporaenous so this is good enough .
code: def vhost_notify_thread(self):
          """Find vhostuser connections with an attached VM
  
          The moment of VM attachment is useful, as it's one of the
          preconditions for notifying Nova a socket is ready.  Watching
          the vhostuser data inside VPP has a performance impact on
          forwarding, so instead we watch the kernel's idea of which
          vhostuser connections are properly opened.
  
          Having two open sockets is 99% ready - technically, the interface
          is ready when VPP has mapped its memory, but these two events are
          nearly contemporaenous, so this is good enough.
          """
          dirname = cfg.CONF.ml2_vpp.vhost_user_dir
          # We need dirname to have precisely one trailing slash.
          dirname = dirname.rstrip('/') + '/'
  
          while True:
              opens: Dict[str, int] = defaultdict(int)
  
              with open('/proc/net/unix') as content:
                  # Track unix sockets in vhost directory that are opened more
                  # than once
                  for f in content:
                      # Problems with fnames with spaces in, though
                      _, fname = f.rsplit(' ', 1)
                      if fname.startswith(dirname):
                          fname = fname[len(dirname):].rstrip("\n")
                          opens[fname] = opens[fname] + 1
  
              # Report on any sockets that are open exactly twice (VPP + KVM)
              # (note list clone so that we can delete entries)
              for f in list(opens.keys()):
                  if opens[f] != 2:
                      del opens[f]
  
              open_names: Set[str] = set(opens.keys())
              open_notifications: Set[str] = open_names - self.port_connected
              # .. we don't have to notify the port drops, that's fine
  
              # Update this *before* making callbacks so that this register is up
              # to date
              self.port_connected = open_names
              if self.vhost_ready_callback:
                  for uuid in open_notifications:
                      self.vhost_ready_callback(uuid)
  
              eventlet.sleep(1)
code_tokens: def vhost_notify_thread ( self ) : dirname = cfg . CONF . ml2_vpp . vhost_user_dir dirname = dirname . rstrip ( '/' ) + '/' while True : opens : Dict [ str , int ] = defaultdict ( int ) with open ( '/proc/net/unix' ) as content : for f in content : _ , fname = f . rsplit ( ' ' , 1 ) if fname . startswith ( dirname ) : fname = fname [ len ( dirname ) : ] . rstrip ( "\n" ) opens [ fname ] = opens [ fname ] + 1 for f in list ( opens . keys ( ) ) : if opens [ f ] != 2 : del opens [ f ] open_names : Set [ str ] = set ( opens . keys ( ) ) open_notifications : Set [ str ] = open_names - self . port_connected self . port_connected = open_names if self . vhost_ready_callback : for uuid in open_notifications : self . vhost_ready_callback ( uuid ) eventlet . sleep ( 1 )
short_docstring: Find vhostuser connections with an attached VM
  The moment of VM attachment is useful, as it's one of the
  preconditions for notifying Nova a socket is ready.
short_docstring_tokens: Find vhostuser connections with an attached VM The moment of VM attachment is useful as it ' s one of the preconditions for notifying Nova a socket is ready .
comment: """Find vhostuser connections with an attached VM
  
          The moment of VM attachment is useful, as it's one of the
          preconditions for notifying Nova a socket is ready.  Watching
          the vhostuser data inside VPP has a performance impact on
          forwarding, so instead we watch the kernel's idea of which
          vhostuser connections are properly opened.
  
          Having two open sockets is 99% ready - technically, the interface
          is ready when VPP has mapped its memory, but these two events are
          nearly contemporaenous, so this is good enough.
          """$SEP$# We need dirname to have precisely one trailing slash.$SEP$# Track unix sockets in vhost directory that are opened more$SEP$# than once$SEP$# Problems with fnames with spaces in, though$SEP$# Report on any sockets that are open exactly twice (VPP + KVM)$SEP$# (note list clone so that we can delete entries)$SEP$# .. we don't have to notify the port drops, that's fine$SEP$# Update this *before* making callbacks so that this register is up$SEP$# to date