Exemplo n.º 1
0
    def set(self,
            device,
            check_exit_code=None,
            state=None,
            mtu=None,
            address=None,
            promisc=None):
        check_exit_code = check_exit_code or []
        ip = iproute.IPRoute()
        idx = ip.link_lookup(ifname=device)
        if not idx:
            raise exception.NetworkInterfaceNotFound(interface=device)
        idx = idx[0]

        args = {'index': idx}
        if state:
            args['state'] = state
        if mtu:
            args['mtu'] = mtu
        if address:
            args['address'] = address
        if promisc is not None:
            flags = ip.link('get', index=idx)[0]['flags']
            args['flags'] = (utils.set_mask(flags, ifinfmsg.IFF_PROMISC)
                             if promisc is True else utils.unset_mask(
                                 flags, ifinfmsg.IFF_PROMISC))

        if isinstance(check_exit_code, int):
            check_exit_code = [check_exit_code]

        return self._ip_link(ip, 'set', check_exit_code, **args)
Exemplo n.º 2
0
    def set(self, device, check_exit_code=None, state=None, mtu=None,
            address=None, promisc=None, master=None):
        check_exit_code = check_exit_code or []
        with iproute.IPRoute() as ip:
            idx = self.lookup_interface(ip, device)
            args = {'index': idx}
            if state:
                args['state'] = state
            if mtu:
                args['mtu'] = mtu
            if address:
                args['address'] = address
            if promisc is not None:
                flags = ip.link('get', index=idx)[0]['flags']
                args['flags'] = (utils.set_mask(flags, ifinfmsg.IFF_PROMISC)
                                 if promisc is True else
                                 utils.unset_mask(flags, ifinfmsg.IFF_PROMISC))
            if master:
                args['master'] = self.lookup_interface(ip, master)

            if isinstance(check_exit_code, int):
                check_exit_code = [check_exit_code]

            return self._ip_link(ip, 'set', check_exit_code, **args)