Exemplo n.º 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}
Exemplo n.º 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
Exemplo n.º 3
0
    def _get_port_request(self, pod, project_id, subnets, security_groups):
        port_req_body = {
            'project_id': project_id,
            'name': self._get_port_name(pod),
            'network_id': self._get_network_id(subnets),
            'fixed_ips': ovu.osvif_to_neutron_fixed_ips(subnets),
            'device_owner': kl_const.DEVICE_OWNER,
            'admin_state_up': True
        }

        if security_groups:
            port_req_body['security_groups'] = security_groups

        return {'port': port_req_body}
Exemplo n.º 4
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}
    def test_osvif_to_neutron_fixed_ips(self):
        ip11 = '1.1.1.1'
        ip12 = '2.2.2.2'
        ip3 = '3.3.3.3'
        subnet_id_1 = str(uuid.uuid4())
        subnet_id_2 = str(uuid.uuid4())
        subnet_id_3 = str(uuid.uuid4())

        subnet_1 = osv_subnet.Subnet(ips=osv_fixed_ip.FixedIPList(objects=[
            osv_fixed_ip.FixedIP(address=ip11),
            osv_fixed_ip.FixedIP(address=ip12)
        ]))
        subnet_2 = osv_subnet.Subnet()
        subnet_3 = osv_subnet.Subnet(ips=osv_fixed_ip.FixedIPList(
            objects=[osv_fixed_ip.FixedIP(address=ip3)]))

        net1 = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_1]))
        net2 = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_2]))
        net3 = osv_network.Network(subnets=osv_subnet.SubnetList(
            objects=[subnet_3]))

        subnets = {subnet_id_1: net1, subnet_id_2: net2, subnet_id_3: net3}

        expected = [{
            'subnet_id': subnet_id_1,
            'ip_address': ip11
        }, {
            'subnet_id': subnet_id_1,
            'ip_address': ip12
        }, {
            'subnet_id': subnet_id_2
        }, {
            'subnet_id': subnet_id_3,
            'ip_address': ip3
        }]

        ret = ovu.osvif_to_neutron_fixed_ips(subnets)

        def _sort_key(e):
            return (e.get('subnet_id'), e.get('ip_address'))

        self.assertEqual(sorted(expected, key=_sort_key),
                         sorted(ret, key=_sort_key))
Exemplo n.º 6
0
    def _get_port_request(self, pod, project_id, subnets, security_groups,
                          unbound=False):
        port_req_body = {'project_id': project_id,
                         'name': self._get_port_name(pod),
                         'network_id': self._get_network_id(subnets),
                         'fixed_ips': ovu.osvif_to_neutron_fixed_ips(subnets),
                         'device_owner': kl_const.DEVICE_OWNER,
                         'device_id': self._get_device_id(pod),
                         'admin_state_up': True,
                         'binding:host_id': self._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 (available-port) and without device_id
        if unbound:
            port_req_body['name'] = 'available-port'
            port_req_body['device_id'] = ''

        if security_groups:
            port_req_body['security_groups'] = security_groups

        return {'port': port_req_body}