public function xListSnapshotsAction() { $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'snapshotId', 'direction' => 'ASC')), 'showPublicSnapshots', 'cloudLocation', 'volumeId', 'snapshotId')); $aws = $this->getEnvironment()->aws($this->getParam('cloudLocation')); $filter = array(); if ($this->getParam('snapshotId')) { $filter[] = array('name' => Ec2DataType\SnapshotFilterNameType::snapshotId(), 'value' => $this->getParam('snapshotId')); } if ($this->getParam('volumeId')) { $filter[] = array('name' => Ec2DataType\SnapshotFilterNameType::volumeId(), 'value' => $this->getParam('volumeId')); } // Rows $snapList = $aws->ec2->snapshot->describe(null, null, empty($filter) ? null : $filter); $snaps = array(); /* @var $snapshot Ec2DataType\SnapshotData */ foreach ($snapList as $snapshot) { $item = array('snapshotId' => $snapshot->snapshotId, 'volumeId' => $snapshot->volumeId, 'volumeSize' => $snapshot->volumeSize, 'status' => $snapshot->status, 'startTime' => $snapshot->startTime->format('c'), 'progress' => $snapshot->progress, 'volumeSize' => $snapshot->volumeSize); if ($snapshot->ownerId != $this->getEnvironment()->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_ID)) { $item['comment'] = $snapshot->description; $item['owner'] = $snapshot->ownerId; if (!$this->getParam('showPublicSnapshots')) { continue; } } else { if ($snapshot->description) { $item['comment'] = $snapshot->description; } $item['owner'] = 'Me'; } $item['progress'] = (int) preg_replace("/[^0-9]+/", "", $item['progress']); unset($item['description']); $snaps[] = $item; } $response = $this->buildResponseFromData($snaps, array('snapshotId', 'volumeId', 'comment', 'owner')); foreach ($response['data'] as &$row) { $row['startTime'] = Scalr_Util_DateTime::convertTz($row['startTime']); if (empty($row['comment'])) { $row['comment'] = $this->db->GetOne("SELECT comment FROM ebs_snaps_info WHERE snapid=? LIMIT 1", array($row['snapshotId'])); } } $this->response->data($response); }
/** * @param string $cloudLocation * @param string $query * @param int $limit * @param string $nextToken */ public function xGetSnapshotsAction($cloudLocation, $query = null, $limit = null, $nextToken = null) { $aws = $this->getEnvironment()->aws($cloudLocation); $filters = [['name' => SnapshotFilterNameType::status(), 'value' => SnapshotData::STATUS_COMPLETED]]; if ($query) { if (strpos($query, 'snap-') === 0) { $filters[] = ['name' => SnapshotFilterNameType::snapshotId(), 'value' => $query . '*']; } elseif (strpos($query, 'vol-') === 0) { $filters[] = ['name' => SnapshotFilterNameType::volumeId(), 'value' => $query . '*']; } else { $filters[] = ['name' => SnapshotFilterNameType::description(), 'value' => '*' . $query . '*']; } } $response = $aws->ec2->snapshot->describe(null, [$this->getEnvironment()->cloudCredentials(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID]], $filters, null, $query ? null : $nextToken, $query ? null : $limit); $data = array(); $count = 0; /* @var $pv \Scalr\Service\Aws\Ec2\DataType\SnapshotData */ foreach ($response as $pv) { $count++; $data[] = array('snapid' => $pv->snapshotId, 'createdat' => Scalr_Util_DateTime::convertTz($pv->startTime), 'size' => $pv->volumeSize, 'snapshotId' => $pv->snapshotId, 'createdDate' => Scalr_Util_DateTime::convertTz($pv->startTime), 'volumeSize' => $pv->volumeSize, 'volumeId' => $pv->volumeId, 'description' => (string) $pv->description, 'encrypted' => $pv->encrypted); } $this->response->data(['data' => $data, 'nextToken' => $response->getNextToken()]); }
public function xListSnapshotsAction($cloudLocation, $snapshotId = null, $volumeId = null, $showPublicSnapshots = null) { $aws = $this->getEnvironment()->aws($cloudLocation); $filter = []; if (!empty($snapshotId)) { $filter[] = array('name' => Ec2DataType\SnapshotFilterNameType::snapshotId(), 'value' => $snapshotId); } if (!empty($volumeId)) { $filter[] = array('name' => Ec2DataType\SnapshotFilterNameType::volumeId(), 'value' => $volumeId); } $snaps = []; $snapList = $nextToken = null; do { if (isset($snapList)) { $nextToken = $snapList->getNextToken(); } $snapList = $aws->ec2->snapshot->describe(null, null, empty($filter) ? null : $filter, null, $nextToken); /* @var $snapshot Ec2DataType\SnapshotData */ foreach ($snapList as $snapshot) { $item = ['snapshotId' => $snapshot->snapshotId, 'volumeId' => $snapshot->volumeId, 'volumeSize' => (int) $snapshot->volumeSize, 'status' => $snapshot->status, 'startTime' => $snapshot->startTime->format('c'), 'progress' => $snapshot->progress]; if ($snapshot->ownerId != $this->getEnvironment()->keychain(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID]) { $item['comment'] = $snapshot->description; $item['owner'] = $snapshot->ownerId; if (!$showPublicSnapshots) { continue; } } else { if ($snapshot->description) { $item['comment'] = $snapshot->description; } $item['owner'] = 'Me'; } $item['progress'] = (int) preg_replace("/[^0-9]+/", "", $item['progress']); unset($item['description']); $snaps[] = $item; } } while ($snapList->getNextToken() !== null); $response = $this->buildResponseFromData($snaps, ['snapshotId', 'volumeId', 'comment', 'owner']); foreach ($response['data'] as &$row) { $row['startTime'] = Scalr_Util_DateTime::convertTz($row['startTime']); if (empty($row['comment'])) { $row['comment'] = $this->db->GetOne("SELECT comment FROM ebs_snaps_info WHERE snapid=? LIMIT 1", [$row['snapshotId']]); } } $this->response->data($response); }