~ubuntu-branches/ubuntu/vivid/php-opencloud/vivid

« back to all changes in this revision

Viewing changes to samples/loadbalancers/listlb.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-07-20 13:48:45 UTC
  • mfrom: (2.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20140720134845-0dsedgwivztyrjow
Tags: 1.10.0-2
* Make dir_to_symlink Wheezy-compatible
* Upload to unstable as needed by latest owncloud version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * (c)2012 Rackspace Hosting. See COPYING for license details
4
 
 *
5
 
 */
6
 
$start = time();
7
 
 
8
 
require_once "php-opencloud.php";
9
 
 
10
 
/**
11
 
 * Relies upon environment variable settings — these are the same environment
12
 
 * variables that are used by python-novaclient. Just make sure that they're
13
 
 * set to the right values before running this test.
14
 
 */
15
 
define('AUTHURL', RACKSPACE_US);
16
 
define('USERNAME', $_ENV['OS_USERNAME']);
17
 
define('TENANT', $_ENV['OS_TENANT_NAME']);
18
 
define('APIKEY', $_ENV['NOVA_API_KEY']);
19
 
 
20
 
define('VOLUMENAME', 'SampleVolume');
21
 
define('VOLUMESIZE', 100);
22
 
 
23
 
/**
24
 
 * numbers each step
25
 
 */
26
 
function step($msg,$p1=NULL,$p2=NULL,$p3=NULL) {
27
 
    global $STEPCOUNTER;
28
 
    printf("\nStep %d. %s\n", ++$STEPCOUNTER, sprintf($msg,$p1,$p2,$p3));
29
 
}
30
 
function info($msg,$p1=NULL,$p2=NULL,$p3=NULL,$p4=NULL,$p5=NULL) {
31
 
    printf("  %s\n", sprintf($msg,$p1,$p2,$p3,$p4,$p5));
32
 
}
33
 
define('TIMEFORMAT', 'r');
34
 
 
35
 
step('Authenticate');
36
 
$rackspace = new \OpenCloud\Rackspace(AUTHURL,
37
 
        array( 'username' => USERNAME,
38
 
                   'apiKey' => APIKEY ));
39
 
 
40
 
step('Connect to the Load Balancer Service');
41
 
$lbservice = $rackspace->LoadBalancerService('cloudLoadBalancers', 'DFW');
42
 
 
43
 
// allowed domains
44
 
$adlist = $lbservice->AllowedDomainList();
45
 
while($ad = $adlist->Next()) {
46
 
        info('Allowed domain: [%s]', $ad->Name());
47
 
}
48
 
 
49
 
// protocols
50
 
info('Protocols:');
51
 
$prolist = $lbservice->ProtocolList();
52
 
while($prot = $prolist->Next()) {
53
 
        info('  %s %4d', 
54
 
                substr($prot->Name().'.....................',0,20), $prot->port);
55
 
}
56
 
 
57
 
// algorithms
58
 
info('Algorithms:');
59
 
$alist = $lbservice->AlgorithmList();
60
 
while($al = $alist->Next()) {
61
 
        info('  %s', $al->Name());
62
 
}
63
 
 
64
 
// list load balancers
65
 
$list = $lbservice->LoadBalancerList();
66
 
if ($list->Size()) {
67
 
        step('Load balancers:');
68
 
        while($lb = $list->Next()) {
69
 
                info('[%s] %s in %s', $lb->id, $lb->Name(), $lb->Region());
70
 
                info('  Status: [%s]', $lb->Status());
71
 
                
72
 
                // Nodes
73
 
                $list = $lb->NodeList();
74
 
                if ($list->Size() == 0)
75
 
                        info('  No nodes');
76
 
                else {
77
 
                        while($node = $list->Next()) {
78
 
                                info('  Node: [%s] %s:%d %s/%s', 
79
 
                                        $node->Id(), $node->address, $node->port,
80
 
                                        $node->condition, $node->status);
81
 
                        }
82
 
                }
83
 
                
84
 
                // NodeEvents
85
 
                $list = $lb->NodeEventList();
86
 
                if ($list->Size() == 0)
87
 
                        info('  No node events');
88
 
                else {
89
 
                        while($event = $list->Next()) {
90
 
                                info('  * Event: %s (%s)', 
91
 
                                        $event->detailedMessage, $event->author);
92
 
                        }
93
 
                }
94
 
                
95
 
                // SSL Termination
96
 
                try {
97
 
                        $ssl = $lb->SSLTermination();
98
 
                        info('  SSL terminated');
99
 
                } catch (OpenCloud\InstanceNotFound $e) {
100
 
                        info('  No SSL termination');
101
 
                }
102
 
                
103
 
                // Metadata
104
 
                $list = $lb->MetadataList();
105
 
                while($meta = $list->Next()) {
106
 
                        info('  [Metadata #%s] %s=%s', 
107
 
                                $meta->Id(), $meta->key, $meta->value);
108
 
                }
109
 
        }
110
 
}
111
 
else
112
 
        step('There are no load balancers');
113
 
 
114
 
// list Billable LBs
115
 
$start = date('Y-m-d', time()-(3600*24*30));
116
 
$end = date('Y-m-d');
117
 
step('Billable Load Balancers from %s to %s', $start, $end);
118
 
$list = $lbservice->BillableLoadBalancerList(
119
 
        TRUE,
120
 
        array('startTime'=>$start, 'endTime'=>$end));
121
 
if ($list->Size() > 0) {
122
 
        while($lb = $list->Next()) {
123
 
                info('%10s %s', $lb->Id(), $lb->Name());
124
 
                info('%10s created: %s', '', $lb->created->time);
125
 
        }
126
 
}
127
 
else
128
 
        info('None');
129
 
 
130
 
step('DONE');
131
 
exit;
132
 
 
133
 
function dot($obj) {
134
 
        info('...%s', $obj->Status());
135
 
}