• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python nm.nm_devices函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyanaconda.nm.nm_devices函数的典型用法代码示例。如果您正苦于以下问题:Python nm_devices函数的具体用法?Python nm_devices怎么用?Python nm_devices使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了nm_devices函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setNetworkOnbootDefault

    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if not nm.nm_device_type_is_wifi(devName) and \
               network.get_ifcfg_value(devName, "ONBOOT", ROOT_PATH) == "yes":
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError as e:
                continue
            if link_up:
                dev = network.NetworkDevice(ROOT_PATH + network.netscriptsDir, devName)
                dev.loadIfcfgFile()
                dev.set(('ONBOOT', 'yes'))
                dev.writeIfcfgFile()
                for nd in ksdata.network.network:
                    if nd.device == dev.iface:
                        nd.onboot = True
                        break
                break
开发者ID:cs2c-zhangchao,项目名称:nkwin1.0-anaconda,代码行数:25,代码来源:fedora.py


示例2: setNetworkOnbootDefault

    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection", "autoconnect")
            except nm.SettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError:
                continue
            if link_up:
                ifcfg_path = network.find_ifcfg_file_of_device(devName, root_path=ROOT_PATH)
                if not ifcfg_path:
                    continue
                ifcfg = network.IfcfgFile(ifcfg_path)
                ifcfg.read()
                ifcfg.set(('ONBOOT', 'yes'))
                ifcfg.write()
                for nd in ksdata.network.network:
                    if nd.device == devName:
                        nd.onboot = True
                        break
                break
开发者ID:mairin,项目名称:anaconda,代码行数:33,代码来源:fedora.py


示例3: find_ifcfg_file_of_device

def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_type_is_wifi(devname):
        ssid = nm.nm_device_active_ssid(devname)
        if ssid:
            ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
    elif nm.nm_device_type_is_bond(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_team(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_vlan(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_ethernet(devname):
        try:
            hwaddr = nm.nm_device_hwaddress(devname)
        except nm.PropertyNotFoundError:
            hwaddr = None
        if hwaddr:
            hwaddr_check = lambda mac: mac.upper() == hwaddr.upper()
            nonempty = lambda x: x
            # slave configration created in GUI takes precedence
            ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("TEAM_MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check)], root_path)
        if not ifcfg_path:
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)

    return ifcfg_path
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:34,代码来源:network.py


示例4: dumpMissingDefaultIfcfgs

def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    For default auto connections created by NM upon start - which happens
    in case of missing ifcfg file - rename the connection using device name
    and dump its ifcfg file. (For server, default auto connections will
    be turned off in NetworkManager.conf.)
    The connection id (and consequently ifcfg file) is set to device name.
    Returns True if any ifcfg file was dumped.

    """
    rv = False

    for devname in nm.nm_devices():
        # for each ethernet device
        # FIXME add more types (infiniband, bond...?)
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        # if there is no ifcfg file for the device
        device_cfg = NetworkDevice(netscriptsDir, devname)
        if os.access(device_cfg.path, os.R_OK):
            continue

        try:
            nm.nm_update_settings_of_device(devname, 'connection', 'id', devname)
            log.debug("network: dumping ifcfg file for default autoconnection on %s" % devname)
            nm.nm_update_settings_of_device(devname, 'connection', 'autoconnect', False)
            log.debug("network: setting autoconnect of %s to False" % devname)
        except nm.DeviceSettingsNotFoundError as e:
            log.debug("network: no ifcfg file for %s" % devname)
        rv = True

    return rv
开发者ID:cs2c-zhangchao,项目名称:nkwin1.0-anaconda,代码行数:34,代码来源:network.py


示例5: _update_network_data

    def _update_network_data(self):
        hostname = self.data.network.hostname

        self.data.network.network = []
        for i, name in enumerate(nm.nm_devices()):
            if network.is_ibft_configured_device(name):
                continue
            nd = network.ksdata_from_ifcfg(name)
            if not nd:
                continue
            if name in nm.nm_activated_devices():
                nd.activate = True
            else:
                # First network command defaults to --activate so we must
                # use --no-activate explicitly to prevent the default
                if i == 0:
                    nd.activate = False
            self.data.network.network.append(nd)

        (valid, error) = network.sanityCheckHostname(self.hostname_dialog.value)
        if valid:
            hostname = self.hostname_dialog.value
        else:
            self.errors.append(_("Host name is not valid: %s") % error)
            self.hostname_dialog.value = hostname
        network.update_hostname_data(self.data, hostname)
开发者ID:dougsland,项目名称:anaconda,代码行数:26,代码来源:network.py


示例6: get_bond_slaves_from_ifcfgs

def get_bond_slaves_from_ifcfgs(master_specs):
    """List of slave device names of master specified by master_specs.

       master_specs is a list containing device name of master (dracut)
       and/or master's connection uuid
    """
    slaves = []

    for filepath in _ifcfg_files(netscriptsDir):
        ifcfg = IfcfgFile(filepath)
        ifcfg.read()
        master = ifcfg.get("MASTER")
        if master in master_specs:
            device = ifcfg.get("DEVICE")
            if device:
                slaves.append(device)
            else:
                hwaddr = ifcfg.get("HWADDR")
                for devname in nm.nm_devices():
                    try:
                        h = nm.nm_device_property(devname, "PermHwAddress")
                    except nm.PropertyNotFoundError:
                        log.debug("can't get PermHwAddress of devname %s", devname)
                        continue
                    if h.upper() == hwaddr.upper():
                        slaves.append(devname)
                        break
    return slaves
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:28,代码来源:network.py


示例7: networkInitialize

def networkInitialize(ksdata):

    log.debug("network: devices found %s", nm.nm_devices())
    logIfcfgFiles("network initialization")

    if not flags.imageInstall:
        devnames = apply_kickstart_from_pre_section(ksdata)
        if devnames:
            msg = "kickstart pre section applied for devices %s" % devnames
            log.debug("network: %s", msg)
            logIfcfgFiles(msg)
        devnames = dumpMissingDefaultIfcfgs()
        if devnames:
            msg = "missing ifcfgs created for devices %s" % devnames
            log.debug("network: %s", msg)
            logIfcfgFiles(msg)

    # For kickstart network --activate option we set ONBOOT=yes
    # in dracut to get devices activated by NM. The real network --onboot
    # value is set here.
    devnames = setOnboot(ksdata)
    if devnames:
        msg = "setting real kickstart ONBOOT value for devices %s" % devnames
        log.debug("network: %s", msg)
        logIfcfgFiles(msg)

    if ksdata.network.hostname is None:
        hostname = getHostname()
        update_hostname_data(ksdata, hostname)
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:29,代码来源:network.py


示例8: refresh

    def refresh(self):
        """
        The refresh method that is called every time the spoke is displayed.
        It should update the UI elements according to the contents of
        self.data.

        :see: pyanaconda.ui.common.UIObject.refresh

        """
        ## Every time we enter, make a list of all the devices that
        # are not the public interface (user might have changed this)
        pubif = network.default_route_device()
        allifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\
                nm.nm_devices())
        privates = filter(lambda x: x != pubif,allifs)
        idx = self.ifaceCombo.get_active()
        self.deviceStore.clear()
        for x in privates:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = x
            entry[TYPEIDX] = "ethernet"
            entry[MACIDX] = nm.nm_device_valid_hwaddress(x)
            entry[LABELIDX] = "%s;%s" % (x,entry[MACIDX])
            self.deviceStore.append(entry)
        if len(privates) == 0:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = "%s:0" % pubif
            entry[LABELIDX] = "%s;virtual interface" % entry[DEVICEIDX] 
            entry[TYPEIDX] = "virtual"
            entry[MACIDX] = ""
            self.deviceStore.append(entry)

        # Set the active entry, even if we reodered 
        self.ifaceCombo.set_active(idx)
开发者ID:rocksclusters,项目名称:kernel,代码行数:34,代码来源:rocks_private.py


示例9: get_device_name

def get_device_name(devspec):

    devices = nm.nm_devices()
    devname = None

    if not devspec:
        if "ksdevice" in flags.cmdline:
            msg = "ksdevice boot parameter"
            devname = ks_spec_to_device_name(flags.cmdline["ksdevice"])
        elif nm.nm_is_connected():
            # device activated in stage 1 by network kickstart command
            msg = "first active device"
            try:
                devname = nm.nm_activated_devices()[0]
            except IndexError:
                log.debug("get_device_name: NM is connected but no activated devices found")
        else:
            msg = "first device found"
            devname = min(devices)
        log.info("unspecified network --device in kickstart, using %s (%s)", devname, msg)
    else:
        if iutil.lowerASCII(devspec) == "ibft":
            devname = ""
        if iutil.lowerASCII(devspec) == "link":
            for dev in sorted(devices):
                try:
                    link_up = nm.nm_device_carrier(dev)
                except ValueError as e:
                    log.debug("get_device_name: %s", e)
                    continue
                if link_up:
                    devname = dev
                    break
            else:
                log.error("Kickstart: No network device with link found")
        elif iutil.lowerASCII(devspec) == "bootif":
            if "BOOTIF" in flags.cmdline:
                # MAC address like 01-aa-bb-cc-dd-ee-ff
                devname = flags.cmdline["BOOTIF"][3:]
                devname = devname.replace("-", ":")
            else:
                log.error("Using --device=bootif without BOOTIF= boot option supplied")
        else:
            devname = devspec

    if devname and devname not in devices:
        for d in devices:
            try:
                hwaddr = nm.nm_device_hwaddress(d)
            except ValueError as e:
                log.debug("get_device_name: %s", e)
                continue
            if hwaddr.lower() == devname.lower():
                devname = d
                break
        else:
            return ""

    return devname
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:59,代码来源:network.py


示例10: refresh

    def refresh(self):
        self._nicCombo.remove_all()

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(0)
开发者ID:KosiehBarter,项目名称:anaconda,代码行数:8,代码来源:fcoe.py


示例11: disableIPV6

def disableIPV6(rootpath):
    cfgfile = os.path.normpath(rootpath + ipv6ConfFile)
    if ('noipv6' in flags.cmdline
        and all(nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore"
                for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))):
        log.info('Disabling ipv6 on target system')
        with open(cfgfile, "a") as f:
            f.write("# Anaconda disabling ipv6 (noipv6 option)\n")
            f.write("net.ipv6.conf.all.disable_ipv6=1\n")
            f.write("net.ipv6.conf.default.disable_ipv6=1\n")
开发者ID:mairin,项目名称:anaconda,代码行数:10,代码来源:network.py


示例12: initialize

    def initialize(self):
        for name in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)

        EditTUISpoke.initialize(self)
        if not self.data.network.seen:
            self._update_network_data()
开发者ID:akozumpl,项目名称:anaconda,代码行数:11,代码来源:network.py


示例13: disableNMForStorageDevices

def disableNMForStorageDevices(rootpath, storage):
    for devname in nm.nm_devices():
        if usedByFCoE(devname, storage) or usedByRootOnISCSI(devname, storage):
            ifcfg_path = find_ifcfg_file_of_device(devname, root_path=rootpath)
            if not ifcfg_path:
                log.warning("disableNMForStorageDevices: ifcfg file for %s not found", devname)
                continue
            ifcfg = IfcfgFile(ifcfg_path)
            ifcfg.read()
            ifcfg.set(("NM_CONTROLLED", "no"))
            ifcfg.write()
            log.info("network device %s used by storage will not be " "controlled by NM", devname)
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:12,代码来源:network.py


示例14: get_device_name

def get_device_name(network_data):

    ksspec = network_data.device or flags.cmdline.get('ksdevice', "")
    dev_name = ks_spec_to_device_name(ksspec)
    if not dev_name:
        return ""
    if dev_name not in nm.nm_devices():
        if not any((network_data.vlanid, network_data.bondslaves, network_data.teamslaves)):
            return ""
    if network_data.vlanid:
        dev_name = "%s.%s" % (dev_name, network_data.vlanid)

    return dev_name
开发者ID:akozumpl,项目名称:anaconda,代码行数:13,代码来源:network.py


示例15: _load_new_devices

    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("Dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)
开发者ID:sujithshankar,项目名称:anaconda,代码行数:14,代码来源:network.py


示例16: setNetworkOnbootDefault

 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, True, ksdata=ksdata)
             break
开发者ID:dougsland,项目名称:anaconda,代码行数:14,代码来源:fedora.py


示例17: disableNMForStorageDevices

def disableNMForStorageDevices(rootpath, storage):
    for devname in nm.nm_devices():
        if (usedByFCoE(devname, storage) or
            usedByRootOnISCSI(devname, storage)):
            dev = NetworkDevice(rootpath + netscriptsDir, devname)
            if os.access(dev.path, os.R_OK):
                dev.loadIfcfgFile()
                dev.set(('NM_CONTROLLED', 'no'))
                dev.writeIfcfgFile()
                log.info("network device %s used by storage will not be "
                         "controlled by NM" % devname)
            else:
                log.warning("disableNMForStorageDevices: ifcfg file for %s not found" %
                            devname)
开发者ID:cs2c-zhangchao,项目名称:nkwin1.0-anaconda,代码行数:14,代码来源:network.py


示例18: setNetworkOnbootDefault

 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, "yes", ksdata)
             break
开发者ID:cyclefusion,项目名称:anaconda,代码行数:14,代码来源:fedora.py


示例19: get_device_name

def get_device_name(network_data):

    ksspec = network_data.device or flags.cmdline.get('ksdevice', "")
    dev_name = ks_spec_to_device_name(ksspec)
    if not dev_name:
        return ""
    if dev_name not in nm.nm_devices():
        if not any((network_data.vlanid, network_data.bondslaves, network_data.teamslaves)):
            return ""
    if network_data.vlanid:
        network_data.parent = dev_name
        dev_name = network_data.interfacename or default_ks_vlan_interface_name(network_data.parent, network_data.vlanid)

    return dev_name
开发者ID:fabiand,项目名称:anaconda,代码行数:14,代码来源:network.py


示例20: autostartFCoEDevices

def autostartFCoEDevices(rootpath, storage, ksdata):
    for devname in nm.nm_devices():
        if usedByFCoE(devname, storage):
            ifcfg_path = find_ifcfg_file_of_device(devname, root_path=rootpath)
            if not ifcfg_path:
                log.warning("autoconnectFCoEDevices: ifcfg file for %s not found", devname)
                continue

            ifcfg = IfcfgFile(ifcfg_path)
            ifcfg.read()
            ifcfg.set(("ONBOOT", "yes"))
            ifcfg.write()
            log.debug("setting ONBOOT=yes for network device %s used by fcoe", devname)
            for nd in ksdata.network.network:
                if nd.device == devname:
                    nd.onboot = True
                    break
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:17,代码来源:network.py



注:本文中的pyanaconda.nm.nm_devices函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python progressQ.send_message函数代码示例发布时间:2022-05-25
下一篇:
Python nm.nm_activated_devices函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap