本文整理汇总了Python中pritunl.server.Server.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Server.commit方法的具体用法?Python Server.commit怎么用?Python Server.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pritunl.server.Server
的用法示例。
在下文中一共展示了Server.commit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: server_put_post
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import commit [as 别名]
#.........这里部分代码省略.........
except ValueError:
return _interface_not_valid()
if interface_num > 64:
return _interface_not_valid()
interface = interface[:3] + str(interface_num)
# Port
try:
port = int(port)
except ValueError:
return _port_not_valid()
if port < 1 or port > 65535:
return _port_not_valid()
# Protocol
if protocol not in ['udp', 'tcp']:
return utils.jsonify({
'error': PROTOCOL_NOT_VALID,
'error_msg': PROTOCOL_NOT_VALID_MSG,
}, 400)
# Local network
if local_network:
local_network_split = local_network.split('/')
if len(local_network_split) != 2:
return _local_network_not_valid()
address = local_network_split[0].split('.')
if len(address) != 4:
return _local_network_not_valid()
for i, value in enumerate(address):
try:
address[i] = int(value)
except ValueError:
return _local_network_not_valid()
if address[0] > 255 or address[0] < 0 or \
address[1] > 255 or address[1] < 0 or \
address[2] > 255 or address[2] < 0 or \
address[3] > 254 or address[3] < 0:
return _local_network_not_valid()
try:
subnet = int(local_network_split[1])
except ValueError:
return _local_network_not_valid()
if subnet < 8 or subnet > 30:
return _local_network_not_valid()
for server in Server.get_servers():
if server.id == server_id:
continue
elif server.network == network:
return utils.jsonify({
'error': NETWORK_IN_USE,
'error_msg': NETWORK_IN_USE_MSG,
}, 400)
elif server.interface == interface:
return utils.jsonify({
'error': INTERFACE_IN_USE,
'error_msg': INTERFACE_IN_USE_MSG,
}, 400)
elif server.port == port and server.protocol == protocol:
return utils.jsonify({
'error': PORT_PROTOCOL_IN_USE,
'error_msg': PORT_PROTOCOL_IN_USE_MSG,
}, 400)
if not server_id:
server = Server(
name=name,
network=network,
interface=interface,
port=port,
protocol=protocol,
local_network=local_network,
public_address=public_address,
debug=debug,
)
else:
server = Server(id=server_id)
if server.status:
return utils.jsonify({
'error': SERVER_NOT_OFFLINE,
'error_msg': SERVER_NOT_OFFLINE_MSG,
}, 400)
server.name = name
server.network = network
server.interface = interface
server.port = port
server.protocol = protocol
server.local_network = local_network
server.public_address = public_address
server.debug = debug
server.commit()
return utils.jsonify({})