Exemple #1
0
def remove(user,subuserNames):
  didSomething = False
  for subuserName in subuserNames:
    if subuserName in user.getRegistry().getSubusers():
      user.getRegistry().logChange("Removing subuser "+str(subuserName))
      try:
        subuserHome = user.getRegistry().getSubusers()[subuserName].getHomeDirOnHost()
        if subuserHome and os.path.exists(subuserHome):
          user.getRegistry().logChange(" If you wish to remove the subusers home directory, issule the command $ rm -r "+subuserHome)
      except:
        pass
      user.getRegistry().logChange(" If you wish to remove the subusers image, issue the command $ subuser remove-old-images")
      subuser = user.getRegistry().getSubusers()[subuserName]
      for serviceSubuser in subuser.getServiceSubuserNames():
        try:
          user.getRegistry().getSubusers()[serviceSubuser].removePermissions()
          del user.getRegistry().getSubusers()[serviceSubuser]
        except KeyError:
          pass
      # Remove service locks
      try:
        shutil.rmtree(os.path.join(user.getConfig()["lock-dir"],"services",subuserName))
      except OSError:
        pass
      # Remove permission files
      user.getRegistry().getSubusers()[subuserName].removePermissions()
      del user.getRegistry().getSubusers()[subuserName]
      didSomething = True
    else:
      print("Cannot remove: subuser "+subuserName+" does not exist.")
  if didSomething:
    subuserlib.verify.verify(user)
    user.getRegistry().commit()
Exemple #2
0
def remove(user,subuserNames):
  didSomething = False
  for subuserName in subuserNames:
    if subuserName in user.getRegistry().getSubusers():
      user.getRegistry().logChange("Removing subuser "+str(subuserName))
      try:
        subuserHome = user.getRegistry().getSubusers()[subuserName].getHomeDirOnHost()
        if subuserHome and os.path.exists(subuserHome):
          user.getRegistry().logChange(" If you wish to remove the subusers home directory, issule the command $ rm -r "+subuserHome)
      except:
        pass
      user.getRegistry().logChange(" If you wish to remove the subusers image, issue the command $ subuser remove-old-images")
      subuser = user.getRegistry().getSubusers()[subuserName]
      for serviceSubuser in subuser.getServiceSubuserNames():
        try:
          user.getRegistry().getSubusers()[serviceSubuser].removePermissions()
          del user.getRegistry().getSubusers()[serviceSubuser]
        except KeyError:
          pass
      # Remove service locks
      try:
        shutil.rmtree(os.path.join(user.getConfig()["lock-dir"],"services",subuserName))
      except OSError:
        pass
      # Remove permission files
      user.getRegistry().getSubusers()[subuserName].removePermissions()
      del user.getRegistry().getSubusers()[subuserName]
      didSomething = True
    else:
      print("Cannot remove: subuser "+subuserName+" does not exist.")
  if didSomething:
    subuserlib.verify.verify(user)
    user.getRegistry().commit()