当前位置: 首页>>代码示例>>Python>>正文


Python swiftclient.Connection方法代码示例

本文整理汇总了Python中swiftclient.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python swiftclient.Connection方法的具体用法?Python swiftclient.Connection怎么用?Python swiftclient.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swiftclient的用法示例。


在下文中一共展示了swiftclient.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_swift

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def init_swift(self, name, config):
    """
    Hack needed because Flask FS backend supports only swift 1.0 authentication.
    """
    import swiftclient

    super(SwiftBackend, self).__init__(name, config)
    version = "3"
    if "2.0" in config.authurl:
        version = "2.0"
    self.conn = swiftclient.Connection(
        user=config.user,
        key=config.key,
        authurl=config.authurl,
        auth_version=version,
        os_options={
            "tenant_name": config.tenant_name,
            "region_name": config.region_name,
        },
    )
    self.conn.put_container(self.name) 
开发者ID:cgwire,项目名称:zou,代码行数:23,代码来源:file_store.py

示例2: get_manager

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def get_manager(self, store_location, context=None, allow_reauth=False):
        """Return appropriate connection manager for store

        The method detects store type (singletenant or multitenant) and returns
        appropriate connection manager (singletenant or multitenant) that
        allows to request swiftclient connections.

        :param store_location: StoreLocation object that define image location
        :param context: user context
        :param allow_reauth: defines if we allow re-authentication when user
            token is expired and refresh swift connection

        :return: connection manager for store
        """
        msg = _("There is no Connection Manager implemented for %s class.")
        raise NotImplementedError(msg % self.__class__.__name__) 
开发者ID:openstack,项目名称:glance_store,代码行数:18,代码来源:store.py

示例3: setup

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def setup(self):
        self.conn = swiftclient.Connection(
            user=USER,
            key=KEY,
            authurl=AUTHURL,
        )
        self.container = 'test'

        self.config = Config({
            'user': USER,
            'key': KEY,
            'authurl': AUTHURL,
        })
        self.backend = SwiftBackend(self.container, self.config)

        yield

        try:
            headers, items = self.conn.get_container(self.backend.name)
            for i in items:
                self.conn.delete_object(self.backend.name, i['name'])

            self.conn.delete_container(self.backend.name)
        except swiftclient.ClientException as e:
            assert False, "Failed to delete container ->" + str(e) 
开发者ID:noirbizarre,项目名称:flask-fs,代码行数:27,代码来源:test_swift_backend.py

示例4: test_integration_fileresource_download_success

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def test_integration_fileresource_download_success(self):

        # initiate a Swift service connection
        conn = swiftclient.Connection(
            user=settings.SWIFT_USERNAME,
            key=settings.SWIFT_KEY,
            authurl=settings.SWIFT_AUTH_URL,
        )
        # upload file to Swift storage
        with io.StringIO("test file") as file1:
            conn.put_object(settings.SWIFT_CONTAINER_NAME, '/tests/file1.txt',
                            contents=file1.read(),
                            content_type='text/plain')

        self.client.login(username=self.username, password=self.password)
        response = self.client.get(self.download_url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(str(response.content, 'utf-8'), "test file")

        # delete file from Swift storage
        conn.delete_object(settings.SWIFT_CONTAINER_NAME, '/tests/file1.txt') 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:23,代码来源:test_views.py

示例5: test_integration_uploadedfile_create_success

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def test_integration_uploadedfile_create_success(self):

        # POST request using multipart/form-data to be able to upload file
        self.client.login(username=self.username, password=self.password)
        upload_path = "{}/uploads/file2.txt".format(self.username)
        with io.StringIO("test file") as f:
            post = {"fname": f, "upload_path": upload_path}
            response = self.client.post(self.create_read_url, data=post)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # initiate a Swift service connection
        conn = swiftclient.Connection(
            user=settings.SWIFT_USERNAME,
            key=settings.SWIFT_KEY,
            authurl=settings.SWIFT_AUTH_URL,
        )
        # delete file from Swift storage
        conn.delete_object(settings.SWIFT_CONTAINER_NAME, upload_path) 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:20,代码来源:test_views.py

示例6: test_integration_uploadedfileresource_download_success

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def test_integration_uploadedfileresource_download_success(self):
        # initiate a Swift service connection
        conn = swiftclient.Connection(
            user=settings.SWIFT_USERNAME,
            key=settings.SWIFT_KEY,
            authurl=settings.SWIFT_AUTH_URL,
        )
        # upload file to Swift storage
        upload_path = "{}/uploads/file1.txt".format(self.username)
        with io.StringIO("test file") as file1:
            conn.put_object(settings.SWIFT_CONTAINER_NAME, upload_path,
                            contents=file1.read(),
                            content_type='text/plain')

        self.client.login(username=self.username, password=self.password)
        response = self.client.get(self.download_url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(str(response.content, 'utf-8'), "test file")

        # delete file from Swift storage
        conn.delete_object(settings.SWIFT_CONTAINER_NAME, upload_path) 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:23,代码来源:test_views.py

示例7: validate_path

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def validate_path(self, path):
        """
        Overriden to check whether the provided path is under SERVICES/PACS/ path.
        """
        path = path.strip(' ').strip('/')
        if not path.startswith('SERVICES/PACS/'):
            raise serializers.ValidationError(
                ["File path must start with 'SERVICES/PACS/'."])
        # verify that the file is indeed already in Swift
        conn = swiftclient.Connection(user=settings.SWIFT_USERNAME,
                                      key=settings.SWIFT_KEY,
                                      authurl=settings.SWIFT_AUTH_URL)
        object_list = conn.get_container(settings.SWIFT_CONTAINER_NAME, prefix=path)[1]
        if not object_list:
            raise serializers.ValidationError(["Could not find this path."])
        return path 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:18,代码来源:serializers.py

示例8: test_integration_servicefileresource_download_success

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def test_integration_servicefileresource_download_success(self):
        # initiate a Swift service connection
        conn = swiftclient.Connection(
            user=settings.SWIFT_USERNAME,
            key=settings.SWIFT_KEY,
            authurl=settings.SWIFT_AUTH_URL,
        )
        # create container in case it doesn't already exist
        conn.put_container(settings.SWIFT_CONTAINER_NAME
                           )
        # upload file to Swift storage
        with io.StringIO("test file") as file1:
            conn.put_object(settings.SWIFT_CONTAINER_NAME, self.path,
                            contents=file1.read(),
                            content_type='text/plain')

        self.client.login(username=self.username, password=self.password)
        response = self.client.get(self.download_url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(str(response.content, 'utf-8'), "test file")

        # delete file from Swift storage
        conn.delete_object(settings.SWIFT_CONTAINER_NAME, self.path) 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:25,代码来源:test_views.py

示例9: _get_swift_connection

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def _get_swift_connection(instance):
        """
        Get Connection object.
        """
        return swiftclient.Connection(
            user=instance.swift_openstack_user,
            key=instance.swift_openstack_password,
            authurl=instance.swift_openstack_auth_url,
            tenant_name=instance.swift_openstack_tenant,
            auth_version='3',
            os_options={'region_name': instance.swift_openstack_region}
        ) 
开发者ID:open-craft,项目名称:opencraft,代码行数:14,代码来源:migrate_swift_to_s3.py

示例10: _create_container_if_missing

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def _create_container_if_missing(self, container, connection):
        """
        Creates a missing container in Swift if the
        ``swift_store_create_container_on_put`` option is set.

        :param container: Name of container to create
        :param connection: Connection to swift service
        """
        if self.backend_group:
            store_conf = getattr(self.conf, self.backend_group)
        else:
            store_conf = self.conf.glance_store
        try:
            connection.head_container(container)
        except swiftclient.ClientException as e:
            if e.http_status == http_client.NOT_FOUND:
                if store_conf.swift_store_create_container_on_put:
                    try:
                        msg = (_LI("Creating swift container %(container)s") %
                               {'container': container})
                        LOG.info(msg)
                        connection.put_container(container)
                    except swiftclient.ClientException as e:
                        msg = (_("Failed to add container to Swift.\n"
                                 "Got error from Swift: %s.")
                               % encodeutils.exception_to_unicode(e))
                        raise glance_store.BackendException(msg)
                else:
                    msg = (_("The container %(container)s does not exist in "
                             "Swift. Please set the "
                             "swift_store_create_container_on_put option "
                             "to add container to Swift automatically.") %
                           {'container': container})
                    raise glance_store.BackendException(msg)
            else:
                raise 
开发者ID:openstack,项目名称:glance_store,代码行数:38,代码来源:store.py

示例11: get_store_connection

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def get_store_connection(self, auth_token, storage_url):
        """Get initialized swift connection

        :param auth_token: auth token
        :param storage_url: swift storage url
        :return: swiftclient connection that allows to request container and
                 others
        """
        # initialize a connection
        return swiftclient.Connection(
            preauthurl=storage_url,
            preauthtoken=auth_token,
            insecure=self.insecure,
            ssl_compression=self.ssl_compression,
            cacert=self.cacert) 
开发者ID:openstack,项目名称:glance_store,代码行数:17,代码来源:store.py

示例12: get_connection

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def get_connection(self, location, context=None):
        if not location.user:
            reason = _("Location is missing user:password information.")
            LOG.info(reason)
            raise exceptions.BadStoreUri(message=reason)

        auth_url = location.swift_url
        if not auth_url.endswith('/'):
            auth_url += '/'

        if self.auth_version in ('2', '3'):
            try:
                tenant_name, user = location.user.split(':')
            except ValueError:
                reason = (_("Badly formed tenant:user '%(user)s' in "
                            "Swift URI") % {'user': location.user})
                LOG.info(reason)
                raise exceptions.BadStoreUri(message=reason)
        else:
            tenant_name = None
            user = location.user

        os_options = {}
        if self.region:
            os_options['region_name'] = self.region
        os_options['endpoint_type'] = self.endpoint_type
        os_options['service_type'] = self.service_type
        if self.user_domain_id:
            os_options['user_domain_id'] = self.user_domain_id
        if self.user_domain_name:
            os_options['user_domain_name'] = self.user_domain_name
        if self.project_domain_id:
            os_options['project_domain_id'] = self.project_domain_id
        if self.project_domain_name:
            os_options['project_domain_name'] = self.project_domain_name

        return swiftclient.Connection(
            auth_url, user, location.key, preauthurl=self.conf_endpoint,
            insecure=self.insecure, tenant_name=tenant_name,
            auth_version=self.auth_version, os_options=os_options,
            ssl_compression=self.ssl_compression, cacert=self.cacert) 
开发者ID:openstack,项目名称:glance_store,代码行数:43,代码来源:store.py

示例13: __init__

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def __init__(self, auth_url, tenant, container, user, password):
        self.swift_client = swiftclient.Connection(
            authurl=auth_url, user=":".join([user, tenant]), key=password
        )
        self._container = container
        self.swift_client.head_container(container) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:8,代码来源:swift_blockstore.py

示例14: __init__

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def __init__(self, name, config):
        super(SwiftBackend, self).__init__(name, config)

        self.conn = swiftclient.Connection(
            user=config.user,
            key=config.key,
            authurl=config.authurl
        )
        self.conn.put_container(self.name) 
开发者ID:noirbizarre,项目名称:flask-fs,代码行数:11,代码来源:swift.py

示例15: connect

# 需要导入模块: import swiftclient [as 别名]
# 或者: from swiftclient import Connection [as 别名]
def connect(*args, **kwargs):
        """
        Connect to swift storage and return the connection object,
        as well an optional "prepend" string to fully qualify
        object location in swift storage.
        """

        b_status = True
        b_prependBucketPath = False

        for k, v in kwargs.items():
            if k == 'prependBucketPath':    b_prependBucketPath = v

        d_ret = {
            'status': b_status,
            'conn': None,
            'prependBucketPath': ""
        }

        # initiate a swift service connection, based on internal
        # settings already available in the django variable space.
        try:
            d_ret['conn'] = swiftclient.Connection(
                user=settings.SWIFT_USERNAME,
                key=settings.SWIFT_KEY,
                authurl=settings.SWIFT_AUTH_URL,
            )
        except:
            d_ret['status'] = False

        if b_prependBucketPath:
            d_ret['prependBucketPath'] = ''

        return d_ret 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:36,代码来源:swiftmanager.py


注:本文中的swiftclient.Connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。