getEnvironmentObject() public method

public getEnvironmentObject ( ) : Scalr_Environment
return Scalr_Environment Enter description here ...
Exemplo n.º 1
0
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach ($DBRole->getImageId(SERVER_PLATFORMS::OPENSTACK) as $location => $imageId) {
         $osClient = $this->getOsClient($DBRole->getEnvironmentObject(), $location);
         try {
             $osClient->imageDelete($imageId);
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "Cannot destroy a destroyed snapshot")) {
                 return true;
             } else {
                 throw $e;
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach ($DBRole->getImageId(SERVER_PLATFORMS::CLOUDSTACK) as $location => $imageId) {
         $cs = $this->getCloudStackClient($DBRole->getEnvironmentObject(), $location);
         try {
             $cs->deleteTemplate($imageId, $location);
         } catch (Exception $e) {
             throw $e;
         }
     }
     return true;
 }
Exemplo n.º 3
0
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach ($DBRole->getImageId(SERVER_PLATFORMS::RACKSPACE) as $location => $imageId) {
         $rsClient = $this->getRsClient($DBRole->getEnvironmentObject(), $location);
         try {
             $rsClient->deleteImage($imageId);
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "Cannot destroy a destroyed snapshot") || stristr($e->getMessage(), "com.rackspace.cloud.service.servers.ItemNotFoundFault") || stristr($e->getMessage(), "Bad username or password") || stristr($e->getMessage(), "NotFoundException")) {
                 return true;
             } else {
                 throw $e;
             }
         }
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  * @see IPlatformModule::RemoveServerSnapshot()
  */
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach ($DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS) as $location => $imageId) {
         try {
             $euca = $DBRole->getEnvironmentObject()->eucalyptus($location);
             try {
                 $ami = $euca->ec2->image->describe($imageId)->get(0);
             } catch (Exception $e) {
                 if (stristr($e->getMessage(), "Failure Signing Data") || stristr($e->getMessage(), "is no longer available") || stristr($e->getMessage(), "does not exist") || stristr($e->getMessage(), "Not authorized for image")) {
                     return true;
                 } else {
                     throw $e;
                 }
             }
             //$ami variable is expected to be defined here
             $platfrom = $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) {
                     $euca->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 = $euca->s3->bucket->listObjects($bucketName, null, null, null, $prefix);
                 } catch (\Exception $e) {
                     if ($e instanceof ClientException && $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) {
                         $euca->ec2->image->deregister($imageId);
                     }
                 }
             }
             unset($euca);
             unset($ami);
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "is no longer available") || stristr($e->getMessage(), "Not authorized for image")) {
                 continue;
             } else {
                 throw $e;
             }
         }
     }
 }
Exemplo n.º 5
0
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach ($DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS) as $location => $imageId) {
         $eucaClient = $this->getEucaClient($DBRole->getEnvironmentObject(), $location);
         try {
             $eucaClient->deregisterImage($imageId);
             //TODO: Remove image from Walrus
         } catch (Exception $e) {
         }
     }
     return true;
 }
Exemplo n.º 6
0
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach (PlatformFactory::getOpenstackBasedPlatforms() as $platform) {
         foreach ($DBRole->getImageId($platform) as $location => $imageId) {
             try {
                 $osClient = $DBRole->getEnvironmentObject()->openstack($platform, $location);
                 $osClient->servers->images->delete($imageId);
             } catch (Exception $e) {
                 if (stristr($e->getMessage(), "Unavailable service \"compute\" or region") || stristr($e->getMessage(), "Image not found") || stristr($e->getMessage(), "Cannot destroy a destroyed snapshot") || stristr($e->getMessage(), "OpenStack error. Could not find user")) {
                     //DO NOTHING
                 } else {
                     throw $e;
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 7
0
 public function RemoveServerSnapshot(DBRole $DBRole)
 {
     foreach ($DBRole->getImageId(SERVER_PLATFORMS::EC2) as $location => $imageId) {
         try {
             $EC2Client = Scalr_Service_Cloud_Aws::newEc2($location, $DBRole->getEnvironmentObject()->getPlatformConfigValue(self::PRIVATE_KEY), $DBRole->getEnvironmentObject()->getPlatformConfigValue(self::CERTIFICATE));
             try {
                 $DescribeImagesType = new DescribeImagesType();
                 $DescribeImagesType->imagesSet = new stdClass();
                 $DescribeImagesType->imagesSet->item[] = array("imageId" => $imageId);
                 $ami_info = $EC2Client->DescribeImages($DescribeImagesType);
             } catch (Exception $e) {
                 if (stristr($e->getMessage(), "Failure Signing Data") || stristr($e->getMessage(), "is no longer available") || stristr($e->getMessage(), "does not exist") || stristr($e->getMessage(), "Not authorized for image")) {
                     return true;
                 } else {
                     throw $e;
                 }
             }
             $platfrom = (string) $ami_info->imagesSet->item->platform;
             $rootDeviceType = (string) $ami_info->imagesSet->item->rootDeviceType;
             if ($rootDeviceType == 'ebs') {
                 $EC2Client->DeregisterImage($imageId);
                 $snapshotId = (string) $ami_info->imagesSet->item->blockDeviceMapping->item->ebs->snapshotId;
                 if ($snapshotId) {
                     $EC2Client->DeleteSnapshot($snapshotId);
                 }
             } else {
                 $image_path = (string) $ami_info->imagesSet->item->imageLocation;
                 $chunks = explode("/", $image_path);
                 $bucket_name = $chunks[0];
                 if (count($chunks) == 3) {
                     $prefix = $chunks[1];
                 } else {
                     $prefix = str_replace(".manifest.xml", "", $chunks[1]);
                 }
                 try {
                     $bucket_not_exists = false;
                     $S3Client = new AmazonS3($DBRole->getEnvironmentObject()->getPlatformConfigValue(self::ACCESS_KEY), $DBRole->getEnvironmentObject()->getPlatformConfigValue(self::SECRET_KEY));
                     $objects = $S3Client->ListBucket($bucket_name, $prefix);
                 } catch (Exception $e) {
                     if (stristr($e->getMessage(), "The specified bucket does not exist")) {
                         $bucket_not_exists = true;
                     }
                 }
                 if ($ami_info) {
                     if (!$bucket_not_exists) {
                         foreach ($objects as $object) {
                             $S3Client->DeleteObject($object->Key, $bucket_name);
                         }
                         $bucket_not_exists = true;
                     }
                     if ($bucket_not_exists) {
                         $EC2Client->DeregisterImage($imageId);
                     }
                 }
             }
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "is no longer available") || stristr($e->getMessage(), "Not authorized for image")) {
                 continue;
             } else {
                 throw $e;
             }
         }
     }
 }