Describes a running instance.
Since: 09.01.2013
Author: Vitaliy Demidov (vitaliy@scalr.com)
Inheritance: extends Scalr\Service\Aws\Ec2\AbstractEc2DataType
Example #1
0
 /**
  * {@inheritdoc}
  * @see AbstractServerImport::applyTags
  */
 protected function applyTags()
 {
     if (empty($this->instance)) {
         throw new ServerImportException("Instance property is empty. Cannot add tags to server");
     }
     $dbServer = DBServer::LoadByID($this->server->serverId);
     try {
         // Invar: move applyGlobalVarsToValue to Entity\Server
         $tags = [['key' => Scalr_Governance::SCALR_META_TAG_NAME, 'value' => $dbServer->applyGlobalVarsToValue(Scalr_Governance::SCALR_META_TAG_VALUE)]];
         foreach ($this->tags as $key => $value) {
             $tags[] = ['key' => $key, 'value' => $dbServer->applyGlobalVarsToValue($value)];
         }
         $this->instance->createTags($tags);
     } catch (Exception $e) {
         throw new ServerImportException(sprintf('Scalr was unable to add tags to server %s: %s', $this->server->serverId, $e->getMessage()), $e->getCode(), $e);
     }
 }
Example #2
0
 /**
  * Loads InstanceList from simple xml object
  *
  * @param   \SimpleXMLElement $sxml
  * @return  InstanceList      Returns InstanceList
  */
 protected function _loadInstanceList(\SimpleXMLElement $sxml)
 {
     $list = new InstanceList();
     $list->setEc2($this->ec2);
     if (!empty($sxml->item)) {
         foreach ($sxml->item as $v) {
             $instanceId = (string) $v->instanceId;
             $item = $this->ec2->getEntityManagerEnabled() ? $this->ec2->instance->get($instanceId) : null;
             if ($item === null) {
                 $item = new InstanceData();
                 $item->setEc2($this->ec2);
                 $bAttach = true;
             } else {
                 $item->resetObject();
                 $bAttach = false;
             }
             $item->instanceId = $instanceId;
             $item->imageId = $this->exist($v->imageId) ? (string) $v->imageId : null;
             $item->privateDnsName = (string) $v->privateDnsName;
             $item->dnsName = $this->exist($v->dnsName) ? (string) $v->dnsName : null;
             $item->reason = $this->exist($v->reason) ? (string) $v->reason : null;
             $item->keyName = $this->exist($v->keyName) ? (string) $v->keyName : null;
             $item->amiLaunchIndex = $this->exist($v->amiLaunchIndex) ? (string) $v->amiLaunchIndex : null;
             $item->instanceType = (string) $v->instanceType;
             $item->launchTime = new DateTime((string) $v->launchTime, new DateTimeZone('UTC'));
             $item->kernelId = $this->exist($v->kernelId) ? (string) $v->kernelId : null;
             $item->ramdiskId = $this->exist($v->ramdiskId) ? (string) $v->ramdiskId : null;
             $item->platform = $this->exist($v->platform) ? (string) $v->platform : null;
             $item->subnetId = $this->exist($v->subnetId) ? (string) $v->subnetId : null;
             $item->vpcId = $this->exist($v->vpcId) ? (string) $v->vpcId : null;
             $item->privateIpAddress = $this->exist($v->privateIpAddress) ? (string) $v->privateIpAddress : null;
             $item->ipAddress = $this->exist($v->ipAddress) ? (string) $v->ipAddress : null;
             $item->sourceDestCheck = $this->exist($v->sourceDestCheck) ? (string) $v->sourceDestCheck == 'true' : null;
             $item->architecture = $this->exist($v->architecture) ? (string) $v->architecture : null;
             $item->rootDeviceType = $this->exist($v->rootDeviceType) ? (string) $v->rootDeviceType : null;
             $item->rootDeviceName = $this->exist($v->rootDeviceName) ? (string) $v->rootDeviceName : null;
             $item->instanceLifecycle = $this->exist($v->instanceLifecycle) ? (string) $v->instanceLifecycle : null;
             $item->spotInstanceRequestId = $this->exist($v->spotInstanceRequestId) ? (string) $v->spotInstanceRequestId : null;
             $item->virtualizationType = $this->exist($v->virtualizationType) ? (string) $v->virtualizationType : null;
             $item->clientToken = $this->exist($v->clientToken) ? (string) $v->clientToken : null;
             $item->hypervisor = $this->exist($v->hypervisor) ? (string) $v->hypervisor : null;
             $item->ebsOptimized = $this->exist($v->ebsOptimized) ? (string) $v->ebsOptimized == 'true' : null;
             $item->sriovNetSupport = $this->exist($v->sriovNetSupport) ? (string) $v->sriovNetSupport : null;
             $item->setInstanceState($this->_loadInstanceStateData($v->instanceState))->setProductCodes($this->_loadProductCodeSetList($v->productCodes))->setPlacement($this->_loadPlacementResponseData($v->placement))->setMonitoring($this->_loadInstanceMonitoringStateData($v->monitoring))->setGroupSet($this->_loadGroupList($v->groupSet))->setStateReason($this->_loadStateReasonData($v->stateReason))->setBlockDeviceMapping($this->_loadInstanceBlockDeviceMappingResponseList($v->blockDeviceMapping))->setTagSet($this->_loadResourceTagSetList($v->tagSet))->setNetworkInterfaceSet($this->_loadInstanceNetworkInterfaceSetList($v->networkInterfaceSet))->setIamInstanceProfile($this->_loadIamInstanceProfileResponseData($v->iamInstanceProfile));
             $list->append($item);
             if ($bAttach && $this->ec2->getEntityManagerEnabled()) {
                 $this->getEntityManager()->attach($item);
             }
             unset($item);
         }
     }
     return $list;
 }