コード例 #1
0
    def __init__(self,
                 username=None,
                 api_key=None,
                 project_id=None,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 tenant_id=None,
                 project_name=None,
                 region_name=None,
                 endpoint_type='publicURL',
                 extensions=None,
                 service_type=constants.V2_SERVICE_TYPE,
                 service_name=None,
                 retries=None,
                 http_log_debug=False,
                 input_auth_token=None,
                 session=None,
                 auth=None,
                 cacert=None,
                 service_catalog_url=None,
                 user_agent='python-manilaclient',
                 use_keyring=False,
                 force_new_token=False,
                 cached_token_lifetime=300,
                 api_version=manilaclient.API_MIN_VERSION,
                 user_id=None,
                 user_domain_id=None,
                 user_domain_name=None,
                 project_domain_id=None,
                 project_domain_name=None,
                 cert=None,
                 password=None,
                 **kwargs):

        self.username = username
        self.password = password or api_key
        self.tenant_id = tenant_id or project_id
        self.tenant_name = project_name

        self.user_id = user_id
        self.project_id = project_id or tenant_id
        self.project_name = project_name
        self.user_domain_id = user_domain_id
        self.user_domain_name = user_domain_name
        self.project_domain_id = project_domain_id
        self.project_domain_name = project_domain_name

        self.endpoint_type = endpoint_type
        self.auth_url = auth_url
        self.region_name = region_name

        self.cacert = cacert
        self.cert = cert
        self.insecure = insecure

        self.use_keyring = use_keyring
        self.force_new_token = force_new_token
        self.cached_token_lifetime = cached_token_lifetime

        service_name = kwargs.get("share_service_name", service_name)

        if input_auth_token and not service_catalog_url:
            msg = ("For token-based authentication you should "
                   "provide 'input_auth_token' and 'service_catalog_url'.")
            raise exceptions.ClientException(msg)

        self.project_id = tenant_id if tenant_id is not None else project_id
        self.keystone_client = None
        self.session = session

        # NOTE(u_glide): token authorization has highest priority.
        # That's why session and/or password will be ignored
        # if token is provided.
        if not input_auth_token:
            if session:
                self.keystone_client = adapter.LegacyJsonAdapter(
                    session=session,
                    auth=auth,
                    interface=endpoint_type,
                    service_type=service_type,
                    service_name=service_name,
                    region_name=region_name)
                input_auth_token = self.keystone_client.session.get_token(auth)

            else:
                self.keystone_client = self._get_keystone_client()
                input_auth_token = self.keystone_client.auth_token

        if not input_auth_token:
            raise RuntimeError("Not Authorized")

        if session and not service_catalog_url:
            service_catalog_url = self.keystone_client.session.get_endpoint(
                auth, interface=endpoint_type, service_type=service_type)
        elif not service_catalog_url:
            catalog = self.keystone_client.service_catalog.get_endpoints(
                service_type)
            for catalog_entry in catalog.get(service_type, []):
                if (catalog_entry.get("interface")
                        == (endpoint_type.lower().split("url")[0])
                        or catalog_entry.get(endpoint_type)):
                    if (region_name and not region_name == (catalog_entry.get(
                            "region", catalog_entry.get("region_id")))):
                        continue
                    service_catalog_url = catalog_entry.get(
                        "url", catalog_entry.get(endpoint_type))
                    break

        if not service_catalog_url:
            raise RuntimeError("Could not find Manila endpoint in catalog")

        self.api_version = api_version
        self.client = httpclient.HTTPClient(service_catalog_url,
                                            input_auth_token,
                                            user_agent,
                                            insecure=insecure,
                                            cacert=cacert,
                                            timeout=timeout,
                                            retries=retries,
                                            http_log_debug=http_log_debug,
                                            api_version=self.api_version)

        self.availability_zones = availability_zones.AvailabilityZoneManager(
            self)
        self.limits = limits.LimitsManager(self)
        self.messages = messages.MessageManager(self)
        self.services = services.ServiceManager(self)
        self.security_services = security_services.SecurityServiceManager(self)
        self.share_networks = share_networks.ShareNetworkManager(self)

        self.quota_classes = quota_classes.QuotaClassSetManager(self)
        self.quotas = quotas.QuotaSetManager(self)

        self.shares = shares.ShareManager(self)
        self.share_export_locations = (
            share_export_locations.ShareExportLocationManager(self))
        self.share_groups = share_groups.ShareGroupManager(self)
        self.share_group_snapshots = (
            share_group_snapshots.ShareGroupSnapshotManager(self))
        self.share_group_type_access = (
            share_group_type_access.ShareGroupTypeAccessManager(self))
        self.share_group_types = share_group_types.ShareGroupTypeManager(self)
        self.share_instances = share_instances.ShareInstanceManager(self)
        self.share_instance_export_locations = (
            share_instance_export_locations.ShareInstanceExportLocationManager(
                self))
        self.share_snapshots = share_snapshots.ShareSnapshotManager(self)
        self.share_snapshot_instances = (
            share_snapshot_instances.ShareSnapshotInstanceManager(self))
        self.share_snapshot_export_locations = (
            share_snapshot_export_locations.ShareSnapshotExportLocationManager(
                self))
        self.share_snapshot_instance_export_locations = (
            share_snapshot_instance_export_locations.
            ShareSnapshotInstanceExportLocationManager(self))

        self.share_types = share_types.ShareTypeManager(self)
        self.share_type_access = share_type_access.ShareTypeAccessManager(self)
        self.share_servers = share_servers.ShareServerManager(self)
        self.share_replicas = share_replicas.ShareReplicaManager(self)
        self.pools = scheduler_stats.PoolManager(self)

        self._load_extensions(extensions)
コード例 #2
0
    })

user_export_location = share_export_locations.ShareExportLocation(
    share_export_locations.ShareExportLocationManager(FakeAPIClient), {
        'id': 'b6bd76ce-12a2-42a9-a30a-8a43b503867d',
        'path': '2.2.2.2:/path/to/user/share',
        'preferred': True,
        'is_admin_only': False,
        'share_instance_id': 'e1c2d35e-fe67-4028-ad7a-45f668732b1d'
    })

export_locations = [admin_export_location, user_export_location]

admin_snapshot_export_locations = [
    share_snapshot_export_locations.ShareSnapshotExportLocation(
        share_snapshot_export_locations.ShareSnapshotExportLocationManager(
            FakeAPIClient), {
                'id': '6921e862-88bc-49a5-a2df-efeed9acd584',
                'path': '1.1.1.1:/path/to/admin/share',
                'is_admin_only': True,
                'share_snapshot_instance_id':
                'e1c2d35e-fe67-4028-ad7a-45f668732b1e'
            }),
    share_snapshot_export_locations.ShareSnapshotExportLocation(
        share_snapshot_export_locations.ShareSnapshotExportLocationManager(
            FakeAPIClient), {
                'id': '6921e862-88bc-49a5-a2df-efeed9acd585',
                'path': '1.1.1.2:/path/to/admin/share',
                'is_admin_only': False,
                'share_snapshot_instance_id':
                'e1c2d35e-fe67-4028-ad7a-45f668732b1f'
            })