public function CreateServerSnapshot(BundleTask $BundleTask)
{
$DBServer = DBServer::LoadByID($BundleTask->serverId);
if ($BundleTask->osFamily == 'windows' || $DBServer->osType == 'windows') {
$BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::CSTACK_WINDOWS;
$BundleTask->Log(sprintf(_("Selected platform snapshot type: %s"), $BundleTask->bundleType));
$createImage = true;
} else {
$BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS;
$BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::CSTACK_DEF;
$msg = new Scalr_Messaging_Msg_Rebundle($BundleTask->id, $BundleTask->roleName, array());
if (!$DBServer->SendMessage($msg)) {
$BundleTask->SnapshotCreationFailed("Cannot send rebundle message to server. Please check event log for more details.");
return;
} else {
$BundleTask->Log(sprintf(_("Snapshot creating initialized (MessageID: %s). Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status));
}
}
if ($createImage) {
$BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS;
try {
$cs = $DBServer->GetEnvironmentObject()->cloudstack($this->platform);
$volList = $cs->volume->describe(array('virtualmachineid' => $DBServer->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID), 'type' => 'ROOT'));
$volInfo = $volList[0];
/* @var $volInfo VolumeResponseData */
} catch (Exception $e) {
$BundleTask->SnapshotCreationFailed(sprintf("Getting ROOT volume details for new snapshot failed: %s", $e->getMessage()));
return false;
}
$BundleTask->Log(sprintf(_("Creating snapshot of ROOT volume (ID: %s). Bundle task status changed to: %s"), $volInfo->id, $BundleTask->status));
try {
$createSnapshotData = new CreateSnapshotData($volInfo->id);
$createSnapshotData->domainid = $volInfo->domainid;
$createSnapshotData->account = $volInfo->account;
$snapInfo = $cs->snapshot->create($createSnapshotData);
} catch (Exception $e) {
$BundleTask->SnapshotCreationFailed(sprintf("Unable to initialize snapshot creation process: %s", $e->getMessage()));
return false;
}
$BundleTask->Log(sprintf(_("Snapshot initialized (ID: %s)"), $snapInfo->id));
$BundleTask->setMetaData(array('cloudStackSnapshotId' => $snapInfo->id, 'cloudStackSnapshotJobId' => $snapInfo->jobid));
}
$BundleTask->setDate('started');
$BundleTask->Save();
}