+
+ # Check if the image file with the same name already exist on the machine.
+ # Back it up. Copy the required working image to the destination.
+ cmd = "/bin/ls -l %s" % req_image
I would just use "ls" instead of "/bin/ls" - I expect every system to
have ls on it, but I suppose it is possible that the executable is
installed in a non-standard location.
+ rc, out = utils.run_remote(t_sysname, cmd)
+ if rc == 0:
+ backup_image = req_image + "." + str(random.randint(1, 100))
+ cmd = 'mv %s %s' % (req_image, backup_image)
+ rc, out = utils.run_remote(t_sysname, cmd)
What renaming the existing file fails?
+ # Make sure we do not remove the images on the local machine
+ if remote_migrate == 1:
+ # Cleanup the images that is copied on the remote machine
+ cmd = "rm -rf %s" % req_image
+ rc, out = utils.run_remote(t_sysname, cmd)
+
+ # Copy the backed up image if any on the remote machine
+ if backup_image != None:
+ cmd = 'mv %s %s' % (backup_image, req_image)
+ rc, out = utils.run_remote(t_sysname, cmd)
I would print a message to the log if either cleanup steps fail. That
way, the user is aware that their environment wasn't cleaned up properly.
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin(a)linux.vnet.ibm.com