Пример #1
0
 def link_show(self):
     try:
         out = self._as_root([], "link", ("show", ))
     except Exception as e:
         LOG.error("Failed executing ip command: %s", e)
         raise exc.IpCommandError(reason=e)
     return out
Пример #2
0
 def link_show(cls):
     try:
         out = cls._execute([], "link", ("show", ), run_as_root=True)
     except Exception as e:
         LOG.error("Failed executing ip command: %s", e)
         raise exc.IpCommandError(reason=e)
     return out
Пример #3
0
    def set_vf_max_rate(self, vf_index, max_tx_rate):
        """sets vf max rate.

        @param vf_index: vf index
        @param max_tx_rate: vf max tx rate in Mbps
        """
        try:
            self._as_root([], "link",
                          ("set", self.dev_name, "vf", str(vf_index), "rate",
                           str(max_tx_rate)))
        except Exception as e:
            LOG.exception(_LE("Failed executing ip command"))
            raise exc.IpCommandError(dev_name=self.dev_name, reason=e)
Пример #4
0
    def set_vf_spoofcheck(self, vf_index, enabled):
        """sets vf spoofcheck

        @param vf_index: vf index
        @param enabled: True to enable spoof checking,
                        False to disable
        """
        setting = "on" if enabled else "off"

        try:
            self._as_root('', "link", ("set", self.dev_name, "vf",
                                       str(vf_index), "spoofchk", setting))
        except Exception as e:
            raise exc.IpCommandError(dev_name=self.dev_name, reason=str(e))
Пример #5
0
    def set_vf_state(self, vf_index, state):
        """sets vf state.

        @param vf_index: vf index
        @param state: required state {True/False}
        """
        status_str = self.LinkState.ENABLE if state else \
            self.LinkState.DISABLE

        try:
            self._as_root([], "link", ("set", self.dev_name, "vf",
                                       str(vf_index), "state", status_str))
        except Exception as e:
            LOG.exception(_LE("Failed executing ip command"))
            raise exc.IpCommandError(dev_name=self.dev_name, reason=e)
Пример #6
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.IpCommandError(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
Пример #7
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.IpCommandError(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
Пример #8
0
    def get_assigned_macs(self, vf_list):
        """Get assigned mac addresses for vf list.

        @param vf_list: list of vf indexes
        @return: list of assigned mac addresses
        """
        try:
            out = self._as_root([], "link", ("show", self.dev_name))
        except Exception as e:
            LOG.exception(_LE("Failed executing ip command"))
            raise exc.IpCommandError(dev_name=self.dev_name, reason=e)
        vf_lines = self._get_vf_link_show(vf_list, out)
        vf_details_list = []
        if vf_lines:
            for vf_line in vf_lines:
                vf_details = self._parse_vf_link_show(vf_line)
                if vf_details:
                    vf_details_list.append(vf_details)
        return [details.get("MAC") for details in vf_details_list]
Пример #9
0
    def is_macvtap_assigned(cls, ifname):
        """Check if vf has macvtap interface assigned

        Parses the output of ip link show command and checks
        if macvtap[0-9]+@<vf interface> regex matches the
        output.
        @param ifname: vf interface name
        @return: True on match otherwise False
        """
        try:
            out = cls._execute([], "link", ("show", ), run_as_root=True)
        except Exception as e:
            LOG.error(_LE("Failed executing ip command: %s"), e)
            raise exc.IpCommandError(reason=e)

        for line in out.splitlines():
            pattern_match = cls.MACVTAP_REG_EX.match(line)
            if pattern_match:
                if ifname == pattern_match.group('vf_interface'):
                    return True
        return False
Пример #10
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("Failed executing ip command")
            raise exc.IpCommandError(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
Пример #11
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.IpCommandError(dev_name=self.dev_name,
                                         reason=str(e))