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
|
|
|
|
2015-09-10 15:16:54 +03:00
|
|
|
from novaclient import api_versions
|
2011-08-03 17:41:33 -04:00
|
|
|
from novaclient import client
|
2015-09-09 14:02:42 +03:00
|
|
|
from novaclient.i18n import _LW
|
2015-02-03 02:32:58 +02:00
|
|
|
from novaclient.v2 import agents
|
|
|
|
from novaclient.v2 import aggregates
|
|
|
|
from novaclient.v2 import availability_zones
|
|
|
|
from novaclient.v2 import certs
|
|
|
|
from novaclient.v2 import cloudpipe
|
|
|
|
from novaclient.v2 import fixed_ips
|
|
|
|
from novaclient.v2 import flavor_access
|
|
|
|
from novaclient.v2 import flavors
|
|
|
|
from novaclient.v2 import floating_ip_dns
|
|
|
|
from novaclient.v2 import floating_ip_pools
|
|
|
|
from novaclient.v2 import floating_ips
|
|
|
|
from novaclient.v2 import floating_ips_bulk
|
|
|
|
from novaclient.v2 import fping
|
|
|
|
from novaclient.v2 import hosts
|
|
|
|
from novaclient.v2 import hypervisors
|
|
|
|
from novaclient.v2 import images
|
|
|
|
from novaclient.v2 import keypairs
|
|
|
|
from novaclient.v2 import limits
|
|
|
|
from novaclient.v2 import networks
|
|
|
|
from novaclient.v2 import quota_classes
|
|
|
|
from novaclient.v2 import quotas
|
|
|
|
from novaclient.v2 import security_group_default_rules
|
|
|
|
from novaclient.v2 import security_group_rules
|
|
|
|
from novaclient.v2 import security_groups
|
|
|
|
from novaclient.v2 import server_groups
|
|
|
|
from novaclient.v2 import servers
|
|
|
|
from novaclient.v2 import services
|
|
|
|
from novaclient.v2 import usage
|
|
|
|
from novaclient.v2 import versions
|
|
|
|
from novaclient.v2 import virtual_interfaces
|
|
|
|
from novaclient.v2 import volume_snapshots
|
|
|
|
from novaclient.v2 import volume_types
|
|
|
|
from novaclient.v2 import volumes
|
2011-01-25 14:01:22 -06:00
|
|
|
|
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
class Client(object):
|
2015-12-07 17:35:19 +09:00
|
|
|
"""Top-level object to access the OpenStack Compute API.
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2015-09-09 14:02:42 +03:00
|
|
|
.. warning:: All scripts and projects should not initialize this class
|
|
|
|
directly. It should be done via `novaclient.client.Client` interface.
|
2011-08-03 17:41:33 -04:00
|
|
|
"""
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2014-04-08 11:40:41 +10:00
|
|
|
def __init__(self, username=None, api_key=None, project_id=None,
|
|
|
|
auth_url=None, insecure=False, timeout=None,
|
|
|
|
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
|
|
|
endpoint_type='publicURL', extensions=None,
|
|
|
|
service_type='compute', service_name=None,
|
|
|
|
volume_service_name=None, timings=False, bypass_url=None,
|
|
|
|
os_cache=False, no_cache=True, http_log_debug=False,
|
|
|
|
auth_system='keystone', auth_plugin=None, auth_token=None,
|
|
|
|
cacert=None, tenant_id=None, user_id=None,
|
|
|
|
connection_pool=False, session=None, auth=None,
|
2015-09-09 14:02:42 +03:00
|
|
|
api_version=None, direct_use=True, **kwargs):
|
2015-12-07 17:35:19 +09:00
|
|
|
"""Initialization of Client object.
|
|
|
|
|
2015-03-11 15:29:14 +11:00
|
|
|
:param str username: Username
|
|
|
|
:param str api_key: API Key
|
|
|
|
:param str project_id: Project ID
|
|
|
|
:param str auth_url: Auth URL
|
|
|
|
:param bool insecure: Allow insecure
|
|
|
|
:param float timeout: API timeout, None or 0 disables
|
|
|
|
:param str proxy_tenant_id: Tenant ID
|
|
|
|
:param str proxy_token: Proxy Token
|
|
|
|
:param str region_name: Region Name
|
|
|
|
:param str endpoint_type: Endpoint Type
|
|
|
|
:param str extensions: Exensions
|
|
|
|
:param str service_type: Service Type
|
|
|
|
:param str service_name: Service Name
|
|
|
|
:param str volume_service_name: Volume Service Name
|
|
|
|
:param bool timings: Timings
|
|
|
|
:param str bypass_url: Bypass URL
|
|
|
|
:param bool os_cache: OS cache
|
|
|
|
:param bool no_cache: No cache
|
|
|
|
:param bool http_log_debug: Enable debugging for HTTP connections
|
|
|
|
:param str auth_system: Auth system
|
|
|
|
:param str auth_plugin: Auth plugin
|
|
|
|
:param str auth_token: Auth token
|
|
|
|
:param str cacert: cacert
|
|
|
|
:param str tenant_id: Tenant ID
|
|
|
|
:param str user_id: User ID
|
|
|
|
:param bool connection_pool: Use a connection pool
|
|
|
|
:param str session: Session
|
|
|
|
:param str auth: Auth
|
2015-04-02 16:37:59 +03:00
|
|
|
:param api_version: Compute API version
|
|
|
|
:type api_version: novaclient.api_versions.APIVersion
|
2015-03-11 15:29:14 +11:00
|
|
|
"""
|
2015-09-09 14:02:42 +03:00
|
|
|
if direct_use:
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
warnings.warn(
|
|
|
|
_LW("'novaclient.v2.client.Client' is not designed to be "
|
|
|
|
"initialized directly. It is inner class of novaclient. "
|
|
|
|
"Please, use 'novaclient.client.Client' instead. "
|
|
|
|
"Related lp bug-report: 1493576"))
|
|
|
|
|
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
|
2014-03-17 15:12:01 +10:30
|
|
|
|
|
|
|
# NOTE(cyeoh): In the novaclient context (unlike Nova) the
|
|
|
|
# project_id is not the same as the tenant_id. Here project_id
|
|
|
|
# is a name (what the Nova API often refers to as a project or
|
|
|
|
# tenant name) and tenant_id is a UUID (what the Nova API
|
|
|
|
# often refers to as a project_id or tenant_id).
|
|
|
|
|
2011-11-17 12:48:58 -08:00
|
|
|
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)
|
2014-07-08 10:56:36 +09:00
|
|
|
self.versions = versions.VersionManager(self)
|
2015-09-10 15:16:54 +03:00
|
|
|
self.api_version = api_version or api_versions.APIVersion("2.0")
|
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)
|
2014-05-29 16:48:32 -03:00
|
|
|
self.quota_classes = quota_classes.QuotaClassSetManager(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)
|
2014-06-05 22:41:34 -06:00
|
|
|
self.security_group_default_rules = \
|
|
|
|
security_group_default_rules.SecurityGroupDefaultRuleManager(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)
|
2014-09-18 14:32:45 +00:00
|
|
|
self.hypervisor_stats = hypervisors.HypervisorStatsManager(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
|
|
|
|
2014-04-08 11:40:41 +10:00
|
|
|
self.client = client._construct_http_client(
|
|
|
|
username=username,
|
|
|
|
password=password,
|
|
|
|
user_id=user_id,
|
|
|
|
project_id=project_id,
|
|
|
|
tenant_id=tenant_id,
|
|
|
|
auth_url=auth_url,
|
|
|
|
auth_token=auth_token,
|
|
|
|
insecure=insecure,
|
|
|
|
timeout=timeout,
|
|
|
|
auth_system=auth_system,
|
|
|
|
auth_plugin=auth_plugin,
|
|
|
|
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,
|
|
|
|
volume_service_name=volume_service_name,
|
|
|
|
timings=timings,
|
|
|
|
bypass_url=bypass_url,
|
|
|
|
os_cache=self.os_cache,
|
|
|
|
http_log_debug=http_log_debug,
|
|
|
|
cacert=cacert,
|
|
|
|
connection_pool=connection_pool,
|
|
|
|
session=session,
|
2014-12-17 15:47:15 +10:00
|
|
|
auth=auth,
|
2015-04-02 16:37:59 +03:00
|
|
|
api_version=api_version,
|
2014-12-17 15:47:15 +10:00
|
|
|
**kwargs)
|
2014-03-26 15:22:03 +04:00
|
|
|
|
2014-04-08 11:40:41 +10:00
|
|
|
@client._original_only
|
2014-03-26 15:22:03 +04:00
|
|
|
def __enter__(self):
|
|
|
|
self.client.open_session()
|
|
|
|
return self
|
|
|
|
|
2014-04-08 11:40:41 +10:00
|
|
|
@client._original_only
|
2014-03-26 15:22:03 +04:00
|
|
|
def __exit__(self, t, v, tb):
|
|
|
|
self.client.close_session()
|
2012-06-15 15:12:23 -03:00
|
|
|
|
2014-04-08 11:40:41 +10:00
|
|
|
@client._original_only
|
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()
|
|
|
|
|
2014-04-08 11:40:41 +10:00
|
|
|
@client._original_only
|
2011-01-25 14:01:22 -06:00
|
|
|
def authenticate(self):
|
2015-12-07 17:35:19 +09:00
|
|
|
"""Authenticate against the server.
|
2011-08-03 17:41:33 -04:00
|
|
|
|
|
|
|
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()
|