Since: 14.01.2013
Author: Vitaliy Demidov (vitaliy@scalr.com)
Inheritance: extends Scalr\Service\Aws\Ec2\AbstractEc2DataType
Exemplo n.º 1
0
 /**
  * DescribeReservedInstances action
  *
  * Describes one or more of the Reserved Instances that you purchased.
  * Starting with the 2011-11-01 API version, AWS expanded its offering of Amazon EC2 Reserved Instances
  * to address a range of projected instance use. There are three types of Reserved Instances based on
  * customer utilization levels: Heavy Utilization, Medium Utilization, and Light Utilization.You determine the
  * type of the Reserved Instances offerings by including the optional offeringType parameter.The Medium
  * Utilization offering type is equivalent to the Reserved Instance offering available before API version
  * 2011-11-01. If you are using tools that predate the 2011-11-01 API version, you only have access to the
  * Medium Utilization Reserved Instance offering type.
  *
  * @param   ListDataType               $reservedInstanceIdList optional One or more instance IDs
  * @param   ReservedInstanceFilterList $filter                 optional A Filter list
  * @return  ReservedInstanceList       Returns reserved list of the reserved instances
  * @throws  ClientException
  * @throws  Ec2Exception
  */
 public function describeReservedInstances(ListDataType $reservedInstanceIdList = null, ReservedInstanceFilterList $filter = null, OfferingType $offefingType = null)
 {
     $result = null;
     $options = array();
     if ($reservedInstanceIdList !== null) {
         $options = array_merge($options, $this->getInstanceIdListQuery($reservedInstanceIdList, 'ReservedInstancesId'));
     }
     if ($filter !== null) {
         $options = array_merge($options, $filter->getQueryArrayBare('Filter'));
     }
     if ($offefingType !== null) {
         $options['OfferingType'] = (string) $offefingType;
     }
     $response = $this->client->call(ucfirst(__FUNCTION__), $options);
     if ($response->getError() === false) {
         //Success
         $sxml = simplexml_load_string($response->getRawContent());
         $response = null;
         $result = new ReservedInstanceList();
         $result->setEc2($this->ec2);
         $result->setRequestId((string) $sxml->requestId);
         if (!empty($sxml->reservedInstancesSet->item)) {
             foreach ($sxml->reservedInstancesSet->item as $v) {
                 $reservedInstancesId = (string) $v->reservedInstancesId;
                 $item = $this->ec2->getEntityManagerEnabled() ? $this->ec2->reservedInstance->get($reservedInstancesId) : null;
                 if ($item === null) {
                     $item = new ReservedInstanceData();
                     $item->setEc2($this->ec2);
                     $bAttach = true;
                 } else {
                     $item->resetObject();
                     $bAttach = false;
                 }
                 $item->reservedInstancesId = $reservedInstancesId;
                 $item->instanceType = $this->exist($v->instanceType) ? (string) $v->instanceType : null;
                 $item->availabilityZone = $this->exist($v->availabilityZone) ? (string) $v->availabilityZone : null;
                 $item->duration = $this->exist($v->duration) ? $v->duration - 0 : null;
                 $item->fixedPrice = $this->exist($v->fixedPrice) ? floatval($v->fixedPrice) : null;
                 $item->usagePrice = $this->exist($v->usagePrice) ? floatval($v->usagePrice) : null;
                 $item->instanceCount = $this->exist($v->instanceCount) ? intval($v->instanceCount) : null;
                 $item->state = $this->exist($v->state) ? (string) $v->state : null;
                 $item->productDescription = $this->exist($v->productDescription) ? (string) $v->productDescription : null;
                 $item->start = $this->exist($v->start) ? new \DateTime((string) $v->start, new \DateTimeZone('UTC')) : null;
                 $item->end = $this->exist($v->end) ? new \DateTime((string) $v->end, new \DateTimeZone('UTC')) : null;
                 $item->instanceTenancy = $this->exist($v->instanceTenancy) ? (string) $v->instanceTenancy : null;
                 $item->currencyCode = $this->exist($v->currencyCode) ? (string) $v->currencyCode : null;
                 $item->offeringType = $this->exist($v->offeringType) ? (string) $v->offeringType : null;
                 $item->setTagSet($this->_loadResourceTagSetList($v->tagSet))->setRecurringCharges($this->_loadRecurringChargesSetList($v->recurringCharges));
                 $result->append($item);
                 if ($bAttach && $this->ec2->getEntityManagerEnabled()) {
                     $this->getEntityManager()->attach($item);
                 }
                 unset($item);
             }
         }
     }
     return $result;
 }