2013-09-20 03:31:42 +08:00
|
|
|
# Copyright (c) 2013 OpenStack Foundation
|
2013-05-06 18:25:26 -05:00
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# under the License.
|
|
|
|
|
2016-04-21 11:28:32 +00:00
|
|
|
import logging
|
|
|
|
|
2016-04-05 15:45:28 -06:00
|
|
|
from cinderclient import api_versions
|
2017-08-01 15:16:22 -04:00
|
|
|
from cinderclient import client
|
2014-03-11 18:29:13 +02:00
|
|
|
from cinderclient.v2 import availability_zones
|
2017-08-01 15:16:22 -04:00
|
|
|
from cinderclient.v2 import capabilities
|
2014-07-03 22:37:40 -04:00
|
|
|
from cinderclient.v2 import cgsnapshots
|
|
|
|
from cinderclient.v2 import consistencygroups
|
2013-02-02 13:26:18 -08:00
|
|
|
from cinderclient.v2 import limits
|
2014-12-04 15:47:44 -08:00
|
|
|
from cinderclient.v2 import pools
|
2013-09-05 12:02:59 +08:00
|
|
|
from cinderclient.v2 import qos_specs
|
2013-02-02 13:26:18 -08:00
|
|
|
from cinderclient.v2 import quota_classes
|
|
|
|
from cinderclient.v2 import quotas
|
2013-07-14 23:18:22 +08:00
|
|
|
from cinderclient.v2 import services
|
2013-04-12 10:36:25 +00:00
|
|
|
from cinderclient.v2 import volume_backups
|
|
|
|
from cinderclient.v2 import volume_backups_restore
|
2017-08-01 15:16:22 -04:00
|
|
|
from cinderclient.v2 import volume_encryption_types
|
|
|
|
from cinderclient.v2 import volume_snapshots
|
2015-02-09 13:11:42 -03:00
|
|
|
from cinderclient.v2 import volume_transfers
|
2017-08-01 15:16:22 -04:00
|
|
|
from cinderclient.v2 import volume_type_access
|
|
|
|
from cinderclient.v2 import volume_types
|
|
|
|
from cinderclient.v2 import volumes
|
2013-02-02 13:26:18 -08:00
|
|
|
|
|
|
|
|
|
|
|
class Client(object):
|
|
|
|
"""Top-level object to access the OpenStack Volume API.
|
|
|
|
|
|
|
|
Create an instance with your creds::
|
|
|
|
|
|
|
|
>>> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
|
|
|
|
|
|
|
|
Then call methods on its managers::
|
|
|
|
|
|
|
|
>>> client.volumes.list()
|
|
|
|
...
|
|
|
|
"""
|
|
|
|
|
2014-08-25 16:11:16 +10:00
|
|
|
def __init__(self, username=None, api_key=None, project_id=None,
|
|
|
|
auth_url='', insecure=False, timeout=None, tenant_id=None,
|
2013-02-02 13:26:18 -08:00
|
|
|
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
|
|
|
endpoint_type='publicURL', extensions=None,
|
2013-08-07 10:01:26 -07:00
|
|
|
service_type='volumev2', service_name=None,
|
2020-03-24 15:52:04 +11:00
|
|
|
volume_service_name=None, os_endpoint=None, retries=0,
|
2014-11-10 23:53:45 -08:00
|
|
|
http_log_debug=False, cacert=None, auth_system='keystone',
|
2016-04-21 11:28:32 +00:00
|
|
|
auth_plugin=None, session=None, api_version=None,
|
|
|
|
logger=None, **kwargs):
|
2013-02-02 13:26:18 -08:00
|
|
|
# FIXME(comstud): Rename the api_key argument above when we
|
|
|
|
# know it's not being used as keyword argument
|
|
|
|
password = api_key
|
2016-04-05 15:45:28 -06:00
|
|
|
self.version = '2.0'
|
2013-02-02 13:26:18 -08:00
|
|
|
self.limits = limits.LimitsManager(self)
|
|
|
|
|
|
|
|
# extensions
|
|
|
|
self.volumes = volumes.VolumeManager(self)
|
|
|
|
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
|
|
|
|
self.volume_types = volume_types.VolumeTypeManager(self)
|
2014-07-26 17:41:26 -04:00
|
|
|
self.volume_type_access = \
|
|
|
|
volume_type_access.VolumeTypeAccessManager(self)
|
2013-08-21 14:20:41 -04:00
|
|
|
self.volume_encryption_types = \
|
|
|
|
volume_encryption_types.VolumeEncryptionTypeManager(self)
|
2013-09-05 12:02:59 +08:00
|
|
|
self.qos_specs = qos_specs.QoSSpecsManager(self)
|
2013-02-02 13:26:18 -08:00
|
|
|
self.quota_classes = quota_classes.QuotaClassSetManager(self)
|
|
|
|
self.quotas = quotas.QuotaSetManager(self)
|
2013-04-12 10:36:25 +00:00
|
|
|
self.backups = volume_backups.VolumeBackupManager(self)
|
|
|
|
self.restores = volume_backups_restore.VolumeBackupRestoreManager(self)
|
2013-05-22 15:09:56 +00:00
|
|
|
self.transfers = volume_transfers.VolumeTransferManager(self)
|
2013-07-14 23:18:22 +08:00
|
|
|
self.services = services.ServiceManager(self)
|
2014-07-03 22:37:40 -04:00
|
|
|
self.consistencygroups = consistencygroups.\
|
|
|
|
ConsistencygroupManager(self)
|
|
|
|
self.cgsnapshots = cgsnapshots.CgsnapshotManager(self)
|
2013-07-22 15:20:04 -05:00
|
|
|
self.availability_zones = \
|
|
|
|
availability_zones.AvailabilityZoneManager(self)
|
2014-12-04 15:47:44 -08:00
|
|
|
self.pools = pools.PoolManager(self)
|
2015-08-12 19:10:32 -04:00
|
|
|
self.capabilities = capabilities.CapabilitiesManager(self)
|
2016-04-05 15:45:28 -06:00
|
|
|
self.api_version = api_version or api_versions.APIVersion(self.version)
|
2013-02-02 13:26:18 -08:00
|
|
|
|
|
|
|
# Add in any extensions...
|
|
|
|
if extensions:
|
|
|
|
for extension in extensions:
|
|
|
|
if extension.manager_class:
|
|
|
|
setattr(self, extension.name,
|
|
|
|
extension.manager_class(self))
|
|
|
|
|
2016-04-21 11:28:32 +00:00
|
|
|
if not logger:
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2014-05-23 16:27:20 -07:00
|
|
|
self.client = client._construct_http_client(
|
|
|
|
username=username,
|
|
|
|
password=password,
|
|
|
|
project_id=project_id,
|
|
|
|
auth_url=auth_url,
|
2013-02-02 13:26:18 -08:00
|
|
|
insecure=insecure,
|
|
|
|
timeout=timeout,
|
|
|
|
tenant_id=tenant_id,
|
2014-05-23 16:27:20 -07:00
|
|
|
proxy_tenant_id=tenant_id,
|
2013-02-02 13:26:18 -08:00
|
|
|
proxy_token=proxy_token,
|
|
|
|
region_name=region_name,
|
|
|
|
endpoint_type=endpoint_type,
|
|
|
|
service_type=service_type,
|
|
|
|
service_name=service_name,
|
|
|
|
volume_service_name=volume_service_name,
|
2020-03-24 15:52:04 +11:00
|
|
|
os_endpoint=os_endpoint,
|
2013-02-02 13:26:18 -08:00
|
|
|
retries=retries,
|
|
|
|
http_log_debug=http_log_debug,
|
2014-02-14 13:42:58 -06:00
|
|
|
cacert=cacert,
|
|
|
|
auth_system=auth_system,
|
2014-05-23 16:27:20 -07:00
|
|
|
auth_plugin=auth_plugin,
|
2014-08-25 16:11:16 +10:00
|
|
|
session=session,
|
2016-05-10 14:31:00 -06:00
|
|
|
api_version=self.api_version,
|
2016-04-21 11:28:32 +00:00
|
|
|
logger=logger,
|
2014-08-25 16:11:16 +10:00
|
|
|
**kwargs)
|
2013-02-02 13:26:18 -08:00
|
|
|
|
|
|
|
def authenticate(self):
|
|
|
|
"""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.
|
|
|
|
|
|
|
|
Returns on success; raises :exc:`exceptions.Unauthorized` if the
|
|
|
|
credentials are wrong.
|
|
|
|
"""
|
|
|
|
self.client.authenticate()
|
2013-06-10 13:08:29 +04:00
|
|
|
|
|
|
|
def get_volume_api_version_from_endpoint(self):
|
|
|
|
return self.client.get_volume_api_version_from_endpoint()
|