示例#1
0
    def _get_port_request(self,
                          pod,
                          project_id,
                          subnets,
                          security_groups,
                          unbound=False):
        port_req_body = {
            'project_id': project_id,
            'network_id': utils.get_network_id(subnets),
            'fixed_ips': ovu.osvif_to_neutron_fixed_ips(subnets),
            'device_owner': kl_const.DEVICE_OWNER,
            'admin_state_up': True,
            'binding:host_id': utils.get_host_id(pod)
        }

        # if unbound argument is set to true, it means the port requested
        # should not be bound and not associated to the pod. Thus the port dict
        # is filled with a generic name (constants.KURYR_PORT_NAME) if
        # port_debug is enabled, and without device_id
        if unbound and config.CONF.kubernetes.port_debug:
            port_req_body['name'] = constants.KURYR_PORT_NAME
        else:
            # only set the name if port_debug is enabled
            if config.CONF.kubernetes.port_debug:
                port_req_body['name'] = utils.get_port_name(pod)
            port_req_body['device_id'] = utils.get_device_id(pod)

        if security_groups:
            port_req_body['security_groups'] = security_groups

        return {'port': port_req_body}
示例#2
0
    def _get_port_request(self,
                          pod,
                          project_id,
                          subnets,
                          security_groups,
                          unbound=False):
        port_req_body = {
            'project_id': project_id,
            'network_id': utils.get_network_id(subnets),
            'fixed_ips': ovu.osvif_to_neutron_fixed_ips(subnets),
            'device_owner': kl_const.DEVICE_OWNER,
            'admin_state_up': True
        }

        # only set name if port_debug is enabled
        if config.CONF.kubernetes.port_debug:
            if unbound:
                port_req_body['name'] = constants.KURYR_PORT_NAME
            else:
                port_req_body['name'] = utils.get_port_name(pod)

        if security_groups:
            port_req_body['security_groups'] = security_groups

        return port_req_body
示例#3
0
 def _get_port_from_pool(self, pool_key, pod, subnets, security_groups):
     try:
         pool_ports = self._available_ports_pools[pool_key]
     except (KeyError, AttributeError):
         raise exceptions.ResourceNotReady(pod)
     try:
         port_id = pool_ports[security_groups].pop()
     except (KeyError, IndexError):
         # Get another port from the pool and update the SG to the
         # appropriate one. It uses a port from the group that was updated
         # longer ago
         pool_updates = self._last_update.get(pool_key, {})
         if not pool_updates:
             # No pools update info. Selecting a random one
             for sg_group, ports in pool_ports.items():
                 if len(ports) > 0:
                     port_id = pool_ports[sg_group].pop()
                     break
             else:
                 raise exceptions.ResourceNotReady(pod)
         else:
             min_date = -1
             for sg_group, date in pool_updates.items():
                 if pool_ports.get(sg_group):
                     if min_date == -1 or date < min_date:
                         min_date = date
                         min_sg_group = sg_group
             if min_date == -1:
                 # pool is empty, no port to reuse
                 raise exceptions.ResourceNotReady(pod)
             port_id = pool_ports[min_sg_group].pop()
         neutron = clients.get_neutron_client()
         neutron.update_port(
             port_id,
             {
                 "port": {
                     'security_groups': list(security_groups)
                 }
             })
     if config.CONF.kubernetes.port_debug:
         neutron = clients.get_neutron_client()
         neutron.update_port(
             port_id,
             {
                 "port": {
                     'name': c_utils.get_port_name(pod),
                     'device_id': pod['metadata']['uid']
                 }
             })
     # check if the pool needs to be populated
     if (self._get_pool_size(pool_key) <
             oslo_cfg.CONF.vif_pool.ports_pool_min):
         eventlet.spawn(self._populate_pool, pool_key, pod, subnets,
                        security_groups)
     return self._existing_vifs[port_id]
示例#4
0
 def _get_port_from_pool(self, pool_key, pod, subnets):
     try:
         port_id = self._available_ports_pools[pool_key].pop()
     except (IndexError, AttributeError):
         raise exceptions.ResourceNotReady(pod)
     if config.CONF.kubernetes.port_debug:
         neutron = clients.get_neutron_client()
         neutron.update_port(
             port_id, {"port": {
                 'name': c_utils.get_port_name(pod),
             }})
     # check if the pool needs to be populated
     if (self._get_pool_size(pool_key) <
             oslo_cfg.CONF.vif_pool.ports_pool_min):
         eventlet.spawn(self._populate_pool, pool_key, pod, subnets)
     return self._existing_vifs[port_id]
示例#5
0
    def _get_port_request(self, pod, project_id, subnets, security_groups):
        port_req_body = {
            'project_id': project_id,
            'name': c_utils.get_port_name(pod),
            'network_id': c_utils.get_network_id(subnets),
            'fixed_ips': ovu.osvif_to_neutron_fixed_ips(subnets),
            'device_owner': kl_const.DEVICE_OWNER + ':sriov',
            'device_id': c_utils.get_device_id(pod),
            'admin_state_up': True,
            'binding:vnic_type': 'direct',
            'binding:host_id': c_utils.get_host_id(pod),
        }

        if security_groups:
            port_req_body['security_groups'] = security_groups

        return {'port': port_req_body}
示例#6
0
    def test_get_port_name(self):
        pod_name = mock.sentinel.pod_name
        port_name = 'default/' + str(pod_name)
        pod = {'metadata': {'name': pod_name, 'namespace': 'default'}}

        self.assertEqual(port_name, utils.get_port_name(pod))