~yolanda.robla/glance/precise-security

« back to all changes in this revision

Viewing changes to glance/client.py

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2011-05-25 15:57:15 UTC
  • mto: (50.1.2 precise-proposed)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20110525155715-bcf1daw2ntyfly1v
Tags: upstream-2011.3~bzr132
ImportĀ upstreamĀ versionĀ 2011.3~bzr132

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
            return response.status
178
178
 
179
179
 
180
 
class Client(BaseClient):
 
180
class V1Client(BaseClient):
181
181
 
182
182
    """Main client class for accessing Glance resources"""
183
183
 
184
184
    DEFAULT_PORT = 9292
185
185
 
186
 
    def __init__(self, host, port=None, use_ssl=False):
 
186
    def __init__(self, host, port=None, use_ssl=False, doc_root="/v1"):
187
187
        """
188
188
        Creates a new client to a Glance API service.
189
189
 
190
190
        :param host: The host where Glance resides
191
191
        :param port: The port where Glance resides (defaults to 9292)
192
192
        :param use_ssl: Should we use HTTPS? (defaults to False)
 
193
        :param doc_root: Prefix for all URLs we request from host
193
194
        """
194
195
 
195
196
        port = port or self.DEFAULT_PORT
 
197
        self.doc_root = doc_root
196
198
        super(Client, self).__init__(host, port, use_ssl)
197
199
 
 
200
    def do_request(self, method, action, body=None, headers=None):
 
201
        action = "%s/%s" % (self.doc_root, action.lstrip("/"))
 
202
        return super(V1Client, self).do_request(method, action,
 
203
                                                   body, headers)
 
204
 
198
205
    def get_images(self):
199
206
        """
200
207
        Returns a list of image id/name mappings from Registry
288
295
        """
289
296
        self.do_request("DELETE", "/images/%s" % image_id)
290
297
        return True
 
298
 
 
299
 
 
300
Client = V1Client