@@ -29,9 +29,7 @@ if os.path.exists("/usr/lib/xcp/sm"):
2929
3030import SR , VDI , SRCommand , util , lvutil
3131from util import CommandException
32- import vhdutil
3332import shutil
34- import lvhdutil
3533import errno
3634import subprocess
3735import xs_errors
@@ -41,6 +39,30 @@ import random
4139import cloudstack_pluginlib as lib
4240import logging
4341
42+ try :
43+ # sm >= 3.2.12-18 (e.g. XCP-ng 8.3), where lvhdutil was folded into
44+ # constants/lvmcowutil and vhdutil became a class
45+ from constants import VG_PREFIX , VG_LOCATION
46+ from lvmcowutil import LvmCowUtil
47+ from vhdutil import VhdUtil
48+ _vhdutil = VhdUtil ()
49+ lvhdutil_extractUuid = LvmCowUtil .extractUuid
50+ vhdutil_getParent = _vhdutil .getParent
51+ vhdutil_getVHDInfoLVM = _vhdutil .getInfoFromLVM
52+ vhdutil_getSizePhys = _vhdutil .getSizePhys
53+ vhdutil_setHidden = _vhdutil .setHidden
54+ except ImportError :
55+ # older sm (XenServer and XCP-ng releases prior to the 8.3 SM refactor)
56+ import vhdutil
57+ import lvhdutil
58+ VG_PREFIX = lvhdutil .VG_PREFIX
59+ VG_LOCATION = lvhdutil .VG_LOCATION
60+ lvhdutil_extractUuid = lvhdutil .extractUuid
61+ vhdutil_getParent = vhdutil .getParent
62+ vhdutil_getVHDInfoLVM = vhdutil .getVHDInfoLVM
63+ vhdutil_getSizePhys = vhdutil .getSizePhys
64+ vhdutil_setHidden = vhdutil .setHidden
65+
4466lib .setup_logging ("/var/log/cloud/cloud.log" )
4567
4668VHDUTIL = "vhd-util"
@@ -242,7 +264,7 @@ def scanParent(path):
242264 lvName = os .path .basename (path )
243265 dirname = os .path .dirname (path )
244266 vgName = os .path .basename (dirname )
245- vhdInfo = vhdutil . getVHDInfoLVM (lvName , lvhdutil . extractUuid , vgName )
267+ vhdInfo = vhdutil_getVHDInfoLVM (lvName , lvhdutil_extractUuid , vgName )
246268 parentUUID = vhdInfo .parentUuid
247269 except :
248270 errMsg = "Could not get vhd parent of " + path
@@ -254,9 +276,9 @@ def getParent(path, isISCSI):
254276 parentUUID = ''
255277 try :
256278 if isISCSI :
257- parentUUID = vhdutil . getParent (path , lvhdutil . extractUuid )
279+ parentUUID = vhdutil_getParent (path , lvhdutil_extractUuid )
258280 else :
259- parentUUID = vhdutil . getParent (path , cleanup .FileVDI .extractUuid )
281+ parentUUID = vhdutil_getParent (path , cleanup .FileVDI .extractUuid )
260282 except :
261283 errMsg = "Could not get vhd parent of " + path
262284 logging .debug (errMsg )
@@ -392,8 +414,8 @@ def unmountSnapshotsDir(session, args):
392414
393415def getPrimarySRPath (primaryStorageSRUuid , isISCSI ):
394416 if isISCSI :
395- primarySRDir = lvhdutil . VG_PREFIX + primaryStorageSRUuid
396- return os .path .join (lvhdutil . VG_LOCATION , primarySRDir )
417+ primarySRDir = VG_PREFIX + primaryStorageSRUuid
418+ return os .path .join (VG_LOCATION , primarySRDir )
397419 else :
398420 return os .path .join (SR .MOUNT_BASE , primaryStorageSRUuid )
399421
@@ -507,7 +529,7 @@ def getSnapshotSize(session, args):
507529
508530 snapshotVHD = getVHD (snapshotUuid , isISCSI )
509531 snapshotPath = os .path .join (primarySRPath , snapshotVHD )
510- physicalSize = vhdutil . getSizePhys (snapshotPath )
532+ physicalSize = vhdutil_getSizePhys (snapshotPath )
511533 return str (physicalSize )
512534
513535def backupSnapshot (session , args ):
@@ -537,7 +559,7 @@ def backupSnapshot(session, args):
537559 prevBackupUuid = prevBackupUuid .split ("/" )[- 1 ]
538560 # Check existence of snapshot on primary storage
539561 isfile (baseCopyPath , isISCSI )
540- physicalSize = vhdutil . getSizePhys (baseCopyPath )
562+ physicalSize = vhdutil_getSizePhys (baseCopyPath )
541563 if prevBackupUuid :
542564 # Check existence of prevBackupFile
543565 prevBackupVHD = getBackupVHD (prevBackupUuid )
@@ -549,7 +571,7 @@ def backupSnapshot(session, args):
549571 backupFile = os .path .join (backupsDir , backupVHD )
550572 logging .debug ("Back up " + baseCopyUuid + " to Secondary Storage as " + backupUuid )
551573 copyfile (baseCopyPath , backupFile , isISCSI )
552- vhdutil . setHidden (backupFile , False )
574+ vhdutil_setHidden (backupFile , False )
553575
554576 # Because the primary storage is always scanned, the parent of this base copy is always the first base copy.
555577 # We don't want that, we want a chain of VHDs each of which is a delta from the previous.
0 commit comments