Since: 23.09.2012
Author: Vitaliy Demidov (vitaliy@scalr.com)
Inheritance: extends Scalr\Service\Aws\AbstractDataType, implements Iterato\Iterator, implements Countabl\Countable, implements ArrayAcces\ArrayAccess
Exemple #1
0
 /**
  * UnmonitorInstances action
  *
  * Disables monitoring for a running instance
  *
  * @param   ListDataType $instanceIdList One or more instance IDs
  * @return  MonitorInstancesResponseSetList  Returns the MonitorInstancesResponseSetList
  * @throws  ClientException
  * @throws  Ec2Exception
  */
 public function unmonitorInstances(ListDataType $instanceIdList)
 {
     $result = null;
     $options = $instanceIdList->getQueryArrayBare('InstanceId');
     $action = ucfirst(__FUNCTION__);
     $response = $this->client->call($action, $options);
     if ($response->getError() === false) {
         $sxml = simplexml_load_string($response->getRawContent());
         $response = null;
         $result = $this->_loadListByName('MonitorInstancesResponseSet', $sxml->instancesSet);
     }
     return $result;
 }
Exemple #2
0
 /**
  * DescribePlacementGroups action
  *
  * Describes one or more of your placement groups.
  *
  * @param   ListDataType             $groupNameList optional One or more placement group names.
  * @param   PlacementGroupFilterList $filter        optional The list of the filters.
  * @return  PlacementGroupList       Returns the list of the PlacementGroupData objects on success
  * @throws  ClientException
  * @throws  Ec2Exception
  */
 public function describePlacementGroups(ListDataType $groupNameList = null, PlacementGroupFilterList $filter = null)
 {
     $result = null;
     $options = array();
     if ($groupNameList !== null) {
         $options = array_merge($options, $groupNameList->getQueryArrayBare('GroupName'));
     }
     if ($filter !== null) {
         $options = array_merge($options, $filter->getQueryArrayBare('Filter'));
     }
     $response = $this->client->call(ucfirst(__FUNCTION__), $options);
     if ($response->getError() === false) {
         $sxml = simplexml_load_string($response->getRawContent());
         $result = new PlacementGroupList();
         $result->setEc2($this->ec2);
         $result->setRequestId((string) $sxml->requestId);
         if (isset($sxml->placementGroupSet->item)) {
             foreach ($sxml->placementGroupSet->item as $v) {
                 $item = $this->_loadPlacementGroupData($v);
                 $result->append($item);
                 unset($item);
             }
         }
     }
     return $result;
 }
Exemple #3
0
 /**
  * SetLoadBalancerPoliciesForBackendServer action
  *
  * Replaces the current set of policies associated with a port on which
  * the back-end server is listening with a new set of policies.
  * After the policies have been created using CreateLoadBalancerPolicy, they
  * can be applied here as a list. At this time, only the back-end server authentication policy type can be
  * applied to the back-end ports; this policy type is composed of multiple public key policies
  *
  * @param   string       $loadBalancerName The mnemonic name associated with the LoadBalancer.
  * @param   int          $instancePort     The port number associated with the back-end server.
  * @param   ListDataType $policyNamesList  List of policy names to be set. If the list is empty, then all
  *                                         current polices are removed from the back-end server.
  * @return  array Returns updated list of policy names.
  * @throws  ClientException
  */
 public function setLoadBalancerPoliciesForBackendServer($loadBalancerName, $instancePort, ListDataType $policyNamesList = null)
 {
     $result = array();
     $options = array('LoadBalancerName' => (string) $loadBalancerName, 'InstancePort' => (int) $instancePort);
     if ($policyNamesList !== null) {
         $options = array_merge($options, $policyNamesList->getQueryArray('PolicyNames'));
     } else {
         $policyNamesList = new ListDataType();
     }
     $response = $this->client->call('SetLoadBalancerPoliciesForBackendServer', $options);
     if ($response->getError() === false) {
         $result = array_values($policyNamesList->getQueryArray('PolicyNames'));
         //Tries to look loadBalancer instance up in the repository.
         $loadBalancer = $this->elb->loadBalancer->get($options['LoadBalancerName']);
         if ($loadBalancer !== null && $loadBalancer->backendServerDescriptions !== null) {
             /* @var $bsDescription BackendServerDescriptionData */
             foreach ($loadBalancer->backendServerDescriptions as $k => $bsDescription) {
                 if ($bsDescription->instancePort == $options['InstancePort']) {
                     $loadBalancer->backendServerDescriptions[$k]->policyNames = $result;
                     break;
                 }
             }
         }
     }
     return $result;
 }
Exemple #4
0
 /**
  * Removes metadata tags from an Amazon RDS resource.
  *
  * @param string            $resourceName  Resource identifier for the Amazon RDS resource.
  * @param string            $resourceType  The type of Amazon RDS resource (db|es|og|pg|ri|secgrp|snapshot|subgrp)
  * @param ListDataType      $tagKeyList    Array of tag keys to remove
  * @return bool
  * @throws RdsException
  */
 public function removeTagsFromResource($resourceName, $resourceType, ListDataType $tagKeyList)
 {
     $result = false;
     $options = $tagKeyList->getQueryArray();
     $options['ResourceName'] = $this->rds->getResourceName($resourceName, $resourceType);
     $response = $this->client->call(ucfirst(__FUNCTION__), $options);
     if ($response->getError() === false) {
         $sxml = simplexml_load_string($response->getRawContent());
         $result = true;
     }
     return $result;
 }
Exemple #5
0
 /**
  * @test
  * @expectedException   \InvalidArgumentException
  */
 public function testIllegalObject()
 {
     $instanceData = new InstanceData();
     $instanceData->instanceId = 1;
     $list = new ListDataType($instanceData, 'instanceId', 'stdClass');
     $list->getComputed();
 }
 /**
  * {@inheritdoc}
  * @see Scalr\Service\Aws.LoaderInterface::load()
  */
 public function load($xml)
 {
     if (isset($this->result)) {
         unset($this->result);
     }
     $this->result = new LoadBalancerDescriptionList();
     $this->result->setElb($this->elb);
     /* @var $simpleXmlElement \SimpleXmlElement */
     $simpleXmlElement = simplexml_load_string($xml);
     if (!isset($simpleXmlElement->DescribeLoadBalancersResult)) {
         throw new LoaderException('An attempt has been made to load inappropriate XML.');
     }
     if (!empty($simpleXmlElement->DescribeLoadBalancersResult->LoadBalancerDescriptions->member)) {
         /* @var $lb \SimpleXmlElement */
         foreach ($simpleXmlElement->DescribeLoadBalancersResult->LoadBalancerDescriptions->member as $lb) {
             $loadBalancerName = (string) $lb->LoadBalancerName;
             //Tries to look loadBalancer in the repository
             /* @var $loadBalancer LoadBalancerDescriptionData */
             $loadBalancer = $this->elb->loadBalancer->get($loadBalancerName);
             if ($loadBalancer !== null) {
                 //We load information directly into the same object, so we need to reset it before.
                 $loadBalancer->resetObject();
             } else {
                 //Object couldn't be found in the repository and it's to be created.
                 $loadBalancer = new LoadBalancerDescriptionData();
             }
             $loadBalancer->setElb($this->elb);
             $loadBalancer->securityGroups = array();
             if (!empty($lb->SecurityGroups->member)) {
                 foreach ($lb->SecurityGroups->member as $v) {
                     $loadBalancer->securityGroups[] = (string) $v;
                 }
             }
             $loadBalancer->loadBalancerName = $loadBalancerName;
             $loadBalancer->createdTime = new \DateTime((string) $lb->CreatedTime);
             $loadBalancer->canonicalHostedZoneName = (string) $lb->CanonicalHostedZoneName;
             $loadBalancer->canonicalHostedZoneNameId = (string) $lb->CanonicalHostedZoneNameID;
             $loadBalancer->scheme = (string) $lb->Scheme;
             $loadBalancer->dnsName = (string) $lb->DNSName;
             if (isset($lb->HealthCheck->Interval)) {
                 $loadBalancer->healthCheck = new HealthCheckData();
                 $loadBalancer->healthCheck->setElb($this->elb);
                 $loadBalancer->healthCheck->setLoadBalancerName($loadBalancerName);
                 $loadBalancer->healthCheck->interval = (int) $lb->HealthCheck->Interval;
                 $loadBalancer->healthCheck->target = (string) $lb->HealthCheck->Target;
                 $loadBalancer->healthCheck->healthyThreshold = (int) $lb->HealthCheck->HealthyThreshold;
                 $loadBalancer->healthCheck->timeout = (int) $lb->HealthCheck->Timeout;
                 $loadBalancer->healthCheck->unhealthyThreshold = (int) $lb->HealthCheck->UnhealthyThreshold;
             }
             $loadBalancer->listenerDescriptions = new ListenerDescriptionList();
             $loadBalancer->listenerDescriptions->setElb($this->elb);
             $loadBalancer->listenerDescriptions->setLoadBalancerName($loadBalancerName);
             if (!empty($lb->ListenerDescriptions->member)) {
                 /* @var $ld \SimpleXmlElement */
                 foreach ($lb->ListenerDescriptions->member as $ld) {
                     $listenerDescription = new ListenerDescriptionData();
                     $listenerDescription->setElb($this->elb);
                     $listenerDescription->setLoadBalancerName($loadBalancerName);
                     $listenerDescription->listener = new ListenerData();
                     $listenerDescription->listener->setElb($this->elb);
                     $listenerDescription->listener->setLoadBalancerName($loadBalancerName);
                     if (isset($ld->Listener->InstancePort)) {
                         $listenerDescription->listener->instancePort = (int) $ld->Listener->InstancePort;
                         $listenerDescription->listener->instanceProtocol = (string) $ld->Listener->InstanceProtocol;
                         $listenerDescription->listener->loadBalancerPort = (int) $ld->Listener->LoadBalancerPort;
                         $listenerDescription->listener->protocol = (string) $ld->Listener->Protocol;
                         $listenerDescription->listener->sslCertificateId = (string) $ld->Listener->SslCertificateId;
                     }
                     $listenerDescription->policyNames = array();
                     if (!empty($ld->PolicyNames->member)) {
                         foreach ($ld->PolicyNames->member as $v) {
                             $listenerDescription->policyNames[] = (string) $v;
                         }
                     }
                     $loadBalancer->listenerDescriptions->append($listenerDescription);
                     unset($listenerDescription);
                 }
             }
             $loadBalancer->instances = new InstanceList();
             $loadBalancer->instances->setElb($this->elb);
             if (!empty($lb->Instances->member)) {
                 foreach ($lb->Instances->member as $v) {
                     $instance = new InstanceData();
                     $instance->setElb($this->elb);
                     $instance->instanceId = (string) $v->InstanceId;
                     $loadBalancer->instances->append($instance);
                     unset($instance);
                 }
             }
             $loadBalancer->availabilityZones = array();
             if (!empty($lb->AvailabilityZones->member)) {
                 foreach ($lb->AvailabilityZones->member as $v) {
                     $loadBalancer->availabilityZones[] = (string) $v;
                 }
             }
             if (!empty($lb->SourceSecurityGroup)) {
                 $loadBalancer->sourceSecurityGroup = new SourceSecurityGroupData();
                 $loadBalancer->sourceSecurityGroup->setElb($this->elb);
                 $loadBalancer->sourceSecurityGroup->groupName = (string) $lb->SourceSecurityGroup->GroupName;
                 $loadBalancer->sourceSecurityGroup->ownerAlias = (string) $lb->SourceSecurityGroup->OwnerAlias;
             }
             $loadBalancer->backendServerDescriptions = new BackendServerDescriptionList();
             $loadBalancer->backendServerDescriptions->setElb($this->elb);
             if (!empty($lb->BackendServerDescriptions->member)) {
                 foreach ($lb->BackendServerDescriptions->member as $v) {
                     $backendServerDescription = new BackendServerDescriptionData();
                     $backendServerDescription->setElb($this->elb);
                     $backendServerDescription->instancePort = (int) $v->InstancePort;
                     $backendServerDescription->policyNames = array();
                     if (!empty($v->PolicyNames->member)) {
                         foreach ($v->PolicyNames->member as $t) {
                             $backendServerDescription->policyNames[] = (string) $t;
                         }
                     }
                     $loadBalancer->backendServerDescriptions->append($backendServerDescription);
                     unset($backendServerDescription);
                 }
             }
             $loadBalancer->subnets = array();
             if (!empty($lb->Subnets->member)) {
                 foreach ($lb->Subnets->member as $v) {
                     $loadBalancer->subnets[] = (string) $v;
                 }
             }
             if (isset($lb->VPCId)) {
                 $loadBalancer->vpcId = (string) $lb->VPCId;
             }
             $loadBalancer->policies = new PoliciesData();
             $loadBalancer->policies->setElb($this->elb);
             $loadBalancer->policies->setLoadBalancerName($loadBalancerName);
             $loadBalancer->policies->appCookieStickinessPolicies = new AppCookieStickinessPolicyList();
             $loadBalancer->policies->appCookieStickinessPolicies->setElb($this->elb);
             $loadBalancer->policies->appCookieStickinessPolicies->setLoadBalancerName($loadBalancerName);
             $loadBalancer->policies->lbCookieStickinessPolicies = new LbCookieStickinessPolicyList();
             $loadBalancer->policies->lbCookieStickinessPolicies->setElb($this->elb);
             $loadBalancer->policies->lbCookieStickinessPolicies->setLoadBalancerName($loadBalancerName);
             $loadBalancer->policies->otherPolicies = array();
             if (!empty($lb->Policies->AppCookieStickinessPolicies->member)) {
                 foreach ($lb->Policies->AppCookieStickinessPolicies->member as $v) {
                     $object = new AppCookieStickinessPolicyData();
                     $object->setElb($this->elb);
                     $object->setLoadBalancerName($loadBalancerName);
                     $object->cookieName = (string) $v->CookieName;
                     $object->policyName = (string) $v->PolicyName;
                     $loadBalancer->policies->appCookieStickinessPolicies->append($object);
                     unset($object);
                 }
             }
             if (!empty($lb->Policies->LBCookieStickinessPolicies->member)) {
                 foreach ($lb->Policies->LBCookieStickinessPolicies->member as $v) {
                     $object = new LbCookieStickinessPolicyData();
                     $object->setElb($this->elb);
                     $object->setLoadBalancerName($loadBalancerName);
                     $object->policyName = (string) $v->PolicyName;
                     //Long int
                     $object->cookieExpirationPeriod = (string) $v->CookieExpirationPeriod - 0;
                     $loadBalancer->policies->lbCookieStickinessPolicies->append($object);
                     unset($object);
                 }
             }
             if (!empty($lb->Policies->OtherPolicies)) {
                 if (!empty($lb->Policies->OtherPolicies->member)) {
                     foreach ($lb->Policies->OtherPolicies->member as $v) {
                         $loadBalancer->policies->otherPolicies[] = (string) $v;
                     }
                 }
             }
             $this->result->append($loadBalancer);
             unset($loadBalancer);
         }
     }
     return $this->result;
 }
Exemple #7
0
 /**
  * Removes one or more tags from the specified load balancer.
  *
  * @param ListDataType $loadBalancerNamesList A list of names associated with the LoadBalancers at creation time.
  * @param ListDataType $tagsKeys              A list of tag keys to remove.
  * @return bool                               Returns true on success. False otherwise
  * @throws ElbException
  */
 public function removeTags(ListDataType $loadBalancerNamesList, ListDataType $tagsKeys)
 {
     $result = false;
     $options = $loadBalancerNamesList->getQueryArray('LoadBalancerNames');
     $tagsArray = $tagsKeys->getQueryArray();
     foreach ($tagsArray as $key => $option) {
         $newKey = $key . '.Key';
         $tagsOptions[$newKey] = $option;
     }
     $options = array_merge($options, $tagsOptions);
     $response = $this->client->call('RemoveTags', $options);
     if ($response->getError() === false) {
         $sxml = simplexml_load_string($response->getRawContent());
         if (!isset($sxml->RemoveTagsResult)) {
             throw new ElbException('Unexpected response ' . $response->getRawContent());
         }
         $result = true;
     }
     return $result;
 }
Exemple #8
0
 /**
  * Gets statistics for the specified metric.
  *
  * Note!
  * The maximum number of data points returned from a single GetMetricStatistics request
  * is 1,440. If a request is made that generates more than 1,440 data points, Amazon CloudWatch
  * returns an error. In such a case, alter the request by narrowing the specified time range or
  * increasing the specified period. Alternatively, make multiple requests across adjacent time ranges.
  *
  * Amazon CloudWatch aggregates data points based on the length of the period that you specify. For
  * example, if you request statistics with a one-minute granularity, Amazon CloudWatch aggregates data
  * points with time stamps that fall within the same one-minute period. In such a case, the data points queried
  * can greatly outnumber the data points returned.
  *
  * Note!
  * The maximum number of data points that can be queried is 50,850; whereas the maximum
  * number of data points returned is 1,440.
  *
  * The following examples show various statistics allowed by the data point query maximum of 50,850 when
  * you call GetMetricStatistics on Amazon EC2 instances with detailed (one-minute) monitoring
  * enabled:
  *  -  Statistics for up to 400 instances for a span of one hour
  *  -  Statistics for up to 35 instances over a span of 24 hours
  *  -  Statistics for up to 2 instances over a span of 2 weeks
  *
  * @param   string        $metricName The name of the metric, with or without spaces.
  * @param   \DateTime     $startTime  The time stamp to use for determining the first datapoint to return.
  *                                    The value specified is inclusive; results include datapoints with the
  *                                    time stamp specified.
  * @param   \DateTime     $endTime    The time stamp to use for determining the last datapoint to return.
  *                                    The value specified is exclusive; results will include datapoints up
  *                                    to the time stamp specified.
  * @param   ListDataType  $statistics The metric statistics to return.
  *                                    Valid Values: Average | Sum | SampleCount | Maximum | Minimum
  * @param   string        $namespace  The namespace of the metric, with or without spaces.
  * @param   int           $period     optional The granularity, in seconds, of the returned datapoints.
  *                                    Period must be at least 60 seconds and must be a multiple of 60.
  *                                    The default value is 60.
  * @param   string        $unit       optional The unit for the metric.
  * @param   DimensionList $dimensions optional A list of dimensions describing qualities of the metric.
  * @return  DatapointList Returns the datapoints for the specified metric.
  * @throws  ClientException
  * @throws  CloudWatchException
  */
 public function getMetricStatistics($metricName, \DateTime $startTime, \DateTime $endTime, ListDataType $statistics, $namespace, $period = 60, $unit = null, DimensionList $dimensions = null)
 {
     $result = null;
     $options = array('MetricName' => (string) $metricName, 'StartTime' => $startTime->format('c'), 'EndTime' => $endTime->format('c'), 'Period' => (int) $period, 'Namespace' => (string) $namespace);
     $options = array_merge($options, $statistics->getQueryArray('Statistics'));
     if ($dimensions != null) {
         $options = array_merge($options, $dimensions->getQueryArray());
     }
     if ($unit !== null) {
         $options['Unit'] = (string) $unit;
     }
     $response = $this->client->call('GetMetricStatistics', $options);
     if ($response->getError() === false) {
         //Success
         $sxml = simplexml_load_string($response->getRawContent());
         if (!isset($sxml->GetMetricStatisticsResult)) {
             throw new CloudWatchException('Unexpected response! ' . $response->getRawContent());
         }
         $ptr =& $sxml->GetMetricStatisticsResult;
         $result = new DatapointList();
         $result->setCloudWatch($this->cloudWatch);
         $result->setMetricName(!empty($ptr->Label) ? (string) $ptr->Label : null);
         if (!empty($ptr->Datapoints->member)) {
             foreach ($ptr->Datapoints->member as $v) {
                 $datapoint = new DatapointData();
                 $datapoint->average = (double) $v->Average;
                 $datapoint->maximum = (double) $v->Maximum;
                 $datapoint->minimum = (double) $v->Minimum;
                 $datapoint->sampleCount = (double) $v->SampleCount;
                 $datapoint->sum = (double) $v->Sum;
                 $datapoint->timestamp = new \DateTime((string) $v->Timestamp);
                 $datapoint->unit = (string) $v->Unit;
                 $result->append($datapoint);
                 unset($datapoint);
             }
         }
         unset($ptr);
     }
     return $result;
 }