1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
# Copyright 2012 OpenStack Foundation
3
# Copyright 2013 IBM Corp.
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
9
# http://www.apache.org/licenses/LICENSE-2.0
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
17
from novaclient import client
22
Top-level object to access the OpenStack Compute API.
24
Create an instance with your creds::
26
>>> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
28
Then call methods on its managers::
30
>>> client.servers.list()
32
>>> client.flavors.list()
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',
47
cacert=None, tenant_id=None):
48
#TODO(bnemec): Add back in v3 extensions
50
# Add in any extensions...
52
for extension in extensions:
53
if extension.manager_class:
54
setattr(self, extension.name,
55
extension.manager_class(self))
57
self.client = client.HTTPClient(username,
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,
74
bypass_url=bypass_url,
76
http_log_debug=http_log_debug,
79
def set_management_url(self, url):
80
self.client.set_management_url(url)
82
def get_timings(self):
83
return self.client.get_timings()
85
def reset_timings(self):
86
self.client.reset_timings()
88
def authenticate(self):
90
Authenticate against the server.
92
Normally this is called automatically when you first access the API,
93
but you can call this method to force authentication right now.
95
Returns on success; raises :exc:`exceptions.Unauthorized` if the
96
credentials are wrong.
98
self.client.authenticate()