Esempio n. 1
0
    def get_vf_state(self, vf_index):
        """Get vf state {enable/disable/auto}

        @param vf_index: vf index
        """
        try:
            out = self._as_root([], "link", ("show", self.dev_name))
        except Exception as e:
            LOG.exception("Failed executing ip command")
            raise exc.IpCommandDeviceError(dev_name=self.dev_name, reason=e)
        vf_lines = self._get_vf_link_show([vf_index], out)
        if vf_lines:
            vf_details = self._parse_vf_link_show(vf_lines[0])
            if vf_details:
                state = vf_details.get("link-state", LinkState.DISABLE)
            if state in (LinkState.AUTO, LinkState.ENABLE):
                return state
        return LinkState.DISABLE
Esempio n. 2
0
    def get_vf_state(self, vf_index):
        """Get vf state {True/False}

        @param vf_index: vf index
        @todo: Handle "auto" state
        """
        try:
            out = self._as_root([], "link", ("show", self.dev_name))
        except Exception as e:
            LOG.exception(_LE("Failed executing ip command"))
            raise exc.IpCommandDeviceError(dev_name=self.dev_name, reason=e)
        vf_lines = self._get_vf_link_show([vf_index], out)
        if vf_lines:
            vf_details = self._parse_vf_link_show(vf_lines[0])
            if vf_details:
                state = vf_details.get("link-state", self.LinkState.DISABLE)
            if state != self.LinkState.DISABLE:
                return True
        return False
Esempio n. 3
0
    def get_assigned_macs(self, vf_list):
        """Get assigned mac addresses for vf list.

        @param vf_list: list of vf indexes
        @return: dict mapping of vf to mac
        """
        try:
            out = self._as_root([], "link", ("show", self.dev_name))
        except Exception as e:
            LOG.exception(_LE("Failed executing ip command"))
            raise exc.IpCommandDeviceError(dev_name=self.dev_name, reason=e)
        vf_to_mac_mapping = {}
        vf_lines = self._get_vf_link_show(vf_list, out)
        if vf_lines:
            for vf_line in vf_lines:
                vf_details = self._parse_vf_link_show(vf_line)
                if vf_details:
                    vf_num = vf_details.get('vf')
                    vf_mac = vf_details.get("MAC")
                    vf_to_mac_mapping[vf_num] = vf_mac
        return vf_to_mac_mapping
Esempio n. 4
0
    def _set_feature(self, vf_index, feature, value):
        """Sets vf feature

        Checks if the feature is not supported or there's some
        general error during ip link invocation and raises
        exception accordingly.

        :param vf_index: vf index
        :param feature: name of a feature to be passed to ip link,
                        such as 'state' or 'spoofchk'
        :param value: value of the feature setting
        """
        try:
            self._as_root([], "link", ("set", self.dev_name, "vf",
                                       str(vf_index), feature, value))
        except Exception as e:
            if self.IP_LINK_OP_NOT_SUPPORTED in str(e):
                raise exc.IpCommandOperationNotSupportedError(
                    dev_name=self.dev_name)
            else:
                raise exc.IpCommandDeviceError(dev_name=self.dev_name,
                                               reason=str(e))