示例#1
0
文件: main.py 项目: whs/OvzCP
	def post(self):
		if self.current_user.credit < 5000:
			self.redirect(self.reverse_url("containers")+"?error=6")
			return
		if not self.get_argument("tos", False):
			self.redirect(self.reverse_url("createvm")+"?error=1")
			return
		if self.get_argument("os", "_/|\_") not in openvz.listTemplates():
			self.redirect(self.reverse_url("createvm")+"?error=2")
			return
		if self.get_argument("root", "omgwtflol") != self.get_argument("root2", "roflcopters"):
			self.redirect(self.reverse_url("createvm")+"?error=3")
			return
		hostnames = map(lambda x: x.hostname,openvz.listVM())
		if not re.match("^([\.0-9A-Za-z_\-]+)$", self.get_argument("hostname", "^^!!!!")) or self.get_argument("hostname") in hostnames:
			self.redirect(self.reverse_url("createvm")+"?error=4")
			return
		try:
			models.Nonce.get(int(self.get_argument("nonce"))).destroySelf()
		except:
			self.redirect(self.reverse_url("createvm")+"?error=5")
			return
		try:
			veid = openvz.listVM()[-1].veid+1
		except IndexError:
			veid = 101
		if not models.VM.select(models.VM.q.veid == veid).count():
			models.VM(veid=veid, user=self.current_user)
		else:
			v = models.VM.select(models.VM.q.veid == veid)[0]
			v.user = self.current_user
		self.redirect(self.reverse_url("containers"))
		vm=openvz.createVM(self.get_argument("os"), veid, _config.get("iface", "nameserver"), self.get_argument("root"))
		# hostname
		vm.hostname = self.get_argument("hostname")
		# ram
		ram = float(self.get_argument("ram"))
		burst = math.floor(ram+(ram*int(_config.get("billing", "memoryBurst"))/100))
		memlimit = [ram, burst, burst+10240]
		vm.memlimit = memlimit
		# disk
		vm.diskinfo = float(self.get_argument("disk"))
		# add IP
		vm.ip = _config.get("iface", "vmIP")+str(vm.veid)
示例#2
0
文件: main.py 项目: whs/OvzCP
	def get(self):
		if self.current_user.credit < 5000:
			self.redirect(self.reverse_url("containers")+"?error=6")
			return
		hostnames = map(lambda x: x.hostname,openvz.listVM())
		err=""
		if self.get_argument("error", None):
			e = self.get_argument("error")
			if e == "1":
				err=_("Terms of Service not accepted")
			elif e == "2":
				err=_("Invalid template name")
			elif e == "3":
				err=_("Passwords do not match")
			elif e == "4":
				err=_("Invalid hostname")
			elif e == "5":
				err = _("Verification failed. Did you double-submitted the form?")
		import random
		nonce=models.Nonce().id
		self.render("create.html", templates=openvz.listTemplates(), hostnames = hostnames,
			title=_("Creating VM"), error=err, nonce=nonce)