~ubuntu-branches/ubuntu/saucy/python-novaclient/saucy-proposed

« back to all changes in this revision

Viewing changes to novaclient/v3/client.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-09-24 09:15:12 UTC
  • mfrom: (1.1.31)
  • Revision ID: package-import@ubuntu.com-20130924091512-yjzov9e7qa8sdb1v
Tags: 1:2.15.0-0ubuntu1
* New upstream version.
* debian/control:
  - Add python-babel, python-keyring, and python-six build-depends.
  - Dropped python-argparse, python-setuptools-git, python-httplib2,
    python-nose as a build-depends.
  - Dropped python-httplib2 and python-keyring as a dependency.
  - Add versioned depends for python-requests, python-simplejson,
    python-fixtures, testrepesitory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
# Copyright 2012 OpenStack Foundation
 
3
# Copyright 2013 IBM Corp.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    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, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
from novaclient import client
 
18
 
 
19
 
 
20
class Client(object):
 
21
    """
 
22
    Top-level object to access the OpenStack Compute API.
 
23
 
 
24
    Create an instance with your creds::
 
25
 
 
26
        >>> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
 
27
 
 
28
    Then call methods on its managers::
 
29
 
 
30
        >>> client.servers.list()
 
31
        ...
 
32
        >>> client.flavors.list()
 
33
        ...
 
34
 
 
35
    """
 
36
 
 
37
    # FIXME(jesse): project_id isn't required to authenticate
 
38
    def __init__(self, username, password, project_id, auth_url=None,
 
39
                  insecure=False, timeout=None, proxy_tenant_id=None,
 
40
                  proxy_token=None, region_name=None,
 
41
                  endpoint_type='publicURL', extensions=None,
 
42
                  service_type='compute', service_name=None,
 
43
                  volume_service_name=None, timings=False,
 
44
                  bypass_url=None, os_cache=False, no_cache=True,
 
45
                  http_log_debug=False, auth_system='keystone',
 
46
                  auth_plugin=None,
 
47
                  cacert=None, tenant_id=None):
 
48
        #TODO(bnemec): Add back in v3 extensions
 
49
 
 
50
        # Add in any extensions...
 
51
        if extensions:
 
52
            for extension in extensions:
 
53
                if extension.manager_class:
 
54
                    setattr(self, extension.name,
 
55
                            extension.manager_class(self))
 
56
 
 
57
        self.client = client.HTTPClient(username,
 
58
                                    password,
 
59
                                    projectid=project_id,
 
60
                                    tenant_id=tenant_id,
 
61
                                    auth_url=auth_url,
 
62
                                    insecure=insecure,
 
63
                                    timeout=timeout,
 
64
                                    auth_system=auth_system,
 
65
                                    auth_plugin=auth_plugin,
 
66
                                    proxy_token=proxy_token,
 
67
                                    proxy_tenant_id=proxy_tenant_id,
 
68
                                    region_name=region_name,
 
69
                                    endpoint_type=endpoint_type,
 
70
                                    service_type=service_type,
 
71
                                    service_name=service_name,
 
72
                                    volume_service_name=volume_service_name,
 
73
                                    timings=timings,
 
74
                                    bypass_url=bypass_url,
 
75
                                    os_cache=os_cache,
 
76
                                    http_log_debug=http_log_debug,
 
77
                                    cacert=cacert)
 
78
 
 
79
    def set_management_url(self, url):
 
80
        self.client.set_management_url(url)
 
81
 
 
82
    def get_timings(self):
 
83
        return self.client.get_timings()
 
84
 
 
85
    def reset_timings(self):
 
86
        self.client.reset_timings()
 
87
 
 
88
    def authenticate(self):
 
89
        """
 
90
        Authenticate against the server.
 
91
 
 
92
        Normally this is called automatically when you first access the API,
 
93
        but you can call this method to force authentication right now.
 
94
 
 
95
        Returns on success; raises :exc:`exceptions.Unauthorized` if the
 
96
        credentials are wrong.
 
97
        """
 
98
        self.client.authenticate()