本文整理汇总了Python中models.Server.create方法的典型用法代码示例。如果您正苦于以下问题:Python Server.create方法的具体用法?Python Server.create怎么用?Python Server.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Server
的用法示例。
在下文中一共展示了Server.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_view
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
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),
}
示例2: post
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
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)
示例3: test_list
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
def test_list(self):
"""
list of servers
"""
clear_db()
s1 = Server.create(server_id=None, tenant_id=1, name="name1", status="ready")
s2 = 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/"), 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 == {
"servers": [
{"status": s1.status, "id": s1.server_id, "name": s1.name},
{"status": s2.status, "id": s2.server_id, "name": s2.name},
]
}
示例4: test_delete
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
def test_delete(self):
"""
delete existing server
"""
clear_db()
s1 = Server.create(server_id=None, tenant_id=1, name="name1", status="ready")
request = HTTPRequest(
self.get_url("/1/servers/" + str(s1.server_id)),
method="DELETE",
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": "deleted", "id": s1.server_id}
示例5: post
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
def post(self, tenant_id):
name = self.get_argument('name')
if not 20 >= len(name) >= 5:
self.write({'status': 'invalid_name'})
return
server = Server.create(
server_id=None,
tenant_id=tenant_id,
name=name,
)
IOLoop.current().spawn_callback(self.run_task, server.server_id)
self.write({
'id': server.server_id,
'name': server.name,
'status': server.status,
})
示例6: post
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
def post(self):
server = Server.create(name=self.request.form.name.data, is_gce=self.request.form.gce.data)
self.json_response(server, SERVER_STRATEGY, status_code=201)
示例7: test_get_multi_server
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
def test_get_multi_server(self):
Server.create()
self.log_in_user()
response = self.get()
self.assertOK(response)
示例8: setUp
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import create [as 别名]
def setUp(self):
super(MainBaseTest, self).setUp()
self.server = Server.create()