public function xCheckAction($imageId, $platform, $cloudLocation = '')
{
$this->request->restrictAccess(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE);
if ($platform == SERVER_PLATFORMS::GCE || $platform == SERVER_PLATFORMS::AZURE) {
$cloudLocation = '';
}
if ($accountId = $this->user->getAccountId()) {
if ($envId = $this->getEnvironmentId(true)) {
if (Image::findOne([['id' => $imageId], ['envId' => $envId], ['platform' => $platform], ['cloudLocation' => $cloudLocation]])) {
throw new Scalr_Exception_Core('This Image has already been registered in the Environment Scope.');
}
}
if (Image::findOne([['id' => $imageId], ['accountId' => $this->user->getAccountId()], ['envId' => null], ['platform' => $platform], ['cloudLocation' => $cloudLocation]])) {
throw new Scalr_Exception_Core('This Image has already been registered in the Account Scope.');
}
}
if (Image::findOne([['id' => $imageId], ['accountId' => null], ['platform' => $platform], ['cloudLocation' => $cloudLocation]])) {
$this->response->failure('This Image has already been registered in the Scalr Scope.');
return;
}
$image = new Image();
$image->envId = $this->getEnvironmentId();
$image->id = $imageId;
$image->platform = $platform;
$image->cloudLocation = $cloudLocation;
if (($data = $image->checkImage()) !== false) {
$data['name'] = $image->name ? $image->name : $image->id;
$data['size'] = $image->size;
$data['architecture'] = $image->architecture ? $image->architecture : 'x86_64';
if ($image->platform == SERVER_PLATFORMS::EC2) {
$data['ec2Type'] = strstr($image->type, 'ebs') ? 'ebs' : 'instance-store';
$data['ec2Hvm'] = strstr($image->type, 'hvm') !== false;
}
$this->response->data(['data' => $data]);
} else {
$this->response->failure("This Image does not exist, or isn't usable by your account");
}
}