Exemplo n.º 1
0
    def mount(self, device, mountpoint):
        """ mount a filesystem
        device: ComDevice.Device
        mountpoint: ComMountPoint.MountPoint
        """

        __exclusive = self.getAttribute("exlock", "")
        __mkdir = self.getAttributeBoolean("mkdir", True)

        __mp = mountpoint.getAttribute("name")
        if not os.path.exists(__mp) and __mkdir:
            log.debug("Path %s does not exists. I'll create it." % __mp)
            ComSystem.execMethod(os.makedirs, __mp)

        if __exclusive and __exclusive != "" and os.path.exists(__exclusive):
            raise ComException("lockfile " + __exclusive + " exists!")

        __cmd = self.mkmountcmd(device, mountpoint)
        __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
        log.debug("mount:" + __cmd + ": " + __ret)
        if __rc != 0:
            raise ComException(__cmd + __ret)
        if __exclusive:
            __fd = open(__exclusive, 'w')
            __fd.write(device.getDevicePath() + " is mounted ")
    def rescan(self, __hosts, __bus, __target, __lun):
        """ Rescan SCSI
        invokes a rescan via /sys/class/scsi_host/hostH/scan interface
        IDEAS
        INPUTS
          * host - name of scsi host ( - for all )
          * bus - number of scsi bus (- for all )
          * target - number of target ( - for all )
          * lun - number of lun ( - for all )

        """
        __syspath = "/sys/class/scsi_host"

        if not os.path.isdir( __syspath ):
            raise ComException(__syspath + " not found")
    
        if __hosts == "-":
            __hosts=self.getAllSCSIHosts()

        if  not ( ComUtils.isInt(__bus) or  __bus == "-"):
            raise ComException( __bus + " is not valid to scan SCSI Bus"); 
    
        if  not ( ComUtils.isInt(__target) or  __target == "-"):
            raise ComException( __bus + " is not valid to scan SCSI Target")

        if  not (ComUtils.isInt(__lun) or  __lun == "-"):
            raise ComException( __bus + " is not valid to scan SCSI Lun")

        print "Hosts: ", __hosts

        for __host in __hosts:
            ComSystem.execLocal( "echo \""+__bus+"\" \""+ __target+"\" \""+ __lun+ "\" > "+__syspath+"/"+__host+"/scan")
Exemplo n.º 3
0
    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
        __rc, __ret = ComSystem.execLocalGetResult(__cmd)
        if __rc != 0:
            raise ComException(__cmd + __ret)

        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 copyPartitionTable(source_device, destination_device):
    __cmd = CMD_SFDISK + " -d " + source_device.getDeviceName() + " | " + CMD_SFDISK \
            + " " + destination_device.getDeviceName()
    __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
    log.debug("copyPartitionTable " + __ret)
    if __rc != 0:
        raise ComException(__cmd)
Exemplo n.º 5
0
 def formatDevice(self, device):
     __devicePath = device.getDevicePath()
     __cmd = self.getMkfsCmd() + " " + __devicePath
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     log.debug("formatDevice: " + __cmd + ": " + __ret)
     if __rc != 0:
         raise ComException(__cmd + __ret)
Exemplo n.º 6
0
 def formatDevice(self, device):
     __cmd = self.getMkfsCmd() + self.getOptionsString(
     ) + device.getDevicePath()
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     #self.getLog().debug("formatDevice: \n" , __cmd + __ret)
     if __rc != 0:
         raise ComException(__cmd + __ret)
Exemplo n.º 7
0
    def scanBootloaderGrub(self):
        #scans bootdisk for a possible grub installation
        #returns (hd0,x) when succeeded
        import tempfile
        __tmp = tempfile.NamedTemporaryFile()

        # This is not working with all devices (e.g. cciss, mpath)
        # So I removed the part.
        #__exp=re.compile("[0-9]*")
        #__dev=__exp.sub("",self.getDeviceName())
        __dev = self.getDeviceName()
        __cmd = """/sbin/grub --batch 2>/dev/null <<EOF | egrep "(hd[0-9]+,[0-9]+)" 1>""" + __tmp.name + """
        device (hd0) """ + __dev + """
        find /grub/stage2
        quit
        EOF
        """
        # TODO this will not work
        if ComSystem.execLocal(__cmd, """(hd0,1)
"""):
            raise ComException("cannot find grub on " + __dev)

        __part = __tmp.readline()
        self.log.debug("Found grub loader on " + __part)
        return __part
Exemplo n.º 8
0
 def __init__(self, *params, **kwds):
     """
     Valid constructors are
     __init__(element, doc)
     __init__(source, dest)
     __init__(source=source, dest=dest)
     """
     if (len(params)==2 and isinstance(params[0], CopyObject) and isinstance(params[1], CopyObject)) or \
        (kwds and kwds.has_key("source") and kwds.has_key("dest")):
         source = None
         dest = None
         if len(params) == 2:
             source = params[0]
             dest = params[1]
         else:
             source = kwds["source"]
             dest = kwds["dest"]
         doc = xml.dom.getDOMImplementation().createDocument(
             None, self.TAGNAME, None)
         element = doc.documentElement
         element.setAttribute("type", "filesystem")
         element.appendChild(source.getElement())
         element.appendChild(dest.getElement())
         Copyset.__init__(self, element, doc)
         self.source = source
         self.dest = dest
     elif len(params) == 2:
         element = params[0]
         doc = params[1]
         Copyset.__init__(self, element, doc)
         try:
             __source = element.getElementsByTagName('source')[0]
             self.source = CopyObject(__source, doc)
         except Exception, e:
             ComLog.getLogger(__logStrLevel__).warning(e)
             ComLog.debugTraceLog(ComLog.getLogger(__logStrLevel__))
             raise ComException(
                 "Source for filesystem copyset with name \"%s\" is not defined"
                 % (self.getAttribute("name", "unknown")))
         try:
             __dest = element.getElementsByTagName('destination')[0]
             self.dest = CopyObject(__dest, doc)
         except Exception, e:
             ComLog.getLogger(__logStrLevel__).warning(e)
             raise ComException(
                 "Destination for filesystem copyset with name \"%s\" is not defined"
                 % (self.getAttribute("name", "unknown")))
Exemplo n.º 9
0
 def labelDevice(self, device, label):
     __devicePath = device.getDevicePath()
     __cmd = self.labelCmd + " " + __devicePath + " " + label
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     log.debug("labelDevice: " + __cmd + ": " + __ret)
     if __rc:
         raise ComException(__cmd + __ret)
     self.setAttribute("label", label)
Exemplo n.º 10
0
 def removeFlag(self, name):
     try:
         from comoonics import XmlTools
         node = XmlTools.evaluateXPath('flag/@name=' + name,
                                       self.element)[0]
         self.element.removeChild(node)
     except Exception:
         raise ComException("no flag with name %s found" % name)
Exemplo n.º 11
0
 def getDataArchive(self):
     ''' returns data archive object'''
     import comoonics.XmlTools
     try:
         __archive = comoonics.XmlTools.evaluateXPath(
             'data/archive', self.element)[0]
         return Archive(__archive, self.document)
     except Exception:
         raise ComException("no data archiv description found")
Exemplo n.º 12
0
 def getLabelFromDevice(self, device):
     # BUG: Cannot function!!!!
     __devicePath = device.getDevicePath()
     __cmd = self.labelCmd + " " + __devicePath
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     log.debug("getLabel: " + __cmd + ": " + __ret)
     if __rc:
         raise ComException(__cmd + __ret)
     return __ret
    def __init__(self, element, doc):
        Copyset.__init__(self, element, doc)

        try:
            _dest = element.getElementsByTagName("destination")[0]
            __dest = element.getElementsByTagName("disk")[0]
            self.destination = BootDisk(__dest, doc)
        except Exception:
            raise ComException("destination for copyset not defined")
Exemplo n.º 14
0
 def umountDir(self, mountpoint):
     """ umount a filesystem with the use of the mountpoint
     mountpoint: ComMountPoint.MountPoint
     """
     __cmd = self.cmd_umount + " " + mountpoint.getAttribute("name")
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     log.debug("umount: " + __cmd + ": " + __ret)
     if __rc != 0:
         raise ComException(__cmd + __ret)
     self.unlinkLockfile()
Exemplo n.º 15
0
 def umountDev(self, device):
     """ umount a filesystem with the use of the device name
     device: ComDevice.Device
     """
     __cmd = self.cmd_umount + " " + device.getDevicePath()
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     log.debug("umount:" + __cmd + ": " + __ret)
     if __rc != 0:
         raise ComException(__cmd + __ret)
     self.unlinkLockfile()
Exemplo n.º 16
0
 def findLabel(self, label):
     """ try to find Device with label
     returns Device
     """
     import ComDevice
     __cmd = "/sbin/findfs LABEL=" + label
     __rc, __path = ComSystem.execLocalGetResult(__cmd)
     if not __rc:
         raise ComException("device with label " + label + "not found")
     return ComDevice.Device(__path[0])
Exemplo n.º 17
0
 def doPost(self):
     super(ISOFSModificationset, self).doPost()
     self.replayJournal()
     self.commitJournal()
     ISOFSModificationset.logger.debug("doPost() CWD: " + os.getcwd())
     __cmd = self._get_mkisofs_command()
     __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
     ISOFSModificationset.logger.debug("mkisofs: " + __cmd + ": " + __ret)
     if __rc != 0:
         raise ComException(__cmd + __ret)
Exemplo n.º 18
0
    def __init__(self, element, doc):
        ModificationsetJournaled.__init__(self, element, doc)
        try:
            __disk=element.getElementsByTagName('disk')[0]
            self.disk=HostDisk(__disk, doc)
        except Exception:
            raise ComException("disk for modificationset not defined")

        self.addToUndoMap(self.disk.__class__.__name__, "savePartitionTable", "restorePartitionTable")
        self.addToUndoMap(self.disk.__class__.__name__, "noPartitionTable", "deletePartitionTable")
    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))
Exemplo n.º 20
0
 def __init__(self, element, doc):
     """
     default constructor:
     __init__(element, doc)
     """
     super(ISOFSModificationset, self).__init__(element, doc)
     try:
         __path = element.getElementsByTagName('path')
     except Exception:
         raise ComException("Path for modificationset \"%s\" not defined" %
                            self.getAttribute("name", "unknown"))
     self.pathlist = __path
     self.createModificationsList(
         self.getElement().getElementsByTagName("modification"), doc)
     self.isoname = self.getAttribute("name")
 def __init__(self, element, doc):
     """
     default constructor:
     __init__(element, doc)
     """
     super(PathModificationset, self).__init__(element, doc)
     try:
         __path = element.getElementsByTagName('path')[0]
     except Exception:
         raise ComException("Path for modificationset \"%s\" not defined" %
                            self.getAttribute("name", "unknown"))
     self.path = Path(__path, doc)
     self.createModificationsList(
         self.path.getElement().getElementsByTagName("modification"), doc)
     self.addToUndoMap(self.path.__class__.__name__, "pushd", "popd")
    def initFromDisk(self):
        """ reads partition information from the disk and fills up DOM
        with new information
        """
        HostDisk.log.debug("initFromDisk()")

        #FIXME: create LabelResolver
        if self.refByLabel():
            pass
        if not self.exists():
            raise ComException("Device %s not found or no valid device!" % self.getDeviceName())
        try:
            self.initFromDiskParted()
        except ImportError:
            self.initFromDiskPartedCmd()
Exemplo n.º 23
0
    def __init__(self, element, doc):
        CopyObjectJournaled.__init__(self, element, doc)
        try:
            __disk = element.getElementsByTagName('disk')[0]
            self.disk = HostDisk(__disk, doc)
        except Exception:
            raise ComException("disk for copyset not defined")

        self.addToUndoMap(self.disk.__class__.__name__, "savePartitionTable",
                          "restorePartitionTable")
        self.addToUndoMap(self.disk.__class__.__name__, "noPartitionTable",
                          "deletePartitionTable")
        # We need to have the tempfile globlally available because of it deleteing itself when not
        # referenced anymore.
        import tempfile
        self.__tmp = tempfile.NamedTemporaryFile()
Exemplo n.º 24
0
    def getPartedSize(self, dev):
        """ returns always size in sectors """
        size = self.getAttribute("size")
        # calculate new size
        # FIXME Round up to next cylinder
        # Test Megabyte e.g. size="200M"
        res = re.search("([0-9]+)M", size)
        if res:
            sectors = int(res.group(1)) * 1024 * 1024 / dev.sector_size
            ComLog.getLogger(self.__logStrLevel__). \
                debug("found size in Megabytes : %s -> %s sectors" % (res.group(1), sectors))
            return sectors

        # Test Gigabyte e.g. size="200G"
        res = re.search("([0-9]+)G", size)
        if res:
            sectors = int(res.group(1)) * 1024 * 1024 * 1024 / dev.sector_size
            ComLog.getLogger(self.__logStrLevel__). \
                debug("found size in Gigabytes : %s -> %s sectors" %(res.group(1), sectors))
            return sectors

        # Test Percentage
        res = re.search("([0-9]+)%", size)
        if res:
            sectors = int(
                float(
                    float(res.group(1)) / 100 * dev.heads * dev.cylinders *
                    dev.sectors))
            ComLog.getLogger(self.__logStrLevel__). \
                debug("found size in %% : %s -> %s sectors" %( res.group(1), sectors))
            return sectors

        # Test REMAIN
        res = re.search("REMAIN", size)
        if res:
            ComLog.getLogger(
                self.__logStrLevel__).debug("found size in Tag :REMAIN")
            return 0

        # Test sectors
        res = re.search("[0-9]+", size)
        if res:
            ComLog.getLogger(self.__logStrLevel__).debug(
                "found size in Tag :%s " % size)
            return int(size)

        raise ComException("size %s not supported" % size)
Exemplo n.º 25
0
    def installBootloaderGrub(self):
        # To DO
        # Add some checks if grub install was successfull.

        __part = self.scanBootloaderGrub()
        # This is not working with all devices (e.g. cciss, mpath)
        # So I removed the part.
        #__exp=re.compile("[0-9]*")
        #__dev=__exp.sub("",self.getDeviceName())
        __dev = self.getDeviceName()
        __cmd = """grub --batch 2>/dev/null <<EOF | grep "succeeded" > /dev/null
        device (hd0) """ + __dev + """
        root """ + __part + """
        setup (hd0)
        quit
        EOF
        """
        if ComSystem.execLocal(__cmd):
            raise ComException("cannot install grub on " + __dev)
    def getMountList(self):
        if not os.path.isfile("/proc/mounts"):
            raise ComException("/proc/mounts not found.")

        if sys.version[:3] < "2.5":
            [i, o] = os.popen2("cat /proc/mounts")
        else:
            import subprocess
            p = subprocess.Popen(["cat /proc/mounts"],
                                 shell=True,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 close_fds=True)
            p.wait()
            i = p.returncode
            o = p.stdout

        return o.readlines()
 def __init__(self, *params, **kwds):
     """
     Supported constructors
     __init__(element, doc)
     __init__(path, source=True|False)
     __init__(path=path, source=True, dest=True)
     """
     PathCopyObject.logger.debug("__init__()")
     if (len(params) == 2 and not isinstance(params[0], xml.dom.Node)) or (
             kwds and kwds.has_key("path") and
         (kwds.has_key("source") or kwds.has_key("dest"))):
         _path = None
         _source = (len(params) == 2 and params[1] == True) or (
             kwds and kwds.has_key("source") and kwds["source"] == True)
         if len(params) >= 1:
             _path = params[0]
         else:
             _path = kwds["path"]
         _tagname = "destination"
         if _source:
             _tagname = "source"
         doc = xml.dom.getDOMImplementation().createDocument(
             None, _tagname, None)
         element = doc.documentElement
         element.setAttribute("type", "path")
         if isinstance(_path, basestring):
             _path = Path(_path)
         element.appendChild(_path.getElement())
         self.path = _path
         CopyObjectJournaled.__init__(self, element, doc)
     else:
         element = params[0]
         doc = params[1]
         CopyObjectJournaled.__init__(self, element, doc)
         try:
             __path = element.getElementsByTagName('path')[0]
             self.path = Path(__path, doc)
         except Exception:
             raise ComException("Path for copyobject \"%s\" not defined" %
                                self.getAttribute("name", "unknown"))
     PathCopyObject.logger.debug("__init__(%s)" % self.path)
     self.addToUndoMap(self.path.__class__.__name__, "pushd", "popd")
Exemplo n.º 28
0
 def doRealModifications(self):
     import xml.dom
     import StringIO
     if self.hasAttribute("command"):
         __cmd=self.getAttribute("command")
     else:
         buf=StringIO.StringIO()
         element=self.getElement()
         child=element.firstChild
         while child != None:
             if child.nodeType==xml.dom.Node.TEXT_NODE:
                 buf.write(child.data)
             child=child.nextSibling
         __cmd=buf.getvalue()
     __rc, __ret, __err = ComSystem.execLocalGetResult(__cmd, True)
     if __rc:
         raise ComException(__cmd + ":  out:" + " ".join(__ret) + \
                                                         " err: " + " ".join(__err))
     else:
         ComLog.getLogger("ExecutionModification").debug(__cmd + ":  return:" + " ".join(__ret) + \
                                                         " err: " + " ".join(__err))
Exemplo n.º 29
0
 def __init__(self, name, value):
     ComException.__init__(self, value)
     self.name = name
 def __init__(self, cls1, cls2):
     ComException.__init__(self, "%s is no instance of %s. Incompatible Object" %(cls1.__name__, cls2.__name__))
Exemplo n.º 31
0
 def __init__(self, src, repository=None):
     ComException.__init__(self, src)
     self.repository=repository
 def __init__(self, name, value):
    ComException.__init__(self, value)
    self.name=name
Exemplo n.º 33
0
#                return False
# 3. copy archive to fs
        elif isinstance(self.source, ArchiveCopyObject):
            if isinstance(self.dest, FilesystemCopyObject) or isinstance(
                    self.dest, PathCopyObject):
                if self.dest.filesystem.copyable:
                    return True
#                try:
                archive = self.source.getDataArchive()
                mountpoint = self.dest.getMountpoint().getAttribute("name")
                archive.extractArchive(mountpoint)
                return True
#                except Exception, e:
#                    ComLog.getLogger(__logStrLevel__).error(e)
#                return False
        raise ComException("data copy %s to %s is not supported" \
                           %( self.source.__class__.__name__, self.dest.__class__.__name__))


# $Log: ComFilesystemCopyset.py,v $
# Revision 1.19  2011-02-21 16:23:53  marc
# - implemented functionality that a filesystem would be queried if it allows copying or not (e.g. swap does not)
#
# Revision 1.18  2011/02/17 13:14:04  marc
# added support for labeled filesystems
#
# Revision 1.17  2010/03/08 12:30:48  marc
# version for comoonics4.6-rc1
#
# Revision 1.16  2010/02/09 21:48:24  mark
# added .storage path in includes
#
 def __init__(self, path):
     ComException.__init__(self, "Could not find module %s." %(path))