Scalr\Modules\Platforms\Cloudstack\CloudstackPlatformModule::CheckServerSnapshotStatus PHP Метод

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

См. также: Scalr\Modules\PlatformModuleInterface::CheckServerSnapshotStatus()
public CheckServerSnapshotStatus ( BundleTask $BundleTask )
$BundleTask BundleTask
    public function CheckServerSnapshotStatus(BundleTask $BundleTask)
    {
        try {
            $DBServer = DBServer::LoadByID($BundleTask->serverId);
            if ($BundleTask->bundleType != SERVER_SNAPSHOT_CREATION_TYPE::CSTACK_WINDOWS) {
                return;
            }
            $meta = $BundleTask->getSnapshotDetails();
            $cs = $DBServer->GetEnvironmentObject()->cloudstack($this->platform);
            if (!$BundleTask->snapshotId) {
                $cloudStackSnapshotId = $meta['cloudStackSnapshotId'];
                $snapshotsList = $cs->snapshot->describe(array('id' => $cloudStackSnapshotId));
                $snapshot = $snapshotsList[0];
                if ($snapshot->state == 'BackedUp') {
                    $BundleTask->Log(sprintf(_("Snapshot created. Registering template.")));
                    try {
                        $vmList = $cs->instance->describe(array('id' => $DBServer->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID)));
                        $vmInfo = $vmList[0];
                        if ($vmInfo->templateid) {
                            $originalTemplate = $cs->template->describe(array('templatefilter' => 'all', 'id' => $vmInfo->templateid))[0];
                        }
                        $request = array('ostypeid' => $vmInfo->guestosid, 'name' => $BundleTask->roleName . "-" . date("YmdHi"), 'displaytext' => $BundleTask->roleName, 'snapshotid' => $cloudStackSnapshotId, 'passwordenabled' => $vmInfo->passwordenabled);
                        if ($originalTemplate) {
                            $request['details'] = $originalTemplate->details->toArray();
                        }
                        $template = $cs->template->create($request);
                        //TODO: Check job and update Image size.
                    } catch (Exception $e) {
                        $BundleTask->SnapshotCreationFailed(sprintf("Unable to register new template: %s", $e->getMessage()));
                        return false;
                    }
                    $BundleTask->Log(sprintf(_("Template successfully registered. (ID: %s)"), $template->id));
                    $BundleTask->SnapshotCreationComplete($template->id);
                } else {
                    $BundleTask->Log(sprintf(_("Snapshot is in progress. Current status: %s"), $snapshot->state));
                }
            }
        } catch (Exception $e) {
            $BundleTask->SnapshotCreationFailed($e->getMessage());
        }
    }