def delete_system_user(user_id, username): """ Delete a system user from Joomla and also delete all accounts on all VMs. FIXME: Delete users in a celery task? What do we do if the user can't be deleted, the VM is off, etc???? """ user_db = Cvl_users.select(Cvl_users.q.id==user_id).getOne() # For each VM that the user is a member of: for vm_id, vm_ip, vm_name in cvlsql.get_users_vms(user_id): # Delete the user's account on the VM. try: cvlfabric.env.hosts = [vm_ip] cvlfabric.execute(cvlfabric.delete_user, username=username, warn_only=True) except: logging.error('Could not delete user %s from VM %s' % (username, vm_ip,)) # Remove the mapping from the user to the VM. cvlsql.delete_user_from_vm(user_id, vm_id) # Remove the user's user_group mapping: Cvl_user_usergroup_map.delete(Cvl_user_usergroup_map.select(Cvl_user_usergroup_map.q.id==user_id).getOne().id) # Remove the user record. Cvl_users.delete(user_id)
def ChangePassword(self): new_unix_password = crypt.crypt(self.password, "CvlEncryption") # At this point: # self.password = new plain text password that the user entered # self.cryptedPassword = new joomla password # new_unix_password = new Unix password, encrypted for (vm_id, vm_ip, vm_name) in cvlsql.get_users_vms(self.userId): job = utils.ChangePasswordsOnVMs.apply_async([vm_name, self.username, Cvl_users.select(Cvl_users.q.id==self.userId).getOne().email, new_unix_password], kwargs={}, queue='usermanagement') # Update Joomla password: Cvl_users.select(Cvl_users.q.id==self.userId).getOne().password = self.cryptedPassword # Update stored Unix VM password: Cvl_cvl_vm_user.select(Cvl_cvl_vm_user.q.id==self.userId).getOne().vmPassword = new_unix_password return True