original_docstring: Fix or remove networks where uplinks have changed in config
  
          - fixes uplink interfaces from VPP where they've changed in
            config or where the config didn't fully get pushed
            to VPPFowarder
          - deletes interfaces and networks from VPP where the
            the physical network is no longer configured
          - evicts ports from bridges with no network
          
docstring: Fix or remove networks where uplinks have changed in config
  fixes uplink interfaces from VPP where they've changed in
  config or where the config didn't fully get pushed
  to VPPFowarder
  deletes interfaces and networks from VPP where the
  the physical network is no longer configured
  evicts ports from bridges with no network
docstring_tokens: Fix or remove networks where uplinks have changed in config fixes uplink interfaces from VPP where they ' ve changed in config or where the config didn ' t fully get pushed to VPPFowarder deletes interfaces and networks from VPP where the the physical network is no longer configured evicts ports from bridges with no network
code: def fix_physnets(self, physnets):
          """Fix or remove networks where uplinks have changed in config
  
          - fixes uplink interfaces from VPP where they've changed in
            config or where the config didn't fully get pushed
            to VPPFowarder
          - deletes interfaces and networks from VPP where the
            the physical network is no longer configured
          - evicts ports from bridges with no network
          """
  
          # One uplink per network
          uplink_ports_found = []
  
          # One physnet can serve multiple uplinks
          physnet_ports_found = {}
  
          for f in self.vpp.get_interfaces():
  
              # Find uplink ports on OpenStack networks
              uplink_data = decode_uplink_tag(f['tag'])
              if uplink_data is not None:
                  uplink_physnet, net_type, seg_id = uplink_data
                  uplink_ports_found.append([
                      uplink_physnet, net_type, seg_id,
                      f['sw_if_idx'],
                      f['sw_if_idx'] if f['sup_sw_if_idx'] is None
                      else f['sup_sw_if_idx']])
  
              # Find physical network ports
              physnet_name = decode_physnet_if_tag(f['tag'])
              if physnet_name is not None:
                  physnet_ports_found[physnet_name] = f['sw_if_idx']
  
          # Find physnets we intend according to the config
          configured_physnet_interfaces = {}
          for name, if_name in physnets.items():
              # Can be 'None', that's fine as it won't match anything later
              configured_physnet_interfaces[name] = \
                  self.vpp.get_ifidx_by_name(if_name)
  
          LOG.debug('Configured physnets %s',
                    ', '.join(sorted(configured_physnet_interfaces.keys())))
  
          for uplink_physnet, net_type, seg_id, sw_if_idx, sup_sw_if_idx \
                  in uplink_ports_found:
              # Delete networks with a physnet whose config changed
              if (uplink_physnet not in configured_physnet_interfaces
                      or (sup_sw_if_idx !=
                          configured_physnet_interfaces[uplink_physnet])):
                  LOG.warning('Deleting outdated network in VPP: net type '
                              '%(type)s physnet %(physnet)s seg id %(seg)s, '
                              'physnet if %(physif)d uplink %(uplinkif)d',
                              {'type': net_type,
                               'physnet': uplink_physnet,
                               'seg': str(seg_id),
                               'physif': sup_sw_if_idx,
                               'uplinkif': sw_if_idx})
                  if uplink_physnet not in configured_physnet_interfaces:
                      LOG.warning('This physnet is no longer in the config')
                  else:
                      LOG.warning(
                          'This physnet now uses interface '
                          '%(idx)d (%(physnet_name)s)',
                          {'idx': configured_physnet_interfaces[uplink_physnet],
                           'physnet_name': physnets[uplink_physnet]})
                  # This will remove ports from bridges, which means
                  # that they may be rebound back into networks later
                  # or may be deleted if no longer used.
                  self.delete_network_bridge_on_host(net_type,
                                                     sw_if_idx,
                                                     sw_if_idx)
  
          for name, if_idx in physnet_ports_found.items():
              if configured_physnet_interfaces.get(name, None) != if_idx:
                  # This configuration has changed.
                  # Untag the original physnet interface, which is no
                  # longer used as a physnet
                  LOG.warning('Removing old physnet from VPP: '
                              'physnet %(physnet_name)s interface %(idx)s',
                              {'physnet_name': name,
                               'idx': str(if_idx)})
  
                  # In case there was a flat network, make sure the flat
                  # network bridge no longer exists
                  self.delete_network_bridge_on_host('flat', if_idx, if_idx)
  
                  self.vpp.set_interface_tag(if_idx, None)
  
          # The remaining networks (with uplinks and bridge domains) are
          # functional, and idempotent binding will do nothing to
          # interfaces in the right bridges.  It will fix those in the
          # wrong bridges.
          # Dead bridges have been deleted and binding
          # will find a new home for the interfaces that still exist.
code_tokens: def fix_physnets ( self , physnets ) : uplink_ports_found = [ ] physnet_ports_found = { } for f in self . vpp . get_interfaces ( ) : uplink_data = decode_uplink_tag ( f [ 'tag' ] ) if uplink_data is not None : uplink_physnet , net_type , seg_id = uplink_data uplink_ports_found . append ( [ uplink_physnet , net_type , seg_id , f [ 'sw_if_idx' ] , f [ 'sw_if_idx' ] if f [ 'sup_sw_if_idx' ] is None else f [ 'sup_sw_if_idx' ] ] ) physnet_name = decode_physnet_if_tag ( f [ 'tag' ] ) if physnet_name is not None : physnet_ports_found [ physnet_name ] = f [ 'sw_if_idx' ] configured_physnet_interfaces = { } for name , if_name in physnets . items ( ) : configured_physnet_interfaces [ name ] = self . vpp . get_ifidx_by_name ( if_name ) LOG . debug ( 'Configured physnets %s' , ', ' . join ( sorted ( configured_physnet_interfaces . keys ( ) ) ) ) for uplink_physnet , net_type , seg_id , sw_if_idx , sup_sw_if_idx in uplink_ports_found : if ( uplink_physnet not in configured_physnet_interfaces or ( sup_sw_if_idx != configured_physnet_interfaces [ uplink_physnet ] ) ) : LOG . warning ( 'Deleting outdated network in VPP: net type ' '%(type)s physnet %(physnet)s seg id %(seg)s, ' 'physnet if %(physif)d uplink %(uplinkif)d' , { 'type' : net_type , 'physnet' : uplink_physnet , 'seg' : str ( seg_id ) , 'physif' : sup_sw_if_idx , 'uplinkif' : sw_if_idx } ) if uplink_physnet not in configured_physnet_interfaces : LOG . warning ( 'This physnet is no longer in the config' ) else : LOG . warning ( 'This physnet now uses interface ' '%(idx)d (%(physnet_name)s)' , { 'idx' : configured_physnet_interfaces [ uplink_physnet ] , 'physnet_name' : physnets [ uplink_physnet ] } ) self . delete_network_bridge_on_host ( net_type , sw_if_idx , sw_if_idx ) for name , if_idx in physnet_ports_found . items ( ) : if configured_physnet_interfaces . get ( name , None ) != if_idx : LOG . warning ( 'Removing old physnet from VPP: ' 'physnet %(physnet_name)s interface %(idx)s' , { 'physnet_name' : name , 'idx' : str ( if_idx ) } ) self . delete_network_bridge_on_host ( 'flat' , if_idx , if_idx ) self . vpp . set_interface_tag ( if_idx , None )
short_docstring: Fix or remove networks where uplinks have changed in config
   fixes uplink interfaces from VPP where they've changed in
  config or where the config didn't fully get pushed
  to VPPFowarder
   deletes interfaces and networks from VPP where the
  the physical network is no longer configured
   evicts ports from bridges with no network
short_docstring_tokens: Fix or remove networks where uplinks have changed in config fixes uplink interfaces from VPP where they ' ve changed in config or where the config didn ' t fully get pushed to VPPFowarder deletes interfaces and networks from VPP where the the physical network is no longer configured evicts ports from bridges with no network
comment: """Fix or remove networks where uplinks have changed in config
  
          - fixes uplink interfaces from VPP where they've changed in
            config or where the config didn't fully get pushed
            to VPPFowarder
          - deletes interfaces and networks from VPP where the
            the physical network is no longer configured
          - evicts ports from bridges with no network
          """$SEP$# One uplink per network$SEP$# One physnet can serve multiple uplinks$SEP$# Find uplink ports on OpenStack networks$SEP$# Find physical network ports$SEP$# Find physnets we intend according to the config$SEP$# Can be 'None', that's fine as it won't match anything later$SEP$# Delete networks with a physnet whose config changed$SEP$# This will remove ports from bridges, which means$SEP$# that they may be rebound back into networks later$SEP$# or may be deleted if no longer used.$SEP$# This configuration has changed.$SEP$# Untag the original physnet interface, which is no$SEP$# longer used as a physnet$SEP$# In case there was a flat network, make sure the flat$SEP$# network bridge no longer exists$SEP$# The remaining networks (with uplinks and bridge domains) are$SEP$# functional, and idempotent binding will do nothing to$SEP$# interfaces in the right bridges.  It will fix those in the$SEP$# wrong bridges.$SEP$# Dead bridges have been deleted and binding$SEP$# will find a new home for the interfaces that still exist.