mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 10363 : cleanup vhd in secondary storage if creating private template fails
status 10363 : resolved fixed Conflicts: core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
This commit is contained in:
parent
96506565e6
commit
9be635367e
@ -2256,22 +2256,25 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
String createTemplateFromSnapshot(Connection conn, String templatePath, String snapshotPath, int wait) {
|
String createTemplateFromSnapshot(Connection conn, String templatePath, String snapshotPath, int wait) {
|
||||||
|
String tmpltLocalDir = UUID.randomUUID().toString();
|
||||||
String results = callHostPluginAsync(conn, "vmopspremium", "create_privatetemplate_from_snapshot",
|
String results = callHostPluginAsync(conn, "vmopspremium", "create_privatetemplate_from_snapshot",
|
||||||
wait, "templatePath", templatePath, "snapshotPath", snapshotPath);
|
wait, "templatePath", templatePath, "snapshotPath", snapshotPath, "tmpltLocalDir", tmpltLocalDir);
|
||||||
|
String errMsg = null;
|
||||||
if (results == null || results.isEmpty()) {
|
if (results == null || results.isEmpty()) {
|
||||||
String msg = "create_privatetemplate_from_snapshot return null";
|
errMsg = "create_privatetemplate_from_snapshot return null";
|
||||||
s_logger.warn(msg);
|
|
||||||
throw new CloudRuntimeException(msg);
|
|
||||||
}
|
|
||||||
String[] tmp = results.split("#");
|
|
||||||
String status = tmp[0];
|
|
||||||
if (status.equals("0")) {
|
|
||||||
return results;
|
|
||||||
} else {
|
} else {
|
||||||
s_logger.warn(results);
|
String[] tmp = results.split("#");
|
||||||
throw new CloudRuntimeException(results);
|
String status = tmp[0];
|
||||||
|
if (status.equals("0")) {
|
||||||
|
return results;
|
||||||
|
} else {
|
||||||
|
errMsg = "create_privatetemplate_from_snapshot failed due to " + tmp[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
String source = "cloud_mount/" + tmpltLocalDir;
|
||||||
|
killCopyProcess(conn, source);
|
||||||
|
s_logger.warn(errMsg);
|
||||||
|
throw new CloudRuntimeException(errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean killCopyProcess(Connection conn, String nameLabel) {
|
boolean killCopyProcess(Connection conn, String nameLabel) {
|
||||||
@ -3143,7 +3146,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
} finally {
|
} finally {
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
try {
|
try {
|
||||||
task.cancel(conn);
|
|
||||||
task.destroy(conn);
|
task.destroy(conn);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
s_logger.warn("unable to destroy task(" + task.toString() + ") on host(" + _host.uuid + ") due to ", e1);
|
s_logger.warn("unable to destroy task(" + task.toString() + ") on host(" + _host.uuid + ") due to ", e1);
|
||||||
@ -5844,11 +5846,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
String details = null;
|
String details = null;
|
||||||
SR tmpltSR = null;
|
SR tmpltSR = null;
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
String secondaryStorageMountPath = null;
|
||||||
|
String installPath = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
URI uri = new URI(secondaryStoragePoolURL);
|
URI uri = new URI(secondaryStoragePoolURL);
|
||||||
String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
|
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
|
||||||
String installPath = "template/tmpl/" + accountId + "/" + templateId;
|
installPath = "template/tmpl/" + accountId + "/" + templateId;
|
||||||
if( !createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
|
if( !createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
|
||||||
details = " Filed to create folder " + installPath + " in secondary storage";
|
details = " Filed to create folder " + installPath + " in secondary storage";
|
||||||
s_logger.warn(details);
|
s_logger.warn(details);
|
||||||
@ -5879,16 +5882,18 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
|
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
|
||||||
}
|
}
|
||||||
installPath = installPath + "/" + tmpltFilename;
|
installPath = installPath + "/" + tmpltFilename;
|
||||||
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUUID, ImageFormat.VHD);
|
|
||||||
} catch (XenAPIException e) {
|
|
||||||
details = "Creating template from volume " + volumeUUID + " failed due to " + e.getMessage();
|
|
||||||
s_logger.error(details, e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
details = "Creating template from volume " + volumeUUID + " failed due to " + e.getMessage();
|
|
||||||
s_logger.error(details, e);
|
|
||||||
} finally {
|
|
||||||
// Remove the secondary storage SR
|
|
||||||
removeSR(conn, tmpltSR);
|
removeSR(conn, tmpltSR);
|
||||||
|
tmpltSR = null;
|
||||||
|
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUUID, ImageFormat.VHD);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (tmpltSR != null) {
|
||||||
|
removeSR(conn, tmpltSR);
|
||||||
|
}
|
||||||
|
if ( secondaryStorageMountPath != null) {
|
||||||
|
deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
|
||||||
|
}
|
||||||
|
details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString();
|
||||||
|
s_logger.error(details, e);
|
||||||
}
|
}
|
||||||
return new CreatePrivateTemplateAnswer(cmd, result, details);
|
return new CreatePrivateTemplateAnswer(cmd, result, details);
|
||||||
}
|
}
|
||||||
@ -5934,10 +5939,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
// By default, assume failure
|
// By default, assume failure
|
||||||
String details = null;
|
String details = null;
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
String secondaryStorageMountPath = null;
|
||||||
|
String installPath = null;
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(secondaryStorageUrl);
|
URI uri = new URI(secondaryStorageUrl);
|
||||||
String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
|
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
|
||||||
String installPath = "template/tmpl/" + accountId + "/" + newTemplateId;
|
installPath = "template/tmpl/" + accountId + "/" + newTemplateId;
|
||||||
if( !createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
|
if( !createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
|
||||||
details = " Filed to create folder " + installPath + " in secondary storage";
|
details = " Filed to create folder " + installPath + " in secondary storage";
|
||||||
s_logger.warn(details);
|
s_logger.warn(details);
|
||||||
@ -5965,6 +5972,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
installPath = installPath + "/" + tmpltFilename;
|
installPath = installPath + "/" + tmpltFilename;
|
||||||
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUuid, ImageFormat.VHD);
|
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUuid, ImageFormat.VHD);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (secondaryStorageMountPath != null) {
|
||||||
|
deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
|
||||||
|
}
|
||||||
details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.toString();
|
details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.toString();
|
||||||
s_logger.error(details, e);
|
s_logger.error(details, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#set -x
|
#set -x
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "Usage: %s [vhd file in secondary storage] [template directory in secondary storage] \n" $(basename $0)
|
printf "Usage: %s [vhd file in secondary storage] [template directory in secondary storage] [template local dir] \n" $(basename $0)
|
||||||
}
|
}
|
||||||
options='tcp,soft,timeo=133,retrans=1'
|
options='tcp,soft,timeo=133,retrans=1'
|
||||||
cleanup()
|
cleanup()
|
||||||
@ -40,6 +40,15 @@ else
|
|||||||
templateurl=$2
|
templateurl=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z $3 ]; then
|
||||||
|
usage
|
||||||
|
echo "3#no template local dir"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
tmpltLocalDir=$3
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
snapshotdir=/var/run/cloud_mount/$(uuidgen -r)
|
snapshotdir=/var/run/cloud_mount/$(uuidgen -r)
|
||||||
mkdir -p $snapshotdir
|
mkdir -p $snapshotdir
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@ -54,7 +63,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
templatedir=/var/run/cloud_mount/$(uuidgen -r)
|
templatedir=/var/run/cloud_mount/$tmpltLocalDir
|
||||||
mkdir -p $templatedir
|
mkdir -p $templatedir
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
templatedir=""
|
templatedir=""
|
||||||
|
|||||||
@ -33,8 +33,9 @@ def forceShutdownVM(session, args):
|
|||||||
def create_privatetemplate_from_snapshot(session, args):
|
def create_privatetemplate_from_snapshot(session, args):
|
||||||
templatePath = args['templatePath']
|
templatePath = args['templatePath']
|
||||||
snapshotPath = args['snapshotPath']
|
snapshotPath = args['snapshotPath']
|
||||||
|
tmpltLocalDir = args['tmpltLocalDir']
|
||||||
try:
|
try:
|
||||||
cmd = ["bash", "/opt/xensource/bin/create_privatetemplate_from_snapshot.sh",snapshotPath, templatePath]
|
cmd = ["bash", "/opt/xensource/bin/create_privatetemplate_from_snapshot.sh",snapshotPath, templatePath, tmpltLocalDir]
|
||||||
txt = util.pread2(cmd)
|
txt = util.pread2(cmd)
|
||||||
except:
|
except:
|
||||||
txt = '10#failed'
|
txt = '10#failed'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user