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: namespace OpenCloud\LoadBalancer;
19:
20: use OpenCloud\Common\Service\NovaService;
21:
22: /**
23: * Class that encapsulates the Rackspace Cloud Load Balancers service
24: *
25: * @package OpenCloud\LoadBalancer
26: */
27: class Service extends NovaService
28: {
29: const DEFAULT_NAME = 'cloudLoadBalancers';
30: const DEFAULT_TYPE = 'rax:load-balancer';
31:
32: /**
33: * Return a Load Balancer
34: *
35: * @param string $id
36: * @return \OpenCloud\LoadBalancer\Resource\LoadBalancer
37: */
38: public function loadBalancer($id = null)
39: {
40: return $this->resource('LoadBalancer', $id);
41: }
42:
43: /**
44: * Return a paginated collection of load balancers
45: *
46: * @param bool $detail If TRUE, all details are returned; otherwise, a
47: * minimal set (ID, name) is retrieved
48: * @param array $filter Optional query params used for search
49: * @return \OpenCloud\Common\Collection\PaginatedIterator
50: */
51: public function loadBalancerList($detail = true, array $filter = array())
52: {
53: $url = $this->getUrl();
54: $url->addPath(Resource\LoadBalancer::resourceName());
55: if ($detail) {
56: $url->addPath('detail');
57: }
58: $url->setQuery($filter);
59:
60: return $this->resourceList('LoadBalancer', $url);
61: }
62:
63: /**
64: * @deprecated
65: */
66: public function billableLoadBalancer($id = null)
67: {
68: $this->getLogger()->deprecated(__METHOD__, 'loadBalancer');
69:
70: return $this->resource('LoadBalancer', $id);
71: }
72:
73: /**
74: * Returns a paginated collection of load balancers that have been billed
75: * between a certain period.
76: *
77: * @link http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/List_Usage-d1e3014.html
78: * @param array $filter
79: * @return \OpenCloud\Common\Collection\PaginatedIterator
80: */
81: public function billableLoadBalancerList(array $filter = array())
82: {
83: $url = $this->getUrl();
84: $url->addPath(Resource\LoadBalancer::resourceName());
85: $url->addPath('billable');
86: $url->setQuery($filter);
87:
88: return $this->resourceList('LoadBalancer', $url);
89: }
90:
91: /**
92: * Returns an allowed domain
93: *
94: * @param mixed $data either an array of values or null
95: * @return \OpenCloud\LoadBalancer\Resource\AllowedDomain
96: */
97: public function allowedDomain($data = null)
98: {
99: return $this->resource('AllowedDomain', $data);
100: }
101:
102: /**
103: * Returns Collection of AllowedDomain object
104: *
105: * @return \OpenCloud\Common\Collection\PaginatedIterator
106: */
107: public function allowedDomainList()
108: {
109: return $this->resourceList('AllowedDomain');
110: }
111:
112: /**
113: * single protocol (should never be called directly)
114: *
115: * Convenience method to be used by the ProtocolList Collection.
116: *
117: * @return \OpenCloud\LoadBalancer\Resource\Protocol
118: */
119: public function protocol($data = null)
120: {
121: return $this->resource('Protocol', $data);
122: }
123:
124: /**
125: * Returns a list of Protocol objects
126: *
127: * @return \OpenCloud\Common\Collection\PaginatedIterator
128: */
129: public function protocolList()
130: {
131: return $this->resourceList('Protocol');
132: }
133:
134: /**
135: * single algorithm (should never be called directly)
136: *
137: * convenience method used by the Collection factory
138: *
139: * @return \OpenCloud\LoadBalancer\Resource\Algorithm
140: */
141: public function algorithm($data = null)
142: {
143: return $this->resource('Algorithm', $data);
144: }
145:
146: /**
147: * Return a list of Algorithm objects
148: *
149: * @return \OpenCloud\Common\Collection\PaginatedIterator
150: */
151: public function algorithmList()
152: {
153: return $this->resourceList('Algorithm');
154: }
155: }
156: