本文整理匯總了Python中comar.network.Profile.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Profile.save方法的具體用法?Python Profile.save怎麽用?Python Profile.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類comar.network.Profile
的用法示例。
在下文中一共展示了Profile.save方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setAddress
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
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()
示例2: setState
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
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:
#.........這裏部分代碼省略.........
示例3: setAuthParameters
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
def setAuthParameters(name, key, value):
profile = Profile(name)
profile.info["auth_%s" % key] = value
profile.save()
示例4: setAuthMethod
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
def setAuthMethod(name, method):
profile = Profile(name)
profile.info["auth"] = method
profile.save()
示例5: setNameService
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
def setNameService(name, namemode, nameserver):
profile = Profile(name)
profile.info["name_mode"] = namemode
profile.info["name_server"] = nameserver
profile.save()
示例6: setRemote
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
def setRemote(name, remote):
profile = Profile(name)
profile.info["remote"] = remote
profile.save()
示例7: setDeviceMode
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
def setDeviceMode(name, mode):
profile = Profile(name)
profile.info["device_mode"] = mode
profile.save()
示例8: setDevice
# 需要導入模塊: from comar.network import Profile [as 別名]
# 或者: from comar.network.Profile import save [as 別名]
def setDevice(name, device):
profile = Profile(name)
profile.info["device"] = device
profile.save()