original_docstring: Bind or unbind the subports of the parent ports as needed.
  
          To unbind all bound subports of a parent port, provide the
          parent_port argument with subports set to an empty list.
          Sample subports data structure: List of dicts
  
          [{"segmentation_id": 11,
           "uplink_seg_id": 149,
           "segmentation_type": "vlan",
           "uplink_seg_type": "vlan",
           "port_id": "9ee91c37-9150-49ff-9ea7-48e98547771a",
           "physnet": "physnet1",
           "allowed_address_pairs": [],
           "port_security_enabled": true,
           "security_groups": ["8d55a44a-935d-4296-99ab-b0749b725df4"],
           "bound_callback" : bind_notifier_object,
           },
  
           {"segmentation_id": 12,
            "uplink_seg_id": 139,
            "segmentation_type": "vlan",
            "uplink_seg_type": "vlan",
            "port_id": "2b1a89ba-78f1-4350-b71a-7caf7f23cbcf",
            "physnet": "physnet1",
            "allowed_address_pairs": [],
            "port_security_enabled": true,
            "security_groups": ["8d55a44a-935d-4296-99ab-b0749b725df4"],
            "bound_callback" : bind_notifier_object,
            }
            ]
  
          
docstring: Bind or unbind the subports of the parent ports as needed.
  To unbind all bound subports of a parent port, provide the
  parent_port argument with subports set to an empty list.
  Sample subports data structure: List of dicts
  
  
  
  
docstring_tokens: Bind or unbind the subports of the parent ports as needed . To unbind all bound subports of a parent port provide the parent_port argument with subports set to an empty list . Sample subports data structure : List of dicts
code: def bind_unbind_subports(self, parent_port, subports):
          """Bind or unbind the subports of the parent ports as needed.
  
          To unbind all bound subports of a parent port, provide the
          parent_port argument with subports set to an empty list.
          Sample subports data structure: List of dicts
  
          [{"segmentation_id": 11,
           "uplink_seg_id": 149,
           "segmentation_type": "vlan",
           "uplink_seg_type": "vlan",
           "port_id": "9ee91c37-9150-49ff-9ea7-48e98547771a",
           "physnet": "physnet1",
           "allowed_address_pairs": [],
           "port_security_enabled": true,
           "security_groups": ["8d55a44a-935d-4296-99ab-b0749b725df4"],
           "bound_callback" : bind_notifier_object,
           },
  
           {"segmentation_id": 12,
            "uplink_seg_id": 139,
            "segmentation_type": "vlan",
            "uplink_seg_type": "vlan",
            "port_id": "2b1a89ba-78f1-4350-b71a-7caf7f23cbcf",
            "physnet": "physnet1",
            "allowed_address_pairs": [],
            "port_security_enabled": true,
            "security_groups": ["8d55a44a-935d-4296-99ab-b0749b725df4"],
            "bound_callback" : bind_notifier_object,
            }
            ]
  
          """
          LOG.debug('Binding or Unbinding subports %s of parent trunk port %s',
                    subports, parent_port)
          subport_set = set([p['port_id'] for p in subports])
          subports_to_bind = self.subports_to_bind(parent_port, subport_set)
          LOG.debug('Binding subports %s of a parent trunk port %s',
                    subports_to_bind, parent_port)
          subports_to_unbind = self.subports_to_unbind(parent_port,
                                                       subport_set)
          LOG.debug('Unbinding subports %s of a parent trunk port %s',
                    subports_to_unbind, parent_port)
          # bind subports we are told to bind
          for subport in subports_to_bind:
              subport_data = [p for p in subports
                              if p['port_id'] == subport][0]
              LOG.debug('Binding subport %s of parent trunk port %s '
                        'sub_port_data %s',
                        subport, parent_port, subport_data)
              props = self.vppf.bind_subport_on_host(parent_port, subport_data)
              # Bring up the subport
              if props:
                  self.bound_subports[parent_port].add(subport)
                  subport_iface_idx = props['iface_idx']
                  LOG.debug("Bringing up the trunk subport vhost ifidx %s",
                            subport_iface_idx)
                  self.vppf.ifup(subport_iface_idx)
                  # Set port security on subport
                  LOG.debug("Setting port security on trunk subport ifidx %s",
                            subport_iface_idx)
                  port_security_enabled = subport_data.get(
                      'port_security_enabled',
                      True)
                  if port_security_enabled:
                      self.iface_awaiting_secgroups[subport_iface_idx] = \
                          subport_data.get('security_groups', [])
                  else:
                      self.iface_awaiting_secgroups[subport_iface_idx] = None
                  id = subport_data['port_id']
                  self.iface_state[subport_iface_idx] = (
                      id,
                      subport_data['bound_callback'],
                      props
                      )
                  self.iface_state_ifidx[id] = subport_iface_idx
                  self.apply_spoof_macip(subport_iface_idx, subport_data, props)
                  self.maybe_apply_secgroups(subport_iface_idx)
          # unbind subports we are told to unbind
          for subport in subports_to_unbind:
              LOG.debug('Unbinding subport %s of parent_port %s',
                        subport, parent_port)
              if self.iface_state_ifidx[subport] in self.iface_state:
                  del self.iface_state[self.iface_state_ifidx[subport]]
              del self.iface_state_ifidx[subport]
              self.vppf.unbind_subport_on_host(subport)
              self.bound_subports[parent_port].remove(subport)
code_tokens: def bind_unbind_subports ( self , parent_port , subports ) : LOG . debug ( 'Binding or Unbinding subports %s of parent trunk port %s' , subports , parent_port ) subport_set = set ( [ p [ 'port_id' ] for p in subports ] ) subports_to_bind = self . subports_to_bind ( parent_port , subport_set ) LOG . debug ( 'Binding subports %s of a parent trunk port %s' , subports_to_bind , parent_port ) subports_to_unbind = self . subports_to_unbind ( parent_port , subport_set ) LOG . debug ( 'Unbinding subports %s of a parent trunk port %s' , subports_to_unbind , parent_port ) for subport in subports_to_bind : subport_data = [ p for p in subports if p [ 'port_id' ] == subport ] [ 0 ] LOG . debug ( 'Binding subport %s of parent trunk port %s ' 'sub_port_data %s' , subport , parent_port , subport_data ) props = self . vppf . bind_subport_on_host ( parent_port , subport_data ) if props : self . bound_subports [ parent_port ] . add ( subport ) subport_iface_idx = props [ 'iface_idx' ] LOG . debug ( "Bringing up the trunk subport vhost ifidx %s" , subport_iface_idx ) self . vppf . ifup ( subport_iface_idx ) LOG . debug ( "Setting port security on trunk subport ifidx %s" , subport_iface_idx ) port_security_enabled = subport_data . get ( 'port_security_enabled' , True ) if port_security_enabled : self . iface_awaiting_secgroups [ subport_iface_idx ] = subport_data . get ( 'security_groups' , [ ] ) else : self . iface_awaiting_secgroups [ subport_iface_idx ] = None id = subport_data [ 'port_id' ] self . iface_state [ subport_iface_idx ] = ( id , subport_data [ 'bound_callback' ] , props ) self . iface_state_ifidx [ id ] = subport_iface_idx self . apply_spoof_macip ( subport_iface_idx , subport_data , props ) self . maybe_apply_secgroups ( subport_iface_idx ) for subport in subports_to_unbind : LOG . debug ( 'Unbinding subport %s of parent_port %s' , subport , parent_port ) if self . iface_state_ifidx [ subport ] in self . iface_state : del self . iface_state [ self . iface_state_ifidx [ subport ] ] del self . iface_state_ifidx [ subport ] self . vppf . unbind_subport_on_host ( subport ) self . bound_subports [ parent_port ] . remove ( subport )
short_docstring: Bind or unbind the subports of the parent ports as needed.
short_docstring_tokens: Bind or unbind the subports of the parent ports as needed .
comment: """Bind or unbind the subports of the parent ports as needed.
  
          To unbind all bound subports of a parent port, provide the
          parent_port argument with subports set to an empty list.
          Sample subports data structure: List of dicts
  
          [{"segmentation_id": 11,
           "uplink_seg_id": 149,
           "segmentation_type": "vlan",
           "uplink_seg_type": "vlan",
           "port_id": "9ee91c37-9150-49ff-9ea7-48e98547771a",
           "physnet": "physnet1",
           "allowed_address_pairs": [],
           "port_security_enabled": true,
           "security_groups": ["8d55a44a-935d-4296-99ab-b0749b725df4"],
           "bound_callback" : bind_notifier_object,
           },
  
           {"segmentation_id": 12,
            "uplink_seg_id": 139,
            "segmentation_type": "vlan",
            "uplink_seg_type": "vlan",
            "port_id": "2b1a89ba-78f1-4350-b71a-7caf7f23cbcf",
            "physnet": "physnet1",
            "allowed_address_pairs": [],
            "port_security_enabled": true,
            "security_groups": ["8d55a44a-935d-4296-99ab-b0749b725df4"],
            "bound_callback" : bind_notifier_object,
            }
            ]
  
          """$SEP$# bind subports we are told to bind$SEP$# Bring up the subport$SEP$# Set port security on subport$SEP$# unbind subports we are told to unbind