Esempio n. 1
0
 def unmount_mapped_image(self, mount_path):
     try:
         if not self.is_admin:
             raise AuthorizationFailedException()
         command = "umount " + mount_path
         shell.call(command, sudo=True)
         os.rmdir(mount_path)
         return self.__return_success(True)
     except (shell_exceptions.CommandFailedException,
             AuthorizationFailedException) as e:
         logger.exception('')
         return self.__return_error(e)
Esempio n. 2
0
    def mount_mapped_image(self, rbd_map_path, mount_path):
        try:
            if not self.is_admin:
                raise AuthorizationFailedException()
            try:
                os.stat(mount_path)
            except:
                os.mkdir(mount_path)

            command = "mount " + rbd_map_path + " " + mount_path
            shell.call(command, sudo=True)

            return self.__return_success(True)
        except (shell_exceptions.CommandFailedException,
                AuthorizationFailedException) as e:
            logger.exception('')
            return self.__return_error(e)
Esempio n. 3
0
File: tgt.py Progetto: CCI-MOC/ABMI
    def add_target(self, target_name):
        """
        Adds target

        :param target_name: Name of target to be added
        :return: None
        """
        try:
            targets = self.list_targets()
            if target_name not in targets:
                self.__generate_config_file(target_name)
                command = "tgt-admin --execute"
                shell.call(command, sudo=True)
            else:
                raise iscsi_exceptions.TargetExistsException()
        except (IOError, OSError) as e:
            raise iscsi_exceptions.TargetCreationFailed(str(e))
        except shell_exceptions.CommandFailedException as e:
            raise iscsi_exceptions.TargetCreationFailed(str(e))
Esempio n. 4
0
    def add_target(self, target_name):
        """
        Adds target

        :param target_name: Name of target to be added
        :return: None
        """
        try:
            targets = self.list_targets()
            if target_name not in targets:
                self.__generate_config_file(target_name)
                command = "tgt-admin --execute"
                shell.call(command, sudo=True)
            else:
                raise iscsi_exceptions.TargetExistsException()
        except (IOError, OSError) as e:
            raise iscsi_exceptions.TargetCreationFailed(str(e))
        except shell_exceptions.CommandFailedException as e:
            raise iscsi_exceptions.TargetCreationFailed(str(e))
Esempio n. 5
0
 def vulnerability_detection(self, mount_path):
     try:
         if not self.is_admin:
             raise AuthorizationFailedException()
         crawler_path = "/root/ims_latest_new/ims/common/agentless-system-crawler/crawler/crawler.py"
         url_path = "/root/ims_latest_new/ims/common/crawler_output/test.csv"
         command = "python " + crawler_path + " --features os,package --crawlmode MOUNTPOINT --mountpoint " + mount_path + " --url file://" + url_path
         csv_frame = shell.call(command, sudo=True)
         json_frame = csv2json(url_path + ".0")
         report = readFrame(json_frame)
         return self.__return_success(report)
     except (shell_exceptions.CommandFailedException,
             AuthorizationFailedException) as e:
         logger.exception('')
         return self.__return_error(e)
Esempio n. 6
0
    def list_targets(self):
        """
        Lists all the targets available by querying tgt-admin

        :return: None
        """
        try:
            command = "tgt-admin -s"
            output = shell.call(command, sudo=True)
            logger.debug("Output = %s", output)
            formatted_output = output.split("\n")
            target_list = [target.split(":")[1].strip() for target in
                           formatted_output if
                           re.match("^Target [0-9]+:", target)]
            return target_list
        except shell_exceptions.CommandFailedException as e:
            raise iscsi_exceptions.ListTargetFailedException(str(e))
Esempio n. 7
0
File: tgt.py Progetto: CCI-MOC/ABMI
    def list_targets(self):
        """
        Lists all the targets available by querying tgt-admin

        :return: None
        """
        try:
            command = "tgt-admin -s"
            output = shell.call(command, sudo=True)
            logger.debug("Output = %s", output)
            formatted_output = output.split("\n")
            target_list = [
                target.split(":")[1].strip() for target in formatted_output
                if re.match("^Target [0-9]+:", target)
            ]
            return target_list
        except shell_exceptions.CommandFailedException as e:
            raise iscsi_exceptions.ListTargetFailedException(str(e))
Esempio n. 8
0
File: tgt.py Progetto: CCI-MOC/ABMI
    def remove_target(self, target_name):
        """
        Removes target specified

        :param target_name: Name of target to be removed
        :return: None
        """
        try:
            targets = self.list_targets()
            if target_name in targets:
                os.remove(
                    os.path.join(self.TGT_ISCSI_CONFIG, target_name + ".conf"))
                command = "tgt-admin -f --delete {0}".format(target_name)
                output = shell.call(command, sudo=True)
                logger.debug("Output = %s", output)
            else:
                raise iscsi_exceptions.TargetDoesntExistException()
        except (IOError, OSError) as e:
            raise iscsi_exceptions.TargetDeletionFailed(str(e))
        except shell_exceptions.CommandFailedException as e:
            raise iscsi_exceptions.TargetDeletionFailed(str(e))
Esempio n. 9
0
    def remove_target(self, target_name):
        """
        Removes target specified

        :param target_name: Name of target to be removed
        :return: None
        """
        try:
            targets = self.list_targets()
            if target_name in targets:
                os.remove(os.path.join(self.TGT_ISCSI_CONFIG,
                                       target_name + ".conf"))
                command = "tgt-admin -f --delete {0}".format(target_name)
                output = shell.call(command, sudo=True)
                logger.debug("Output = %s", output)
            else:
                raise iscsi_exceptions.TargetDoesntExistException()
        except (IOError, OSError) as e:
            raise iscsi_exceptions.TargetDeletionFailed(str(e))
        except shell_exceptions.CommandFailedException as e:
            raise iscsi_exceptions.TargetDeletionFailed(str(e))