public function xCreateAction()
{
$this->request->defineParams(array('volumeId', 'cloudLocation'));
$aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
$snapshot = $aws->ec2->snapshot->create($this->getParam('volumeId'));
if (isset($snapshot->snapshotId)) {
/* @var $volume \Scalr\Service\Aws\Ec2\DataType\VolumeData */
$volume = $aws->ec2->volume->describe($snapshot->volumeId)->get(0);
if (count($volume->attachmentSet) && !empty($volume->attachmentSet[0]->instanceId)) {
$instanceId = $volume->attachmentSet[0]->instanceId;
try {
$dBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $instanceId);
$dBFarm = $dBServer->GetFarmObject();
} catch (Exception $e) {
}
if (isset($dBServer) && isset($dBFarm)) {
$comment = sprintf(_("Created on farm '%s', server '%s' (Instance ID: %s)"), $dBFarm->Name, $dBServer->serverId, $instanceId);
}
} else {
$comment = '';
}
$this->db->Execute("\n INSERT INTO ebs_snaps_info\n SET snapid = ?,\n comment = ?,\n dtcreated = NOW(),\n region = ?\n ", array($snapshot->snapshotId, $comment, $this->getParam('cloudLocation')));
$this->response->data(array('data' => array('snapshotId' => $snapshot->snapshotId)));
} else {
throw new Exception("Unable to create snapshot. Please try again later.");
}
}