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\Image;
19:
20: use OpenCloud\Common\Service\CatalogService;
21: use OpenCloud\Image\Resource\Image;
22: use OpenCloud\Image\Resource\Schema\Schema;
23:
24: /**
25: * Service class that represents OpenStack Glance / Rackspace Cloud Images
26: *
27: * @package OpenCloud\Images
28: */
29: class Service extends CatalogService
30: {
31: const DEFAULT_TYPE = 'image';
32: const DEFAULT_NAME = 'cloudImages';
33:
34: /**
35: * This operation returns images you created, shared images that you accepted, and standard images.
36: *
37: * @param array $params
38: * @return \OpenCloud\Common\Collection\PaginatedIterator
39: */
40: public function listImages(array $params = array())
41: {
42: $url = clone $this->getUrl();
43: $url->addPath(Image::resourceName())->setQuery($params);
44:
45: return $this->resourceList('Image', $url);
46: }
47:
48: /**
49: * Returns details for a specific image.
50: *
51: * @param $imageId
52: * @return object
53: */
54: public function getImage($imageId)
55: {
56: $image = $this->resource('Image');
57: $image->setId($imageId);
58: $image->refresh();
59:
60: return $image;
61: }
62:
63: /**
64: * For iterator use only.
65: *
66: * @param $data
67: * @return object
68: */
69: public function image($data)
70: {
71: $image = $this->resource('Image');
72: $image->setData((array) $data);
73:
74: return $image;
75: }
76:
77: /**
78: * A convenience method which returns the URL needed to retrieve schemas.
79: *
80: * @param $path
81: * @return \Guzzle\Http\Url
82: */
83: protected function getSchemaUrl($path)
84: {
85: $url = clone $this->getUrl();
86:
87: return $url->addPath('schemas')->addPath($path);
88: }
89:
90: /**
91: * Return a JSON schema for a collection of image resources
92: *
93: * @return Schema
94: */
95: public function getImagesSchema()
96: {
97: $data = $this->getClient()->get($this->getSchemaUrl('images'))->send()->json();
98:
99: return Schema::factory($data);
100: }
101:
102: /**
103: * Return a JSON schema for an individual image resource
104: *
105: * @return Schema
106: */
107: public function getImageSchema()
108: {
109: $data = $this->getClient()->get($this->getSchemaUrl('image'))->send()->json();
110:
111: return Schema::factory($data);
112: }
113:
114: /**
115: * Return a JSON schema for a collection of member resources
116: *
117: * @return Schema
118: */
119: public function getMembersSchema()
120: {
121: $data = $this->getClient()->get($this->getSchemaUrl('members'))->send()->json();
122:
123: return Schema::factory($data);
124: }
125:
126: /**
127: * Return a JSON schema for an individual member resource
128: *
129: * @return Schema
130: */
131: public function getMemberSchema()
132: {
133: $data = $this->getClient()->get($this->getSchemaUrl('member'))->send()->json();
134:
135: return Schema::factory($data);
136: }
137: }
138: