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"
            )
    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")
示例#3
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
    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
 def rereadPartitionTable(self):
    """ rereads the partition table of a disk """
    __cmd = CMD_SFDISK + " -R " + self.getDeviceName() + " >/dev/null 2>&1"
    if ComSystem.execLocal(__cmd):
       self.commit()
       return False
    else:
       self.commit()
       return True
 def rereadPartitionTable(self):
     """ rereads the partition table of a disk """
     __cmd = CMD_SFDISK + " -R " + self.getDeviceName() + " >/dev/null 2>&1"
     if ComSystem.execLocal(__cmd):
         self.commit()
         return False
     else:
         self.commit()
         return True
 def check(*args, **kwds):
     ret = False
     try:
         if not kwds and not args:
             #                SystemInformation.log.debug("Checking for cluster availability")
             if (
                 os.path.exists(RedhatClusterSystemInformation.REDHAT_CLUSTER_CONF)
                 and ComSystem.execLocal("%s >/dev/null 2>&1" % (RedhatClusterSystemInformation.CLUSTAT_CMD)) == 0
             ):
                 #                    SystemInformation.log.debug("OK")
                 ret = True
         #                else:
         #                    SystemInformation.log.debug("FAILED")
         else:
             if kwds.has_key("type") and kwds["type"] == "cluster":
                 ret = True
     finally:
         return ret
   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)
示例#9
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 check(*args, **kwds):
        ret = False
        try:
            if not kwds and not args:
                #                SystemInformation.log.debug("Checking for cluster availability")
                if os.path.exists(
                        RedhatClusterSystemInformation.REDHAT_CLUSTER_CONF
                ) and ComSystem.execLocal(
                        "%s >/dev/null 2>&1" %
                    (RedhatClusterSystemInformation.CLUSTAT_CMD)) == 0:
                    #                    SystemInformation.log.debug("OK")
                    ret = True


#                else:
#                    SystemInformation.log.debug("FAILED")
            else:
                if kwds.has_key("type") and kwds["type"] == "cluster":
                    ret = True
        finally:
            return ret
 def deletePartitionTable(self):
    """ deletes the partition table """
    __cmd = CMD_DD + " if=/dev/zero of=" + self.getDeviceName() + " bs=512 count=2 >/dev/null 2>&1"
    if ComSystem.execLocal(__cmd):
       return False
    return self.rereadPartitionTable()
 def testExecLocalFalse(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocal("/bin/false", "output of /bin/false, execLocal")
     self.assertEquals(result, 256)
 def tearDown(self):
     from comoonics import ComSystem
     ComSystem.execLocal("rm -rf %s" %self.__tmpdir)
 def deletePartitionTable(self):
     """ deletes the partition table """
     __cmd = CMD_DD + " if=/dev/zero of=" + self.getDeviceName() + " bs=512 count=2 >/dev/null 2>&1"
     if ComSystem.execLocal(__cmd):
         return False
     return self.rereadPartitionTable()
 def testExecLocalFalse(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocal("/bin/false",
                                  "output of /bin/false, execLocal")
     self.assertEquals(result, 256)