def post(self): taskname = self.get_argument("taskname") repo_uri = self.get_argument("repo_uri") entry_point = self.get_argument("entry_point") hosts = json.loads(self.get_argument("hosts")) username = self.get_secure_cookie("username") user_id = UserMeta.query.filter_by(username=username).first().id deploy_item = DeployMeta(taskname=taskname, user_id=user_id, repo_uri=repo_uri, entry_point=entry_point, hosts=hosts) session.add(deploy_item) session.commit() session.close() do_deploy(deploy_id=deploy_item.id, entry_point=entry_point, user="******", hosts=hosts, repo_uri=repo_uri) self.write({ deploy_item.id: { "Taskname": deploy_item.taskname, "Status": deploy_item.status, "Created": created2str(created=deploy_item.created) } })
def post(self): hostname = self.get_argument("hostname") ip = self.get_argument("ip") ssh_secret_key = self.get_argument("ssh_secret_key") new_host(ip=ip, ssh_secret_key=ssh_secret_key) _host_item = HostMeta(hostname=hostname, ip=ip) session.add(_host_item) session.commit() session.close() self.write({ _host_item.id: json.loads(_host_item.status) })
def post(self): username = self.get_argument("username") password = self.get_argument("password") user_type = self.get_argument("type") public_key = self.get_argument("public_key") current_username = self.get_secure_cookie("username") query_data = UserMeta.query.filter_by(username=current_username).first() if query_data.user_type != 1: raise HTTPError(403) public_key_path = new_user_public_key(public_key) user = UserMeta(username=username, user_type=int(user_type), password=password, public_key=public_key_path) session.add(user) session.commit() session.close() self.write({"msg": "success"})
def patch(self): username = self.get_secure_cookie("username") user_item = UserMeta.query.filter_by(username=username).first() user_id, public_key_path = user_item.id, user_item.public_key host_id, has_permission = ( int(self.get_argument("host_id")), True if self.get_argument("has_permission") == "true" else False ) if has_permission: host_ip = HostMeta.get_all_hosts_status()[host_id]["IP"] ssh_permission_item = SSHPermissionMeta( user_id=user_id, host_id=host_id ) session.add(ssh_permission_item) session.commit() session.close() print public_key_path, user_id subprocess.call( "cat " + public_key_path + " | ssh root@" + host_ip + " \'cat >> ~/.ssh/authorized_keys\'", shell=True ) self.write({"msg": "success"})
def change_password(cls, username, password): user_mata_info = cls.query.filter_by(username=username).first() user_mata_info.password = pbkdf2_sha256.encrypt(password) session.add(user_mata_info) session.commit() session.close()
def update_host_dockers_status(cls, ip, dockers_status): host = cls.query.filter_by(ip=ip).first() if host: host.dockers_status = json.dumps(dockers_status) session.commit() session.close()
def update_host_process_status(cls, ip, process_status): host = cls.query.filter_by(ip=ip).first() if host: host.process_status = json.dumps(process_status) session.commit() session.close()