Ejemplo n.º 1
0
 def run(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("checkUtilityDirectory: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     
     session = dissomniag.Session()
     self.success = False
     self.job.trace("IN CHECK UTILITY DIRECTORY")
     
     maintainanceIp = self.context.host.getMaintainanceIP().addr
     self.job.trace("UtilityFolder: %s" % self.context.host.utilityFolder)
     checkUtilityFolderExistsCmd = dissomniag.utils.SSHCommand("[ -d '%s' ]" % self.context.host.utilityFolder, hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
     code, output = checkUtilityFolderExistsCmd.callAndGetOutput()
     if code != 0:
         #Directory does not exists. Try to create it.
         fullpath = os.path.join(self.context.host.utilityFolder, dissomniag.config.hostConfig.vmSubdirectory)
         self.job.trace("Make Utility Directory! %s" % fullpath)
         createUtilityFolderCmd = dissomniag.utils.SSHCommand("mkdir -p %s" % fullpath, hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
         code, output = createUtilityFolderCmd.callAndGetOutput()
         if code != 0 :
             self.job.trace("createUtilityFolder: Unable To create Utility Folder.")
             self.context.host.configurationMissmatch = True
             dissomniag.saveFlush(session)
             self.success = False
             raise dissomniag.taskManager.UnrevertableFailure("Could not operate on Host!")
     #everything is ok.
     self.context.host.configurationMissmatch = False
     dissomniag.saveFlush(session)
     self.success = True
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 2
0
    def run(self):
        if not hasattr(self.context, "host") or type(
                self.context.host) != dissomniag.model.Host:
            self.job.trace(
                "chekLibvirtVersionOnHost: In Context missing host object.")
            raise dissomniag.taskManager.UnrevertableFailure(
                "In Context missing host object.")

        maintainanceIp = self.context.host.getMaintainanceIP().addr
        self.job.trace(
            "checkLibvirtVersionOnHost: (Host: %s) virsh --version" %
            self.context.host.commonName)

        sshCmd = dissomniag.utils.SSHCommand(
            "virsh --version",
            hostOrIp=maintainanceIp,
            username=self.context.host.administrativeUserName)
        code, output = sshCmd.callAndGetOutput(withError=False)
        if code != 0:
            self.job.trace(
                "checkLibvirtVersionOnHost: Could not execute 'virsh --version'!"
            )
            return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
        self.context.host.changeState(self.job.getUser(),
                                      dissomniag.model.NodeState.UP)
        self.context.host.libvirtVersion = output[0]
        self.context.host.lastChecked = datetime.datetime.now()
        session = dissomniag.Session()
        dissomniag.saveFlush(session)
        return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 3
0
 def __init__(self, context, description, user = None, group = None, target = None, name = None,
              args = (), kwargs = None, verbose = None):
     """
     Constructor
     """
     threading.Thread.__init__(self, group = group, target = target,
                                   name = name, verbose = verbose)
     session = dissomniag.Session()
     self.state = JobStates.QUEUED
     self.infoObj = JobInfo(description = description, state = self.state, user = user)
     session.add(self.infoObj)
     dissomniag.saveCommit(session)
     dissomniag.saveFlush(session)
     self.id = self.infoObj.id
     if user != None:
         self.user = user
     else:
         self.user = None
     
     
     self.context = context
     self.description = description
     self.taskList = []
     self.currentTaskId = 0
     self.runningLock = threading.RLock()
     self.writeProperty = threading.RLock()
     self.dispatcher = None
     
     self.infoObj = None
Ejemplo n.º 4
0
 def run(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("getFreeDiskSpaceOnHost: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     
     maintainanceIp = self.context.host.getMaintainanceIP().addr
     
     folder = "/" #self.context.host.utilityFolder
     if folder == None:
         folder = "/"
     self.job.trace("getFreeDiskSpaceOnHost: (Host: %s) df -h %s" % (self.context.host.commonName, folder))
     sshCmd = dissomniag.utils.SSHCommand(("df -h %s" % folder), hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
     code, output = sshCmd.callAndGetOutput()
     if code != 0:
         self.job.trace("getFreeDiskSpaceOnHost: Unable to get FreeDiskSpace on Host %s" % self.context.host.commonName)
         return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
     
     line = output[1] # First line is Description, Second Line is Info Line of df
     freeSpace = shlex.split(line)[3] # Third object in Line if info about Free Diskspace
     self.context.host.freeDiskspace = freeSpace
     self.context.host.lastChecked = datetime.datetime.now()
     self.context.host.changeState(self.job.getUser(), dissomniag.model.NodeState.UP)
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 5
0
    def run(self):
        if not hasattr(self.context, "host") or type(
                self.context.host) != dissomniag.model.Host:
            self.job.trace(
                "getRamCapacityOnHost: In Context missing host object.")
            raise dissomniag.taskManager.UnrevertableFailure(
                "In Context missing host object.")

        maintainanceIp = self.context.host.getMaintainanceIP().addr
        self.job.trace(
            "getRamCapacityOnHost: (Host: %s) at /proc/meminfo | head -n 1 | awk '/[0-9]/ {print $2}'"
            % self.context.host.commonName)
        sshCmd = dissomniag.utils.SSHCommand(
            "cat /proc/meminfo",
            hostOrIp=maintainanceIp,
            username=self.context.host.administrativeUserName)
        code, output = sshCmd.callAndGetOutput()
        if code != 0:
            self.job.trace("getRamCapacityOnHost: Unable to get RAM Capacity.")
            return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
        line = shlex.split(
            output[0])  #The first line is the only interesting line
        self.context.host.ramCapacity = str(
            int(line[1]) /
            1024) + "MB"  # The second fieled in this line is interesting
        self.context.host.lastChecked = datetime.datetime.now()
        self.context.host.changeState(self.job.getUser(),
                                      dissomniag.model.NodeState.UP)
        session = dissomniag.Session()
        dissomniag.saveFlush(session)
        return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 6
0
    def run(self):
        if not hasattr(self.context, "host") or type(
                self.context.host) != dissomniag.model.Host:
            self.job.trace("chekKvmOnHost: In Context missing host object.")
            raise dissomniag.taskManager.UnrevertableFailure(
                "In Context missing host object.")

        maintainanceIp = self.context.host.getMaintainanceIP().addr
        self.job.trace(
            "chekKvmOnHost: (Host: %s) egrep vmx --color=always /proc/cpuinfo"
            % self.context.host.commonName)
        sshCmd1 = dissomniag.utils.SSHCommand(
            "egrep vmx --color=always /proc/cpuinfo",
            hostOrIp=maintainanceIp,
            username=self.context.host.administrativeUserName)
        code1, output1 = sshCmd1.callAndGetOutput()
        sshCmd2 = dissomniag.utils.SSHCommand(
            "egrep svm --color=always /proc/cpuinfo",
            hostOrIp=maintainanceIp,
            username=self.context.host.administrativeUserName)
        code2, output2 = sshCmd2.callAndGetOutput()
        if code1 != 0 and code2 != 0:
            out = "\n".join(output1 + output2)
            self.job.trace(
                "checkLibvirtVersionOnHost: Could not execute 'egrep vmx --color=always /proc/cpuinfo' %s!"
                % out)
            self.context.host.kvmUsable = False
            return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
        self.context.host.changeState(self.job.getUser(),
                                      dissomniag.model.NodeState.UP)
        self.context.host.kvmUsable = True
        self.context.host.lastChecked = datetime.datetime.now()
        session = dissomniag.Session()
        dissomniag.saveFlush(session)
        return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 7
0
 def revert(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("gatherLibvirtCapabilities: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     self.context.host.libvirtCapabilities = None
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 8
0
 def revert(self):
     if not hasattr(self.context, "host") or type(
             self.context.host) != dissomniag.model.Host:
         self.job.trace(
             "gatherLibvirtCapabilities: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure(
             "In Context missing host object.")
     self.context.host.libvirtCapabilities = None
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 9
0
    def implementation(self, *args):
        sys.stdout = self.terminal
        sys.stderr = self.terminal

        parser = argparse.ArgumentParser(description="Delete a user",
                                         prog=args[0])
        parser.add_argument(
            "username",
            action="store",
            help="Enter the username of the User you want to delete.")
        options = parser.parse_args(args[1:])

        if not self.user.isAdmin:
            self.printError(
                "Permission denied: Only Admin users are allowed to delete a users!"
            )
            return

        if options.username == self.user.username:
            self.printError("Permission denied: You cannot delete yourself!")
            return

        if options.username == dissomniag.config.htpasswd.adminUser:
            self.printError(
                "Permission denied: You cannot delete the default admin user!")
            return

        if options.username == dissomniag.Identity.systemUserName:
            self.printError(
                "Permission denied: You cannot delete the system user!")
            return

        session = dissomniag.Session()

        try:
            user = session.query(User).filter(
                User.username == options.username).one()
            if user.isMaintain:
                self.printError(
                    "Permission denied: You cannot delete a maintainance User!"
                )
                return
            session.delete(user)
            dissomniag.saveCommit(session)
            dissomniag.saveFlush(session)
        except NoResultFound:
            self.printError("User %s does not exists." % options.username)
            return
        except Exception:
            self.printError("Unspecified Error")
            return

        self.printSuccess("User %s successful deleted." % options.username)
Ejemplo n.º 10
0
 def implementation(self, *args):
     sys.stdout = self.terminal
     sys.stderr = self.terminal
     
     parser = argparse.ArgumentParser(description = "Delete a key", prog = args[0])
     parser.add_argument("keyId", action = "store", type = int, help = "Enter the Key-ID of the key you want to delete.")
     if self.user.isAdmin:
         parser.add_argument("-u", "--username", action = "store", help = "The user where to delete a key.", dest = "username", default = None)
         parser.add_argument("-f", "--force", action = "store_true", help = "Force to delete key in all users.", dest = "force", default = False)
     options = parser.parse_args(args[1:])
     
     session = dissomniag.Session()
     
     user = self.user
     
     if self.user.isAdmin:
         if options.force:
             try:
                 key = session.query(PublicKey).filter(PublicKey.id == options.keyId).one()
             except Exception:
                 self.printError("Could not find Key.")
                 return
             session.delete(key)
             dissomniag.saveCommit(session)
             dissomniag.saveFlush(session)
             return
         
         if options.username and options.username != self.user.username:
             # Change in other user
             try:
                 user = session.query(User).filter(User.username == options.username).one()
             except NoResultFound:
                 self.printError("Could not find user.")
                 return
         
     for key in user.publicKeys:
         if key.id == options.keyId:
             user.publicKeys.remove(key)
             if len(key.users) == 0:
                 #Only the actual user owns that key
                 session.delete(key)
                 dissomniag.saveCommit(session)
                 dissomniag.saveFlush(session)
             return
                     
     #Key not found
     self.printError("Could not find the key. Key-ID: %s" % options.keyId)
     return
Ejemplo n.º 11
0
 def run(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("gatherLibvirtCapabilities: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     
     try:
         con = libvirt.open(str(self.context.host.qemuConnector))
     except libvirt.libvirtError:
         raise dissomniag.taskManager.TaskFailed("Could Not Connect to Libvirt Host!")
     
     try:
         self.context.host.libvirtCapabilities = con.getCapabilities()
     except libvirt.libvirtError:
         return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
     
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 12
0
    def run(self):
        if not hasattr(self.context, "host") or type(
                self.context.host) != dissomniag.model.Host:
            self.job.trace(
                "checkUtilityDirectory: In Context missing host object.")
            raise dissomniag.taskManager.UnrevertableFailure(
                "In Context missing host object.")

        session = dissomniag.Session()
        self.success = False
        self.job.trace("IN CHECK UTILITY DIRECTORY")

        maintainanceIp = self.context.host.getMaintainanceIP().addr
        self.job.trace("UtilityFolder: %s" % self.context.host.utilityFolder)
        checkUtilityFolderExistsCmd = dissomniag.utils.SSHCommand(
            "[ -d '%s' ]" % self.context.host.utilityFolder,
            hostOrIp=maintainanceIp,
            username=self.context.host.administrativeUserName)
        code, output = checkUtilityFolderExistsCmd.callAndGetOutput()
        if code != 0:
            #Directory does not exists. Try to create it.
            fullpath = os.path.join(
                self.context.host.utilityFolder,
                dissomniag.config.hostConfig.vmSubdirectory)
            self.job.trace("Make Utility Directory! %s" % fullpath)
            createUtilityFolderCmd = dissomniag.utils.SSHCommand(
                "mkdir -p %s" % fullpath,
                hostOrIp=maintainanceIp,
                username=self.context.host.administrativeUserName)
            code, output = createUtilityFolderCmd.callAndGetOutput()
            if code != 0:
                self.job.trace(
                    "createUtilityFolder: Unable To create Utility Folder.")
                self.context.host.configurationMissmatch = True
                dissomniag.saveFlush(session)
                self.success = False
                raise dissomniag.taskManager.UnrevertableFailure(
                    "Could not operate on Host!")
        #everything is ok.
        self.context.host.configurationMissmatch = False
        dissomniag.saveFlush(session)
        self.success = True
        return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 13
0
 def run(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("getRamCapacityOnHost: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     
     maintainanceIp = self.context.host.getMaintainanceIP().addr
     self.job.trace("getRamCapacityOnHost: (Host: %s) at /proc/meminfo | head -n 1 | awk '/[0-9]/ {print $2}'" % self.context.host.commonName)
     sshCmd = dissomniag.utils.SSHCommand("cat /proc/meminfo", hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
     code, output = sshCmd.callAndGetOutput()
     if code != 0:
         self.job.trace("getRamCapacityOnHost: Unable to get RAM Capacity.")
         return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
     line = shlex.split(output[0]) #The first line is the only interesting line
     self.context.host.ramCapacity = str(int(line[1]) / 1024) + "MB" # The second fieled in this line is interesting
     self.context.host.lastChecked = datetime.datetime.now()
     self.context.host.changeState(self.job.getUser(), dissomniag.model.NodeState.UP)
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 14
0
 def run(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("chekLibvirtVersionOnHost: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     
     maintainanceIp = self.context.host.getMaintainanceIP().addr
     self.job.trace("checkLibvirtVersionOnHost: (Host: %s) virsh --version" % self.context.host.commonName)
     
     sshCmd = dissomniag.utils.SSHCommand("virsh --version", hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
     code, output = sshCmd.callAndGetOutput(withError = False)
     if code != 0:
         self.job.trace("checkLibvirtVersionOnHost: Could not execute 'virsh --version'!")
         return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
     self.context.host.changeState(self.job.getUser(), dissomniag.model.NodeState.UP)
     self.context.host.libvirtVersion = output[0]
     self.context.host.lastChecked = datetime.datetime.now()
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 15
0
 def implementation(self, *args):
     sys.stdout = self.terminal
     sys.stderr = self.terminal
     
     parser = argparse.ArgumentParser(description = "Delete a user", prog = args[0])
     parser.add_argument("username", action = "store", help = "Enter the username of the User you want to delete.")
     options = parser.parse_args(args[1:])
     
     if not self.user.isAdmin:
         self.printError("Permission denied: Only Admin users are allowed to delete a users!")
         return
     
     if options.username == self.user.username:
         self.printError("Permission denied: You cannot delete yourself!")
         return
     
     if options.username == dissomniag.config.htpasswd.adminUser:
         self.printError("Permission denied: You cannot delete the default admin user!")
         return
     
     if options.username == dissomniag.Identity.systemUserName:
         self.printError("Permission denied: You cannot delete the system user!")
         return
     
     session = dissomniag.Session()
     
     try:
         user = session.query(User).filter(User.username == options.username).one()
         if user.isMaintain:
             self.printError("Permission denied: You cannot delete a maintainance User!")
             return
         session.delete(user)
         dissomniag.saveCommit(session)
         dissomniag.saveFlush(session)
     except NoResultFound:
         self.printError("User %s does not exists." % options.username)
         return
     except Exception:
         self.printError("Unspecified Error")
         return
     
     self.printSuccess("User %s successful deleted." % options.username)
Ejemplo n.º 16
0
    def implementation(self, *args):
        sys.stdout = self.terminal
        sys.stderr = self.terminal
        
        parser = argparse.ArgumentParser(description = "Add a user to DiSSOmniaG. ADMIN ACCESS NEEDED!", prog = args[0])
        parser.add_argument("-a", "--admin", action = "store_true", dest = "isAdmin", default = False)
        parser.add_argument("--dissable-ssh", action = "store_false", dest = "loginSSH", default = True)
        parser.add_argument("--dissable-rpc", action = "store_false", dest = "loginRPC", default = True)
        parser.add_argument("--enable-manhole", action = "store_true", dest = "loginManhole", default = False)
        parser.add_argument("username", action = "store")
        parser.add_argument("password", action = "store")
        parser.add_argument("-k", "--key", action = "store", nargs = "*", dest = "key", help = "Provide the key as the last Argument!", default = None)
        
        options = parser.parse_args(args[1:])
        if not self.user.isAdmin:
            self.printError("Permission denied: Only Admin users are allowed to add a users!")
            return
        
        if options.key != None:
            options.key = " ".join(options.key)

        session = dissomniag.Session()
        try:
            existingUser = session.query(User).filter(User.username == options.username).one()
            if existingUser:
                self.printError("User already exists.")
                return
        except NoResultFound:
            newUser = User(options.username, options.password, publicKey = options.key,
                           isAdmin = options.isAdmin, loginRPC = options.loginRPC, loginSSH = options.loginSSH,
                           loginManhole = options.loginManhole, isHtpasswd = False)
            session.add(newUser)
            dissomniag.saveCommit(session)
            dissomniag.saveFlush(session)
        except MultipleResultsFound:
            self.printError("User already exists.")
            return
        
        self.printSuccess("SUCCESS")
Ejemplo n.º 17
0
 def run(self):
     if not hasattr(self.context, "host") or  type(self.context.host) != dissomniag.model.Host:
         self.job.trace("chekKvmOnHost: In Context missing host object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing host object.")
     
     maintainanceIp = self.context.host.getMaintainanceIP().addr
     self.job.trace("chekKvmOnHost: (Host: %s) egrep vmx --color=always /proc/cpuinfo" % self.context.host.commonName)
     sshCmd1 = dissomniag.utils.SSHCommand("egrep vmx --color=always /proc/cpuinfo", hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
     code1, output1 = sshCmd1.callAndGetOutput()
     sshCmd2 = dissomniag.utils.SSHCommand("egrep svm --color=always /proc/cpuinfo", hostOrIp = maintainanceIp, username = self.context.host.administrativeUserName)
     code2, output2 = sshCmd2.callAndGetOutput()
     if code1 != 0 and code2 != 0:
         out = "\n".join(output1 + output2)
         self.job.trace("checkLibvirtVersionOnHost: Could not execute 'egrep vmx --color=always /proc/cpuinfo' %s!" % out)
         self.context.host.kvmUsable = False
         return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
     self.context.host.changeState(self.job.getUser(), dissomniag.model.NodeState.UP)
     self.context.host.kvmUsable = True
     self.context.host.lastChecked = datetime.datetime.now()
     session = dissomniag.Session()
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 18
0
    def run(self):
        if not hasattr(self.context, "host") or type(
                self.context.host) != dissomniag.model.Host:
            self.job.trace(
                "gatherLibvirtCapabilities: In Context missing host object.")
            raise dissomniag.taskManager.UnrevertableFailure(
                "In Context missing host object.")

        try:
            con = libvirt.open(str(self.context.host.qemuConnector))
        except libvirt.libvirtError:
            raise dissomniag.taskManager.TaskFailed(
                "Could Not Connect to Libvirt Host!")

        try:
            self.context.host.libvirtCapabilities = con.getCapabilities()
        except libvirt.libvirtError:
            return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD

        session = dissomniag.Session()
        dissomniag.saveFlush(session)
        return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 19
0
    def run(self):
        if not hasattr(self.context, "host") or type(
                self.context.host) != dissomniag.model.Host:
            self.job.trace(
                "getFreeDiskSpaceOnHost: In Context missing host object.")
            raise dissomniag.taskManager.UnrevertableFailure(
                "In Context missing host object.")

        maintainanceIp = self.context.host.getMaintainanceIP().addr

        folder = "/"  #self.context.host.utilityFolder
        if folder == None:
            folder = "/"
        self.job.trace("getFreeDiskSpaceOnHost: (Host: %s) df -h %s" %
                       (self.context.host.commonName, folder))
        sshCmd = dissomniag.utils.SSHCommand(
            ("df -h %s" % folder),
            hostOrIp=maintainanceIp,
            username=self.context.host.administrativeUserName)
        code, output = sshCmd.callAndGetOutput()
        if code != 0:
            self.job.trace(
                "getFreeDiskSpaceOnHost: Unable to get FreeDiskSpace on Host %s"
                % self.context.host.commonName)
            return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD

        line = output[
            1]  # First line is Description, Second Line is Info Line of df
        freeSpace = shlex.split(line)[
            3]  # Third object in Line if info about Free Diskspace
        self.context.host.freeDiskspace = freeSpace
        self.context.host.lastChecked = datetime.datetime.now()
        self.context.host.changeState(self.job.getUser(),
                                      dissomniag.model.NodeState.UP)
        session = dissomniag.Session()
        dissomniag.saveFlush(session)
        return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 20
0
 def run(self):
     if not hasattr(self.context, "net") or not isinstance(self.context.net, dissomniag.model.generatedNetwork):
         self.job.trace("getStatusNetwork: In Context missing net object.")
         raise dissomniag.taskManager.UnrevertableFailure("In Context missing net object.")
     session = dissomniag.Session()
     con = None
     try:
         con = libvirt.open(str(self.context.net.getHost(self.job.getUser()).qemuConnector))
     except libvirt.libvirtError:
         raise dissomniag.taskManager.TaskFailed("Could Not Connect to Libvirt Host!")
     
     try:
         net = con.networkLookupByName(self.context.net.name)
     except libvirt.libvirtError:
         if self.context.net.state == dissomniag.model.GenNetworkState.INACTIVE:
             return dissomniag.taskManager.TaskReturns.SUCCESS
         elif self.context.net.state == dissomniag.model.GenNetworkState.CREATED:
             self.context.net.state = dissomniag.model.GenNetworkState.RUNTIME_ERROR
             dissomniag.saveFlush(session)
             self.context.net.operate(self.job.getUser())
             return dissomniag.taskManager.TaskReturns.FAILED_BUT_GO_AHEAD
         else:
             self.context.net.state = dissomniag.model.GenNetworkState.GENERAL_ERROR
             dissomniag.saveFlush(session)
             self.context.net.operate(self.job.getUser())
             raise dissomniag.taskManager.TaskFailed("Network Status Check GENERAL_ERROR!")
     
     if net.isActive() == 1:
         if self.context.net.state == dissomniag.model.GenNetworkState.INACTIVE:
             self.context.net.state = dissomniag.model.GenNetworkState.GENERAL_ERROR
             dissomniag.saveFlush(session)
             self.context.net.operate(self.job.getUser())
             raise dissomniag.taskManager.TaskFailed("Network Status Check GENERAL_ERROR!")
         self.context.net.state = dissomniag.model.GenNetworkState.CREATED
     
     dissomniag.saveFlush(session)
     return dissomniag.taskManager.TaskReturns.SUCCESS
Ejemplo n.º 21
0
    def implementation(self, *args):
        sys.stdout = self.terminal
        sys.stderr = self.terminal

        parser = argparse.ArgumentParser(description="Delete a key",
                                         prog=args[0])
        parser.add_argument(
            "keyId",
            action="store",
            type=int,
            help="Enter the Key-ID of the key you want to delete.")
        if self.user.isAdmin:
            parser.add_argument("-u",
                                "--username",
                                action="store",
                                help="The user where to delete a key.",
                                dest="username",
                                default=None)
            parser.add_argument("-f",
                                "--force",
                                action="store_true",
                                help="Force to delete key in all users.",
                                dest="force",
                                default=False)
        options = parser.parse_args(args[1:])

        session = dissomniag.Session()

        user = self.user

        if self.user.isAdmin:
            if options.force:
                try:
                    key = session.query(PublicKey).filter(
                        PublicKey.id == options.keyId).one()
                except Exception:
                    self.printError("Could not find Key.")
                    return
                session.delete(key)
                dissomniag.saveCommit(session)
                dissomniag.saveFlush(session)
                return

            if options.username and options.username != self.user.username:
                # Change in other user
                try:
                    user = session.query(User).filter(
                        User.username == options.username).one()
                except NoResultFound:
                    self.printError("Could not find user.")
                    return

        for key in user.publicKeys:
            if key.id == options.keyId:
                user.publicKeys.remove(key)
                if len(key.users) == 0:
                    #Only the actual user owns that key
                    session.delete(key)
                    dissomniag.saveCommit(session)
                    dissomniag.saveFlush(session)
                return

        #Key not found
        self.printError("Could not find the key. Key-ID: %s" % options.keyId)
        return
Ejemplo n.º 22
0
 def deleteIpAddress(user, ipAddress, isAdministrative = False):
     session = dissomniag.Session()
     session.delete(ipAddress)
     dissomniag.saveFlush(session)
Ejemplo n.º 23
0
    def implementation(self, *args):
        sys.stdout = self.terminal
        sys.stderr = self.terminal

        parser = argparse.ArgumentParser(
            description="Add a user to DiSSOmniaG. ADMIN ACCESS NEEDED!",
            prog=args[0])
        parser.add_argument("-a",
                            "--admin",
                            action="store_true",
                            dest="isAdmin",
                            default=False)
        parser.add_argument("--dissable-ssh",
                            action="store_false",
                            dest="loginSSH",
                            default=True)
        parser.add_argument("--dissable-rpc",
                            action="store_false",
                            dest="loginRPC",
                            default=True)
        parser.add_argument("--enable-manhole",
                            action="store_true",
                            dest="loginManhole",
                            default=False)
        parser.add_argument("username", action="store")
        parser.add_argument("password", action="store")
        parser.add_argument("-k",
                            "--key",
                            action="store",
                            nargs="*",
                            dest="key",
                            help="Provide the key as the last Argument!",
                            default=None)

        options = parser.parse_args(args[1:])
        if not self.user.isAdmin:
            self.printError(
                "Permission denied: Only Admin users are allowed to add a users!"
            )
            return

        if options.key != None:
            options.key = " ".join(options.key)

        session = dissomniag.Session()
        try:
            existingUser = session.query(User).filter(
                User.username == options.username).one()
            if existingUser:
                self.printError("User already exists.")
                return
        except NoResultFound:
            newUser = User(options.username,
                           options.password,
                           publicKey=options.key,
                           isAdmin=options.isAdmin,
                           loginRPC=options.loginRPC,
                           loginSSH=options.loginSSH,
                           loginManhole=options.loginManhole,
                           isHtpasswd=False)
            session.add(newUser)
            dissomniag.saveCommit(session)
            dissomniag.saveFlush(session)
        except MultipleResultsFound:
            self.printError("User already exists.")
            return

        self.printSuccess("SUCCESS")
Ejemplo n.º 24
0
    def implementation(self, *args):
        sys.stdout = self.terminal
        sys.stderr = self.terminal

        parser = argparse.ArgumentParser(description="Modify a user.",
                                         prog=args[0])
        parser.add_argument("-a",
                            "--admin",
                            action="store_true",
                            dest="isAdmin",
                            default=None)
        parser.add_argument("-A",
                            "--notAdmin",
                            action="store_false",
                            dest="isAdmin",
                            default=None)
        parser.add_argument("--dissable-ssh",
                            action="store_false",
                            dest="loginSSH",
                            default=None)
        parser.add_argument("--enable-ssh",
                            action="store_true",
                            dest="loginSSH",
                            default=None)
        parser.add_argument("--dissable-rpc",
                            action="store_false",
                            dest="loginRPC",
                            default=None)
        parser.add_argument("--enable-rpc",
                            action="store_true",
                            dest="loginRPC",
                            default=None)
        parser.add_argument("--enable-manhole",
                            action="store_true",
                            dest="loginManhole",
                            default=None)
        parser.add_argument("--dissable-manhole",
                            action="store_false",
                            dest="loginManhole",
                            default=None)

        if self.user.isAdmin:
            parser.add_argument("-u",
                                "--username",
                                action="store",
                                dest="username")

        parser.add_argument("-p",
                            "--newPassword",
                            action="store",
                            help="Enter the new password to store.",
                            dest="newPassword",
                            default=None)
        parser.add_argument("-o",
                            "--oldPassword",
                            action="store",
                            help="Enter the new password to store.",
                            dest="oldPassword",
                            default=None)

        parser.add_argument("-k",
                            "--key",
                            action="store",
                            nargs="*",
                            dest="key",
                            help="Provide the key as the last Argument!",
                            default=None)

        options = parser.parse_args(args[1:])

        if options.key != None:
            options.key = " ".join(options.key)

        if not self.user.isAdmin:
            if options.username == dissomniag.Identity.systemUserName:
                self.printError("Could not find user.")
            if options.isAdmin != None or options.loginSSH != None or options.loginRPC != None or options.loginManhole != None:
                self.printError("You don't have the permissions to do that.")
                return
            if options.newPassword:
                if not options.oldPassword:
                    self.printError("Please enter your old Password.")
                    return
                if not self.user.checkPassword(options.oldPassword):
                    self.printError("Your old Password is not valid.")
                self.user.saveNewPassword(options.newPassword)
            if options.key:
                try:
                    self.user.addKey(options.key)
                except dissomniag.BadKeyError:
                    self.printError("Please enter a valid PublicKey.")
                    return
        else:

            user = self.user
            session = dissomniag.Session()
            if options.username and options.username != self.user.username:
                try:
                    user = session.query(User).filter(
                        User.username == options.username).one()
                except NoResultFound:
                    self.printError("Could not find the user.")
                    return
            if options.isAdmin != None:
                if self.user == user or user.username == dissomniag.config.htpasswd.adminUser:
                    self.printError(
                        "You can not change the admin status of yourself or the default admin user."
                    )
                    self.printInfo("I continue.")
                else:
                    user.isAdmin = options.isAdmin
            if options.loginSSH != None:
                if self.user == user or user.username == dissomniag.config.htpasswd.adminUser:
                    self.printError(
                        "You can not exclude yourself or the default admin user from accessing this shell."
                    )
                    self.printInfo("I continue.")
                else:
                    user.isAdmin = options.isAdmin
            if options.loginRPC != None:
                user.loginRPC = options.loginRPC

            if options.loginManhole != None:
                user.loginManhole = options.loginManhole

            if options.key != None:
                try:
                    user.addKey(options.key)
                except dissomniag.BadKeyError:
                    self.printError("Please enter a valid PublicKey.")
                    return

            dissomniag.saveCommit(session)
            dissomniag.saveFlush(session)

            if options.newPassword and user.username != self.user.username:
                user.saveNewPassword(options.newPassword)
            elif options.newPassword:
                if not options.oldPassword != None:
                    self.printError("Please enter your old Password.")
                    return
                if not self.user.checkPassword(options.oldPassword):
                    self.printError("Your old Password is not valid.")
                    return
                self.user.saveNewPassword(options.newPassword)
Ejemplo n.º 25
0
 def implementation(self, *args):
     sys.stdout = self.terminal
     sys.stderr = self.terminal
     
     parser = argparse.ArgumentParser(description = "Modify a user.", prog = args[0])
     parser.add_argument("-a", "--admin", action = "store_true", dest = "isAdmin", default = None)
     parser.add_argument("-A", "--notAdmin", action = "store_false", dest = "isAdmin", default = None)
     parser.add_argument("--dissable-ssh", action = "store_false", dest = "loginSSH", default = None)
     parser.add_argument("--enable-ssh", action = "store_true", dest = "loginSSH", default = None)
     parser.add_argument("--dissable-rpc", action = "store_false", dest = "loginRPC", default = None)
     parser.add_argument("--enable-rpc", action = "store_true", dest = "loginRPC", default = None)
     parser.add_argument("--enable-manhole", action = "store_true", dest = "loginManhole", default = None)
     parser.add_argument("--dissable-manhole", action = "store_false", dest = "loginManhole", default = None)
     
     if self.user.isAdmin:
         parser.add_argument("-u", "--username", action = "store", dest = "username")
     
     parser.add_argument("-p", "--newPassword", action = "store", help = "Enter the new password to store.", dest = "newPassword", default = None)
     parser.add_argument("-o", "--oldPassword", action = "store", help = "Enter the new password to store.", dest = "oldPassword", default = None)
     
     parser.add_argument("-k", "--key", action = "store", nargs = "*", dest = "key", help = "Provide the key as the last Argument!", default = None)
     
     options = parser.parse_args(args[1:])
     
     if options.key != None:
         options.key = " ".join(options.key)
     
     if not self.user.isAdmin:
         if options.username == dissomniag.Identity.systemUserName:
             self.printError("Could not find user.")
         if options.isAdmin != None or options.loginSSH != None or options.loginRPC != None or options.loginManhole != None:
             self.printError("You don't have the permissions to do that.")
             return
         if options.newPassword:
             if not options.oldPassword:
                 self.printError("Please enter your old Password.")
                 return
             if not self.user.checkPassword(options.oldPassword):
                 self.printError("Your old Password is not valid.")
             self.user.saveNewPassword(options.newPassword)
         if options.key:
             try:
                 self.user.addKey(options.key)
             except dissomniag.BadKeyError:
                 self.printError("Please enter a valid PublicKey.")
                 return
     else:
         
         user = self.user
         session = dissomniag.Session()
         if options.username and options.username != self.user.username:
             try:
                 user = session.query(User).filter(User.username == options.username).one()
             except NoResultFound:
                 self.printError("Could not find the user.")
                 return
         if options.isAdmin != None:
             if self.user == user or user.username == dissomniag.config.htpasswd.adminUser:
                 self.printError("You can not change the admin status of yourself or the default admin user.")
                 self.printInfo("I continue.")
             else:
                 user.isAdmin = options.isAdmin
         if options.loginSSH != None:
             if self.user == user or user.username == dissomniag.config.htpasswd.adminUser:
                 self.printError("You can not exclude yourself or the default admin user from accessing this shell.")
                 self.printInfo("I continue.")
             else:
                 user.isAdmin = options.isAdmin
         if options.loginRPC != None:
             user.loginRPC = options.loginRPC
             
         if options.loginManhole != None:
             user.loginManhole = options.loginManhole
         
         if options.key != None:
             try:
                 user.addKey(options.key)
             except dissomniag.BadKeyError:
                 self.printError("Please enter a valid PublicKey.")
                 return   
         
         dissomniag.saveCommit(session)
         dissomniag.saveFlush(session)
         
         if options.newPassword and user.username != self.user.username:
             user.saveNewPassword(options.newPassword)
         elif options.newPassword:
             if not options.oldPassword != None:
                 self.printError("Please enter your old Password.")
                 return
             if not self.user.checkPassword(options.oldPassword):
                 self.printError("Your old Password is not valid.")
                 return
             self.user.saveNewPassword(options.newPassword)