getEnvironment() публичный Метод

Return NULL, if image is owned by admin
public getEnvironment ( ) : null | Scalr_Environmen\Scalr_Environment
Результат null | Scalr_Environmen\Scalr_Environment
Пример #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(Image $image)
 {
     if (!$image->getEnvironment()) {
         return true;
     }
     $gce = $this->getClient($image->getEnvironment());
     try {
         $projectId = $image->getEnvironment()->keychain(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
         $imageId = str_replace("{$projectId}/images/", "", $image->id);
         $gce->images->delete($projectId, $imageId);
     } catch (Exception $e) {
         if (stristr($e->getMessage(), "was not found")) {
             return true;
         } else {
             throw $e;
         }
     }
     return true;
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(Image $image)
 {
     if (!$image->getEnvironment()) {
         return true;
     }
     $cs = $image->getEnvironment()->cloudstack($this->platform);
     try {
         $cs->template->delete($image->id, $image->cloudLocation);
     } catch (\Exception $e) {
         throw $e;
     }
     return true;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(Image $image)
 {
     try {
         if (!$image->getEnvironment()) {
             return true;
         }
         $aws = $image->getEnvironment()->aws($image->cloudLocation);
         try {
             $ami = $aws->ec2->image->describe($image->id)->get(0);
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "is no longer available") || stristr($e->getMessage(), "does not exist")) {
                 return true;
             } else {
                 throw $e;
             }
         }
         //$ami variable is expected to be defined here
         $platform = $ami->platform;
         $rootDeviceType = $ami->rootDeviceType;
         if ($rootDeviceType == 'ebs') {
             $ami->deregister();
             //blockDeviceMapping is not mandatory option in the response as well as ebs data set.
             $snapshotId = $ami->blockDeviceMapping && count($ami->blockDeviceMapping) > 0 && $ami->blockDeviceMapping->get(0)->ebs ? $ami->blockDeviceMapping->get(0)->ebs->snapshotId : null;
             if ($snapshotId) {
                 $aws->ec2->snapshot->delete($snapshotId);
             }
         } else {
             $image_path = $ami->imageLocation;
             $chunks = explode("/", $image_path);
             $bucketName = array_shift($chunks);
             $manifestObjectName = implode('/', $chunks);
             $prefix = str_replace(".manifest.xml", "", $manifestObjectName);
             try {
                 $bucket_not_exists = false;
                 $objects = $aws->s3->bucket->listObjects($bucketName, null, null, null, $prefix);
             } catch (\Exception $e) {
                 if ($e instanceof AwsClientException && $e->getErrorData() instanceof ErrorData && $e->getErrorData()->getCode() == 404) {
                     $bucket_not_exists = true;
                 }
             }
             if ($ami) {
                 if (!$bucket_not_exists) {
                     /* @var $object ObjectData */
                     foreach ($objects as $object) {
                         $object->delete();
                     }
                     $bucket_not_exists = true;
                 }
                 if ($bucket_not_exists) {
                     $aws->ec2->image->deregister($image->id);
                 }
             }
         }
         unset($aws);
         unset($ami);
     } catch (Exception $e) {
         if (stristr($e->getMessage(), "is no longer available")) {
         } else {
             throw $e;
         }
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(Image $image)
 {
     if (!$image->getEnvironment()) {
         return true;
     }
     try {
         $cloudLocation = $image->cloudLocation;
         if ($image->cloudLocation == '') {
             $locations = $this->getLocations($image->getEnvironment());
             $cloudLocation = array_keys($locations)[0];
         }
         $osClient = $image->getEnvironment()->openstack($image->platform, $cloudLocation);
         $osClient->servers->images->delete($image->id);
     } catch (\Exception $e) {
         if (stristr($e->getMessage(), "Image not found") || stristr($e->getMessage(), "Cannot destroy a destroyed snapshot")) {
             //DO NOTHING
         } else {
             throw $e;
         }
     }
     return true;
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(Image $image)
 {
     if (!$image->getEnvironment()) {
         return true;
     }
     $gce = $this->getClient($image->getEnvironment());
     try {
         $projectId = $image->getEnvironment()->getPlatformConfigValue(self::PROJECT_ID);
         $imageId = str_replace("{$projectId}/images/", "", $image->id);
         $gce->images->delete($projectId, $imageId);
     } catch (\Exception $e) {
         if (stristr($e->getMessage(), "was not found")) {
             return true;
         } else {
             throw $e;
         }
     }
     return true;
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(Image $image)
 {
     if (!$image->getEnvironment()) {
         return true;
     }
     $rsClient = $this->getRsClient($image->getEnvironment(), $image->cloudLocation);
     try {
         $rsClient->deleteImage($image->id);
     } catch (Exception $e) {
         if (stristr($e->getMessage(), "Cannot destroy a destroyed snapshot") || stristr($e->getMessage(), "com.rackspace.cloud.service.servers.ItemNotFoundFault") || stristr($e->getMessage(), "NotFoundException")) {
             return true;
         } else {
             throw $e;
         }
     }
     return true;
 }