Skip to content

Commit f2d5e10

Browse files
author
Daan Hoogland
committed
deal with xcpng refactors
1 parent 2e63c60 commit f2d5e10

3 files changed

Lines changed: 65 additions & 18 deletions

File tree

‎scripts/vm/hypervisor/xenserver/xcpserver83/NFSSR.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
from lock import Lock
2929
import cleanup
3030

31+
try:
32+
# sm >= 3.2.12-18 (e.g. XCP-ng 8.3), where LOCK_TYPE_SR moved to lock.py
33+
from lock import LOCK_TYPE_SR
34+
except ImportError:
35+
# older sm (XenServer and XCP-ng releases prior to the 8.3 SM refactor)
36+
LOCK_TYPE_SR = vhdutil.LOCK_TYPE_SR
37+
3138
CAPABILITIES = ["SR_PROBE","SR_UPDATE", "SR_CACHING", \
3239
"VDI_CREATE","VDI_DELETE","VDI_ATTACH","VDI_DETACH", \
3340
"VDI_UPDATE", "VDI_CLONE","VDI_SNAPSHOT","VDI_RESIZE", \
@@ -64,7 +71,7 @@ def handles(type):
6471

6572
def load(self, sr_uuid):
6673
self.ops_exclusive = FileSR.OPS_EXCLUSIVE
67-
self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid)
74+
self.lock = Lock(LOCK_TYPE_SR, self.uuid)
6875
self.sr_vditype = SR.DEFAULT_TAP
6976
if 'server' not in self.dconf:
7077
raise xs_errors.XenError('ConfigServerMissing')

‎scripts/vm/hypervisor/xenserver/xenserver84/cloud-plugin-storage‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ if os.path.exists("/usr/lib/xcp/sm"):
2929

3030
import SR, VDI, SRCommand, util, lvutil
3131
from util import CommandException
32-
import vhdutil
3332
import shutil
34-
import lvhdutil
3533
import errno
3634
import subprocess
3735
import xs_errors
@@ -41,6 +39,26 @@ import random
4139
import cloudstack_pluginlib as lib
4240
import 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+
except ImportError:
53+
# older sm (XenServer and XCP-ng releases prior to the 8.3 SM refactor)
54+
import vhdutil
55+
import lvhdutil
56+
VG_PREFIX = lvhdutil.VG_PREFIX
57+
VG_LOCATION = lvhdutil.VG_LOCATION
58+
lvhdutil_extractUuid = lvhdutil.extractUuid
59+
vhdutil_getParent = vhdutil.getParent
60+
vhdutil_getVHDInfoLVM = vhdutil.getVHDInfoLVM
61+
4462
lib.setup_logging("/var/log/cloud/cloud.log")
4563

4664
VHDUTIL = "vhd-util"
@@ -58,8 +76,8 @@ def echo(fn):
5876

5977
def getPrimarySRPath(primaryStorageSRUuid, isISCSI):
6078
if isISCSI:
61-
primarySRDir = lvhdutil.VG_PREFIX + primaryStorageSRUuid
62-
return os.path.join(lvhdutil.VG_LOCATION, primarySRDir)
79+
primarySRDir = VG_PREFIX + primaryStorageSRUuid
80+
return os.path.join(VG_LOCATION, primarySRDir)
6381
else:
6482
return os.path.join(SR.MOUNT_BASE, primaryStorageSRUuid)
6583

@@ -158,7 +176,7 @@ def scanParent(path):
158176
lvName = os.path.basename(path)
159177
dirname = os.path.dirname(path)
160178
vgName = os.path.basename(dirname)
161-
vhdInfo = vhdutil.getVHDInfoLVM(lvName, lvhdutil.extractUuid, vgName)
179+
vhdInfo = vhdutil_getVHDInfoLVM(lvName, lvhdutil_extractUuid, vgName)
162180
parentUUID = vhdInfo.parentUuid
163181
except:
164182
errMsg = "Could not get vhd parent of " + path
@@ -184,9 +202,9 @@ def getParent(path, isISCSI):
184202
parentUUID = ''
185203
try :
186204
if isISCSI:
187-
parentUUID = vhdutil.getParent(path, lvhdutil.extractUuid)
205+
parentUUID = vhdutil_getParent(path, lvhdutil_extractUuid)
188206
else:
189-
parentUUID = vhdutil.getParent(path, cleanup.FileVDI.extractUuid)
207+
parentUUID = vhdutil_getParent(path, cleanup.FileVDI.extractUuid)
190208
except:
191209
errMsg = "Could not get vhd parent of " + path
192210
logging.debug(errMsg)

‎scripts/vm/hypervisor/xenserver/xenserver84/vmopsSnapshot‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ if os.path.exists("/usr/lib/xcp/sm"):
2929

3030
import SR, VDI, SRCommand, util, lvutil
3131
from util import CommandException
32-
import vhdutil
3332
import shutil
34-
import lvhdutil
3533
import errno
3634
import subprocess
3735
import xs_errors
@@ -41,6 +39,30 @@ import random
4139
import cloudstack_pluginlib as lib
4240
import 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+
4466
lib.setup_logging("/var/log/cloud/cloud.log")
4567

4668
VHDUTIL = "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

393415
def 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

513535
def 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

Comments
 (0)