本文整理匯總了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({})