2013-03-13 18:09:17 -04:00
|
|
|
# Copyright 2012 OpenStack Foundation
|
2013-02-05 15:14:18 +08:00
|
|
|
# Copyright 2013 IBM Corp.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
2013-06-27 21:42:11 +02:00
|
|
|
# under the License.
|
2013-02-05 15:14:18 +08:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
from novaclient import client
|
2012-11-12 17:04:49 +08:00
|
|
|
from novaclient.v1_1 import agents
|
2012-01-13 13:36:01 +00:00
|
|
|
from novaclient.v1_1 import aggregates
|
2013-02-05 15:14:18 +08:00
|
|
|
from novaclient.v1_1 import availability_zones
|
2013-12-11 17:38:56 +00:00
|
|
|
from novaclient.v1_1 import certs
|
|
|
|
from novaclient.v1_1 import cloudpipe
|
|
|
|
from novaclient.v1_1 import fixed_ips
|
2012-08-13 20:25:05 +08:00
|
|
|
from novaclient.v1_1 import flavor_access
|
2013-12-11 17:38:56 +00:00
|
|
|
from novaclient.v1_1 import flavors
|
2011-12-28 17:33:43 -06:00
|
|
|
from novaclient.v1_1 import floating_ip_dns
|
2012-01-09 14:49:12 -08:00
|
|
|
from novaclient.v1_1 import floating_ip_pools
|
2013-12-11 17:38:56 +00:00
|
|
|
from novaclient.v1_1 import floating_ips
|
|
|
|
from novaclient.v1_1 import floating_ips_bulk
|
2012-11-19 11:33:50 +02:00
|
|
|
from novaclient.v1_1 import fping
|
2012-02-03 19:04:30 +09:00
|
|
|
from novaclient.v1_1 import hosts
|
2012-06-27 18:45:28 -05:00
|
|
|
from novaclient.v1_1 import hypervisors
|
2011-08-03 17:41:33 -04:00
|
|
|
from novaclient.v1_1 import images
|
2011-08-06 13:08:53 -07:00
|
|
|
from novaclient.v1_1 import keypairs
|
2011-12-06 12:11:50 -05:00
|
|
|
from novaclient.v1_1 import limits
|
2012-08-22 15:41:50 +03:00
|
|
|
from novaclient.v1_1 import networks
|
2011-12-06 12:11:50 -05:00
|
|
|
from novaclient.v1_1 import quotas
|
2011-08-10 14:55:50 -05:00
|
|
|
from novaclient.v1_1 import security_group_rules
|
2011-08-13 16:17:21 -07:00
|
|
|
from novaclient.v1_1 import security_groups
|
2013-06-13 15:25:39 +00:00
|
|
|
from novaclient.v1_1 import server_groups
|
2011-08-03 17:41:33 -04:00
|
|
|
from novaclient.v1_1 import servers
|
2013-12-11 17:38:56 +00:00
|
|
|
from novaclient.v1_1 import services
|
2012-01-22 18:56:39 -05:00
|
|
|
from novaclient.v1_1 import usage
|
2012-01-24 11:20:51 -08:00
|
|
|
from novaclient.v1_1 import virtual_interfaces
|
2011-11-09 10:36:16 -08:00
|
|
|
from novaclient.v1_1 import volume_snapshots
|
2012-02-17 16:29:59 -05:00
|
|
|
from novaclient.v1_1 import volume_types
|
2013-12-11 17:38:56 +00:00
|
|
|
from novaclient.v1_1 import volumes
|
2011-01-25 14:01:22 -06:00
|
|
|
|
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
class Client(object):
|
|
|
|
"""
|
|
|
|
Top-level object to access the OpenStack Compute API.
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
Create an instance with your creds::
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-11-09 04:35:39 -08:00
|
|
|
>>> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
Then call methods on its managers::
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
>>> client.servers.list()
|
|
|
|
...
|
|
|
|
>>> client.flavors.list()
|
|
|
|
...
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2014-03-26 15:22:03 +04:00
|
|
|
It is also possible to use an instance as a context manager in which
|
|
|
|
case there will be a session kept alive for the duration of the with
|
|
|
|
statement::
|
|
|
|
|
|
|
|
>>> with Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL) as client:
|
|
|
|
... client.servers.list()
|
|
|
|
... client.flavors.list()
|
|
|
|
...
|
|
|
|
|
|
|
|
It is also possible to have a permanent (process-long) connection pool,
|
|
|
|
by passing a connection_pool=True::
|
|
|
|
|
|
|
|
>>> client = Client(USERNAME, PASSWORD, PROJECT_ID,
|
|
|
|
... AUTH_URL, connection_pool=True)
|
2011-08-03 17:41:33 -04:00
|
|
|
"""
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2013-07-12 08:27:28 +01:00
|
|
|
# FIXME(jesse): project_id isn't required to authenticate
|
|
|
|
def __init__(self, username, api_key, project_id, auth_url=None,
|
2012-03-06 22:40:28 -06:00
|
|
|
insecure=False, timeout=None, proxy_tenant_id=None,
|
|
|
|
proxy_token=None, region_name=None,
|
2012-01-31 18:08:22 -06:00
|
|
|
endpoint_type='publicURL', extensions=None,
|
2012-04-12 15:41:35 -05:00
|
|
|
service_type='compute', service_name=None,
|
2012-06-18 17:37:45 -03:00
|
|
|
volume_service_name=None, timings=False,
|
2012-12-07 11:47:49 -05:00
|
|
|
bypass_url=None, os_cache=False, no_cache=True,
|
2012-12-18 14:05:29 -06:00
|
|
|
http_log_debug=False, auth_system='keystone',
|
2013-12-19 19:26:06 +00:00
|
|
|
auth_plugin=None, auth_token=None,
|
2014-03-26 15:22:03 +04:00
|
|
|
cacert=None, tenant_id=None, user_id=None,
|
|
|
|
connection_pool=False):
|
2011-11-17 12:48:58 -08:00
|
|
|
# FIXME(comstud): Rename the api_key argument above when we
|
|
|
|
# know it's not being used as keyword argument
|
|
|
|
password = api_key
|
2013-07-12 08:27:28 +01:00
|
|
|
self.projectid = project_id
|
2013-06-27 22:57:10 +01:00
|
|
|
self.tenant_id = tenant_id
|
2014-03-06 12:37:12 +00:00
|
|
|
self.user_id = user_id
|
2011-08-03 17:41:33 -04:00
|
|
|
self.flavors = flavors.FlavorManager(self)
|
2012-08-13 20:25:05 +08:00
|
|
|
self.flavor_access = flavor_access.FlavorAccessManager(self)
|
2011-08-03 17:41:33 -04:00
|
|
|
self.images = images.ImageManager(self)
|
2011-12-06 12:11:50 -05:00
|
|
|
self.limits = limits.LimitsManager(self)
|
2011-08-03 17:41:33 -04:00
|
|
|
self.servers = servers.ServerManager(self)
|
2011-08-06 13:08:53 -07:00
|
|
|
|
|
|
|
# extensions
|
2012-11-12 17:04:49 +08:00
|
|
|
self.agents = agents.AgentsManager(self)
|
2012-01-15 20:05:10 -06:00
|
|
|
self.dns_domains = floating_ip_dns.FloatingIPDNSDomainManager(self)
|
|
|
|
self.dns_entries = floating_ip_dns.FloatingIPDNSEntryManager(self)
|
2012-03-22 12:23:39 +01:00
|
|
|
self.cloudpipe = cloudpipe.CloudpipeManager(self)
|
2012-01-20 15:08:53 -08:00
|
|
|
self.certs = certs.CertificateManager(self)
|
2011-12-06 12:11:50 -05:00
|
|
|
self.floating_ips = floating_ips.FloatingIPManager(self)
|
2012-01-09 14:49:12 -08:00
|
|
|
self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
|
2012-11-19 11:33:50 +02:00
|
|
|
self.fping = fping.FpingManager(self)
|
2011-09-29 08:09:50 -07:00
|
|
|
self.volumes = volumes.VolumeManager(self)
|
2011-11-09 10:36:16 -08:00
|
|
|
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
|
2012-02-17 16:29:59 -05:00
|
|
|
self.volume_types = volume_types.VolumeTypeManager(self)
|
2011-08-06 13:08:53 -07:00
|
|
|
self.keypairs = keypairs.KeypairManager(self)
|
2012-08-22 15:41:50 +03:00
|
|
|
self.networks = networks.NetworkManager(self)
|
2011-08-08 14:48:07 -07:00
|
|
|
self.quotas = quotas.QuotaSetManager(self)
|
2011-08-13 16:17:21 -07:00
|
|
|
self.security_groups = security_groups.SecurityGroupManager(self)
|
|
|
|
self.security_group_rules = \
|
|
|
|
security_group_rules.SecurityGroupRuleManager(self)
|
2012-01-22 18:56:39 -05:00
|
|
|
self.usage = usage.UsageManager(self)
|
2012-01-24 11:20:51 -08:00
|
|
|
self.virtual_interfaces = \
|
|
|
|
virtual_interfaces.VirtualInterfaceManager(self)
|
2012-01-13 13:36:01 +00:00
|
|
|
self.aggregates = aggregates.AggregateManager(self)
|
2012-02-03 19:04:30 +09:00
|
|
|
self.hosts = hosts.HostManager(self)
|
2012-06-27 18:45:28 -05:00
|
|
|
self.hypervisors = hypervisors.HypervisorManager(self)
|
2012-11-08 17:56:18 +08:00
|
|
|
self.services = services.ServiceManager(self)
|
2012-11-22 22:43:59 +10:30
|
|
|
self.fixed_ips = fixed_ips.FixedIPsManager(self)
|
2012-11-28 18:39:15 +10:30
|
|
|
self.floating_ips_bulk = floating_ips_bulk.FloatingIPBulkManager(self)
|
2012-12-07 11:47:49 -05:00
|
|
|
self.os_cache = os_cache or not no_cache
|
2013-02-05 15:14:18 +08:00
|
|
|
self.availability_zones = \
|
|
|
|
availability_zones.AvailabilityZoneManager(self)
|
2013-06-13 15:25:39 +00:00
|
|
|
self.server_groups = server_groups.ServerGroupsManager(self)
|
2011-08-03 16:36:03 -04:00
|
|
|
|
2011-12-15 19:39:33 +00:00
|
|
|
# Add in any extensions...
|
|
|
|
if extensions:
|
2011-12-21 19:25:19 +00:00
|
|
|
for extension in extensions:
|
|
|
|
if extension.manager_class:
|
|
|
|
setattr(self, extension.name,
|
|
|
|
extension.manager_class(self))
|
2011-12-15 19:39:33 +00:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
self.client = client.HTTPClient(username,
|
2012-04-12 15:41:35 -05:00
|
|
|
password,
|
2014-03-06 12:37:12 +00:00
|
|
|
user_id=user_id,
|
2013-07-12 08:27:28 +01:00
|
|
|
projectid=project_id,
|
2013-06-27 22:57:10 +01:00
|
|
|
tenant_id=tenant_id,
|
|
|
|
auth_url=auth_url,
|
2013-12-19 19:26:06 +00:00
|
|
|
auth_token=auth_token,
|
2012-04-12 15:41:35 -05:00
|
|
|
insecure=insecure,
|
|
|
|
timeout=timeout,
|
2012-08-02 16:41:47 +02:00
|
|
|
auth_system=auth_system,
|
2013-03-06 16:41:46 +01:00
|
|
|
auth_plugin=auth_plugin,
|
2012-04-12 15:41:35 -05:00
|
|
|
proxy_token=proxy_token,
|
|
|
|
proxy_tenant_id=proxy_tenant_id,
|
|
|
|
region_name=region_name,
|
|
|
|
endpoint_type=endpoint_type,
|
|
|
|
service_type=service_type,
|
|
|
|
service_name=service_name,
|
2012-06-15 15:12:23 -03:00
|
|
|
volume_service_name=volume_service_name,
|
2012-06-18 17:37:45 -03:00
|
|
|
timings=timings,
|
|
|
|
bypass_url=bypass_url,
|
2012-12-07 11:47:49 -05:00
|
|
|
os_cache=self.os_cache,
|
2012-12-18 14:05:29 -06:00
|
|
|
http_log_debug=http_log_debug,
|
2014-03-26 15:22:03 +04:00
|
|
|
cacert=cacert,
|
|
|
|
connection_pool=connection_pool)
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.client.open_session()
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, t, v, tb):
|
|
|
|
self.client.close_session()
|
2012-06-15 15:12:23 -03:00
|
|
|
|
|
|
|
def set_management_url(self, url):
|
2012-06-18 17:37:45 -03:00
|
|
|
self.client.set_management_url(url)
|
2012-06-15 15:12:23 -03:00
|
|
|
|
|
|
|
def get_timings(self):
|
|
|
|
return self.client.get_timings()
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2012-06-28 17:00:47 -03:00
|
|
|
def reset_timings(self):
|
|
|
|
self.client.reset_timings()
|
|
|
|
|
2011-01-25 14:01:22 -06:00
|
|
|
def authenticate(self):
|
|
|
|
"""
|
2011-08-03 17:41:33 -04:00
|
|
|
Authenticate against the server.
|
|
|
|
|
|
|
|
Normally this is called automatically when you first access the API,
|
|
|
|
but you can call this method to force authentication right now.
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
Returns on success; raises :exc:`exceptions.Unauthorized` if the
|
|
|
|
credentials are wrong.
|
2011-01-25 14:01:22 -06:00
|
|
|
"""
|
2011-08-03 17:41:33 -04:00
|
|
|
self.client.authenticate()
|