original_docstring: Create or update vpp interface on host based on if_type.
  
          Depending on the if_type (maketap, plugtap or vhostuser) call vpp papi
          to do vpp side of the plumbing. This will change depending on the
          if_type. The interfaces are tagged saved in the internal dict for easy
          retrieval.
  
          The call is idempotent if the uuid and its associated
          interface is already present.
  
          :return: dict indexed on uuid
          
docstring: Create or update vpp interface on host based on if_type.
  Depending on the if_type (maketap, plugtap or vhostuser) call vpp papi
  to do vpp side of the plumbing. This will change depending on the
  if_type. The interfaces are tagged saved in the internal dict for easy
  retrieval.
  
  The call is idempotent if the uuid and its associated
  interface is already present.
docstring_tokens: Create or update vpp interface on host based on if_type . Depending on the if_type ( maketap plugtap or vhostuser ) call vpp papi to do vpp side of the plumbing . This will change depending on the if_type . The interfaces are tagged saved in the internal dict for easy retrieval . The call is idempotent if the uuid and its associated interface is already present .
code: def ensure_interface_on_host(self, if_type, uuid, mac=None):
          """Create or update vpp interface on host based on if_type.
  
          Depending on the if_type (maketap, plugtap or vhostuser) call vpp papi
          to do vpp side of the plumbing. This will change depending on the
          if_type. The interfaces are tagged saved in the internal dict for easy
          retrieval.
  
          The call is idempotent if the uuid and its associated
          interface is already present.
  
          :return: dict indexed on uuid
          """
  
          if uuid in self.interfaces:
              # It's definitely there, we made it ourselves
              pass
          else:
              # TODO(ijw): it may exist, but we may need to create it
              # - and what exists may be wrong so we may have to
              # recreate it
              # TODO(ijw): idempotency
  
              LOG.debug('Creating port %s as type %s with mac %s',
                        uuid, if_type, mac)
  
              # Deal with the naming conventions of interfaces
  
              # TODO(ijw): naming not obviously consistent with
              # Neutron's naming
              tap_name = get_tap_name(uuid)
  
              # TODO(ijw) structured type
              props: dict
  
              if if_type == 'tap':
                  bridge_name = get_bridge_name(uuid)
                  int_tap_name = get_vpptap_name(uuid)
  
                  props = {'bridge_name': bridge_name,
                           'ext_tap_name': tap_name,
                           'int_tap_name': int_tap_name}
              elif if_type == 'vhostuser':
                  path = get_vhostuser_name(uuid)
                  props = {'path': path}
              else:
                  raise UnsupportedInterfaceException()
  
              tag = port_tag(uuid)
  
              props['bind_type'] = if_type
              # NB(onong): In case the if_type is vhostuser then this is the
              # neutron port's/VM's mac and it has implications for gpe networks
              # so please be mindful before altering this
              props['mac'] = mac
  
              iface_idx = self.vpp.get_ifidx_by_tag(tag)
              if iface_idx is not None:
                  # The agent has at some point reset, but before the reset
                  # this interface was at least created.  A previous sweep
                  # will have ensured it's the right sort of interface.
  
                  LOG.debug('port %s recovering existing port in VPP',
                            uuid)
  
              else:
                  # Make an interface, and tag it for refinding.
                  LOG.debug('binding port %s as type %s' %
                            (uuid, if_type))
  
                  if if_type == 'tap':
                      iface_idx = self.vpp.create_tap(int_tap_name, mac=None,
                                                      tag=tag)
                  elif if_type == 'vhostuser':
                      iface_idx = self.vpp.create_vhostuser(path, tag)
  
              if if_type == 'tap':
                  # Plugtap interfaces belong in a kernel bridge, and we need
                  # to monitor for the other side attaching.
                  self._ensure_kernelside_tap(bridge_name,
                                              tap_name,
                                              int_tap_name)
  
              props['iface_idx'] = iface_idx
              self.interfaces[uuid] = props
          return self.interfaces[uuid]
code_tokens: def ensure_interface_on_host ( self , if_type , uuid , mac = None ) : if uuid in self . interfaces : pass else : LOG . debug ( 'Creating port %s as type %s with mac %s' , uuid , if_type , mac ) tap_name = get_tap_name ( uuid ) props : dict if if_type == 'tap' : bridge_name = get_bridge_name ( uuid ) int_tap_name = get_vpptap_name ( uuid ) props = { 'bridge_name' : bridge_name , 'ext_tap_name' : tap_name , 'int_tap_name' : int_tap_name } elif if_type == 'vhostuser' : path = get_vhostuser_name ( uuid ) props = { 'path' : path } else : raise UnsupportedInterfaceException ( ) tag = port_tag ( uuid ) props [ 'bind_type' ] = if_type props [ 'mac' ] = mac iface_idx = self . vpp . get_ifidx_by_tag ( tag ) if iface_idx is not None : LOG . debug ( 'port %s recovering existing port in VPP' , uuid ) else : LOG . debug ( 'binding port %s as type %s' % ( uuid , if_type ) ) if if_type == 'tap' : iface_idx = self . vpp . create_tap ( int_tap_name , mac = None , tag = tag ) elif if_type == 'vhostuser' : iface_idx = self . vpp . create_vhostuser ( path , tag ) if if_type == 'tap' : self . _ensure_kernelside_tap ( bridge_name , tap_name , int_tap_name ) props [ 'iface_idx' ] = iface_idx self . interfaces [ uuid ] = props return self . interfaces [ uuid ]
short_docstring: Create or update vpp interface on host based on if_type.
short_docstring_tokens: Create or update vpp interface on host based on if_type .
comment: """Create or update vpp interface on host based on if_type.
  
          Depending on the if_type (maketap, plugtap or vhostuser) call vpp papi
          to do vpp side of the plumbing. This will change depending on the
          if_type. The interfaces are tagged saved in the internal dict for easy
          retrieval.
  
          The call is idempotent if the uuid and its associated
          interface is already present.
  
          :return: dict indexed on uuid
          """$SEP$# It's definitely there, we made it ourselves$SEP$# TODO(ijw): it may exist, but we may need to create it$SEP$# - and what exists may be wrong so we may have to$SEP$# recreate it$SEP$# TODO(ijw): idempotency$SEP$# Deal with the naming conventions of interfaces$SEP$# TODO(ijw): naming not obviously consistent with$SEP$# Neutron's naming$SEP$# TODO(ijw) structured type$SEP$# NB(onong): In case the if_type is vhostuser then this is the$SEP$# neutron port's/VM's mac and it has implications for gpe networks$SEP$# so please be mindful before altering this$SEP$# The agent has at some point reset, but before the reset$SEP$# this interface was at least created.  A previous sweep$SEP$# will have ensured it's the right sort of interface.$SEP$# Make an interface, and tag it for refinding.$SEP$# Plugtap interfaces belong in a kernel bridge, and we need$SEP$# to monitor for the other side attaching.