Blame view
sources/3rdparty/rackspace/php-opencloud/tests/OpenCloud/Smoke/Unit/LoadBalancer.php
6.41 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
<?php
/**
* PHP OpenCloud library.
*
* @copyright 2014 Rackspace Hosting, Inc. See LICENSE for information.
* @license https://www.apache.org/licenses/LICENSE-2.0
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Smoke\Unit;
use OpenCloud\Smoke\Enum;
use OpenCloud\Smoke\Utils;
use Guzzle\Http\Exception\ClientErrorResponseException;
use OpenCloud\Common\Exceptions\DeleteError;
class LoadBalancer extends AbstractUnit implements UnitInterface
{
const LB_NAME = 'TEST_LB';
public function setupService()
{
return $this->getConnection()->loadBalancerService('cloudLoadBalancers', Utils::getRegion());
}
public function main()
{
$this->step('Connect to the Load Balancer Service');
$this->step('Create a Load Balancer');
$loadBalancer = $this->getService()->loadBalancer();
$loadBalancer->addVirtualIp('public');
$loadBalancer->addNode('192.168.0.1', 80);
$loadBalancer->addNode('192.168.0.2', 80);
$loadBalancer->create(array(
'name' => $this->prepend(self::LB_NAME),
'protocol' => 'HTTP',
'port' => 80
));
$loadBalancer->waitFor('ACTIVE', 300, $this->getWaiterCallback());
$this->step('Add a metadata item');
$metadata = $loadBalancer->metadata();
$metadata->key = 'author';
$metadata->value = 'Jamie';
$metadata->create();
$this->step('Add a public IPv6 address');
$loadBalancer->addVirtualIp('PUBLIC', 6);
// allowed domains
$this->step('List allowed domains');
$allowedDomains = $this->getService()->allowedDomainList();
foreach ($allowedDomains as $allowedDomain) {
$this->stepInfo('Allowed domain: [%s]', $allowedDomain->name());
}
// protocols
$this->step('List protocols:');
$protocolList = $this->getService()->protocolList();
foreach ($protocolList as $protocol) {
$this->stepInfo(
'%s %4d',
substr($protocol->name() . '..................', 0, 20),
$protocol->port
);
}
// algorithms
$this->step('List algorithms:');
$algorithmList = $this->getService()->algorithmList();
foreach ($algorithmList as $algorithm) {
$this->stepInfo('%s', $algorithm->name());
}
// list load balancers
$this->step('Listing load balancers');
$loadBalancers = $this->getService()->loadBalancerList();
$loadBalancers->setOption('limit.total', Enum::DISPLAY_ITER_LIMIT);
if ($loadBalancers->count()) {
$i = 1;
$total = $loadBalancers->count() > 10 ? 10 : $loadBalancers->count();
foreach ($loadBalancers as $loadBalancer) {
$step = $this->stepInfo('Load balancer (%d/%d)', $i, $total);
$step->stepInfo(
'ID [%s], Name [%s], Status [%s]',
$loadBalancer->id,
$loadBalancer->name(),
$loadBalancer->status()
);
// Nodes
$step1 = $step->subStep('Listing nodes');
$nodeList = $loadBalancer->nodeList();
if (!$nodeList->count()) {
$step1->stepInfo('No nodes');
} else {
foreach ($nodeList as $node) {
$step1->stepInfo('Node: [%s] %s:%d %s/%s',
$node->id(),
$node->address,
$node->port,
$node->condition,
$node->status
);
}
}
// NodeEvents
$step2 = $step->subStep('Listing node events');
$nodeEvents = $loadBalancer->nodeEventList();
if (!$nodeEvents->count()) {
$step2->stepInfo('No node events');
} else {
foreach ($nodeEvents as $event) {
$step2->stepInfo('Event: %s (%s)',
$event->detailedMessage,
$event->author
);
}
}
// SSL Termination
try {
$loadBalancer->SSLTermination();
$step->subStep('SSL terminated');
} catch (ClientErrorResponseException $e) {
$step->subStep('No SSL termination');
}
// Metadata
$step3 = $step->subStep('Listing metadata');
$metadataList = $loadBalancer->metadataList();
foreach ($metadataList as $metadataItem) {
$step3->stepInfo('[Metadata #%s] %s=%s',
$metadataItem->Id(),
$metadataItem->key,
$metadataItem->value
);
}
$i++;
}
} else {
$this->stepInfo('There are no load balancers');
}
// list Billable LBs
$start = date('Y-m-d', time() - (3600 * 24 * 30));
$end = date('Y-m-d');
$this->step('Billable Load Balancers from %s to %s', $start, $end);
$list = $this->getService()->billableLoadBalancerList(true, array(
'startTime' => $start,
'endTime' => $end
));
if ($list->count()) {
foreach ($list as $lb) {
$this->stepInfo('%10s %s', $lb->Id(), $lb->name());
$this->stepInfo('%10s created: %s', '', $lb->created->time);
}
} else {
$this->stepInfo('No billable load balancers');
}
}
public function teardown()
{
$this->step('Teardown');
$loadBalancers = $this->getService()->loadBalancerList();
foreach ($loadBalancers as $loadBalancer) {
if ($this->shouldDelete($loadBalancer->name())) {
try {
$this->stepInfo('Deleting %s', $loadBalancer->getId());
$loadBalancer->delete();
} catch (\Exception $e) {
$this->stepInfo('Failed to delete %s', $loadBalancer->getId());
}
}
}
}
}
|