/** * @param string $protocol * @param string $ipAddress * @param string $port * @param string $requestInterval * @param string $failureThreshold * @param string $cloudLocation * @param string $hostName optional * @param string $resourcePath optional * @param string $searchString optional */ public function xCreateAction($protocol, $ipAddress, $port, $requestInterval, $failureThreshold, $cloudLocation, $hostName = null, $resourcePath = null, $searchString = null) { $healthData = new HealthData(); $protocol = strtoupper($protocol); $healthConfig = new HealthConfigData($ipAddress, $port, null, null, null, null, $requestInterval, $failureThreshold); if ('TCP' != $protocol) { $healthConfig->domainName = !empty($hostName) ? $hostName : null; $healthConfig->resourcePath = !empty($resourcePath) ? $resourcePath : null; } if (('HTTP' == $protocol || 'HTTPS' == $protocol) && !empty($searchString)) { $healthConfig->searchString = $searchString; $protocol .= '_STR_MATCH'; } $healthConfig->type = $protocol; $healthData->setHealthConfig($healthConfig); $response = $this->environment->aws($cloudLocation)->route53->health->create($healthData); $this->response->data(['data' => $response]); }
/** * @param string $protocol * @param string $ipAddress * @param string $port * @param string $requestInterval * @param string $failureThreshold * @param string $hostName optional * @param string $resourcePath optional * @param string $searchString optional */ public function xCreateAction($protocol, $ipAddress, $port, $requestInterval, $failureThreshold, $hostName = null, $resourcePath = null, $searchString = null) { $this->request->restrictAccess(Acl::RESOURCE_AWS_ROUTE53, Acl::PERM_AWS_ROUTE53_MANAGE); $healthData = new HealthData(); $protocol = strtoupper($protocol); $healthConfig = new HealthConfigData($ipAddress, $port, null, null, null, null, $requestInterval, $failureThreshold); if ('TCP' != $protocol) { $healthConfig->domainName = !empty($hostName) ? $hostName : null; $healthConfig->resourcePath = !empty($resourcePath) ? $resourcePath : null; } if (('HTTP' == $protocol || 'HTTPS' == $protocol) && !empty($searchString)) { $healthConfig->searchString = $searchString; $protocol .= '_STR_MATCH'; } $healthConfig->type = $protocol; $healthData->setHealthConfig($healthConfig); $response = $this->getAws()->route53->health->create($healthData); $this->response->data(['data' => $response]); }
/** * @test */ public function testFunctionalEc2() { $this->skipIfEc2PlatformDisabled(); $aws = $this->getContainer()->aws(AwsTestCase::REGION); $aws->ec2->enableEntityManager(); //We should use different ec2 instance for another region $aws2 = $this->getContainer()->aws(Aws::REGION_US_WEST_2); $nameTag = new ResourceTagSetData(self::TAG_NAME_KEY, self::getTestName(self::NAME_TAG_VALUE)); $subnetList = $aws->ec2->subnet->describe(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\SubnetList'), $subnetList); unset($subnetList); $imageList = $aws->ec2->image->describe(null, 'self'); $this->assertInstanceOf($this->getEc2ClassName('DataType\\ImageList'), $imageList); unset($imageList); $volumeList = $aws->ec2->volume->describe(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\VolumeList'), $volumeList); unset($volumeList); $snapshotList = $aws->ec2->snapshot->describe(null, 'self', new SnapshotFilterData(SnapshotFilterNameType::tag(self::TAG_NAME_KEY), self::getTestName(self::NAME_TAG_VALUE))); $this->assertInstanceOf($this->getEc2ClassName('DataType\\SnapshotList'), $snapshotList); /* @var $sn SnapshotList */ foreach ($snapshotList as $sn) { $sn->delete(); } unset($snapshotList); $reservationsList = $aws->ec2->instance->describe(null, new InstanceFilterData(InstanceFilterNameType::tag(self::TAG_NAME_KEY), self::getTestName(self::NAME_TAG_VALUE))); $this->assertInstanceOf($this->getEc2ClassName('DataType\\ReservationList'), $reservationsList); foreach ($reservationsList as $r) { /* @var $i InstanceData */ foreach ($r->instancesSet as $i) { $ds = $i->describeStatus(); if ($ds->instanceState->name == InstanceStateData::NAME_RUNNING) { //Whether the elastic ip is still associated with the instance $adlist = $aws->ec2->address->describe(null, null, array(array('name' => AddressFilterNameType::instanceId(), 'value' => $i->instanceId))); foreach ($adlist as $v) { //Removes associated elastic IP address $aws->ec2->address->disassociate($v->publicIp); $aws->ec2->address->release($v->publicIp); } unset($adlist); } else { if ($ds->instanceState->name == InstanceStateData::NAME_TERMINATED || $ds->instanceState->name == InstanceStateData::NAME_SHUTTING_DOWN) { continue; } } $i->terminate(); $i = $i->refresh(); for ($t = time(); time() - $t < 100 && isset($i->instanceState) && !in_array($i->instanceState->name, array(InstanceStateData::NAME_TERMINATED)); sleep(5)) { $i = $i->refresh(); } } } $placementGroups = $aws->ec2->placementGroup->describe(null, new PlacementGroupFilterData(PlacementGroupFilterNameType::groupName(), self::getTestName('placement-group'))); $this->assertInstanceOf($this->getEc2ClassName('DataType\\PlacementGroupList'), $placementGroups); /* @var $pg PlacementGroupData */ foreach ($placementGroups as $pg) { $pg->delete(); unset($pg); } unset($placementGroups); $reservedInstancesList = $aws->ec2->reservedInstance->describe(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\ReservedInstanceList'), $reservedInstancesList); $availabilityZoneList = $aws->ec2->availabilityZone->describe('us-east-1a', array(array('name' => AvailabilityZoneFilterNameType::state(), 'value' => array('available')))); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AvailabilityZoneList'), $availabilityZoneList); $this->assertEquals(1, count($availabilityZoneList)); $this->assertInstanceOf($this->getAwsClassName('Ec2'), $availabilityZoneList->getEc2()); $this->assertNotEmpty($availabilityZoneList->getRequestId()); $this->assertEquals('us-east-1a', $availabilityZoneList[0]->getZoneName()); $this->assertEquals('available', $availabilityZoneList[0]->getZoneState()); $this->assertEquals('us-east-1', $availabilityZoneList[0]->getRegionName()); $ml = $availabilityZoneList[0]->getMessageSet(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AvailabilityZoneMessageList'), $ml); $this->assertInstanceOf($this->getAwsClassName('Ec2'), $ml->getEc2()); unset($ml); $al = $aws->ec2->address->describe(null, null, array(array('name' => AddressFilterNameType::domain(), 'value' => 'standard'))); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AddressList'), $al); unset($al); //Describes keypair $keyname = self::getTestName('keyname'); $kplist = $aws->ec2->keyPair->describe(null, array('key-name' => $keyname)); $this->assertInstanceOf($this->getEc2ClassName('DataType\\KeyPairList'), $kplist); if (count($kplist) > 0) { foreach ($kplist as $kp) { $kp->delete(); } } unset($kplist); //Creates keypair $kp = $aws->ec2->keyPair->create($keyname); $this->assertInstanceOf($this->getEc2ClassName('DataType\\KeyPairData'), $kp); $this->assertEquals($keyname, $kp->keyName); $this->assertNotNull($kp->keyFingerprint); $this->assertNotNull($kp->keyMaterial); //We should be assured that group which is used for the test does not exists $list = $aws->ec2->securityGroup->describe(null, null, new SecurityGroupFilterData(SecurityGroupFilterNameType::groupName(), self::getTestName('security-group'))); if (count($list) > 0) { foreach ($list as $v) { $v->delete(); } } unset($list); //Creates security group $securityGroupId = $aws->ec2->securityGroup->create(self::getTestName('security-group'), self::getTestName('security-group') . ' description'); $this->assertNotEmpty($securityGroupId); sleep(2); /* @var $sg SecurityGroupData */ $sg = $aws->ec2->securityGroup->describe(null, $securityGroupId)->get(0); $this->assertInstanceOf($this->getEc2ClassName('DataType\\SecurityGroupData'), $sg); $this->assertNotEmpty($sg->groupId); $this->assertEquals(self::getTestName('security-group'), $sg->groupName); $this->assertContains(self::getTestName('security-group'), $sg->groupDescription); $ret = $sg->createTags($nameTag); $this->assertTrue($ret); //Verifies that security group entity which is stored in manager is the same object $sgMirror = $aws->ec2->securityGroup->get($sg->groupId); $this->assertSame($sg, $sgMirror); unset($sgMirror); //Athorizes Security Group Ingress $ipperm = new IpPermissionData('tcp', 80, 80, new IpRangeList(array(new IpRangeData('192.0.2.0/24'), new IpRangeData('192.51.100.0/24')))); $ret = $sg->authorizeIngress($ipperm); $this->assertTrue($ret); $ipperm2 = new IpPermissionData('tcp', 8080, 8080, new IpRangeList(array(new IpRangeData('192.66.12.0/24')))); $ret = $sg->authorizeIngress($ipperm2); $this->assertTrue($ret); $ret = $sg->revokeIngress($ipperm2); $this->assertTrue($ret); //Describes itself $sg->refresh(); $this->assertContains(self::TAG_NAME_KEY, $sg->tagSet->getQueryArrayBare('Tag')); //Creates placement group $ret = $aws->ec2->placementGroup->create(self::getTestName('placement-group')); $this->assertTrue($ret); //Sometimes it takes a moment sleep(3); $pg = $aws->ec2->placementGroup->describe(self::getTestName('placement-group'))->get(0); $this->assertInstanceOf($this->getEc2ClassName('DataType\\PlacementGroupData'), $pg); $this->assertEquals(self::getTestName('placement-group'), $pg->groupName); $this->assertSame($pg, $aws->ec2->placementGroup->get($pg->groupName)); //RunInstance test $request = new RunInstancesRequestData(self::INSTANCE_IMAGE_ID, 1, 1); $request->instanceType = self::INSTANCE_TYPE; //Placement groups may not be used with instances of type 'm1.small'. $request->setPlacement(new PlacementResponseData(AwsTestCase::AVAILABILITY_ZONE_C)); $request->setMonitoring(true); $request->ebsOptimized = false; $request->userData = base64_encode("test=26;"); $request->appendSecurityGroupId($securityGroupId); $request->appendBlockDeviceMapping(new BlockDeviceMappingData("/dev/sdb", 'ephemeral0', null, new EbsBlockDeviceData(1, null, null, null, true, true))); $request->keyName = $keyname; $rd = $aws->ec2->instance->run($request); $this->assertInstanceOf($this->getEc2ClassName('DataType\\ReservationData'), $rd); /* @var $ind InstanceData */ $ind = $rd->instancesSet[0]; unset($request); //Monitors instance $ret = $ind->monitor(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\MonitorInstancesResponseSetList'), $ret); $this->assertContains($ret->get(0)->monitoring->state, array(InstanceMonitoringStateData::STATE_PENDING, InstanceMonitoringStateData::STATE_ENABLED)); unset($ret); //Instance state must be in the running state for ($t = time(), $s = 5; time() - $t < 300 && $ind->instanceState->name !== InstanceStateData::NAME_RUNNING; $s += 5) { sleep($s); $ind = $ind->refresh(); } $this->assertEquals(InstanceStateData::NAME_RUNNING, $ind->instanceState->name); // route53 test $dns = self::getTestName('testname') . '.com'; // clean up $listZones = $aws->route53->zone->describe(); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\ZoneList'), $listZones); /* @var $zone \Scalr\Service\Aws\Route53\DataType\ZoneData */ foreach ($listZones as $zone) { $this->assertNotNull($zone->zoneId); if ($dns . '.' == $zone->name) { $rrsRequest = new ChangeRecordSetsRequestData(); $rrsCnahgeList = new ChangeRecordSetList(); $rrsCnahgeListData = new ChangeRecordSetData('DELETE'); $rrsData = new RecordSetData($dns, 'A', 60); $rrsData->setResourceRecord([['value' => $ind->ipAddress]]); $rrsCnahgeListData->setRecordSet($rrsData); $rrsCnahgeList->append($rrsCnahgeListData); $rrsRequest->setChange($rrsCnahgeList); $changeRequest = $aws->route53->record->update($zone->zoneId, $rrsRequest); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\ChangeData'), $changeRequest); $zone->delete($zone->zoneId); } unset($zone); } unset($listZones); $list = $aws->route53->health->describe(); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\HealthList'), $list); foreach ($list as $check) { /* @var $check \Scalr\Service\Aws\Route53\DataType\HealthData */ $this->assertInstanceOf($this->getRoute53ClassName('DataType\\HealthConfigData'), $check->healthConfig); $this->assertNotNull($check->healthId); $this->assertNotNull($check->healthConfig->domainName); if ($dns . '.' == $check->healthConfig->domainName) { $check->delete($check->healthId); } unset($check); } unset($list); // create hosted zone $config = new ZoneData($dns); $hostedZone = $aws->route53->zone->create($config); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\ZoneData'), $hostedZone); $this->assertNotNull($hostedZone->zoneId); $zoneId = (string) $hostedZone->zoneId; // create record set for hosted zone $rrsRequest = new ChangeRecordSetsRequestData(); $rrsCnahgeList = new ChangeRecordSetList(); $rrsCnahgeListData = new ChangeRecordSetData('CREATE'); $rrsData = new RecordSetData($dns, 'A', 60); $rrsData->setResourceRecord([['value' => $ind->ipAddress]]); $rrsCnahgeListData->setRecordSet($rrsData); $rrsCnahgeList->append($rrsCnahgeListData); $rrsRequest->setChange($rrsCnahgeList); $changeRequest = $aws->route53->record->update($zoneId, $rrsRequest); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\ChangeData'), $changeRequest); $this->assertNotNull($changeRequest->changeId); $getChange = $aws->route53->record->fetch($changeRequest->changeId); $this->assertEquals($changeRequest->changeId, $getChange->changeId); // create health check using record set's idAddress $healthData = new HealthData(); $healthConfig = new HealthConfigData($ind->ipAddress, 80, 'HTTP', '/index.html', $dns); $healthData->setHealthConfig($healthConfig); $healthCheck = $aws->route53->health->create($healthData); $this->assertNotNull($healthCheck->healthId); $list = $aws->route53->health->describe(); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\HealthList'), $list); foreach ($list as $check) { $this->assertInstanceOf($this->getRoute53ClassName('DataType\\HealthConfigData'), $check->healthConfig); $this->assertNotNull($check->healthId); $this->assertNotNull($check->healthConfig->domainName); if ($dns == $check->healthConfig->domainName) { $getCheck = $aws->route53->health->fetch($check->healthId); $this->assertEquals($check->healthId, $getCheck->healthId); $check->delete($check->healthId); } unset($check); } unset($list); // clean up $listZones = $aws->route53->zone->describe(); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\ZoneList'), $listZones); foreach ($listZones as $zone) { /* @var $zone \Scalr\Service\Aws\Route53\DataType\ZoneData */ $this->assertNotNull($zone->zoneId); if ($dns . '.' == $zone->name) { $rrsRequest = new ChangeRecordSetsRequestData(); $rrsCnahgeList = new ChangeRecordSetList(); $rrsCnahgeListData = new ChangeRecordSetData('DELETE'); $rrsData = new RecordSetData($dns, 'A', 60); $rrsData->setResourceRecord([['value' => $ind->ipAddress]]); $rrsCnahgeListData->setRecordSet($rrsData); $rrsCnahgeList->append($rrsCnahgeListData); $rrsRequest->setChange($rrsCnahgeList); $changeRequest = $aws->route53->record->update($zone->zoneId, $rrsRequest); $this->assertInstanceOf($this->getRoute53ClassName('DataType\\ChangeData'), $changeRequest); $getZone = $aws->route53->zone->fetch($zone->zoneId); $this->assertEquals($zone->zoneId, $getZone->zoneId); $zone->delete($zone->zoneId); } unset($zone); } unset($listZones); //Creates the tag for the instance $res = $ind->createTags(array($nameTag, array('key' => 'Extratag', 'value' => 'extravalue'))); $this->assertTrue($res); //Verifies that tag has been successfully set. $ind->refresh(); $this->assertContains(self::TAG_NAME_KEY, $ind->tagSet->getQueryArrayBare()); $this->assertContains('Extratag', $ind->tagSet->getQueryArrayBare()); //Removes an extratag $ind->deleteTags(array(array('key' => 'Extratag', 'value' => null))); $this->assertEquals(self::INSTANCE_TYPE, $ind->instanceType); $this->assertEquals(self::INSTANCE_IMAGE_ID, $ind->imageId); $this->assertEquals(false, $ind->ebsOptimized); $this->assertContains($ind->monitoring->state, array('enabled', 'pending')); $this->assertEquals(AwsTestCase::AVAILABILITY_ZONE_C, $ind->placement->availabilityZone); $this->assertEquals($keyname, $ind->keyName); $this->assertContains($securityGroupId, array_map(function ($arr) { return $arr->groupId; }, iterator_to_array($ind->groupSet, false))); $this->assertContains(array("/dev/sdb", ''), array_map(function ($arr) { return array($arr->deviceName, $arr->virtualName); }, iterator_to_array($ind->blockDeviceMapping, false))); //Creates AMI // $cr = new CreateImageRequestData($ind->instanceId, sprintf(self::getTestName('i%s'), $ind->instanceId)); // $cr->description = 'It is supposed to be removed immediately after creation.'; // $imageId = $aws->ec2->image->create($cr); // sleep(3); // $ami = $aws->ec2->image->describe($imageId); // $this->assertInstanceOf($this->getEc2ClassName('DataType\\ImageData'), $ami); // $this->assertNotNull($ami->imageId); // //Waits while snapshot is created. // for ($t = time(), $s = 5; time() - $t < 300 && $ami->imageState === ImageData::STATE_PENDING; $s += 5) { // sleep($s); // $ami = $ami->refresh(); // } // $this->assertTrue(in_array($ami->imageState, array(ImageData::STATE_AVAILABLE, SnapshotData::STATUS_ERROR))); // unset($cr); // $ami->createTags($nameTag); // //Copy // $copyImageId = $ami->copy(substr(AwsTestCase::AVAILABILITY_ZONE_A, 0, -1), null, 'phpunit copied AMI', null, Aws::REGION_US_WEST_2); // $this->assertNotNull($copyImageId); // /* @var $ami2 ImageData */ // $ami2 = $aws2->ec2->image->describe($copyImageId)->get(0); // $this->assertNotNull($ami2); // $ami2->deregister(); // //Deregisters an AMI // $ami->deregister(); //Creates Elastic IP Address $address = $aws->ec2->address->allocate(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AddressData'), $address); $this->assertNotNull($address->publicIp); $ret = $aws->ec2->address->associate(new AssociateAddressRequestData($ind->instanceId, $address->publicIp)); $this->assertTrue($ret); //DescribeAddress should return allocated addres $adlist = $aws->ec2->address->describe($address->publicIp, null, array(array('name' => AddressFilterNameType::instanceId(), 'value' => $ind->instanceId))); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AddressList'), $adlist); $this->assertEquals(1, count($adlist)); $this->assertEquals($address->publicIp, $adlist->get(0)->publicIp); //It must be associated with the instance $this->assertEquals($ind->instanceId, $adlist->get(0)->instanceId); $this->assertEquals($address->domain, $adlist->get(0)->domain); //Dissassociates address $ret = $aws->ec2->address->disassociate($address->publicIp); $this->assertTrue($ret); //Releases address $ret = $aws->ec2->address->release($address->publicIp); $this->assertTrue($ret); unset($adlist); unset($address); //Creates the volume $cvRequest = new CreateVolumeRequestData(AwsTestCase::AVAILABILITY_ZONE_C); $cvRequest->encrypted = true; $cvRequest->setSize(2)->setVolumeType(CreateVolumeRequestData::VOLUME_TYPE_STANDARD); $vd = $aws->ec2->volume->create($cvRequest); $this->assertInstanceOf($this->getEc2ClassName('DataType\\VolumeData'), $vd); $volumeid = $vd->volumeId; $this->assertTrue($vd->encrypted); unset($cvRequest); $res = $vd->createTags($nameTag); $this->assertTrue($res); //Volume must be in the Available status for ($t = time(), $s = 2; time() - $t < 300 && $vd->status !== VolumeData::STATUS_AVAILABLE; $s += 5) { sleep($s); $vd = $vd->refresh(); } $this->assertEquals(VolumeData::STATUS_AVAILABLE, $vd->status); //Attaching the volume $at = $vd->attach($ind->instanceId, '/dev/sdh'); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AttachmentSetResponseData'), $at); //Creates snapshot $sn = $vd->createSnapshot(self::getTestName(self::NAME_SNAPSHOT)); $this->assertTrue($sn->encrypted); $this->assertInstanceOf($this->getEc2ClassName('DataType\\SnapshotData'), $sn); $this->assertNotEmpty($sn->snapshotId); $sn->createTags($nameTag); //Waits while snapshot is created. for ($t = time(), $s = 2; time() - $t < 300 && $sn->status === SnapshotData::STATUS_PENDING; $s += 5) { sleep($s); $sn->refresh(); } $this->assertTrue(in_array($sn->status, array(SnapshotData::STATUS_COMPLETED, SnapshotData::STATUS_ERROR))); //Copies snapshot to different region $copySnapshotId = $sn->copy($aws->getRegion(), 'phpunit copied encrypted snapshot', Aws::REGION_US_WEST_2, $aws->getPresignedUrl('ec2', 'CopySnapshot', Aws::REGION_US_WEST_2, $sn->snapshotId)); $this->assertNotNull($copySnapshotId); $aws2->ec2->tag->create($copySnapshotId, $nameTag); $csn = $aws2->ec2->snapshot->describe($copySnapshotId)->get(0); $this->assertInstanceOf($this->getEc2ClassName('DataType\\SnapshotData'), $csn); //Waits while snapshot is created. for ($t = time(), $s = 2; time() - $t < 600 && $csn->status === SnapshotData::STATUS_PENDING; $s += 5) { sleep($s); $csn = $csn->refresh(); } $this->assertTrue($csn->status == SnapshotData::STATUS_COMPLETED); $this->assertTrue($csn->encrypted); //Removes snapshot $ret = $sn->delete(); $this->assertTrue($ret); //Removes copied snapshot $ret = $csn->delete(); $this->assertTrue($ret); //Detaching the volume $at = $vd->detach(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\AttachmentSetResponseData'), $at); $maxTimeout = 200; $interval = 2; while ($maxTimeout > 0) { if (count($vd->attachmentSet) == 0 || $vd->attachmentSet[0]->status == AttachmentSetResponseData::STATUS_DETACHED) { break; } sleep($interval); $maxTimeout -= $interval; $interval *= 2; $vd->refresh(); } if (isset($vd->attachmentSet[0]->status) && $vd->attachmentSet[0]->status !== AttachmentSetResponseData::STATUS_DETACHED) { $this->assertTrue(false, sprintf('The volume %s has not been detached from the instance %s yet.', $volumeid, $ind->instanceId)); } $vd->refresh(); $this->assertContains(self::TAG_NAME_KEY, $vd->tagSet->getQueryArrayBare('Tag')); //Deletes the volume. $ret = $vd->delete(); $this->assertTrue($ret); $this->assertNull($aws->ec2->volume->get($volumeid)); unset($volumeid); unset($vd); unset($at); $ind->refresh(); //Verifies that extratag has been successfully removed $this->assertNotContains('Extratag', $ind->tagSet->getQueryArrayBare()); $consoleOutput = $ind->getConsoleOutput(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\GetConsoleOutputResponseData'), $consoleOutput); unset($consoleOutput); //Reboots the instance $ret = $ind->reboot(); $this->assertTrue($ret); //Stoping the instance $scList = $ind->stop(true); $this->assertInstanceOf($this->getEc2ClassName('DataType\\InstanceStateChangeList'), $scList); $this->assertEquals(1, count($scList)); unset($scList); for ($t = time(); time() - $t < 300 && $ind->instanceState->name !== InstanceStateData::NAME_STOPPED; sleep(5)) { $ind = $ind->refresh(); } $this->assertEquals(InstanceStateData::NAME_STOPPED, $ind->instanceState->name); //For an each attributes it will get it values foreach (InstanceAttributeType::getAllowedValues() as $attibute) { //This is allowed only for VPC instances, so we have to skip if ($attibute == InstanceAttributeType::TYPE_SOURCE_DEST_CHECK) { continue; } $attrValue = $ind->describeAttribute($attibute); } //Modifies instance attribute //Instance is required to be stopped. $ret = $ind->modifyAttribute(InstanceAttributeType::userData(), base64_encode('user data')); $this->assertTrue($ret); //Starts the instance $scList = $ind->start(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\InstanceStateChangeList'), $scList); unset($scList); $ind = $ind->refresh(); for ($t = time(), $s = 5; time() - $t < 200 && $ind->instanceState->name !== InstanceStateData::NAME_RUNNING; $s += 5) { sleep($s); $ind = $ind->refresh(); } $this->assertEquals(InstanceStateData::NAME_RUNNING, $ind->instanceState->name); //Unmonitors instance $ret = $ind->unmonitor(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\MonitorInstancesResponseSetList'), $ret); $this->assertContains($ret->get(0)->monitoring->state, array(InstanceMonitoringStateData::STATE_DISABLING, InstanceMonitoringStateData::STATE_DISABLED)); unset($ret); //Terminates the instance $st = $ind->terminate(); $this->assertInstanceOf($this->getEc2ClassName('DataType\\InstanceStateChangeList'), $st); $this->assertEquals(1, count($st)); $this->assertEquals($rd->instancesSet[0]->instanceId, $st[0]->getInstanceId()); for ($t = time(); time() - $t < 200 && $ind && $ind->instanceState->name != InstanceStateData::NAME_TERMINATED; sleep(5)) { $ind = $ind->refresh(); } $this->assertTrue(!$ind || $ind->instanceState->name == InstanceStateData::NAME_TERMINATED); if (isset($ind)) { unset($ind); } //Removes keypair $ret = $kp->delete(); $this->assertTrue($ret); unset($kp); //Removes security group $sg->delete(); //Verifies that security group is detached from the storage $sgMirror = $aws->ec2->securityGroup->get($sg->groupId); $this->assertNull($sgMirror); unset($sg); //Deletes placement group. $ret = $pg->delete(); $this->assertTrue($ret); $this->assertNull($aws->ec2->placementGroup->get(self::getTestName('placement-group'))); //Releases all memory $aws->getEntityManager()->detachAll(); }
/** * Loads HealthData from simple xml object * * @param \SimpleXMLElement $v * @return HealthData Returns HealthData */ protected function _loadHealthCheckData(\SimpleXMLElement $v) { $item = null; if ($this->exist($v)) { $healthId = (string) $v->Id; $item = new HealthData(); $item->setRoute53($this->route53); $item->setHealthId($healthId)->setCallerReference($v->CallerReference)->setHealthConfig($this->exist($v->HealthCheckConfig) ? $this->_loadHealthCheckConfigData($v->HealthCheckConfig) : null); } return $item; }