Skip to content

Commit ff3a4bd

Browse files
author
Jamie Hannaford
committed
Adding more LB sample scripts
1 parent bd4162d commit ff3a4bd

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

samples/LoadBalancer/create-lb.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// Prior to running this script, you must setup the following environment variables:
19+
// * RS_AUTH_URL: your Rackspace authentication URL
20+
// * RS_USERNAME: your Rackspace username
21+
// * RS_API_KEY: your Rackspace API key
22+
// * RS_REGION: the Rackspace Cloud region you want to use
23+
24+
require dirname(__DIR__) . '/../vendor/autoload.php';
25+
26+
use OpenCloud\Rackspace;
27+
28+
$client = new Rackspace(getenv('RS_AUTH_URL'), array(
29+
'username' => getenv('RS_USERNAME'),
30+
'apiKey' => getenv('RS_API_KEY'),
31+
));
32+
33+
$service = $client->loadBalancerService(null, getenv('RS_REGION'));
34+
35+
// Create empty object
36+
$lb = $service->loadBalancer();
37+
38+
// Optional: add back-end nodes that need to be load balanced. These are
39+
// usually servers.
40+
$serverNode = $lb->node(array(
41+
'address' => '{ipAddress}', // substitute your server's IPv4 address
42+
'port' => 80,
43+
'condition' => 'ENABLED',
44+
));
45+
46+
// Configure the type of Virtual IP your LB will use
47+
$lb->addVirtualIp('PUBLIC');
48+
49+
// Create it
50+
$lb->create(array(
51+
'name' => '{name}',
52+
'port' => 80,
53+
'protocol' => 'HTTP',
54+
'nodes' => array($serverNode)
55+
));

samples/LoadBalancer/delete-lb.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// Prior to running this script, you must setup the following environment variables:
19+
// * RS_AUTH_URL: your Rackspace authentication URL
20+
// * RS_USERNAME: your Rackspace username
21+
// * RS_API_KEY: your Rackspace API key
22+
// * RS_REGION: the Rackspace Cloud region you want to use
23+
24+
require dirname(__DIR__) . '/../vendor/autoload.php';
25+
26+
use OpenCloud\Rackspace;
27+
28+
$client = new Rackspace(getenv('RS_AUTH_URL'), array(
29+
'username' => getenv('RS_USERNAME'),
30+
'apiKey' => getenv('RS_API_KEY'),
31+
));
32+
33+
$service = $client->loadBalancerService(null, getenv('RS_REGION'));
34+
35+
// Retrieve existing LB
36+
$lb = $service->loadBalancer('{loadBalancerId}');
37+
38+
// Delete
39+
$lb->delete();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// Prior to running this script, you must setup the following environment variables:
19+
// * RS_AUTH_URL: your Rackspace authentication URL
20+
// * RS_USERNAME: your Rackspace username
21+
// * RS_API_KEY: your Rackspace API key
22+
// * RS_REGION: the Rackspace Cloud region you want to use
23+
24+
require dirname(__DIR__) . '/../vendor/autoload.php';
25+
26+
use OpenCloud\Rackspace;
27+
28+
$client = new Rackspace(getenv('RS_AUTH_URL'), array(
29+
'username' => getenv('RS_USERNAME'),
30+
'apiKey' => getenv('RS_API_KEY'),
31+
));
32+
33+
$service = $client->loadBalancerService(null, getenv('RS_REGION'));
34+
35+
// Retrieve existing LB
36+
$lb = $service->loadBalancer('{loadBalancerId}');
37+
38+
// Update SSL config
39+
$sslConfig = $lb->SSLTermination();
40+
$sslConfig->update(array(
41+
'enabled' => true,
42+
'securePort' => 443,
43+
'privateKey' => '{privateKey}', // specify your private key
44+
'certificate' => '{certificate}', // specify your SSL certificate
45+
));
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// Prior to running this script, you must setup the following environment variables:
19+
// * RS_AUTH_URL: your Rackspace authentication URL
20+
// * RS_USERNAME: your Rackspace username
21+
// * RS_API_KEY: your Rackspace API key
22+
// * RS_REGION: the Rackspace Cloud region you want to use
23+
24+
require dirname(__DIR__) . '/../vendor/autoload.php';
25+
26+
use OpenCloud\Rackspace;
27+
28+
$client = new Rackspace(getenv('RS_AUTH_URL'), array(
29+
'username' => getenv('RS_USERNAME'),
30+
'apiKey' => getenv('RS_API_KEY'),
31+
));
32+
33+
$service = $client->loadBalancerService(null, getenv('RS_REGION'));
34+
35+
// Retrieve existing LB
36+
$lb = $service->loadBalancer('{loadBalancerId}');
37+
38+
// Set up throttling
39+
$throttle = $lb->connectionThrottle();
40+
41+
// Allow a maximum of 5,000 simultaneous connections (maxConnections) per
42+
// minute (rateInterval). Limit each IP to a maximum of 50 connections (maxConnectionRate).
43+
$throttle->create(array(
44+
'maxConnections' => 5000,
45+
'minConnections' => 10,
46+
'rateInterval' => 60,
47+
'maxConnectionRate' => 50
48+
));

0 commit comments

Comments
 (0)