本文整理汇总了Python中models.Server类的典型用法代码示例。如果您正苦于以下问题:Python Server类的具体用法?Python Server怎么用?Python Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_post_idle_timeout
def test_post_idle_timeout(self):
mc = MinecraftDownload.create(
'1.7.4',
'https://s3.amazonaws.com/Minecraft.Download/versions/1.7.4/minecraft_server.1.7.4.jar'
)
self.server.key.delete()
self.log_in_admin()
self.assertEqual(0, Server.query().count())
self.assertEqual(0, Client.query().count())
response = self.post(params={
'name': 'new server',
'version': mc.version,
'memory': '1G',
'motd': 'Welcome',
'white_list': True,
'server_port': 25565,
'idle_timeout': 0,
'eula_agree': True
})
self.assertEqual(1, Server.query().count())
self.assertEqual(1, Client.query().count())
server = Server.query().get()
self.assertEqual('new server', server.name)
self.assertEqual(True, server.is_gce)
self.assertEqual('1G', server.memory)
self.assertEqual(0, server.idle_timeout)
mc_properties = server.mc_properties
self.assertEqual('Welcome', mc_properties.motd)
self.assertEqual(True, mc_properties.white_list)
self.assertEqual(25565, mc_properties.server_port)
self.assertRedirects(response, '/servers/{0}'.format(server.key.urlsafe()))
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:31,代码来源:test_admin.py
示例2: test_post_non_unique_port
def test_post_non_unique_port(self):
mc = MinecraftDownload.create(
'1.7.4',
'https://s3.amazonaws.com/Minecraft.Download/versions/1.7.4/minecraft_server.1.7.4.jar'
)
self.server.key.delete()
self.log_in_admin()
self.assertEqual(0, Server.query().count())
self.assertEqual(0, Client.query().count())
response = self.post(params={
'name': 'new server',
'version': mc.version,
'memory': '1G',
'motd': 'Welcome',
'white_list': True,
'server_port': 25565,
'idle_timeout': 10,
'eula_agree': True
})
response = self.post(params={
'name': 'new server',
'version': mc.version,
'memory': '1G',
'motd': 'Welcome',
'white_list': True,
'server_port': 25565,
'idle_timeout': 10,
'eula_agree': True
})
self.assertEqual(1, Server.query().count())
self.assertEqual(1, Client.query().count())
self.assertOK(response)
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:32,代码来源:test_admin.py
示例3: test_view
def test_view(self):
"""
test getting one server
"""
clear_db()
s1 = Server.create(server_id=None, tenant_id=1, name="name1", status="ready")
Server.create(server_id=None, tenant_id=1, name="name2", status="scheduled")
Server.create(server_id=None, tenant_id=2, name="name3", status="ready")
request = HTTPRequest(
self.get_url("/1/servers/" + str(s1.server_id)),
method="GET",
headers=HTTPHeaders({"X-AUTH-TOKEN": X_AUTH_TOKEN}),
)
self.http_client.fetch(request, self.stop)
response = self.wait()
message = json.loads(response.body)
assert message == {
"status": s1.status,
"id": s1.server_id,
"name": s1.name,
"date_created": str(s1.date_created),
}
开发者ID:eugene-kuchansky,项目名称:serv-test,代码行数:25,代码来源:test.py
示例4: change_center
def change_center(request):
attr = request.POST.get('type', '')
if attr == 'report':
Server.change_report()
return JsonResponse({'code':0})
elif attr == 'mode':
Server.change_mode()
return JsonResponse({'code':0})
else:
print 'ERROR PARAM:', attr
开发者ID:2013211450,项目名称:air_conditioner,代码行数:10,代码来源:views.py
示例5: profile
def profile(request):
host = get_server_host()
port = request.get_port()
user = request.user
if not user.is_superuser:
print "ERROR"
return HttpResponseRedirect('/account/logout/')
page_num = request.GET.get('page_num', 1)
page_num = int(page_num)
page_size = 6
offset = page_size * (page_num - 1)
server = Server.objects.filter(user_id=user.id).first()
host = host + ':' + port
server.host = host
if not server.work:
server_init()
server.work = 1
server.save()
count = Room.objects.filter(host=server.host).count()
page_count = (count + page_size - 1)/ page_size
if page_count < 1:
page_count = 1
if offset > count:
offset = count
if offset + page_size > count:
page_size = count - offset
rooms = Room.objects.filter(host=server.host)[offset:(offset+page_size)]
data = []
for room in rooms:
is_service = u'服务中'
is_link = u'已连接'
if not room.service:
is_service = u'未服务'
if not room.link:
is_link = u'连接已断开'
room_mode = MODE_DICT[MODE[Server.get_attr('mode')]]
room_speed = SPEED_DICT[SPEED[room.speed]]
data.append({
'id': room.id,
'is_link': is_link,
'numbers':room.numbers,
'ip_address': room.ip_address,
'service': is_service,
'mode': room_mode,
'speed': room_speed,
'power': CostPerDay.get_power(room.id, back=Server.get_report_days()),
'room_temperature': room.room_temperature,
'setting_temperature': room.setting_temperature,
'total_cost': CostPerDay.get_cost(room.id, back=Server.get_report_days()),
'rest_cost': room.total_cost,
})
return render(request, 'center.html', {'list': data, 'page_num':page_num, 'page_count':
page_count, 'user':user, 'host': host, 'report': Server.get_report_name(), 'mode':
MODE_DICT[MODE[server.mode]]})
开发者ID:2013211450,项目名称:air_conditioner,代码行数:54,代码来源:views.py
示例6: test_post
def test_post(self):
self.server.key.delete()
self.log_in_admin()
self.assertEqual(0, Server.query().count())
self.assertEqual(0, Client.query().count())
response = self.post(params={'name': 'new server'})
self.assertEqual(1, Server.query().count())
self.assertEqual(1, Client.query().count())
server = Server.query().get()
self.assertEqual('new server', server.name)
self.assertEqual(False, server.is_gce)
self.assertRedirects(response, '/servers/{0}'.format(server.key.urlsafe()))
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:12,代码来源:test_admin.py
示例7: update_room_info
def update_room_info():
mode = Server.get_attr('mode')
query = Room.objects.select_for_update().filter(host=Server.get_host(), link=1)
for room in query.all():
resp = query_room_temperature(room.ip_address, room.numbers)
if not room.link:
continue
if resp['code'] == 0:
room.setting_temperature = resp['setting_temperature']
room.room_temperature = resp['room_temperature']
else:
room.link = 0
room.service = 0
print "break link!"
speed = room.speed
room.save()
if not room.service:
continue
if (room.setting_temperature >= room.room_temperature + 0.1 and mode == 0) or (room.setting_temperature + 0.1 <= room.room_temperature and mode == 2):
room.service = 0
if room.service == 0:
old_cost = RoomRequest.objects.filter(room_id=room.id).order_by("-id").first()
old_cost.end_time = datetime.now()
old_cost.end_temperature = room.room_temperature
old_cost.save()
resp = post_to_client(room.ip_address, {'type':'stop', 'source': 'host'})
if room.service == 1:
update_cost(room.id, POWER_PER_MIN[room.speed], room.price)
room.power += POWER_PER_MIN[room.speed]
room.total_cost = room.power * room.price
room.save()
service_count = query.filter(service=1).count()
if service_count < 3:
rooms = query.filter(service=0, speed__gt=0).all()
for room in rooms:
speed = room.speed
if (room.setting_temperature >= room.room_temperature + 0.1 and mode == 0) or (room.setting_temperature + 0.1 <= room.room_temperature and mode == 2):
continue
resp = post_to_client(room.ip_address, {'type':'send', 'source':'host'})
if resp['code'] == 0:
room.service = 1
room_request = RoomRequest.objects.create(room_id=room.id, start_time=datetime.now(), power = 0, cost = 0, start_temperature=room.room_temperature, speed=speed)
print "start service"
room.start_service_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
room.save()
break
return JsonResponse({'code': 0})
开发者ID:2013211450,项目名称:air_conditioner,代码行数:48,代码来源:views.py
示例8: post
def post(self):
try:
form = ServerPropertiesForm(formdata=self.request.POST)
if form.validate():
server = Server.create(
name=form.name.data,
is_gce=True,
version=form.version.data,
memory=form.memory.data,
operator=form.operator.data or None,
idle_timeout=form.idle_timeout.data
)
mc_properties = server.mc_properties
for prop in form:
if prop.name not in ['name', 'version', 'memory', 'operator', 'idle_timeout']:
if prop.type == 'IntegerField' or prop.name in [
'gamemode', 'difficulty', 'op_permission_level'
]:
if prop.data is not None:
setattr(mc_properties, prop.name, int(prop.data))
else:
setattr(mc_properties, prop.name, prop.data)
mc_properties.put()
if not set_form_short_name(server, form):
message = "Short name '{0}' is already assigned to another world".format(form.short_name.data)
self.session.add_flash(message, level='warn')
self.redirect(webapp2.uri_for('home', server_key=server.url_key))
except Exception, e:
logging.error(u"Error POSTing GCE server: {0}".format(e))
self.abort(404)
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:30,代码来源:admin.py
示例9: __call__
def __call__(self, form, field):
server = self.server or form.server
port = field.data
if port:
port = int(port)
if port in Server.reserved_ports(ignore_server=server):
raise validators.ValidationError("Port {0} is already reserved for another server".format(port))
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:7,代码来源:forms.py
示例10: test_post_duplicate_none_port
def test_post_duplicate_none_port(self):
self.server.mc_properties.server_port = 25565
self.server.mc_properties.put()
self.log_in_admin()
self.mc = MinecraftDownload.create(
'1.7.4', 'https://s3.amazonaws.com/Minecraft.Download/versions/1.7.4/minecraft_server.1.7.4.jar'
)
self.server.version = self.mc.version
self.server.put()
response = self.post(
params={
'name': self.server.name,
'version': self.server.version,
'memory': '1G',
'server_port': '',
'idle_timeout': 10,
'eula_agree': True
}
)
self.assertEqual(1, Server.query().count())
self.assertEqual(1, Client.query().count())
server = self.server.key.get()
server = self.server.key.get()
self.assertIsNone(server.mc_properties.server_port)
self.assertRedirects(response, '/servers/{0}'.format(server.key.urlsafe()))
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:25,代码来源:test_admin.py
示例11: get_home_redirect
def get_home_redirect(handler, *args, **kwargs):
short_name = kwargs.get('short_name', None)
if not short_name:
return handler.uri_for('main')
server = Server.get_by_short_name(short_name)
if not server:
return handler.uri_for('main')
return handler.uri_for('home', server_key=server.short_name)
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:8,代码来源:main.py
示例12: server_parser_v1
def server_parser_v1(self, json):
serverName, osSystem = json["server"], json["system"]
if serverName and osSystem:
if not Server.isdupe(serverName):
db.session.add(Server(ServerName=serverName, ServerOS=osSystem))
db.session.commit()
else:
pass
开发者ID:beatsbears,项目名称:prettyunit,代码行数:8,代码来源:APIValidation.py
示例13: communication
def communication(request):
import pdb
# pdb.set_trace()
print "start=====com"
if request.method != 'POST':
resp = JsonResponse({'type': 'login', 'source': 'host', 'ack_nak': 'NAK'})
resp['Access-Control-Allow-Origin'] = '*'
return resp
source = request.POST.get('source', '')
op = request.POST.get('type', 'login')
room = Room.objects.select_for_update().filter(numbers=source).first()
print "operator======, ", op
if op == 'login':
if not room:
user = User.objects.create(username=get_rand_name(), password='xxxx')
room = Room.objects.create(user_id=user.id, numbers=source)
ip_port = request.POST.get('ip_port', None)
print "ip___port:_______ ", ip_port
room.ip_address = ip_port
room.host = Server.get_host()
room.link = 1
room.save()
print "========================="
resp = JsonResponse({'type':'login', 'source':'host', 'ack_nak': 'ACK'})
resp['Access-Control-Allow-Origin'] = '*'
return resp
if not room:
resp = JsonResponse({'type': op, 'source': 'host', 'ack_nak': 'NAK'})
resp['Access-Control-Allow-Origin'] = '*'
return resp
if op == 'logout':
room.link = 0
room.save()
resp = JsonResponse({'type':'logout', 'source':'host', 'ack_nak': 'ACK'})
resp['Access-Control-Allow-Origin'] = '*'
return resp
elif op == 'require':
speed = request.POST.get('speed', 'low')
print "start stop"
resp = post_to_client(room.ip_address, {'type':'stop', 'source': 'host'})
stop_cost(room.id, room.room_temperature)
room.speed = RESPEED[speed]
room.service = 0
room.save()
resp = JsonResponse({'type':'require', 'source':'host', 'ack_nak': 'ACK'})
resp['Access-Control-Allow-Origin'] = '*'
return resp
elif op == 'query_cost':
resp = JsonResponse({'type': 'query_cost', 'source': 'host', 'ack_nak': 'ACK', 'power_consumption': room.power,
'price': room.price, 'total_cost': room.total_cost})
resp['Access-Control-Allow-Origin'] = '*'
return resp
elif op == 'query_mode':
resp = JsonResponse({'type': 'query_mode', 'source': 'host', 'ack_nak': 'ACK', 'mode': MODE[Server.get_attr('mode')]})
resp['Access-Control-Allow-Origin'] = '*'
return resp
开发者ID:2013211450,项目名称:air_conditioner,代码行数:56,代码来源:views.py
示例14: post
def post(self):
server = Server(key_name=self.request.get('serverdomain'))
server.serverdomain = self.request.get('serverdomain')
if self.request.get('ssl') == "True":
server.ssl = True
else:
server.ssl = False
if self.request.get('notifywithprowl') == "True":
server.notifywithprowl = True
if self.request.get('notifywithemail') == "True":
server.notifywithemail = True
#server.notifywithprowl = self.request.get('notifywithtwitter')
server.email = users.get_current_user().email()
server.put()
self.redirect('/admin')
开发者ID:JoshuaEstes,项目名称:aeservmon,代码行数:15,代码来源:admin.py
示例15: get_template_context
def get_template_context(self, context=None):
template_context = dict()
if context:
template_context.update(context)
template_context['flashes'] = self.session.get_flashes()
template_context['request'] = self.request
template_context['user'] = self.user
template_context['config'] = coal_config
template_context['server'] = Server.global_key().get()
return template_context
开发者ID:gumptioncom,项目名称:mc-coal,代码行数:10,代码来源:main.py
示例16: get
def get(self, tenant_id):
servers = [
{
'id': server.server_id,
'name': server.name,
'status': server.status,
}
for server in Server.select(Server.server_id, Server.name, Server.status).where(Server.tenant_id == tenant_id).order_by(Server.server_id)
]
self.write({'servers': servers})
开发者ID:eugene-kuchansky,项目名称:serv-test,代码行数:10,代码来源:serv.py
示例17: get
def get(self):
results, previous_cursor, next_cursor = self.get_results_with_cursors(
User.query_all(), User.query_all_reverse(), RESULTS_PER_PAGE
)
servers = []
for server in Server.query():
servers.append(server)
instance = gce.Instance.singleton()
status = instance.get_status()
context = {'servers': servers, 'instance': instance, 'status': status}
self.render_template('admin.html', context=context)
开发者ID:RubyCoin,项目名称:mc-coal,代码行数:11,代码来源:admin.py
示例18: make_task
def make_task(server_id, status):
sleep(10)
db.connect()
try:
server = Server.get(Server.server_id == server_id)
except Server.DoesNotExist:
db.close()
return False
server.status = status
server.save()
db.close()
return True
开发者ID:eugene-kuchansky,项目名称:serv-test,代码行数:12,代码来源:serv.py
示例19: delete
def delete(self, tenant_id, server_id):
try:
server = Server.get(Server.tenant_id == tenant_id, Server.server_id == server_id)
except Server.DoesNotExist:
self.write({'status': 'not_found'})
return
server.delete_instance()
self.write({
'id': int(server_id),
'status': 'deleted',
})
开发者ID:eugene-kuchansky,项目名称:serv-test,代码行数:12,代码来源:serv.py
示例20: post
def post(self, package_id):
data = self.request.json
for srvdict in data:
srvcpts = srvdict.pop("components")
query = self.db.query(Server).filter_by(host=srvdict["host"])
if query.count() == 0:
srv = Server(**srvdict)
self.db.add(srv)
else:
srv = query.one()
for key, value in srvdict.iteritems():
srv.__setattr__(key, value)
self.db.execute("DELETE FROM server_component \
WHERE server_id=:server_id \
AND component_id IN (SELECT id FROM component WHERE package_id=:package_id)",
{ "server_id": srv.id, "package_id": package_id} )
for dic in srvcpts:
component_id = self.db.query(Component.id).filter_by(package_id=package_id, name=dic["name"]).scalar()
self.db.add( ServerComponent(srv.id, component_id, dic["active"]) )
self.db.commit()
开发者ID:yaleyang,项目名称:pydeploy,代码行数:23,代码来源:views.py
注:本文中的models.Server类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论