當前位置: 首頁>>代碼示例>>Python>>正文


Python swiftclient.Connection類代碼示例

本文整理匯總了Python中swiftclient.Connection的典型用法代碼示例。如果您正苦於以下問題:Python Connection類的具體用法?Python Connection怎麽用?Python Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Connection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SwiftBackend

class SwiftBackend(BakthatBackend):
    """Backend to handle OpenStack Swift upload/download."""
    def __init__(self, conf={}, profile="default"):
        BakthatBackend.__init__(self, conf, profile)

        from swiftclient import Connection, ClientException

        self.con = Connection(self.conf["auth_url"],
                                          self.conf["access_key"],
                                          self.conf["secret_key"],
                                          auth_version=self.conf["auth_version"],
                                          tenant_name=self.conf["tenant_name"],
                                          insecure=self.conf["insecure"])

        region_name = self.conf["region_name"]
        if region_name == DEFAULT_LOCATION:
            region_name = ""

        try:
            self.con.head_container(self.conf["s3_bucket"])
        except ClientException, e:
            self.con.put_container(self.conf["s3_bucket"])

        self.container = self.conf["s3_bucket"]
        self.container_key = "s3_bucket"
開發者ID:mmccarry,項目名稱:bakthat,代碼行數:25,代碼來源:backends.py

示例2: get_session

def get_session():
    SWIFT_USER = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'account')
    SWIFT_PASS = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'password')
    SWIFT_KEY = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'key')
    SWIFT_AUTH_URL = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'auth_url')
    cnx = Connection(SWIFT_AUTH_URL, '%s:%s' % (SWIFT_USER,SWIFT_PASS), SWIFT_KEY)
    cnx.get_auth()
    return cnx
開發者ID:pacopablo,項目名稱:anagogic-backup-swift,代碼行數:8,代碼來源:storage.py

示例3: SwiftStorage

class SwiftStorage(Storage):

    def __init__(self, config):
        self._config = config
        self._root_path = self._config.storage_path
        self._connection = Connection(self._config.storage_auth_url, self._config.storage_account + ':' + self._config.storage_username, self._config.storage_password)
        self._container = self._config.storage_container
        self._index_lastupdate = None
    
    def _update_index(self):
        logger.info("_update_index")
        try:
            headers = self._connection.head_object(self._container, 'docker-registry.index')  
            lastupdatestr = headers['last-modified']
            if not lastupdatestr:
                return
            lastupdate = datetime.strptime(lastupdatestr, "%a, %d %b %Y %H:%M:%S %Z")
            logger.info('lastupdate: ' + str(lastupdate))
            refresh_index = False
            
            if not self._index_lastupdate:
                refresh_index = True
            elif self._index_lastupdate < lastupdate:
                refresh_index = True
            
            if not refresh_index:
                return
            logger.info("refresh index...")
            
            (headers, data) = self._connection.get_object(self._container, 'docker-registry.index')
            (level, temppath) = mkstemp()
            tempfile = open(temppath, 'w')
            tempfile.write(data)
            tempfile.close()
            
            with open(temppath, 'r') as f:
                for line in f:
                    line = line.strip()
                    if line.startswith("#"):
                        continue
                    tokens = line.split('\t')
                    if len(tokens) < 2:
                        continue
                    logger.info("Index: " + str(tokens))
                    realpath = os.path.join(self._root_path, tokens[0])
                    if not os.path.exists(realpath):
                        os.makedirs(realpath)
                    metafile = open(os.path.join(realpath, '.object'), 'w')
                    metafile.write(tokens[1])
                    metafile.close()
            
            os.remove(temppath)

            self._index_lastupdate = lastupdate
        except ClientException, inst:
            if inst.http_status != 404:
                raise inst
開發者ID:yacchin1205,項目名稱:docker-registry,代碼行數:57,代碼來源:swift.py

示例4: SwiftBackend

class SwiftBackend(duplicity.backend.Backend):
    """
    Backend for Swift
    """
    def __init__(self, parsed_url):
        try:
            from swiftclient import Connection
            from swiftclient import ClientException
        except ImportError:
            raise BackendException("This backend requires "
                                   "the python-swiftclient library.")

        self.resp_exc = ClientException
        conn_kwargs = {}

        # if the user has already authenticated
        if os.environ.has_key('SWIFT_PREAUTHURL') and os.environ.has_key('SWIFT_PREAUTHTOKEN'):
            conn_kwargs['preauthurl'] = os.environ['SWIFT_PREAUTHURL']
            conn_kwargs['preauthtoken'] = os.environ['SWIFT_PREAUTHTOKEN']           
        
        else:
            if not os.environ.has_key('SWIFT_USERNAME'):
                raise BackendException('SWIFT_USERNAME environment variable '
                                       'not set.')

            if not os.environ.has_key('SWIFT_PASSWORD'):
                raise BackendException('SWIFT_PASSWORD environment variable '
                                       'not set.')

            if not os.environ.has_key('SWIFT_AUTHURL'):
                raise BackendException('SWIFT_AUTHURL environment variable '
                                       'not set.')

            conn_kwargs['user'] = os.environ['SWIFT_USERNAME']
            conn_kwargs['key'] = os.environ['SWIFT_PASSWORD']
            conn_kwargs['authurl'] = os.environ['SWIFT_AUTHURL']

        if os.environ.has_key('SWIFT_AUTHVERSION'):
            conn_kwargs['auth_version'] = os.environ['SWIFT_AUTHVERSION']
        else:
            conn_kwargs['auth_version'] = '1'
        if os.environ.has_key('SWIFT_TENANTNAME'):
            conn_kwargs['tenant_name'] = os.environ['SWIFT_TENANTNAME']
            
        self.container = parsed_url.path.lstrip('/')

        try:
            self.conn = Connection(**conn_kwargs)
            self.conn.put_container(self.container)
        except Exception, e:
            log.FatalError("Connection failed: %s %s"
                           % (e.__class__.__name__, str(e)),
                           log.ErrorCode.connection_failed)
開發者ID:ArslanRafique,項目名稱:dist-packages,代碼行數:53,代碼來源:swiftbackend.py

示例5: SwiftBackend

class SwiftBackend(duplicity.backend.Backend):
    """
    Backend for Swift
    """

    def __init__(self, parsed_url):
        try:
            from swiftclient import Connection
            from swiftclient import ClientException
        except ImportError:
            raise BackendException("This backend requires " "the python-swiftclient library.")

        self.resp_exc = ClientException
        conn_kwargs = {}

        # if the user has already authenticated
        if os.environ.has_key("SWIFT_PREAUTHURL") and os.environ.has_key("SWIFT_PREAUTHTOKEN"):
            conn_kwargs["preauthurl"] = os.environ["SWIFT_PREAUTHURL"]
            conn_kwargs["preauthtoken"] = os.environ["SWIFT_PREAUTHTOKEN"]

        else:
            if not os.environ.has_key("SWIFT_USERNAME"):
                raise BackendException("SWIFT_USERNAME environment variable " "not set.")

            if not os.environ.has_key("SWIFT_PASSWORD"):
                raise BackendException("SWIFT_PASSWORD environment variable " "not set.")

            if not os.environ.has_key("SWIFT_AUTHURL"):
                raise BackendException("SWIFT_AUTHURL environment variable " "not set.")

            conn_kwargs["user"] = os.environ["SWIFT_USERNAME"]
            conn_kwargs["key"] = os.environ["SWIFT_PASSWORD"]
            conn_kwargs["authurl"] = os.environ["SWIFT_AUTHURL"]

        if os.environ.has_key("SWIFT_AUTHVERSION"):
            conn_kwargs["auth_version"] = os.environ["SWIFT_AUTHVERSION"]
        else:
            conn_kwargs["auth_version"] = "1"
        if os.environ.has_key("SWIFT_TENANTNAME"):
            conn_kwargs["tenant_name"] = os.environ["SWIFT_TENANTNAME"]

        self.container = parsed_url.path.lstrip("/")

        try:
            self.conn = Connection(**conn_kwargs)
            self.conn.put_container(self.container)
        except Exception, e:
            log.FatalError("Connection failed: %s %s" % (e.__class__.__name__, str(e)), log.ErrorCode.connection_failed)
開發者ID:hurlebouc,項目名稱:GDuplicity,代碼行數:48,代碼來源:swiftbackend.py

示例6: __init__

        def __init__(self, *args, **kwargs):
            super(SwiftStorage, self).__init__()
            self.__dict__.update(kwargs)
            config_data = get_config_json()
            # Load config variables.
            self.auth_url = config_data.get('swift').get('auth_url')
            self.access_key = config_data.get('swift').get('access_key')
            self.secret_key = config_data.get('swift').get('secret_key')
            self.auth_version = config_data.get('swift').get('auth_version')
            self.tenant_name = config_data.get('swift').get('tenant_name')
            self.insecure = True
            self.container = config_data.get('swift').get('container')
            self.name_backup = kwargs.get('name_backup', None)
            self.conn = Connection(
                authurl=self.auth_url,
                user=self.access_key,
                key=self.secret_key,
                auth_version=self.auth_version,
                tenant_name=self.tenant_name,
                insecure=self.insecure)
            try:
                self.conn.head_container(self.container)
            except:
                self.conn.put_container(self.container)

            if not self.name_backup:
                raise SystemExit(_error_codes.get(103))
開發者ID:LisandroSeijo,項目名稱:zoort,代碼行數:27,代碼來源:zoort.py

示例7: __init__

    def __init__(self, logger, exec_time, **kwargs):
        self.keystone_client = keystone_client.Client(
            username=kwargs['os_username'],
            password=kwargs['os_password'],
            tenant_name=kwargs['os_tenant_name'],
            auth_url=kwargs['os_auth_url'])
        self.token = self.keystone_client.auth_ref['token']['id']
        self.tenant_id = self.keystone_client.auth_ref['token']['tenant']['id']
        self.end_points = self.keystone_client.service_catalog.get_endpoints()
        self.region1 = str(self.end_points['hpext:cdn'][0]['region'])
        self.region2 = str(self.end_points['hpext:cdn'][1]['region'])
        self.url1 = str(self.end_points['hpext:cdn'][0]['versionList'])
        self.url1 = self.url1[:-1]
        self.url2 = str(self.end_points['hpext:cdn'][1]['versionList'])
        self.url2 = self.url2[:-1]

        self.END_POINTS = {
            self.region1: self.url1,
            self.region2: self.url2
        }

        self.cdn_client = Connection(
            user=kwargs['os_username'],
            key=kwargs['os_password'],
            tenant_name=kwargs['os_tenant_name'],
            authurl=kwargs['os_auth_url'],
            auth_version="2.0",
            os_options={'region_name': kwargs['os_region'],
                        'service_type': 'hpext:cdn'})

        self.swift_client = Connection(
            user=kwargs['os_username'],
            key=kwargs['os_password'],
            tenant_name=kwargs['os_tenant_name'],
            authurl=kwargs['os_auth_url'],
            auth_version="2.0",
            os_options={'region_name': kwargs['os_region']})

        self.service = 'cdn'
        self.authurl = kwargs['os_auth_url']
        self.logger = logger
        self.exec_time = exec_time
        self.zone = kwargs['os_zone']
        self.failure = None
        self.overall_success = True
        self.region = kwargs['os_region']
        self.tenant_name = kwargs['os_tenant_name']
開發者ID:rygy,項目名稱:OpenFunc,代碼行數:47,代碼來源:cdn.py

示例8: _upload_swift

    def _upload_swift(self):
        tag = str(int(time.time()))

        (tenant, user) = self.cfg["s3user"].split(':')
        auth_url = "http://" + self.cfg["s3host"] + "/v2.0/"

        conn = Connection(auth_url, user, self.cfg["s3pass"],
                          snet=False, tenant_name=tenant, auth_version="2")

        # Not calling conn.put_container() for the same reason of permissions.

        key_name = self.cfg["prefix"] + '/' + "i" + tag
        mimetype = "image/jpeg"
        headers = { "Content-Type": mimetype }
        fp = open(self.cfg["file"], 'rb')
        conn.put_object(self.cfg["bucket"], key_name, fp, headers=headers)
        fp.close()
開發者ID:zaitcev,項目名稱:hailcam,代碼行數:17,代碼來源:hailcamsnap.py

示例9: swift_upload

def swift_upload(container, path, auth, user, key):
    conn = SwiftConnection(auth, user, key, snet=False, insecure=True)
    put_headers = { 'x-object-meta-mtime': "%f" % getmtime(path) }
    retry = SWIFT_RETRY_TIMES 
    while retry > 0:
        try:
            with open(path, 'rb') as fd:
                conn.put_object(container, path, fd,
                                content_length=getsize(path), headers=put_headers)
            return True
        except ClientException:
            log_normal(logger, {
                'action': 'upload-error',
                'error': 'swift client exception'
            }, LOG_ERROR)
            conn.put_container(container, headers={})
            retry -= 1
    return False
開發者ID:dlf412,項目名稱:thunderCopyright,代碼行數:18,代碼來源:uploader.py

示例10: SwiftStorage

    class SwiftStorage(object):
        def __init__(self, *args, **kwargs):
            super(SwiftStorage, self).__init__()
            self.__dict__.update(kwargs)
            config_data = get_config_json()
            # Load config variables.
            self.auth_url = config_data.get('swift').get('auth_url')
            self.access_key = config_data.get('swift').get('access_key')
            self.secret_key = config_data.get('swift').get('secret_key')
            self.auth_version = config_data.get('swift').get('auth_version')
            self.tenant_name = config_data.get('swift').get('tenant_name')
            self.insecure = True
            self.container = config_data.get('swift').get('container')
            self.name_backup = kwargs.get('name_backup', None)
            self.conn = Connection(
                authurl=self.auth_url,
                user=self.access_key,
                key=self.secret_key,
                auth_version=self.auth_version,
                tenant_name=self.tenant_name,
                insecure=self.insecure)
            try:
                self.conn.head_container(self.container)
            except:
                self.conn.put_container(self.container)

            if not self.name_backup:
                raise SystemExit(_error_codes.get(103))

        def send_file(self, filename, **kwargs):
            try:
                backup_file = open(filename, 'rb')
                response = self.conn.put_object(
                    self.container, filename, backup_file)
                print('Uploading file {0} to container "{1}" on swift'.
                      format(filename,
                             self.container))
            except Exception, e:
                raise SystemExit(_error_codes.get(115).format(
                                 filename, 'Swift', e))
開發者ID:LisandroSeijo,項目名稱:zoort,代碼行數:40,代碼來源:zoort.py

示例11: __init__

    def __init__(self, auth_url, user_name, key, logger, cache_file_path,
                 object_store_url=None, auth_version="2",
                 os_options=None):
        socket.setdefaulttimeout(30.0)  # timeout set at socket level
        Connection.__init__(self, auth_url, user_name, key, retries=0,
                            os_options=os_options,
                            auth_version=auth_version)
        # needed if keystone-get-token does not work
        self.object_store_url = object_store_url
        self.state = dict()
        for sev in severities:
            for component_name in self.component_names():
                self.state[component_name + sev] = \
                    dict(current_state=component_states.unknown,
                         reason='',
                         metrics={})

        self.latency = dict()
        self.metric_data = []
        self.latency_reset()
        self.logger = logger
        self.cache_file_path = cache_file_path
開發者ID:grze,項目名稱:helion-ansible,代碼行數:22,代碼來源:uptime_mon.py

示例12: __init__

    def __init__(self, username, password, tenant, auth_url, region):
        self.swift_client = Connection(
            user=username,
            key=password,
            tenant_name=tenant,
            authurl=auth_url,
            auth_version="2.0",
            os_options={'region_name': region}
        )

        # Setup logging
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.WARNING)
    
        # Allow the logger to write all output to stdout too
        self.logger.addHandler(logging.StreamHandler())
開發者ID:aditaa,項目名稱:jenkins,代碼行數:16,代碼來源:swift.py

示例13: __init__

    def __init__(self, conf={}, profile="default"):
        BakthatBackend.__init__(self, conf, profile)

        from swiftclient import Connection, ClientException

        self.con = Connection(self.conf["auth_url"], self.conf["access_key"], 
                              self.conf["secret_key"],
                              auth_version=self.conf["auth_version"],
                              insecure=True)

        region_name = self.conf["region_name"]
        if region_name == DEFAULT_LOCATION:
            region_name = ""

        try:
            self.con.head_container(self.conf["s3_bucket"])
        except ClientException, e:
            self.con.put_container(self.conf["s3_bucket"])
開發者ID:235,項目名稱:bakthat,代碼行數:18,代碼來源:backends.py

示例14: __init__

    def __init__(self, logger, exec_time, **kwargs):
        self.swift_client = Connection(
            user=kwargs['os_username'],
            key=kwargs['os_password'],
            tenant_name=kwargs['os_tenant_name'],
            authurl=kwargs['os_auth_url'],
            auth_version="2.0",
            os_options={'region_name': kwargs['os_region']}
        )

        self.service = 'Object Storage'
        self.logger = logger
        self.exec_time = exec_time
        self.zone = kwargs['os_zone']
        self.region = kwargs['os_region']
        self.failure = None
        self.overall_success = True
        self.tenant_name = kwargs['os_tenant_name']
開發者ID:rygy,項目名稱:OpenFunc,代碼行數:18,代碼來源:swift.py

示例15: __init__

	def __init__(self, conf):
		'''
		根據配置文件初始化連接Swift雲存儲的客戶端,包括認證係統和存儲係統。
		'''
		self.conf = conf
		colon = conf['storuser'].find(":")
		if colon > 0 :
			self.user = conf['storuser'][:colon]
			self.tenant = conf['storuser'][colon+1:] 
		else:
			self.user = self.tenant = conf['storuser']
		print self.user, self.tenant
		self.pawd = conf['storpass']
		self.authurl = "http://" + conf['storip'] + ":" + conf['storport'] + "/v2.0/"
		
#		self.keystone = client.Client(username="admin", password="admin",
#									tenant_name="admin", auth_url=self.authurl)        
		self.swift = Connection(authurl=self.authurl, user=self.user, key=self.pawd, 
								auth_version="2", tenant_name=self.tenant, insecure = True)
開發者ID:hjckevin,項目名稱:bak,代碼行數:19,代碼來源:connStorage.py


注:本文中的swiftclient.Connection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。