예제 #1
0
 def running(self, wait=True):
   """Returns True if the module is loaded and DM target is available."""
   retries = 20 if wait else 1
   try:
     runCommand(["lsmod", "|", "grep", "-q", "'" + self._name + "'"],
                shell=True, retries=retries)
     runCommand(["dmsetup", "targets", "|", "grep", "-q",
                 Defaults.vdoTargetName], shell=True, retries=retries)
     return True
   except CommandError:
     return False
예제 #2
0
파일: Configuration.py 프로젝트: xahmad/vdo
 def _fsyncDirectory(self):
     """Open and issue an fsync on the directory containing the config file.
 """
     dirname = os.path.dirname(self.filepath)
     if Command.noRunMode():
         runCommand(['fsync', dirname])
         return
     fd = os.open(dirname, os.O_RDONLY)
     try:
         os.fsync(fd)
     finally:
         os.close(fd)
예제 #3
0
    def execute(self, args):
        #pylint: disable=R0201
        conf = Configuration(self.confFile, readonly=False)
        if not args.name:
            args.all = True

        try:
            # To be consistent with previous output we must present each section as
            # its own rather than organizing them into one structure to dump.
            # Also, we gather all the info before printing it out to avoid
            # interspersing command info when run in verbose mode.
            values = {}
            vdoStatus = {_("VDO status"): values}
            values[_("Node")] = runCommand(['uname', '-n'],
                                           noThrow=True,
                                           strip=True)
            values[_("Date")] = runCommand(['date', '--rfc-3339=seconds'],
                                           noThrow=True,
                                           strip=True)
            if os.getuid() != 0:
                values[_("Note")] = _("Not running as root," +
                                      " some status may be unavailable")

            kernelStatus = {
                _("Kernel module"): VDOKernelModuleService().status()
            }

            confStatus = {_("Configuration"): conf.status()}

            vdos = {}
            perVdoStatus = {_("VDOs"): vdos}
            for vdo in self.getVdoServices(args, conf):
                try:
                    vdos[vdo.getName()] = vdo.status()
                except VDOServiceError as ex:
                    vdos[vdo.getName()] = str(ex)

            # YAML adds a newline at the end.  To maintain consistency with the
            # previous output we need to eliminate that.
            print(yaml.safe_dump(vdoStatus, default_flow_style=False)[:-1])
            print(yaml.safe_dump(kernelStatus, default_flow_style=False)[:-1])
            print(yaml.safe_dump(confStatus, default_flow_style=False)[:-1])
            print(
                yaml.safe_dump(perVdoStatus,
                               default_flow_style=False,
                               width=float("inf"))[:-1])

            sys.stdout.flush()
            sys.stderr.flush()
        except IOError as ex:
            self.log.debug("exception ignored: {0}".format(ex))
예제 #4
0
파일: Configuration.py 프로젝트: xahmad/vdo
    def _removeFile(self):
        """Deletes the current configuration file.
    In noRun mode, pretend that we're doing an rm of the file."""
        if Command.noRunMode():
            runCommand(['rm', self.filepath])
            return

        if os.path.exists(self.filepath):
            os.remove(self.filepath)
            self._fsyncDirectory()

        try:
            with FileLock(self.singletonLock, "r+") as f:
                del Configuration.modifiableSingltons[self.filepath]
        except KeyError:
            pass
예제 #5
0
 def version(self):
   """Returns the module version as a string."""
   s = self._name + " "
   for line in runCommand(['modinfo', self._name], noThrow=True).splitlines():
     if line.find('version') == 0:
       s += line
   return s
예제 #6
0
 def statusHelper(cls, commandList):
     """Helper function for returning status summaries."""
     try:
         s = runCommand(commandList,
                        environment={'UDS_LOG_LEVEL': 'WARNING'},
                        strip=True)
         return s.replace("\"", "")
     except CommandError:
         return _("not available")
예제 #7
0
    def targetVersion(self):
        """Returns the dmsetup targets version as a number"""
        for line in runCommand(["dmsetup", "targets"],
                               noThrow=True).splitlines():
            versionMatch = re.escape(
                Defaults.vdoTargetName) + r"\s+v(\d+\.\d+\.\d+)"
            version = re.match(versionMatch, line)
            if version is not None:
                return tuple(map(int, version.group(1).split(".")))

        return (0, 0, 0)
예제 #8
0
  def execute(self, args):
    cmd = ['dmsetup', 'status', '--target', Defaults.vdoTargetName]
    vdos = set([line.split(':')[0]
                for line in runCommand(cmd, noThrow=True).splitlines()])
    
    cmd = ['lvs', '--config', 'devices/scan_lvs=1', '--select',
           'segtype=vdo-pool', '--noheadings', '--option', 'lv_dm_path']
    lvmVdos = set([os.path.basename(line)
                   for line in runCommand(cmd, noThrow=True).splitlines()])
    vdos = vdos - lvmVdos

    if args.all:
      conf = Configuration(self.confFile)
      vdos |= set(conf.getAllVdos().keys())

    # We want to provide a stable ordering and a set, while great for
    # avoiding duplicates, doesn't guarantee ordering.  So, make a list
    # from the set and sort it.
    vdos = list(vdos)
    vdos.sort()
    print(os.linesep.join(vdos))
예제 #9
0
    def execute(self, args):
        vdos = set()
        cmd = ["lsblk", "--pairs", "--paths", "--output", "type,name"]
        for line in runCommand(cmd, noThrow=True).splitlines():
            blktype, foo, name = line.replace('"', '').partition(" ")
            if blktype.split("=")[1] == "vdo":
                vdos.add(os.path.basename(name.split("=")[1]))

        if args.all:
            conf = Configuration(self.confFile)
            vdos |= set(conf.getAllVdos().keys())

        # We want to provide a stable ordering and a set, while great for
        # avoiding duplicates, doesn't guarantee ordering.  So, make a list
        # from the set and sort it.
        vdos = list(vdos)
        vdos.sort()
        print(os.linesep.join(vdos))
예제 #10
0
    def execute(self, args):
        vdos = set()
        for line in runCommand(['dmsetup', 'status'],
                               noThrow=True).splitlines():
            m = re.match(r"(.+?): \d \d+ " + Defaults.vdoTargetName, line)
            if m:
                vdos.add(m.group(1))

        if args.all:
            conf = Configuration(self.confFile)
            vdos |= set(conf.getAllVdos().keys())

        # We want to provide a stable ordering and a set, while great for
        # avoiding duplicates, doesn't guarantee ordering.  So, make a list
        # from the set and sort it.
        vdos = list(vdos)
        vdos.sort()
        print(os.linesep.join(vdos))
예제 #11
0
 def stop(self):
   """Removes the module."""
   runCommand(['modprobe', '-r', self._name])
예제 #12
0
 def start(self):
   """Loads the module if necessary."""
   runCommand(['modprobe', self._name])
예제 #13
0
 def execute(self, unused_args):
     output = runCommand(['vdoformat', '--version'], noThrow=True)
     version = re.findall('\d+', output)
     print("VDO version: " + '.'.join(version))
예제 #14
0
 def setLogLevel(self, level):
     """Sets the module log level."""
     if level != Defaults.vdoLogLevel:
         commandStr = "echo " + level + " > /sys/" + self._name + "/log_level"
         runCommand(commandStr.split(), shell=True, noThrow=True)