def lock(self, sleeptime=-1, retries=-1, locktimeout=-1, suspend=-1):
     try:
         ComSystem.execLocalOutput("%s %s %s" %(self.COMMAND, self._buildOptions(sleeptime, retries, locktimeout, suspend), self.filename))
     except ComSystem.ExecLocalException, ele:
         if ele.rc==73<<8:
             raise lockfileTimeout(self.filename)
         else:
             raise ele
 def isDMMultipath(self):
     if not os.path.exists(CMD_DMSETUP):
         return False
     __cmd="%s table %s --target=multipath 2>/dev/null | grep multipath &>/dev/null"  % (CMD_DMSETUP, self.getDeviceName())
     try:
         ComSystem.execLocalOutput(__cmd, True, "")
         return True
     except ComSystem.ExecLocalException: 
         return False
 def isDMMultipath(self):
    if not os.path.exists(CMD_DMSETUP):
       return False
    __cmd="%s table %s --target=multipath 2>/dev/null | grep multipath &>/dev/null"  % (CMD_DMSETUP, self.getDeviceName())
    try:
       ComSystem.execLocalOutput(__cmd, True, "")
       return True
    except ComSystem.ExecLocalException: 
       return False
示例#4
0
        def mount(self, device, mountpoint, readOnly=0, bindMount=0, instroot=""):
            if not self.isMountable():
                return
            iutil.mkdirChain("%s/%s" %(instroot, mountpoint))
#            if flags.selinux:
#                log.info("Could not mount nfs filesystem with selinux context enabled.")
#                return
            anacondalog.debug("nfsFileSystem: Mounting nfs %s => %s" %(device, "%s/%s" %(instroot, mountpoint)))
            ComSystem.execLocalOutput("mount -t nfs -o nolock %s %s/%s" %(device, instroot, mountpoint))
 def checkFs(self, device):
     """ check filesystem on device (virtual method)
     device: ComDevice.Device
     """
     if self.getFsckCmd():
         (__cmd)=self.getFsckCmd()+" "+device.getDeviceName()
         log.debug("checkFs: cmd: %s" %(__cmd))
         ComSystem.execLocalOutput(__cmd)
     else:
         raise NotImplementedYetException("Method checkFs is not implemented by filesystem %s (class: %s)." %(self.getName(), self.__class__.__name__))
def scsi_remove_disk(host, disk_path):
   target=False
   if os.path.isdir(disk_path) and os.access(disk_path, os.W_OK):
      log.debug("scsi_remove_disk(%s/delete)" %(disk_path))
      try: 
         ComSystem.execLocalOutput("echo %s > %s" %(SCSIDELETE_CMD, disk_path+"/device/delete"))
      except Exception, e:
         log.debug("Error during scsi_remove_disk %s." %e)
      #remove=open(disk_path+"/delete", "w")
      #print >> remove, SCSIDELETE_CMD
      target=True
示例#7
0
 def lock(self, sleeptime=-1, retries=-1, locktimeout=-1, suspend=-1):
     try:
         ComSystem.execLocalOutput(
             "%s %s %s" %
             (self.COMMAND,
              self._buildOptions(sleeptime, retries, locktimeout,
                                 suspend), self.filename))
     except ComSystem.ExecLocalException, ele:
         if ele.rc == 73 << 8:
             raise lockfileTimeout(self.filename)
         else:
             raise ele
示例#8
0
 def checkFs(self, device):
     """ check filesystem on device (virtual method)
     device: ComDevice.Device
     """
     if self.getFsckCmd():
         (__cmd) = self.getFsckCmd() + " " + device.getDeviceName()
         log.debug("checkFs: cmd: %s" % (__cmd))
         ComSystem.execLocalOutput(__cmd)
     else:
         raise NotImplementedYetException(
             "Method checkFs is not implemented by filesystem %s (class: %s)."
             % (self.getName(), self.__class__.__name__))
 def _do(self):
    """
    If need be does something
    """
    from comoonics.scsi import ComSCSI
    if self.name == "rescan":
       ComSCSI.rescan(self.dest)
    elif self.name == "rescan_qla":
       ComSCSI.rescan_qla(self.dest)
    else:
       raise SCSIRequirementException("Unsupported SCSI Rescan name %s", self.name)
    ComSystem.execLocalOutput("udevsettle")
    stabilized.stabilized(file="/proc/partitions", iterations=10, type="hash")
    def createPartitionsParted(self):
        import parted
        import ComParted
        if not self.exists():
            raise ComException("Device %s not found" % self.getDeviceName())

        phelper=ComParted.PartedHelper()
        #IDEA compare the partition configurations for update
        #1. delete all aprtitions
        dev=parted.PedDevice.get(self.getDeviceName())

        try:
            disk=parted.PedDisk.new(dev)
            disk.delete_all()
        except parted.error:
            #FIXME use generic disk types
            disk=dev.disk_new_fresh(parted.disk_type_get("msdos"))

        # create new partitions
        for com_part in self.getAllPartitions():
            type=com_part.getPartedType()
            if self.sameSize():
                size=com_part.getPartedSize(dev)
            else:
                size=com_part.getPartedSizeOptimum(dev)
            flags=com_part.getPartedFlags()
            self.log.debug("creating partition: size: %i" % size )
            phelper.add_partition(disk, type, size, flags)

        disk.commit()
        self.commit()

        #dev.sync()
        #dev.close()

        # run partx if the device is a multipath device
        self.log.debug("ComHostDisk: checking for multipath devices")
        if self.isDMMultipath():
            self.log.debug("Device %s is a dm_multipath device, adding partitions" %self.getDeviceName())
            __cmd=CMD_KPARTX + " -d " + self.getDeviceName()
            try:
                __ret = ComSystem.execLocalOutput(__cmd, True, "")
                self.log.debug(__ret)
                __cmd=CMD_KPARTX + " -a " + self.getDeviceName()
                __ret = ComSystem.execLocalOutput(__cmd, True, "")
                self.log.debug(__ret)
                #FIXME: crappy fix to give os some time to create devicefiles.
                time.sleep(10)
            except ComSystem.ExecLocalException, ele:
                ComLog.debugTraceLog(self.log)
                self.log.debug("Could not execute %s. Error %s" %(ele.cmd, ele))
 def check(*args, **kwds):
     ret=False
     try:
         if not kwds and not args:
             ComSystem.execLocalOutput("%s -qf $(which rpm)" %(RPMLinuxSystemInformation.RPM_CMD))
             ret= True
         elif kwds.has_key("operatingsystem") and  \
             (re.compile("linux", re.I).search(kwds["operatingsystem"]) or \
              re.compile("centos", re.I).search(kwds["operatingsystem"]) or \
              re.compile("fedora", re.I).search(kwds["operatingsystem"]) or \
              re.compile("redhat", re.I).search(kwds["operatingsystem"])):
             ret=True
     finally:
         return ret
 def check(*args, **kwds):
     ret = False
     try:
         if not kwds and not args:
             ComSystem.execLocalOutput("%s -qf $(which rpm)" %
                                       (RPMLinuxSystemInformation.RPM_CMD))
             ret = True
         elif kwds.has_key("operatingsystem") and  \
             (re.compile("linux", re.I).search(kwds["operatingsystem"]) or \
              re.compile("centos", re.I).search(kwds["operatingsystem"]) or \
              re.compile("fedora", re.I).search(kwds["operatingsystem"]) or \
              re.compile("redhat", re.I).search(kwds["operatingsystem"])):
             ret = True
     finally:
         return ret
 def queryStatusElement(self, **kwds):
     import xml.dom
     self.__setfromkwds("clusterstatus_cmd", kwds, self.clusterstatus_cmd)
     self.__setfromkwds("clusterstatus_opts", kwds, self.clusterstatus_opts)
     asValue=self.__getfromkwds("asvalue", kwds, True)
     delimitor=self.__getfromkwds("delimitor", kwds, " ")
     query=self.__getfromkwds("query", kwds, None)
     __output=self.__getfromkwds("output", kwds, None)
     self.log.debug("queryStatusElement: query=%s" %query)
     try:
         # create Reader object
         _dom=comoonics.XmlTools.parseXMLString(ComSystem.execLocalOutput(self.getClusterStatusCmd(True, delimitor), True, __output))
         if not query:
             return _dom.documentElement
         else:
             _tmp1 = comoonics.XmlTools.evaluateXPath(query, _dom.documentElement)
             _tmp2 = None
             if asValue:
                 _tmp2=list()
                 for i in range(len(_tmp1)):
                     if isinstance(_tmp1[i], xml.dom.Node) and _tmp1[i].nodeType == xml.dom.Node.ATTRIBUTE_NODE:
                         _tmp2.append(_tmp1[i].value)
                     else:
                         _tmp2.append(_tmp1[i])
                 return delimitor.join(_tmp2)
             else:
                 return comoonics.XmlTools.toPrettyXML(_tmp1[0])
     except ComSystem.ExecLocalException, error:
         warnings.warn("Could not query the running cluster with %s. No active values will be available." %self.clusterstatus_cmd)
         self.log.debug("Error: %s" %error)
         return None
示例#14
0
 def getIP(self):
     """
     @return: Returns ip-address of interface
     @rtype: string
     """
     #optional attribute, return empty string if not set
     try:
         self.log.debug("get ip attribute: " + self.getAttribute(ComoonicsClusterRepository.attribute_netdev_ip))
         # special case for dhcp we'll return the given ipaddress
         if self.isDHCP():
             from comoonics import ComSystem
             import re
             try:
                 output=ComSystem.execLocalOutput("PATH=/sbin:/usr/sbin ip addr show %s" %self.getName(), True)
                 _mac=re.search("link/ether (?P<mac>\S+)", output).group("mac")
                 _ip=re.search(".*inet (?P<ip>[0-9.]+)", output).group("ip")
                 if _mac.upper() == self.getMac().upper():
                     return _ip
                 else:
                     return self.getAttribute(ComoonicsClusterRepository.attribute_netdev_ip)
             except:
                 ComLog.debugTraceLog(self.log)
                 return self.getAttribute(ComoonicsClusterRepository.attribute_netdev_ip)
         else:
             return self.getAttribute(ComoonicsClusterRepository.attribute_netdev_ip)
     except NameError:
         return ""
 def savePartitionTable(self, filename):
    """ saves the Disks partition table in sfdisk format to <filename>
    Throws ComException on error
    """
    __cmd = self.getDumpStdout() + " > " + filename
    __ret = ComSystem.execLocalOutput(__cmd, True, "saved partition table")
    self.log.debug("savePartitionTable( " + filename + "):\n " + __ret)
 def doRealModifications(self):
     """
     calls doCatifAction for every action
     """
     _dest=self.getAttribute("destination", "./")
     self.errors=self.getAttribute("errors", "log")
     _childs=self.getElement().getElementsByTagName(self.child)
     for _child in _childs:
         _name=_child.getAttribute("name")
         _names=list()
         _names.append(_name)
         try:
             if re.findall("\$\(.+\)", _name):
                 _names=re.split("\s+", str(ComSystem.execLocalOutput("echo %s" %_name)[0])[:-1])
                 CatifModification.logger.debug("doRealModifications() _names: %s" %_names)
         except ExecLocalException:
             _names=None
         _log=None
         if self.hasAttribute("log"):
             _log=self.getAttribute("log")
         elif _child.hasAttribute("log"):
             _log=_child.getAttribute("log")
         if not _names:
             continue
         for _name in _names:
             try:
                 if _name and _name != "":
                     self.doCatifAction(_name, _dest, _log)
             except ExecLocalException, _ale:
                 self._handleError(_ale)
             except pexpect.ExceptionPexpect, ep:
                 self._handleError(ep)
 def savePartitionTable(self, filename):
     """ saves the Disks partition table in sfdisk format to <filename>
     Throws ComException on error
     """
     __cmd = self.getDumpStdout() + " > " + filename
     __ret = ComSystem.execLocalOutput(__cmd, True, "saved partition table")
     self.log.debug("savePartitionTable( " + filename + "):\n " + __ret)
    def _copyData(self):
        # FIXME: this implementation is VERY POOR!! This should be fixed without any instance casting of classes on
        #        the end of the child tree. There should be a abstract class FilesystemCopyObject and PathCopyObject
        #        derive from!!!!
        # 1. copy fs/path to fs/path
        ComLog.getLogger(__logStrLevel__).debug("doCopy: instance(self.source: %s), instance(self.dest: %s)" %(self.source.__class__, self.dest.__class__))
        ComLog.getLogger(__logStrLevel__).debug("doCopy: isinstance(%s, PathCopyObject): %s" %(self.source.__class__, isinstance(self.source, PathCopyObject)))
        if isinstance(self.source, FilesystemCopyObject) or isinstance(self.source, PathCopyObject):
            if isinstance(self.source, FilesystemCopyObject):
                if not self.source.filesystem.isCopyable():
                    return True
            mountpoint=self.source.getMountpoint().getAttribute("name")
            ComLog.getLogger(__logStrLevel__).debug("doCopy: isinstance(%s, PathCopyObject): %s" %(self.dest.__class__, isinstance(self.dest, PathCopyObject)))
            if isinstance(self.dest, FilesystemCopyObject) or isinstance(self.dest, PathCopyObject):
                __cmd = self._getFSCopyCommand()
                try:
                    __out = ComSystem.execLocalOutput(__cmd, True)
                except ComSystem.ExecLocalException, ele:
                    raise RSyncError(ele)
                #ComLog.getLogger(__logStrLevel__).debug("doCopy: "  + __cmd +" "+ __ret)
                return True

            # 2. copy fs to archive
            elif isinstance(self.dest, ArchiveCopyObject):
#                try:
                archive=self.dest.getDataArchive()
                archive.createArchive("./", mountpoint)
                return True
示例#19
0
 def executeSaveFs(self, level, file=None):
     values = list()
     if file:
         self.savefs_options.append(LegatoNetworker.OPTION_NOT_IN_SAVESET)
         values.append(file)
     _cmd="%s %s -l %s -c %s -s %s -g %s %s" %(LegatoNetworker.LEGATO_CMD_SAVEFS, " ".join(self.savefs_options), level, \
                                              self.client, self.server, self.group, " ".join(values))
     _output = ComSystem.execLocalOutput(_cmd)
     self.log.debug("executeSaveFs: cmd=%s, output=%s" % (_cmd, _output))
 def executeSaveFs(self, level, file=None):
    values=list()
    if file:
       self.savefs_options.append(LegatoNetworker.OPTION_NOT_IN_SAVESET)
       values.append(file)
    _cmd="%s %s -l %s -c %s -s %s -g %s %s" %(LegatoNetworker.LEGATO_CMD_SAVEFS, " ".join(self.savefs_options), level, \
                                   self.client, self.server, self.group, " ".join(values))
    _output=ComSystem.execLocalOutput(_cmd)
    self.log.debug("executeSaveFs: cmd=%s, output=%s" %(_cmd, _output))
 def restorePartitionTable(self, filename):
     """ writes partition table stored in <filename> to Disk.
     Note, that the format has to be sfdisk stdin compatible
     see sfdisk -d
     Throws ComException on error
     """
     __cmd = self.getRestoreStdin(True) + " < " + filename
     __out = ComSystem.execLocalOutput(__cmd, True, "")
     self.log.debug("restorePartitionTable( " + filename + "):\n " + __out)
     self.commit()
 def lvmarray(command, *params):
     """
     Executes the lvm command @command with given parameters as list.
     @returns: returns the output of the command as list if successful.
     """
     try:
         _command="%s %s %s" %(LinuxVolumeManager.CMD_LVM, command, " ".join(params))
         return ComSystem.execLocalOutput(_command, False, "%s")
     except ComSystem.ExecLocalException, el:
         raise LinuxVolumeManager.LVMCommandException(el.cmd, el.rc, el.out, el.err)
 def restorePartitionTable(self, filename):
    """ writes partition table stored in <filename> to Disk.
    Note, that the format has to be sfdisk stdin compatible
    see sfdisk -d
    Throws ComException on error
    """
    __cmd = self.getRestoreStdin(True) + " < " + filename
    __out = ComSystem.execLocalOutput(__cmd, True, "")
    self.log.debug("restorePartitionTable( " + filename + "):\n " + __out)
    self.commit()
示例#24
0
 def lvmarray(command, *params):
     """
     Executes the lvm command @command with given parameters as list.
     @returns: returns the output of the command as list if successful.
     """
     try:
         _command = "%s %s %s" % (LinuxVolumeManager.CMD_LVM, command,
                                  " ".join(params))
         return ComSystem.execLocalOutput(_command, False, "%s")
     except ComSystem.ExecLocalException, el:
         raise LinuxVolumeManager.LVMCommandException(
             el.cmd, el.rc, el.out, el.err)
示例#25
0
 def check(self, chroot="/mnt/sysimage"):
     """
     Will automatically check if the nfs export is availble or not and also update internal values.
     """
     filesystem=fsset.fileSystemTypeGet("nfs")
     filesystem.mount(self.device, chroot)
     dfoutput=ComSystem.execLocalOutput("df %s" %chroot )
     spaces=re.match(self.getExport()+"\W+\s(?P<all>\d+)\s+(?P<used>\d+)\s+(?P<available>\d+)\s", "\n".join(dfoutput[1:]))
     if spaces:
         self.size=int(spaces.group("all"))
         self.used=int(spaces.group("used"))
         self.available=int(spaces.group("available"))
     filesystem.umount(self.device, chroot)
 def getBootDevice(self):
     _labels=["/boot", "boot", "/bootsr", "bootsr"]
     _devs=[]
     for _label in _labels:
         try: 
             _part = ComSystem.execLocalOutput("findfs LABEL=%s" %_label)
             ComLog.getLogger(__logStrLevel__).debug("detected disk %s" %_part)
             _device=self._normalizeDisk(_part[0])[0]
             ComLog.getLogger(__logStrLevel__).debug("normalized disk %s" %_device)
             _devs.append(_device)
         except Exception:
             pass
             #ComLog.errorTraceLog()
     return _devs
   def stabilize(self):
      self.commit()

      #dev.sync()
      #dev.close()

      # run partx if the device is a multipath device
      self.log.debug("ComHostDisk: checking for multipath devices")
      if self.isDMMultipath():
         devicename=HostDisk.map2realDMName(self.getDeviceName())
         self.log.debug("Device %s is a dm_multipath device, adding partitions" %devicename)
         __cmd=CMD_KPARTX + " " + OPTS_KPARTX +" -d " + devicename
         try:
            __ret = ComSystem.execLocalOutput(__cmd, True, "")
            self.log.debug(__ret)
            __cmd=CMD_KPARTX + " " + OPTS_KPARTX + " -a " + devicename
            __ret = ComSystem.execLocalOutput(__cmd, True, "")
            self.log.debug(__ret)
            #FIXME: crappy fix to give os some time to create devicefiles.
            time.sleep(10)
         except ComSystem.ExecLocalException, ele:
            ComLog.debugTraceLog(self.log)
            self.log.debug("Could not execute %s. Error %s" %(ele.cmd, ele))
 def getBootDevice(self):
     _labels = ["/boot", "boot", "/bootsr", "bootsr"]
     _devs = []
     for _label in _labels:
         try:
             _part = ComSystem.execLocalOutput("findfs LABEL=%s" % _label)
             ComLog.getLogger(__logStrLevel__).debug("detected disk %s" %
                                                     _part)
             _device = self._normalizeDisk(_part[0])[0]
             ComLog.getLogger(__logStrLevel__).debug("normalized disk %s" %
                                                     _device)
             _devs.append(_device)
         except Exception:
             pass
             #ComLog.errorTraceLog()
     return _devs
   def scanOptions(self, device, mountpoint=None):
      """ Scans a mountded gfs and puts the meta information into the DOM
      raises ComException
      """

      if mountpoint:
         __mountpoint=mountpoint.getAttribute("name")
      else:
         __mountpoint, fstype = device.scanMountPoint()
      if not __mountpoint:
         raise ComException("device " + device.getDevicePath() + " is not mounted.")
      __cmd = CMD_GFS_TOOL + " getsb " + __mountpoint
      __ret = ComSystem.execLocalOutput(__cmd)

      if __ret[0] == ComSystem.SKIPPED:
         # Just to keep up working when SIMULATING
         self.setAttribute("bsize", "4096")
         self.setAttribute("lockproto", "lock_dlm")
         self.setAttribute("clustername", "testcluster")
         self.setAttribute("journals", "4")
      else:
         __bsize=ComUtils.grepInLines(__ret, "  sb_bsize = ([0-9]*)")[0]
         log.debug("scan Options bsize: " + __bsize)
         self.setAttribute("bsize", __bsize)

         __lockproto=ComUtils.grepInLines(__ret, "  sb_lockproto = (.*)")[0]
         log.debug("scan Options lockproto: " + __lockproto)
         self.setAttribute("lockproto",__lockproto)

         __locktable=ComUtils.grepInLines(__ret, "  sb_locktable = .*?:(.*)")
         if len(__locktable) == 1:
            log.debug("scan Options locktable: " + __locktable[0])
            self.setAttribute("locktable", __locktable[0])

         __clustername=ComUtils.grepInLines(__ret, "  sb_locktable = (.*?):.*")
         if len(__clustername) == 1:
            log.debug("scan Options clustername: " +__clustername[0])
            self.setAttribute("clustername", __clustername[0])

         __cmd = CMD_GFS_TOOL + " df " + __mountpoint
         __rc, __ret = ComSystem.execLocalGetResult(__cmd)
         if __rc != 0:
            raise ComException(__cmd + __ret)
         __journals=ComUtils.grepInLines(__ret, "  Journals = ([0-9]+)")[0]
         log.debug("scan Options Journals: " +__journals)
         self.setAttribute("journals", __journals)
 def map2realDMName(device, prefixpath="/dev/mapper"):
    """
    Maps the given devicemapper name to the real one (first created).
    Should be executed on every proper device mapper device.
    """
    if os.path.islink(device):
       # more recent versions of multipath will not use device files but symbolic links to the 
       # dm-* devices. Those links are relative and need therefore be converted to absolute 
       # paths.
       return os.path.realpath(os.path.join(os.path.dirname(device), os.readlink(device)))
    else:
       cmd="%s info -c --noheadings -o name %s" %(CMD_DMSETUP, device)
       try:
          return os.path.join(prefixpath, ComSystem.execLocalOutput(cmd, True, "")[:-1])
       except ComSystem.ExecLocalException:
          ComLog.debugTraceLog()
          return device
def getBlockDeviceForUID(uid):
   """ Returns the block devicefile for the given uid """
   if os.path.exists(SCSIPATH_2_DEVICE):
      for target in os.listdir(SCSIPATH_2_DEVICE):
         try:
            blockdev_path=SCSIPATH_2_DEVICE+"/"+target+"/device/block"
            if os.path.exists(blockdev_path):
               blockdev=os.path.basename(os.readlink(blockdev_path))
               _uid=ComSystem.execLocalOutput(SCSIID_CMD_GETUID+"/block/"+blockdev)[0].splitlines()[0]
               log.debug("getBlockDeviceForUID(): %s == %s" %(uid, _uid))
               if _uid==uid:
                  return "/dev/"+blockdev
         except:
            ComLog.debugTraceLog(log)
            pass

   else:
      raise SCSIException("Syspath %s does not exist. Old Linux or no Linux or no sys mounted??" %(SYSPATH_2_BLOCK))
def getBlockDeviceForUID(uid):
    """ Returns the block devicefile for the given uid """
    if os.path.exists(SCSIPATH_2_DEVICE):
        for target in os.listdir(SCSIPATH_2_DEVICE):
            try:
                blockdev_path = SCSIPATH_2_DEVICE + "/" + target + "/device/block"
                if os.path.exists(blockdev_path):
                    blockdev = os.path.basename(os.readlink(blockdev_path))
                    _uid = ComSystem.execLocalOutput(
                        SCSIID_CMD_GETUID + "/block/" +
                        blockdev)[0].splitlines()[0]
                    log.debug("getBlockDeviceForUID(): %s == %s" % (uid, _uid))
                    if _uid == uid:
                        return "/dev/" + blockdev
            except:
                ComLog.debugTraceLog(log)
                pass

    else:
        raise SCSIException(
            "Syspath %s does not exist. Old Linux or no Linux or no sys mounted??"
            % (SYSPATH_2_BLOCK))
示例#33
0
 def queryStatusElement(self, **kwds):
     import xml.dom
     self.__setfromkwds("clusterstatus_cmd", kwds, self.clusterstatus_cmd)
     self.__setfromkwds("clusterstatus_opts", kwds, self.clusterstatus_opts)
     asValue = self.__getfromkwds("asvalue", kwds, True)
     delimitor = self.__getfromkwds("delimitor", kwds, " ")
     query = self.__getfromkwds("query", kwds, None)
     __output = self.__getfromkwds("output", kwds, None)
     self.log.debug("queryStatusElement: query=%s" % query)
     from comoonics import ComSystem
     try:
         # create Reader object
         _dom = comoonics.XmlTools.parseXMLString(
             ComSystem.execLocalOutput(
                 self.getClusterStatusCmd(True, delimitor), True, __output))
         if not query:
             return _dom.documentElement
         else:
             _tmp1 = comoonics.XmlTools.evaluateXPath(
                 query, _dom.documentElement)
             _tmp2 = None
             if asValue:
                 _tmp2 = list()
                 for i in range(len(_tmp1)):
                     if isinstance(
                             _tmp1[i], xml.dom.Node
                     ) and _tmp1[i].nodeType == xml.dom.Node.ATTRIBUTE_NODE:
                         _tmp2.append(_tmp1[i].value)
                     else:
                         _tmp2.append(_tmp1[i])
                 return delimitor.join(_tmp2)
             else:
                 return comoonics.XmlTools.toPrettyXML(_tmp1[0])
     except ComSystem.ExecLocalException, error:
         warnings.warn(
             "Could not query the running cluster with %s. No active values will be available."
             % self.clusterstatus_cmd)
         self.log.debug("Error: %s" % error)
         return None
示例#34
0
    def _copyData(self):
        # FIXME: this implementation is VERY POOR!! This should be fixed without any instance casting of classes on
        #        the end of the child tree. There should be a abstract class FilesystemCopyObject and PathCopyObject
        #        derive from!!!!
        # 1. copy fs/path to fs/path
        ComLog.getLogger(__logStrLevel__).debug(
            "doCopy: instance(self.source: %s), instance(self.dest: %s)" %
            (self.source.__class__, self.dest.__class__))
        ComLog.getLogger(__logStrLevel__).debug(
            "doCopy: isinstance(%s, PathCopyObject): %s" %
            (self.source.__class__, isinstance(self.source, PathCopyObject)))
        if isinstance(self.source, FilesystemCopyObject) or isinstance(
                self.source, PathCopyObject):
            if isinstance(self.source, FilesystemCopyObject):
                if not self.source.filesystem.isCopyable():
                    return True
            mountpoint = self.source.getMountpoint().getAttribute("name")
            ComLog.getLogger(__logStrLevel__).debug(
                "doCopy: isinstance(%s, PathCopyObject): %s" %
                (self.dest.__class__, isinstance(self.dest, PathCopyObject)))
            if isinstance(self.dest, FilesystemCopyObject) or isinstance(
                    self.dest, PathCopyObject):
                __cmd = self._getFSCopyCommand()
                try:
                    __out = ComSystem.execLocalOutput(__cmd, True)
                except ComSystem.ExecLocalException, ele:
                    raise RSyncError(ele)
                #ComLog.getLogger(__logStrLevel__).debug("doCopy: "  + __cmd +" "+ __ret)
                return True

            # 2. copy fs to archive
            elif isinstance(self.dest, ArchiveCopyObject):
                #                try:
                archive = self.dest.getDataArchive()
                archive.createArchive("./", mountpoint)
                return True
 def testExecLocalOutputSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalOutput(self.cmd1, False, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[1])
 def testExecLocalOutput(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalOutput(self.cmd1, False, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[1])
 def getPartitionTable(self):
    try:
       rv = ComSystem.execLocalOutput(self.getDumpStdout(), True, "getPartitionTable")
       return rv
    except ComSystem.ExecLocalException:
       return list()
示例#38
0
 def unlock(self):
     ComSystem.execLocalOutput("rm -f %s" % self.filename)
 def testExecLocalOutputSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalOutput(self.cmd1, False, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[1])
 def scan_release(self):
     _ret = ComSystem.execLocalOutput("uname -r") 
     return [ _ret[0].strip("\n") ]
 def testExecLocalOutputAsStringSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[0])
 def scan_processor(self):
     _ret = ComSystem.execLocalOutput("uname -p") 
     return [ _ret[0].strip("\n") ]
 def testExecLocalOutputAsString(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[0])
 def getPartitionTable(self):
     try:
         rv = ComSystem.execLocalOutput(self.getDumpStdout(), True, "getPartitionTable")
         return rv
     except ComSystem.ExecLocalException:
         return list()
 def execute(self, cmd):
    return ComSystem.execLocalOutput("%s %s" %(self.cmd, cmd), asstr=True)
 def testExecLocalOutput(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalOutput(self.cmd1, False, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[1])
 def testExecLocalOutputAsStringSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[0])
 def testExecLocalOutputAsString(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[0])