Пример #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::CheckServerSnapshotStatus()
  */
 public function CheckServerSnapshotStatus(BundleTask $BundleTask)
 {
     if ($BundleTask->status != \SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS) {
         return;
     }
     if ($BundleTask->osFamily != 'windows') {
         return;
     }
     $meta = $BundleTask->getSnapshotDetails();
     $env = \Scalr_Environment::init()->loadById($BundleTask->envId);
     $gce = $this->getClient($env);
     $projectId = $env->keychain(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
     if ($meta['gceSnapshotOpPhase3Id']) {
         try {
             $op3 = $gce->globalOperations->get($projectId, $meta['gceSnapshotOpPhase3Id']);
             if ($op3->status == 'DONE') {
                 $BundleTask->SnapshotCreationComplete($BundleTask->snapshotId, $meta);
             } else {
                 $BundleTask->Log("CreateImage operation status: {$op3->status}");
             }
         } catch (Exception $e) {
             $BundleTask->Log("CheckServerSnapshotStatus(2): {$e->getMessage()}");
             return;
         }
     } else {
         //Check operations status
         try {
             $op1 = $gce->zoneOperations->get($projectId, $meta['gceSnapshotZone'], $meta['gceSnapshotOpPhase1Id']);
             $op2 = $gce->zoneOperations->get($projectId, $meta['gceSnapshotZone'], $meta['gceSnapshotOpPhase2Id']);
         } catch (Exception $e) {
             $BundleTask->Log("CheckServerSnapshotStatus(1): {$e->getMessage()}");
             return;
         }
         if ($op1->status == 'DONE' && $op2->status == 'DONE') {
             try {
                 // identifier of google cloud resource must start from [a-z]
                 $imageName = (preg_match('/^[^a-z]/', $BundleTask->roleName) ? 'i' : '') . $BundleTask->roleName . '-' . date('YmdHi');
                 $postBody = new \Google_Service_Compute_Image();
                 $postBody->setName($imageName);
                 $postBody->setSourceDisk($this->getObjectUrl($meta['gceSnapshotDeviceName'], 'disks', $projectId, $meta['gceSnapshotZone']));
                 $op3 = $gce->images->insert($projectId, $postBody);
                 $BundleTask->setMetaData(array('gceSnapshotOpPhase3Id' => $op3->name, 'gceSnapshotTargetLink' => $op3->targetLink));
                 $BundleTask->snapshotId = "{$projectId}/global/images/{$this->getObjectName($op3->targetLink)}";
                 $BundleTask->Log(sprintf(_("Snapshot initialized (ID: %s). Operation: {$op3->name}"), $BundleTask->snapshotId));
                 $BundleTask->Save();
             } catch (Exception $e) {
                 $BundleTask->Log("CheckServerSnapshotStatus(3): {$e->getMessage()}");
             }
         } else {
             $BundleTask->Log("CheckServerSnapshotStatus(0): {$op1->status}:{$op2->status}");
         }
     }
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::CheckServerSnapshotStatus()
  */
 public function CheckServerSnapshotStatus(BundleTask $BundleTask)
 {
     if ($BundleTask->status != \SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS) {
         return;
     }
     if ($BundleTask->osFamily != 'windows') {
         return;
     }
     $meta = $BundleTask->getSnapshotDetails();
     $env = \Scalr_Environment::init()->loadById($BundleTask->envId);
     $gce = $this->getClient($env);
     if ($meta['gceSnapshotOpPhase3Id']) {
         try {
             $op3 = $gce->zoneOperations->get($env->getPlatformConfigValue(self::PROJECT_ID), $meta['gceSnapshotZone'], $meta['gceSnapshotOpPhase3Id']);
             if ($op3->status == 'DONE') {
                 $BundleTask->SnapshotCreationComplete($BundleTask->snapshotId, $meta);
             } else {
                 $BundleTask->Log("CreateImage operation status: {$op3->status}");
             }
         } catch (\Exception $e) {
             $BundleTask->Log("CheckServerSnapshotStatus(2): {$e->getMessage()}");
             return;
         }
     } else {
         //Check operations status
         try {
             $op1 = $gce->zoneOperations->get($env->getPlatformConfigValue(self::PROJECT_ID), $meta['gceSnapshotZone'], $meta['gceSnapshotOpPhase1Id']);
             $op2 = $gce->zoneOperations->get($env->getPlatformConfigValue(self::PROJECT_ID), $meta['gceSnapshotZone'], $meta['gceSnapshotOpPhase2Id']);
         } catch (\Exception $e) {
             $BundleTask->Log("CheckServerSnapshotStatus(1): {$e->getMessage()}");
             return;
         }
         if ($op1->status == 'DONE' && $op2->status == 'DONE') {
             $postBody = new \Google_Service_Compute_Image();
             $postBody->setName($BundleTask->roleName . "-" . date("YmdHi"));
             $postBody->setSourceDisk($this->getObjectUrl("root-{$BundleTask->serverId}", 'disks', $env->getPlatformConfigValue(self::PROJECT_ID), $meta['gceSnapshotZone']));
             $op3 = $gce->images->insert($env->getPlatformConfigValue(self::PROJECT_ID), $postBody);
             $BundleTask->setMetaData(array('gceSnapshotOpPhase3Id' => $op3->name, 'gceSnapshotTargetLink' => $op3->targetLink));
             $BundleTask->snapshotId = $env->getPlatformConfigValue(self::PROJECT_ID) . "/global/images/" . $this->getObjectName($op3->targetLink);
             $BundleTask->Log(sprintf(_("Snapshot initialized (ID: %s). Operation: {$op3->name}"), $BundleTask->snapshotId));
             $BundleTask->Save();
         } else {
             $BundleTask->Log("CheckServerSnapshotStatus(0): {$op1->status}:{$op2->status}");
         }
     }
 }