66# to you under the Apache License, Version 2.0 (the
77# "License"); you may not use this file except in compliance
88# with the License. You may obtain a copy of the License at
9- #
9+ #
1010# http://www.apache.org/licenses/LICENSE-2.0
11- #
11+ #
1212# Unless required by applicable law or agreed to in writing,
1313# software distributed under the License is distributed on an
1414# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1818
1919# Version @VERSION@
2020#
21- # A plugin for executing script needed by vmops cloud
21+ # A plugin for executing script needed by vmops cloud
2222
2323import os , sys , time
2424import XenAPIPlugin
@@ -91,7 +91,7 @@ def create_secondary_storage_folder(session, args):
9191 umount (local_mount_path )
9292 # Remove the local folder
9393 os .system ("rmdir " + local_mount_path )
94-
94+
9595 return "1"
9696
9797@echo
@@ -127,15 +127,15 @@ def delete_secondary_storage_folder(session, args):
127127 umount (local_mount_path )
128128 # Remove the local folder
129129 os .system ("rmdir " + local_mount_path )
130-
130+
131131 return "1"
132-
132+
133133@echo
134134def post_create_private_template (session , args ):
135135 local_mount_path = None
136136 try :
137137 try :
138- # get local template folder
138+ # get local template folder
139139 templatePath = args ["templatePath" ]
140140 local_mount_path = os .path .join (CLOUD_DIR , util .gen_uuid ())
141141 nfsVersion = args ["nfsVersion" ]
@@ -148,7 +148,7 @@ def post_create_private_template(session, args):
148148 file_size = args ["size" ]
149149 virtual_size = args ["virtualSize" ]
150150 template_id = args ["templateId" ]
151-
151+
152152 # Create the template.properties file
153153 template_properties_install_path = local_mount_path + "/template.properties"
154154 f = open (template_properties_install_path , "w" )
@@ -167,7 +167,7 @@ def post_create_private_template(session, args):
167167 f .write ("size=" + str (file_size ) + "\n " )
168168 f .close ()
169169 logging .debug ("Created template.properties file" )
170-
170+
171171 # Set permissions
172172 permissions = stat .S_IREAD | stat .S_IWRITE | stat .S_IRGRP | stat .S_IWGRP | stat .S_IROTH | stat .S_IWOTH
173173 os .chmod (template_properties_install_path , permissions )
@@ -184,16 +184,16 @@ def post_create_private_template(session, args):
184184 umount (local_mount_path )
185185 # Remove the local folder
186186 os .system ("rmdir " + local_mount_path )
187- return "1"
188-
187+ return "1"
188+
189189def isfile (path , isISCSI ):
190190 errMsg = ''
191191 exists = True
192192 if isISCSI :
193193 exists = checkVolumeAvailability (path )
194194 else :
195195 exists = os .path .isfile (path )
196-
196+
197197 if not exists :
198198 errMsg = "File " + path + " does not exist."
199199 logging .debug (errMsg )
@@ -241,7 +241,7 @@ def scanParent(path):
241241 try :
242242 lvName = os .path .basename (path )
243243 dirname = os .path .dirname (path )
244- vgName = os .path .basename (dirname )
244+ vgName = os .path .basename (dirname )
245245 vhdInfo = vhdutil .getVHDInfoLVM (lvName , lvhdutil .extractUuid , vgName )
246246 parentUUID = vhdInfo .parentUuid
247247 except :
@@ -273,7 +273,7 @@ def getParentOfSnapshot(snapshotUuid, primarySRPath, isISCSI):
273273 baseCopyUuid = scanParent (snapshotPath )
274274 else :
275275 baseCopyUuid = getParent (snapshotPath , isISCSI )
276-
276+
277277 logging .debug ("Base copy of snapshotUuid: " + snapshotUuid + " is " + baseCopyUuid )
278278 return baseCopyUuid
279279
@@ -282,7 +282,7 @@ def setParent(parent, child):
282282 cmd = [VHDUTIL , "modify" , "-p" , parent , "-n" , child ]
283283 txt = util .pread2 (cmd )
284284 except :
285- errMsg = "Unexpected error while trying to set parent of " + child + " to " + parent
285+ errMsg = "Unexpected error while trying to set parent of " + child + " to " + parent
286286 logging .debug (errMsg )
287287 raise xs_errors .XenError (errMsg )
288288 logging .debug ("Successfully set parent of " + child + " to " + parent )
@@ -315,32 +315,32 @@ def mount(remoteDir, localDir, nfsVersion=None):
315315 options = "soft,tcp,timeo=133,retrans=1"
316316 if nfsVersion :
317317 options += ",vers=" + nfsVersion
318- try :
318+ try :
319319 cmd = ['mount' , '-o' , options , remoteDir , localDir ]
320320 txt = util .pread2 (cmd )
321321 except :
322322 txt = ''
323- errMsg = "Unexpected error while trying to mount " + remoteDir + " to " + localDir
323+ errMsg = "Unexpected error while trying to mount " + remoteDir + " to " + localDir
324324 logging .debug (errMsg )
325325 raise xs_errors .XenError (errMsg )
326326 logging .debug ("Successfully mounted " + remoteDir + " to " + localDir )
327327
328328 return
329329
330330def umount (localDir ):
331- try :
331+ try :
332332 cmd = ['umount' , localDir ]
333333 util .pread2 (cmd )
334334 except CommandException :
335- errMsg = "CommandException raised while trying to umount " + localDir
335+ errMsg = "CommandException raised while trying to umount " + localDir
336336 logging .debug (errMsg )
337337 raise xs_errors .XenError (errMsg )
338338
339339 logging .debug ("Successfully unmounted " + localDir )
340340 return
341341
342342def mountSnapshotsDir (secondaryStorageMountPath , localMountPointPath , path ):
343- # The aim is to mount secondaryStorageMountPath on
343+ # The aim is to mount secondaryStorageMountPath on
344344 # And create <accountId>/<instanceId> dir on it, if it doesn't exist already.
345345 # Assuming that secondaryStorageMountPath exists remotely
346346
@@ -410,7 +410,7 @@ def getIsTrueString(stringValue):
410410 booleanValue = False
411411 if (stringValue and stringValue == 'true' ):
412412 booleanValue = True
413- return booleanValue
413+ return booleanValue
414414
415415def makeUnavailable (uuid , primarySRPath , isISCSI ):
416416 if not isISCSI :
@@ -433,7 +433,7 @@ def manageAvailability(path, value):
433433 logging .debug (errMsg )
434434 if value == "-ay" :
435435 # Raise an error only if we are trying to make it available.
436- # Just warn if we are trying to make it unavailable after the
436+ # Just warn if we are trying to make it unavailable after the
437437 # snapshot operation is done.
438438 raise xs_errors .XenError (errMsg )
439439 return
@@ -450,7 +450,7 @@ def checkVolumeAvailability(path):
450450 errMsg = "Could not determine status of ISCSI path: " + path
451451 logging .debug (errMsg )
452452 raise xs_errors .XenError (errMsg )
453-
453+
454454 success = False
455455 i = 0
456456 while i < 6 :
@@ -482,20 +482,20 @@ def isVolumeAvailable(path):
482482 logging .debug (errMsg )
483483 raise xs_errors .XenError (errMsg )
484484
485- return (status == "1" )
485+ return (status == "1" )
486486
487487def getVhdParent (session , args ):
488488 logging .debug ("getParent with " + str (args ))
489489 primaryStorageSRUuid = args ['primaryStorageSRUuid' ]
490490 snapshotUuid = args ['snapshotUuid' ]
491- isISCSI = getIsTrueString (args ['isISCSI' ])
491+ isISCSI = getIsTrueString (args ['isISCSI' ])
492492
493493 primarySRPath = getPrimarySRPath (primaryStorageSRUuid , isISCSI )
494494 logging .debug ("primarySRPath: " + primarySRPath )
495495
496496 baseCopyUuid = getParentOfSnapshot (snapshotUuid , primarySRPath , isISCSI )
497497
498- return baseCopyUuid
498+ return baseCopyUuid
499499
500500def getSnapshotSize (session , args ):
501501 primaryStorageSRUuid = args ['primaryStorageSRUuid' ]
@@ -545,15 +545,15 @@ def backupSnapshot(session, args):
545545 isfile (prevBackupFile , False )
546546
547547 # copy baseCopyPath to backupsDir with new uuid
548- backupVHD = getBackupVHD (backupUuid )
548+ backupVHD = getBackupVHD (backupUuid )
549549 backupFile = os .path .join (backupsDir , backupVHD )
550550 logging .debug ("Back up " + baseCopyUuid + " to Secondary Storage as " + backupUuid )
551551 copyfile (baseCopyPath , backupFile , isISCSI )
552552 vhdutil .setHidden (backupFile , False )
553553
554554 # Because the primary storage is always scanned, the parent of this base copy is always the first base copy.
555555 # We don't want that, we want a chain of VHDs each of which is a delta from the previous.
556- # So set the parent of the current baseCopyVHD to prevBackupVHD
556+ # So set the parent of the current baseCopyVHD to prevBackupVHD
557557 if prevBackupUuid :
558558 # If there was a previous snapshot
559559 setParent (prevBackupFile , backupFile )
@@ -581,7 +581,7 @@ def deleteSnapshotBackup(session, args):
581581 logging .debug ("backupVHD " + backupVHD + "does not exist. Not trying to delete it" )
582582 return "1"
583583 logging .debug ("backupVHD " + backupVHD + " exists." )
584-
584+
585585 # Just delete the backupVHD
586586 try :
587587 os .remove (backupVHD )
@@ -591,7 +591,7 @@ def deleteSnapshotBackup(session, args):
591591 raise xs_errors .XenError (errMsg )
592592
593593 return "1"
594-
594+
595595@echo
596596def revert_memory_snapshot (session , args ):
597597 logging .debug ("Calling revert_memory_snapshot with " + str (args ))
@@ -620,4 +620,3 @@ def revert_memory_snapshot(session, args):
620620
621621if __name__ == "__main__" :
622622 XenAPIPlugin .dispatch ({"getVhdParent" :getVhdParent , "create_secondary_storage_folder" :create_secondary_storage_folder , "delete_secondary_storage_folder" :delete_secondary_storage_folder , "post_create_private_template" :post_create_private_template , "backupSnapshot" : backupSnapshot , "deleteSnapshotBackup" : deleteSnapshotBackup , "unmountSnapshotsDir" : unmountSnapshotsDir , "revert_memory_snapshot" :revert_memory_snapshot , "getSnapshotSize" :getSnapshotSize })
623-
0 commit comments