예제 #1
0
 def updateMetaData(self, element):
     ComLog.getLogger(self.__logStrLevel__).debug(
         "%u logical volumes cloning all from source" %
         (len(self.getVolumeGroup().getLogicalVolumes())))
     #ComLog.getLogger(self.__logStrLevel__).debug("Element to copy %s" %(element))
     if (len(self.getVolumeGroup().getLogicalVolumes()) == 0):
         #ComLog.getLogger(self.__logStrLevel__).debug("0 logical volumes cloning all from source")
         XmlTools.merge_trees_with_pk(
             element,
             self.getVolumeGroup().getElement(), self.document, "name",
             XmlTools.ElementFilter("logicalvolume"))
         self.vg = VolumeGroup(self.getVolumeGroup().getElement(),
                               self.getDocument())
 def updateMetaData(self, element):
    ComLog.getLogger(self.__logStrLevel__).debug("%u logical volumes cloning all from source" %(len(self.getVolumeGroup().getLogicalVolumes())))
    #ComLog.getLogger(self.__logStrLevel__).debug("Element to copy %s" %(element))
    if (len(self.getVolumeGroup().getLogicalVolumes()) == 0):
       #ComLog.getLogger(self.__logStrLevel__).debug("0 logical volumes cloning all from source")
       XmlTools.merge_trees_with_pk(element, self.getVolumeGroup().getElement(), self.document, "name", XmlTools.ElementFilter("logicalvolume"))
       self.vg=VolumeGroup(self.getVolumeGroup().getElement(), self.getDocument())
 def __init__(self, element, doc):
    CopyObject.__init__(self, element, doc)
    self.vg=None
    vg_element = element.getElementsByTagName(VolumeGroup.TAGNAME)[0]
    self.vg=VolumeGroup(vg_element, doc)
    self.sactivated=False
    self.dactivated=False
class LVMCopyObject(CopyObject):
   """ Class for all LVM source and destination objects"""
   __logStrLevel__ = "LVMCopyObject"

   def __init__(self, element, doc):
      CopyObject.__init__(self, element, doc)
      self.vg=None
      vg_element = element.getElementsByTagName(VolumeGroup.TAGNAME)[0]
      self.vg=VolumeGroup(vg_element, doc)
      self.sactivated=False
      self.dactivated=False

   def prepareAsSource(self):
      self.getVolumeGroup().init_from_disk()
      for pv in LinuxVolumeManager.pvlist(self.getVolumeGroup(), self.getDocument()):
         pv.init_from_disk()
         self.getVolumeGroup().addPhysicalVolume(pv)
      for lv in LinuxVolumeManager.lvlist(self.getVolumeGroup(), self.getDocument()):
         lv.init_from_disk()
         self.getVolumeGroup().addLogicalVolume(lv)
         if not lv.isActivated() and not self.sactivated:
            if lv.getAttribute("attrs", "") != "": 
               self.sactivated=True
            self.vg.activate()

   def prepareAsDest(self):
      self.dactivated=True
      for pv in self.getVolumeGroup().getPhysicalVolumes():
         self.getVolumeGroup().delPhysicalVolume(pv)
         pv.resolveName()
         self.getVolumeGroup().addPhysicalVolume(pv)

   def updateMetaData(self, element):
      ComLog.getLogger(self.__logStrLevel__).debug("%u logical volumes cloning all from source" %(len(self.getVolumeGroup().getLogicalVolumes())))
      #ComLog.getLogger(self.__logStrLevel__).debug("Element to copy %s" %(element))
      if (len(self.getVolumeGroup().getLogicalVolumes()) == 0):
         #ComLog.getLogger(self.__logStrLevel__).debug("0 logical volumes cloning all from source")
         XmlTools.merge_trees_with_pk(element, self.getVolumeGroup().getElement(), self.document, "name", XmlTools.ElementFilter("logicalvolume"))
         self.vg=VolumeGroup(self.getVolumeGroup().getElement(), self.getDocument())
         #self.getVolumeGroup().updateChildrenWithPK(element)
         #from xml.dom.ext import PrettyPrint
         #PrettyPrint(self.getVolumeGroup().getElement())
         #ComLog.getLogger(self.__logStrLevel__).debug("Successfully updated the dom structure for volumegroup")

   def cleanupSource(self):
      if self.sactivated:
         self.vg.deactivate()

   def cleanupDest(self):
      if self.dactivated:
         self.vg.deactivate()

   def getVolumeGroup(self):
      return self.vg

   def getMetaData(self):
      return self.vg.getElement()
 def _getLVM_physicalVolume(self, device):
     from comoonics.storage.ComLVM import LogicalVolume, LinuxVolumeManager, VolumeGroup
     try:
         (vgname, lvname) = LogicalVolume.splitLVPath(device)
         _vg = VolumeGroup(vgname)
         _pv = LinuxVolumeManager.pvlist(_vg)
         ComLog.getLogger(__logStrLevel__).debug(
             "detected physical volume %s" % _pv)
         return _pv[0].getAttribute("name")
     except LogicalVolume.LVMInvalidLVPathException, e:
         ComLog.errorTraceLog()
         return
예제 #6
0
 def __init__(self, element, doc):
     CopyObject.__init__(self, element, doc)
     self.vg = None
     vg_element = element.getElementsByTagName(VolumeGroup.TAGNAME)[0]
     self.vg = VolumeGroup(vg_element, doc)
     self.activated = False
예제 #7
0
class LVMCopyObject(CopyObject):
    """ Class for all LVM source and destination objects"""
    __logStrLevel__ = "LVMCopyObject"

    def __init__(self, element, doc):
        CopyObject.__init__(self, element, doc)
        self.vg = None
        vg_element = element.getElementsByTagName(VolumeGroup.TAGNAME)[0]
        self.vg = VolumeGroup(vg_element, doc)
        self.activated = False

    def prepareAsSource(self):
        self.getVolumeGroup().init_from_disk()
        for pv in LinuxVolumeManager.pvlist(self.getVolumeGroup(),
                                            self.getDocument()):
            pv.init_from_disk()
            self.getVolumeGroup().addPhysicalVolume(pv)
        for lv in LinuxVolumeManager.lvlist(self.getVolumeGroup(),
                                            self.getDocument()):
            lv.init_from_disk()
            self.getVolumeGroup().addLogicalVolume(lv)
            if not lv.isActivated() and not self.activated:
                self.activated = True
                self.vg.activate()

    def prepareAsDest(self):
        self.activated = True
        for pv in self.getVolumeGroup().getPhysicalVolumes():
            self.getVolumeGroup().delPhysicalVolume(pv)
            pv.resolveName()
            self.getVolumeGroup().addPhysicalVolume(pv)

    def updateMetaData(self, element):
        ComLog.getLogger(self.__logStrLevel__).debug(
            "%u logical volumes cloning all from source" %
            (len(self.getVolumeGroup().getLogicalVolumes())))
        #ComLog.getLogger(self.__logStrLevel__).debug("Element to copy %s" %(element))
        if (len(self.getVolumeGroup().getLogicalVolumes()) == 0):
            #ComLog.getLogger(self.__logStrLevel__).debug("0 logical volumes cloning all from source")
            XmlTools.merge_trees_with_pk(
                element,
                self.getVolumeGroup().getElement(), self.document, "name",
                XmlTools.ElementFilter("logicalvolume"))
            self.vg = VolumeGroup(self.getVolumeGroup().getElement(),
                                  self.getDocument())
            #self.getVolumeGroup().updateChildrenWithPK(element)
            #from xml.dom.ext import PrettyPrint
            #PrettyPrint(self.getVolumeGroup().getElement())
            #ComLog.getLogger(self.__logStrLevel__).debug("Successfully updated the dom structure for volumegroup")

    def cleanupSource(self):
        if self.activated:
            self.vg.deactivate()

    def cleanupDest(self):
        if self.activated:
            self.vg.deactivate()

    def getVolumeGroup(self):
        return self.vg

    def getMetaData(self):
        return self.vg.getElement()
    def testCreateLVMEnvironment(self):
        try:
            vgname = "test_vg"
            lvname = "test_lv"
            pvname = "/dev/sda"
            print("Creating pv: %s" % pvname)
            _pv = PhysicalVolume(pvname)
            _pv.create()
            print("Creating vg: %s" % vgname)
            _vg = VolumeGroup(vgname, _pv)
            _vg.create()
            _vg.addPhysicalVolume(_pv)
            print("Creating lv: %s" % lvname)
            _lv = LogicalVolume(lvname, _vg)
            _lv.create()
            _vg.addLogicalVolume(_lv)

            print "Volumegroup %s: %s" % (vgname, _vg)

            print("Changing clustered")
            _vg.clustered()
            _vg.notclustered()

            print("Removing lv")
            _lv.remove()
            print("Removing vg")
            _vg.remove()
            print("Removing pv")
            _pv.remove()
        except Exception, e:
            import traceback
            traceback.print_exc()
            self.fail(
                "Caught unexpected exception during lvm environment creation %s."
                % e)
 def testCreateLVMEnvironment(self):
     try:
         vgname="test_vg"
         lvname="test_lv"
         pvname="/dev/sda"
         print("Creating pv: %s" %pvname)
         _pv=PhysicalVolume(pvname)
         _pv.create()
         print("Creating vg: %s" %vgname)
         _vg=VolumeGroup(vgname, _pv)
         _vg.create()
         _vg.addPhysicalVolume(_pv)
         print("Creating lv: %s" %lvname)
         _lv=LogicalVolume(lvname, _vg)
         _lv.create()
         _vg.addLogicalVolume(_lv)
     
         print "Volumegroup %s: %s" %(vgname, _vg)
     
         print("Changing clustered")
         _vg.clustered()
         _vg.notclustered()
     
         print("Removing lv")
         _lv.remove()
         print("Removing vg")
         _vg.remove()
         print("Removing pv")
         _pv.remove()
     except Exception, e:
         import traceback
         traceback.print_exc()
         self.fail("Caught unexpected exception during lvm environment creation %s." %e)
class LVMCopyObject(CopyObject):
    """ Class for all LVM source and destination objects"""
    __logStrLevel__ = "LVMCopyObject"

    def __init__(self, element, doc):
        CopyObject.__init__(self, element, doc)
        self.vg=None
        vg_element = element.getElementsByTagName(VolumeGroup.TAGNAME)[0]
        self.vg=VolumeGroup(vg_element, doc)
        self.activated=False

    def prepareAsSource(self):
        self.getVolumeGroup().init_from_disk()
        for pv in LinuxVolumeManager.pvlist(self.getVolumeGroup(), self.getDocument()):
            pv.init_from_disk()
            self.getVolumeGroup().addPhysicalVolume(pv)
        for lv in LinuxVolumeManager.lvlist(self.getVolumeGroup(), self.getDocument()):
            lv.init_from_disk()
            self.getVolumeGroup().addLogicalVolume(lv)
            if not lv.isActivated() and not self.activated:
                self.activated=True
                self.vg.activate()

    def prepareAsDest(self):
        self.activated=True
        for pv in self.getVolumeGroup().getPhysicalVolumes():
            self.getVolumeGroup().delPhysicalVolume(pv)
            pv.resolveName()
            self.getVolumeGroup().addPhysicalVolume(pv)

    def updateMetaData(self, element):
        ComLog.getLogger(self.__logStrLevel__).debug("%u logical volumes cloning all from source" %(len(self.getVolumeGroup().getLogicalVolumes())))
        #ComLog.getLogger(self.__logStrLevel__).debug("Element to copy %s" %(element))
        if (len(self.getVolumeGroup().getLogicalVolumes()) == 0):
            #ComLog.getLogger(self.__logStrLevel__).debug("0 logical volumes cloning all from source")
            XmlTools.merge_trees_with_pk(element, self.getVolumeGroup().getElement(), self.document, "name", XmlTools.ElementFilter("logicalvolume"))
            self.vg=VolumeGroup(self.getVolumeGroup().getElement(), self.getDocument())
            #self.getVolumeGroup().updateChildrenWithPK(element)
            #from xml.dom.ext import PrettyPrint
            #PrettyPrint(self.getVolumeGroup().getElement())
            #ComLog.getLogger(self.__logStrLevel__).debug("Successfully updated the dom structure for volumegroup")

    def cleanupSource(self):
        if self.activated:
            self.vg.deactivate()

    def cleanupDest(self):
        if self.activated:
            self.vg.deactivate()

    def getVolumeGroup(self):
        return self.vg

    def getMetaData(self):
        return self.vg.getElement()

#################
# $Log: ComLVMCopyObject.py,v $
# Revision 1.9  2010-03-08 12:30:48  marc
# version for comoonics4.6-rc1
#
# Revision 1.8  2010/02/09 21:48:24  mark
# added .storage path in includes
#
# Revision 1.7  2008/02/27 10:50:04  marc
# - better testing
#
# Revision 1.6  2007/04/04 12:52:20  marc
# MMG Backup Legato Integration
# - moved prepareAsDest and added activation support for not activated devices as Destination
#
# Revision 1.5  2007/04/02 11:49:22  marc
# MMG Backup Legato Integration:
# - Journaling for vg_activation
#
# Revision 1.4  2006/12/13 20:17:41  marc
# Support for Metadata
#
# Revision 1.3  2006/11/27 12:11:09  marc
# new version with metadata
#
# Revision 1.2  2006/11/23 14:16:16  marc
# added logStrLevel
#
# Revision 1.1  2006/07/19 14:29:15  marc
# removed the filehierarchie
#
# Revision 1.1  2006/06/29 13:47:39  marc
# initial revision
#