def cmd_setup_slave(args): ''' Setup proper slave environment and connect to master server ''' if not args.export: cmd = ["mkt", "setup", "--no-dirs"] if args.yes: cmd.append("-y") if args.force: cmd.append("-f") subprocess.call(cmd) utils.init_config_file() section = utils.load_config_file() subprocess.call(["sudo", "mkdir", "-p", section['src']]) subprocess.call(["sudo", "chown", "-R", utils.username() + ":" + utils.group(), section['src']]) subprocess.call(["sudo", "mkdir", "-p", section['logs']]) subprocess.call(["sudo", "chown", "-R", utils.username() + ":" + utils.group(), section['logs']]) with tempfile.NamedTemporaryFile("w") as f: f.write(open("/etc/fstab").read()) export = args.hostname[0] + ":" + \ section['src'][:-1] + "\t" + section['src'][:-1] + \ "\t" + "nfs" + "\t" + "ro,nolock 0 0" + "\n" + \ args.hostname[0] + ":" + \ section['logs'][:-1] + "\t" + section['logs'][:-1] + \ "\t" + "nfs" + "\t" + "rw,nolock 0 0" + "\n" f.write(export) f.flush() subprocess.call(["sudo", "cp", f.name, "/etc/fstab"]) subprocess.call(["sudo", "mount", "-a", "-t", "nfs", "-o", "remount"])
def get(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() if user: is_admin = username(user) in dojo('/groups/events') is_staff = username(user) in dojo('/groups/staff') can_approve = (event.status in ['pending'] and is_admin) can_staff = (event.status in ['pending', 'understaffed', 'approved'] and is_staff and not user in event.staff) logout_url = users.create_logout_url('/') else: login_url = users.create_login_url('/') self.response.out.write(template.render('templates/event.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() is_admin = username(user) in dojo('/groups/events') is_staff = username(user) in dojo('/groups/staff') state = self.request.get('state') if state: if state.lower() == 'approve' and is_admin: event.approve() if state.lower() == 'staff' and is_staff: event.add_staff(user) if state.lower() == 'cancel' and is_admin: event.cancel() if state.lower() == 'expire' and is_admin: event.expire() if event.status == 'approved': notify_owner_approved(event) self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name)))
def get(self): user = users.get_current_user() if user: logout_url = users.create_logout_url('/') else: login_url = users.create_login_url('/') today = datetime.today() events = Event.all().filter('start_time < ', today).order('-start_time') is_admin = username(user) in dojo('/groups/events') self.response.out.write(template.render('templates/past.html', locals()))
def get(self): user = users.get_current_user() if user: logout_url = users.create_logout_url('/') else: login_url = users.create_login_url('/') events = Event.all().filter('member = ', user).order('start_time') today = datetime.today() tomorrow = today + timedelta(days=1) is_admin = username(user) in dojo('/groups/events') self.response.out.write(template.render('templates/myevents.html', locals()))
def get(self): user = users.get_current_user() if user: logout_url = users.create_logout_url('/') else: login_url = users.create_login_url('/') events = Event.get_pending_list() today = datetime.today() tomorrow = today + timedelta(days=1) is_admin = username(user) in dojo('/groups/events') self.response.out.write(template.render('templates/pending.html', locals()))
def cmd_setup(args): """Setup environment.""" if not args.dirs: args.kernel = False args.rdma_core = False args.iproute = False if args.installs: print(""" This setup script will update your hypervisor to latest distribution packages and install docker. Please restart the hypervisor to complete the installation. """) if args.yes is False and utils.query_yes_no("Do you want to proceed?", 'no') is False: exit("Exiting ...") supported_os = { 'fedora': '26', 'ubuntu': '16', 'rhel': '8', 'redhat': '8', } # Python API stability is dissaster # module platform was deprecated https://docs.python.org/3/library/platform.html # Luckily enough, they added distro module before removing platform try: import distro distro_id = distro.id() distro_v = distro.major_version() except ModuleNotFoundError: import platform distro_id = platform.dist()[0].lower() distro_v = platform.dist()[1].split('.')[0] if distro_id not in supported_os.keys( ) or distro_v < supported_os[distro_id]: exit(""" Your hypervisor is not supported. Exiting ...""") if args.installs: setuphv = utils.get_internal_fn('scripts/') if distro_id == 'redhat': distro_id = 'rhel' setuphv += 'setup-hv.' + distro_id subprocess.check_call(setuphv) utils.init_config_file() section = utils.load_config_file() if args.dirs: for key, value in section.items(): if args.force: subprocess.call(["sudo", "rm", "-rf", value]) if os.path.exists(value): exit("Please remove " + value + " Exiting ...") if key == "kernel" and not args.kernel: continue if key == "rdma-core" and not args.rdma_core: continue if key == "iproute2" and not args.iproute: continue if key == 'os': continue print("Prepare " + key) subprocess.call(["sudo", "mkdir", "-p", value]) subprocess.call([ "sudo", "chown", "-R", utils.username() + ":" + utils.group(), value ]) if key == "src" or key == "logs" or key == "ccache": continue if key == "kernel": key = "linux" p = subprocess.Popen([ "git", "clone", "ssh://" + utils.username() + "@l-gerrit.mtl.labs.mlnx:29418/upstream/" + key, "." ], cwd=value) p.wait() p = subprocess.Popen([ "scp", "-p", "-P", "29418", utils.username() + "@l-gerrit.mtl.labs.mlnx:hooks/commit-msg", ".git/hooks/" ], cwd=value) p.wait() if key == "linux": shutil.copy( os.path.join(os.path.dirname(__file__), "../configs/kconfig-kvm"), value + "/.config") print("Completed, PLEASE RESTART server")