当前位置: 首页>>代码示例>>Python>>正文


Python network.Profile类代码示例

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


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

示例1: setAddress

def setAddress(name, mode, address, mask, gateway):
    profile = Profile(name)
    profile.info["net_mode"] = mode
    profile.info["net_address"] = address
    profile.info["net_mask"] = mask
    profile.info["net_gateway"] = gateway
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:7,代码来源:link.py

示例2: setState

def setState(name, state):
    profile = Profile(name)
    ifname = profile.info["device"].split(":")[-1].split("_")[-1]
    iface = netutils.findInterface(profile.info["device"])
    if state == "unplugged" or not iface:
        # Reset Network Stack
        unregisterNameServers(ifname)
        if state == "down":
            # Save state to profile database
            profile.info["state"] = "down"
            profile.save(no_notify=True)
            # Notify clients
            notify("Network.Link", "stateChanged", (name, "down", ""))
        else:
            # Save state to profile database
            profile.info["state"] = "unplugged"
            profile.save(no_notify=True)
            # Notify clients
            notify("Network.Link", "stateChanged", (name, "unplugged", ""))
        # Run profile script (/etc/network/netlink.d/profilename.down)
        callScript(name, "down")
        return
    # Here we go...
    device_mode = profile.info.get("device_mode", "managed")
    if device_mode == "managed":
        if state == "up":
            # Stop other profiles on same device
            stopSameDevice(name)
            # Notify clients
            notify("Network.Link", "stateChanged", (name, "connecting", ""))
            # Save state to profile database
            profile.info["state"] = "connecting"
            profile.save(no_notify=True)
            # Wifi settings
            wifi = Wireless(iface)
            wifi.setSSID(profile.info["remote"])
            # Set encryption
            try:
                wifi.setEncryption(getAuthMethod(name), getAuthParameters(name))
            except Exception, e:
                # Stop ifplug deamon
                plugService(ifname, "down")
                # Save state to profile database
                profile.info["state"] = "inaccessible %s" % unicode(e)
                profile.save(no_notify=True)
                # Notify clients
                notify("Network.Link", "stateChanged", (name, "inaccessible", unicode(e)))
                fail(unicode(e))
            if profile.info.get("net_mode", "auto") == "auto":
                # Start DHCP client
                ret = iface.startAuto()
                if ret == 0 and iface.isUp():
                    if "net_address" in profile.info or "net_gateway" in profile.info:
                        net_address = profile.info.get("net_address", None)
                        net_mask = profile.info.get("net_mask", "255.255.255.0")
                        net_gateway = profile.info.get("net_gateway", None)
                        if net_address:
                            iface.setAddress(net_address, net_mask)
                            if not net_gateway:
                                gateways = iface.autoGateways()
                                if len(gateways):
                                    net_gateway = gateways[0]
                        if net_gateway:
                            route = netutils.Route()
                            route.setDefault(net_gateway)
                    elif iface.getAddress():
                        net_address = iface.getAddress()[0]
                    else:
                        # Bring device down
                        iface.down()
                        # Save state to profile database
                        profile.info["state"] = "inaccessible %s" % _(MSG_DHCP_FAILED)
                        profile.save(no_notify=True)
                        # Notify clients
                        notify("Network.Link", "stateChanged", (name, "inaccessible", _(MSG_DHCP_FAILED)))
                        return
                    # Set nameservers
                    registerNameServers(profile, iface)
                    # Save state to profile database
                    profile.info["state"] = "up " + net_address
                    profile.save(no_notify=True)
                    # Notify clients
                    notify("Network.Link", "stateChanged", (name, "up", net_address))
                    # Run profile script (/etc/network/netlink.d/profilename.up)
                    callScript(name, "up")
                    # Start ifplug daemon
                    plugService(ifname, "up", wireless=True)
                else:
                    # Bring device down
                    iface.down()
                    # Save state to profile database
                    profile.info["state"] = "inaccessible %s" % _(MSG_DHCP_FAILED)
                    profile.save(no_notify=True)
                    # Notify clients
                    notify("Network.Link", "stateChanged", (name, "inaccessible", _(MSG_DHCP_FAILED)))
            else:
                try:
                    net_address = profile.info["net_address"]
                    net_mask = profile.info["net_mask"]
                except KeyError:
#.........这里部分代码省略.........
开发者ID:blue-devil,项目名称:kuller,代码行数:101,代码来源:link.py

示例3: setAuthParameters

def setAuthParameters(name, key, value):
    profile = Profile(name)
    profile.info["auth_%s" % key] = value
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:4,代码来源:link.py

示例4: setAuthMethod

def setAuthMethod(name, method):
    profile = Profile(name)
    profile.info["auth"] = method
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:4,代码来源:link.py

示例5: setNameService

def setNameService(name, namemode, nameserver):
    profile = Profile(name)
    profile.info["name_mode"] = namemode
    profile.info["name_server"] = nameserver
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:5,代码来源:link.py

示例6: setRemote

def setRemote(name, remote):
    profile = Profile(name)
    profile.info["remote"] = remote
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:4,代码来源:link.py

示例7: deleteConnection

def deleteConnection(name):
    profile = Profile(name)
    profile.delete()
    notify("Network.Link", "connectionChanged", ("deleted", name))
开发者ID:blue-devil,项目名称:kuller,代码行数:4,代码来源:link.py

示例8: setDeviceMode

def setDeviceMode(name, mode):
    profile = Profile(name)
    profile.info["device_mode"] = mode
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:4,代码来源:link.py

示例9: setDevice

def setDevice(name, device):
    profile = Profile(name)
    profile.info["device"] = device
    profile.save()
开发者ID:blue-devil,项目名称:kuller,代码行数:4,代码来源:link.py


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