示例#1
0
    def _make_request(self, path, cni_envs, expected_status=None):
        method = 'POST'

        address = config.CONF.cni_daemon.bind_address
        url = 'http://%s/%s' % (address, path)
        try:
            LOG.debug(
                'Making request to CNI Daemon. %(method)s %(path)s\n'
                '%(body)s', {
                    'method': method,
                    'path': url,
                    'body': cni_envs
                })
            resp = requests.post(url,
                                 json=cni_envs,
                                 headers={'Connection': 'close'})
        except requests.ConnectionError:
            LOG.exception(
                'Looks like %s cannot be reached. Is kuryr-daemon '
                'running?', address)
            raise
        LOG.debug('CNI Daemon returned "%(status)d %(reason)s".', {
            'status': resp.status_code,
            'reason': resp.reason
        })
        if expected_status and resp.status_code != expected_status:
            LOG.error('CNI daemon returned error "%(status)d %(reason)s".', {
                'status': resp.status_code,
                'reason': resp.reason
            })
            raise k_exc.CNIError('Got invalid status code from CNI daemon.')
        return resp
示例#2
0
    def connect(self, vif, ifname, netns):
        physnet = vif.physnet

        h_ipdb = b_base.get_ipdb()
        c_ipdb = b_base.get_ipdb(netns)

        pf_names = self._get_host_pf_names(physnet)
        vf_name, vf_index, pf = self._get_available_vf_info(pf_names)

        if not vf_name:
            error_msg = "No free interfaces for pfysnet {} available".format(
                physnet)
            LOG.error(error_msg)
            raise exceptions.CNIError(error_msg)

        if vif.network.should_provide_vlan:
            vlan_id = vif.network.vlan
            self._set_vf_vlan(pf, vf_index, vlan_id)

        with h_ipdb.interfaces[vf_name] as host_iface:
            host_iface.net_ns_fd = utils.convert_netns(netns)

        with c_ipdb.interfaces[vf_name] as iface:
            iface.ifname = ifname
            iface.address = vif.address
            iface.mtu = vif.network.mtu
            iface.up()
示例#3
0
    def connect(self, vif, ifname, netns, container_id):
        physnet = vif.physnet
        pf_names = self._get_host_pf_names(physnet)
        vf_name, vf_index, pf, pci_info = self._get_available_vf_info(pf_names)

        if not vf_name:
            raise exceptions.CNIError(
                "No free interfaces for physnet {} available".format(physnet))

        LOG.debug("Connect {} as {} (port_id={}) in container_id={}".format(
            vf_name, ifname, vif.id, container_id))

        if vif.network.should_provide_vlan:
            vlan_id = vif.network.vlan
            self._set_vf_vlan(pf, vf_index, vlan_id)

        self._set_vf_mac(pf, vf_index, vif.address)

        with b_base.get_ipdb() as h_ipdb, b_base.get_ipdb(netns) as c_ipdb:
            with h_ipdb.interfaces[vf_name] as host_iface:
                host_iface.net_ns_fd = utils.convert_netns(netns)

            with c_ipdb.interfaces[vf_name] as iface:
                iface.ifname = ifname
                iface.mtu = vif.network.mtu
                iface.up()

        self._save_pci_info(vif.id, pci_info)
示例#4
0
    def run(self, env, fin, fout):
        try:
            params = CNIParameters(env, jsonutils.load(fin))

            if params.CNI_COMMAND == 'ADD':
                vif = self._plugin.add(params)
                self._write_vif(fout, vif)
            elif params.CNI_COMMAND == 'DEL':
                self._plugin.delete(params)
            elif params.CNI_COMMAND == 'VERSION':
                self._write_version(fout)
            else:
                raise k_exc.CNIError(
                    _LE("unknown CNI_COMMAND: %s") % params.CNI_COMMAND)
        except Exception as ex:
            # LOG.exception
            self._write_exception(fout, str(ex))
            return 1
示例#5
0
    def _process_vif(self, vif, ifname, netns):
        pr_client = clients.get_pod_resources_client()
        pod_resources_list = pr_client.list()
        resources = pod_resources_list.pod_resources
        pod_name = vif.pod_name
        pod_link = vif.pod_link
        physnet = vif.physnet
        resource_name = self._get_resource_by_physnet(physnet)
        driver = self._get_driver_by_res(resource_name)
        resource = self._make_resource(resource_name)
        LOG.debug(
            "Vif %s will correspond to pci device belonging to "
            "resource %s", vif, resource)
        pod_devices = self._get_pod_devices(pod_link)
        pod_resource = None
        container_devices = None
        for res in resources:
            if res.name == pod_name:
                pod_resource = res
                break
        if not pod_resource:
            raise exceptions.CNIError(
                "No resources are discovered for pod {}".format(pod_name))
        LOG.debug(
            "Looking for PCI device used by kubelet service and not "
            "used by pod %s yet ...", pod_name)
        for container in pod_resource.containers:
            try:
                container_devices = container.devices
            except Exception:
                LOG.warning("No devices in container %s", container.name)
                continue

            for dev in container_devices:
                if dev.resource_name != resource:
                    continue

                for pci in dev.device_ids:
                    if pci in pod_devices:
                        continue
                    LOG.debug("Appropriate PCI device %s is found", pci)
                    pci_info = self._compute_pci(pci, driver, pod_link, vif,
                                                 ifname, netns)
                    return pci_info
示例#6
0
 def run(self, env, fin, fout):
     try:
         # Prepare params according to calling Object
         params = self.prepare_env(env, fin)
         if env.get('CNI_COMMAND') == 'ADD':
             vif = self._add(params)
             self._write_dict(fout, vif)
         elif env.get('CNI_COMMAND') == 'DEL':
             self._delete(params)
         elif env.get('CNI_COMMAND') == 'VERSION':
             self._write_version(fout)
         else:
             raise k_exc.CNIError(
                 _("unknown CNI_COMMAND: %s") % env['CNI_COMMAND'])
         return 0
     except Exception as ex:
         # LOG.exception
         self._write_exception(fout, str(ex))
         return 1
示例#7
0
    def connect(self, vif, ifname, netns, container_id):
        port_name = _get_vhostuser_port_name(vif)
        self._write_config(container_id, ifname, port_name, vif)
        # no need to copy in case of SERVER mode
        if vif.mode == osv_fields.VIFVHostUserMode.SERVER:
            return

        src_vhu_sock = os.path.join(self.ovs_vu_path, port_name)

        if _check_sock_file(src_vhu_sock):
            dst_vhu_sock = os.path.join(vif.path, port_name)
            LOG.debug("Moving %s to %s while processing VIF %s", src_vhu_sock,
                      dst_vhu_sock, vif.id)
            os.rename(src_vhu_sock, dst_vhu_sock)
        else:
            error_msg = ("Socket %s required for VIF %s doesn't exist" %
                         (src_vhu_sock, vif.id))
            LOG.error(error_msg)
            raise k_exc.CNIError(error_msg)