def add_one_user(self): self.deactivate_buttons() temp_id = int(self.id_entry.get()) e_mail = self.em_entry.get() first_name = self.fn_entry.get() last_name = self.ln_entry.get() # Checks that all the fields are filled in. if temp_id != "" and e_mail != "" and first_name != "" and last_name != "": # Checks that user has not been previously added if cT.user_by_id(temp_id) is None: curr_user = cT.create_single_user(temp_id, first_name, last_name, e_mail)[0] curr_vm = cT.get_vm_object(curr_user.assigned_VM) curr_vm.is_instance_ready() curr_vm.stop_instance() else: messagebox.showinfo("User Error", "This user already exist", parent=self) else: messagebox.showinfo( "Missing Requirements", "ID, eMail, First Name, and Last Name fields must be filled.", parent=self) self.clear_single_user_fields() self.activate_buttons()
def delete_user(self): curr_user = self.selected_user if curr_user.isTeacher is False: curr_vm = cT.get_vm_object(curr_user.assigned_VM) user_response = messagebox.askokcancel( "Delete", "Are you sure you want to delete this user? " "This will result in the irreversible deletion of the " "associated VM.", parent=self) if user_response is False: print("Canceled") else: # delete current user VM cT.del_vm(curr_vm) # delete current user cT.del_user(curr_user) # refresh the list of students self.update_list() else: messagebox.showinfo( "Warning", "This is a teacher and cannot be removed this way.", parent=self) self.clear_form()
def on_select(self, event): widget = event.widget index = widget.curselection()[0] self.curr_user = self.users[index] # Sets the VM globally in case of shutdown of app self.controller.vm = cT.get_vm_object(self.curr_user.assigned_VM) self.link_button.config(state=tk.ACTIVE) self.link_button.update()
def create_multi_user(self): cs_file = self.csv_entry.get() self.deactivate_buttons() if cs_file != "": user_csv_list = [] with open(cs_file, 'r', newline='') as CSV_FILE: reader = csv.reader(CSV_FILE) next(reader) for user_list in reader: user_csv_list.append(user_list) # Sets up the progress bar self.csv_progress['maximum'] = len(user_csv_list) * 2 bar = 0 # Creates user and assigns vm for new_user in user_csv_list: if new_user: if cT.user_by_id(int(new_user[0])) is None: success = cT.create_single_user( new_user[0].strip(), new_user[1].strip(), new_user[2].strip(), new_user[3].strip()) if not success[1]: messagebox.showinfo( "Warning", "Unable to notify user {0} of their account's password." .format(new_user[0]), parent=self) bar += 1 self.csv_progress["value"] = bar self.csv_progress.update() # waits for all machines to finish loading and shuts them down for curr_user in cT.get_list_users(): if curr_user.isTeacher is False: curr_vm = cT.get_vm_object(curr_user.assigned_VM) curr_vm.is_instance_ready() curr_vm.stop_instance() bar += 1 self.csv_progress["value"] = bar self.csv_progress.update() messagebox.showinfo("Done", "Process completed.", parent=self) self.csv_progress["value"] = 0 self.csv_progress.update() else: messagebox.showinfo( "Missing Info", "You need to first load a .csv file and provide a valid AMI.", parent=self) self.clear_multi_user_fields() self.activate_buttons()
def disconnect(self): curr_vm = self.controller.vm curr_vm.stop_instance() self.disconnect_flag = True # Returns Global VM to Users self.controller.vm = cT.get_vm_object(self.controller.user.assigned_VM) self.toggle_button() self.user_list.config(state=tk.NORMAL) self.ser_button.config(state=tk.ACTIVE) self.user_list.update() self.ser_button.update()
def on_select(self, event): widget = event.widget index = widget.curselection()[0] self.selected_vm = cT.get_vm_object(self.user_list[index].assigned_VM) info = self.selected_vm.get_info() self.ami_out.config( text=info['Reservations'][0]['Instances'][0]['ImageId']) self.owner_out.config(text=(self.user_list[index].firstName + " " + self.user_list[index].lastName)) self.status_out.config( text=info['Reservations'][0]['Instances'][0]['State']['Name']) self.dwn_button.config(state=tk.ACTIVE, command=lambda: self.download(self.selected_vm)) self.on_button.config(state=tk.ACTIVE, command=lambda: self.power("ON")) self.off_button.config(state=tk.ACTIVE, command=lambda: self.power("OFF"))
def open_site(self): global vm messagebox.showinfo( "Warning", "This process may take a while. A window will open on your browser when it's ready.", parent=self) curr_user = self.selected_user if curr_user.assigned_VM is not None: vm = cT.get_vm_object(curr_user.assigned_VM) vm.start_instance() vm.is_instance_ready() site = "http://" + vm.get_instance_ip() + "/moodle" webbrowser.open(site) else: messagebox.showinfo( "Warning", "This is a teacher and does not have a VM assigned.", parent=self)
def verify_login(self): user_id = int(self.unEntry.get()) if cT.verify_user(user_id, self.pwEntry.get()): user = cT.user_by_id(user_id) if user.isTeacher is False: if user.isSuspended is False: self.controller.vm = cT.get_vm_object(user.assigned_VM) self.controller.vm.start_instance() self.controller.user = user self.controller.show_frame("StudentPage") else: messagebox.showinfo( "Warning", "Your Account Has Been Suspended. Please Contact Instructor", parent=self) else: self.controller.show_frame("TeacherPage") else: messagebox.showinfo( "Warning", "Please Check Your Username And Password Then Try Again", parent=self)
def shutdown_all(self): for vm_user in self.user_list: curr_vm = cT.get_vm_object(vm_user.assigned_VM) curr_vm.stop_instance()
def power_all(self): for vm_user in self.user_list: curr_vm = cT.get_vm_object(vm_user.assigned_VM) curr_vm.start_instance()
def test_vm_created(self): test_user = cT.user_by_id(self.user) self.assertIsNotNone(cT.get_vm_object(test_user.assigned_VM))
def tearDown(self) -> None: test_user = cT.user_by_id(self.user) test_vm = cT.get_vm_object(test_user.assigned_VM) cT.del_user(test_user) cT.del_vm(test_vm)