예제 #1
0
파일: main.py 프로젝트: LXiong/Smweb
	def post(self):
		import datetime
		modlist = {"test":" --dry-run ","sync":" ","backup":" ","restart":"restart"}
		user = self.current_user
		project = self.get_argument('item')
		items = db.query('select * from Deployinfo where item="%s"' % project)
		hosts = []
		ips = self.get_body_arguments('ipaddr[]')
		for item in items:
			source_dir = item["s_dir"]
			dest_dir = item["d_dir"]
			exclude_file = item["execlude"]
			for ip in ips:
				if ip == item["ipaddress"]:
					hosts.append(item["hostname"])
		method = self.get_argument('cmd')
		if method == "test":
			mod = modlist["test"]
			logresult = multisync(mod=mod,hosts=ips,source_dir=source_dir,dest_dir=dest_dir,exclude_file=exclude_file)
			self.write(logresult)
		elif method == "sync":
			mod = modlist["sync"]
			logresult = multisync(mod=mod,hosts=ips,source_dir=source_dir,dest_dir=dest_dir,exclude_file=exclude_file)
			self.write(logresult)
		elif method == "backup":
			s_dir = os.path.split(dest_dir)[0]
			format = "%Y%m%d"
			today = datetime.datetime.today()
			Date = today.strftime(format)
			Backup_dir = "/backup/" + Date
			logresult = Backup(host=ips[0],s_dir=s_dir,d_dir=Backup_dir)
			self.write(logresult)
		elif method == "restart":
			cmd = "/home/mark/web_service.sh restart"
			logresult = salt_client(hosts,cmd)
			self.write(logresult)	
예제 #2
0
파일: main.py 프로젝트: LXiong/Smweb
	def post(self):
		host = self.get_argument("ipaddr")
		cmd = self.get_argument("cmd")
		logresult = salt_client(host,cmd)
		self.write(logresult)