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


Python Connection.get_account方法代码示例

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


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

示例1: __init__

# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import get_account [as 别名]
class CdnCheck:

    """

    Functional test for CDN - basic workflow as follows

    Create a CDN enabled container
    List all the CDN containers
    Select a CDN enabled container
    Upload Metadata to the account
    Retrieve Metadata to the account
    Create and upload an object
    Access the object with the CDN http url
    Access the object with the CDN https url
    Delete the object created in the previous step
    Delete the CDN container we created in our first step

    """

    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']

    @monitoring.timeit
    def list_containers(self):
        """

        List all the CDN containers

        """

        try:
            self.success = True
            self.cdn_containers = self.cdn_client.get_account()[1]
            self.logger.warning('Listing CDN Containers')

            for container in self.cdn_containers:
                self.logger.warning(
                    container['name'] + ' ' + container['x-cdn-uri'] +
                    ' ' + container['x-cdn-ssl-uri'])

        except Exception as e:
            self.success, self.overall_success = False, False
            self.failure = e
            self.logger.error(
                "Listing CDN containers failed %s", sys.exc_info()[1])

    @monitoring.timeit
    def select_container(self):
        """

        Select a CDN enabled container. Usually this is the container we created.

        """

        try:
#.........这里部分代码省略.........
开发者ID:rygy,项目名称:OpenFunc,代码行数:103,代码来源:cdn.py

示例2: __init__

# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import get_account [as 别名]
class SwiftCheck:

    """

    Functional test for Swift - basic workflow as follows:

    List containers
    List objects in those containers
    Update Metadata of the account
    Retrieve Metadata of the account
    Create a Container
    Select that container
    Update Metadata of the container
    Retrieve Metadata of the container
    Create an object in the container
    Retrieve the object in the container
    Update metadata of the object
    Retrieve metadata of the object
    Delete object
    Delete container.

    """

    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']

    @monitoring.timeit
    def list_containers(self):
        """
        List all the existing containers
        """

        try:
            self.success = True
            self.containers = self.swift_client.get_account()[1]
            self.logger.warning("Listing Containers:")
            for self.container in self.containers:
                self.logger.warning(self.container['name'])

        except Exception as e:
            self.success, self.overall_success = False, False
            self.failure = e
            self.logger.error(
                "Listing Swift containers failed %s", sys.exc_info()[1])

    @monitoring.timeit
    def list_objects(self):
        """
        List all the objects contained in each container
        """

        try:
            self.success = True
            self.containers = self.swift_client.get_account()[1]
            self.logger.warning("Listing Objects:")
            for self.container in self.containers:
                try:
                    for swift_container in self.swift_client.get_container(
                            self.container['name'])[1]:
                        self.logger.warning(
                            self.container['name'] + " " +
                            swift_container['name'])
                except:
                    pass

        except Exception as e:
            self.success, self.overall_success = False, False
            self.failure = e
            self.logger.error(
                "Listing objects failed %s", sys.exc_info()[1])

    @monitoring.timeit
    def create_container(self):
        """
        Create a new container
        """

        try:
            self.success = True
            self.container = 'swiftcheck' + str(time.time())
            self.swift_client.put_container(self.container)

            self.logger.warning("Created Container %s", self.container)

#.........这里部分代码省略.........
开发者ID:rygy,项目名称:OpenFunc,代码行数:103,代码来源:swift.py

示例3: __init__

# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import get_account [as 别名]

#.........这里部分代码省略.........
            sum_output = ''
            for lists in outs:
                sum_output = sum_output + lists
                if lists == '\n':
                    sum_output = ''
                if name in sum_output:
                    sum_split = sum_output.split()
                    proc = subprocess.Popen(['libra',
                                             '--insecure',
                                             '--os-region-name',
                                             self.region,
                                             'delete', sum_split[1]])
                    sum_output = ''
                    proc.wait()
                    if proc.returncode == 0:
                        self.logger.warning('deleting %s', sum_split[1])
                    else:
                        self.failure = "Return code " + str(proc.returncode)
                        self.logger.error("did not delete lb return code %s",
                                          proc.returncode)
        except Exception as e:
            self.success, self.overall_success = False, True
            self.failure = e
            self.logger.error("<*>delete_lb Failed %s", e)

    @monitoring.timeit
    def delete_cdn_containers(self):
        """
        Description - Delete all containers where name starts with
                        'cdncheck' and all objects in that container
        """
        try:
            self.success = True
            self.cdn_containers = self.cdn_client.get_account()[1]

            if len(self.cdn_containers) == 0:
                self.logger.warning(
                    'No CDN containers to clean up')
                return

            self.cdn_container_names = []
            for i in self.cdn_containers:
                if str(i['name']).startswith('cdncheck'):
                    self.cdn_container_names.append(str(i['name']))

            if len(self.cdn_container_names) == 0:
                self.logger.warning(
                    'No CDN containers (cdncheck string) to delete')
                return

            for self.container_name in self.cdn_container_names:

                try:
                    self.objects = self.swift_client.get_container(
                        self.container_name)[1]
                except Exception:
                    self.logger.warning(
                        "Couldn't retrieve objects for %s", self.container_name)
                    self.logger.warning("Deleting the container directly")
                    self.cdn_client.delete_container(self.container_name)
                    continue

                if len(self.objects) == 0:
                    self.logger.warning(
                        'No objects found for %s', self.container_name)
                    self.logger.warning(
开发者ID:rygy,项目名称:OpenFunc,代码行数:70,代码来源:purge_service.py

示例4: __init__

# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import get_account [as 别名]
class Swift:

    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())
  
    def list_containers(self):
        try:
            self.containers = self.swift_client.get_account()[1]
      
            self.logger.warning("Listing Containers")
            for container in self.containers:
                self.logger.warning(container['name'])
    
        except Exception:
            self.logger.error("Listing Containers Failed")
            self.exit(1)

    def list_objects(self):
        try:
            self.logger.warning("Listing Objects")
            for container in self.containers:
                for swift_container in self.swift_client.get_container(container['name'])[1]:
                    self.logger.warning(container['name'] + " " + swift_container['name'])
    
        except Exception as e:
            self.logger.error('Listing Objects Failed, Got exception: %s' % e)
            self.exit(1)

    def create_container(self, name):
        try:
            self.container = name
            self.swift_client.put_container(self.container)
            self.logger.warning("Created Container %s", self.container)

        except Exception:
            self.logger.error("Creating Container Failed")
            self.exit(1)

    def create_object(self, name, contents):
        try:
            self.object = name
            self.swift_client.put_object(self.container, self.object, contents)
            self.logger.warning("Created Object %s", self.object)

        except Exception:
            self.logger.error("Creating Object Failed")
            self.exit(1)

    def get_container(self):
        try:
            self.containers = self.swift_client.get_account()[1]

            for container in self.containers:
                if container['name'] == self.container:
                    self.logger.warning("Getting Container Succeeded")

                    return True

            self.logger.error("Getting Container Failed")
            self.exit(1)

        except Exception as e:
            self.logger.error('Getting Container Failed: Got exception: ' % e)
            self.exit(1)

    def get_object(self):
        try:
            object = self.swift_client.get_object(self.container, self.object)
            self.logger.warning("Object Get: %s", object)

        except Exception as e:
            self.logger.error('Object Get Failed, Got exception: %s' % e)
            self.exit(1)

    def delete_object(self):
        try:
            self.swift_client.delete_object(self.container, self.object)
            self.logger.warning("Object Deleted")

        except Exception as e:
            self.logger.error('Object Deletion Failed: Got exception: ' % e)
      
    def delete_container(self):
        try:
            self.swift_client.delete_container(self.container)
            self.logger.warning("Container Deleted")
#.........这里部分代码省略.........
开发者ID:aditaa,项目名称:jenkins,代码行数:103,代码来源:swift.py

示例5: ConnStorage

# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import get_account [as 别名]
class ConnStorage(object):
	'''
	classdocs
	'''

	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)
		
#	def getTenantList(self):
#		items = self.keystone.tenants.list()
#		tenantlist=[]
#		for item in items:
#			tenantlist.append(item.name)            
#		return tenantlist
#	
#	def getUserList(self):
#		items = self.keystone.users.list()
#		userlist = []
#		for item in items:
#			userlist.append(item.name)
#		return userlist
	
#	def addTenant(self):
#		tenantlist = self.getTenantList()
#		if self.tenant not in tenantlist:
#			self.keystone.tenants.create(tenant_name = self.tenant)
#		else:
#			print "The tenant \"%s\" already existed!" % self.tenant
#	
#	def addUser(self):
#		tenantlist = self.keystone.tenants.list()
#		my_tenant = [x for x in tenantlist if x.name == self.tenant][0]
#		
#		userlist = self.getUserList()
#		if self.user not in userlist:
#			self.keystone.users.create(name = self.tenant, password = self.pawd, 
#									tenant_id = my_tenant.id)
#		else:
#			print "The user \"%s\" already existed under tenant \"%s\"!" % (self.tenant, self.user) 
	
	def getContainerList(self):
		items = self.swift.get_account()[1]
		conlist=[]
		for item in items:
			conlist.append(item.get('name', item.get('hjc')))
			
		print conlist
		return conlist
	
	def getObjectList(self, conName):
		items = self.swift.get_container(container=conName)[1]
		objlist = []
		for item in items:
			objlist.append(item.get('name', item.get('hjc')))
		
		return objlist
	
	def upload_file(self, container, objpath):
		conlist = self.getContainerList()
		if container not in conlist:
			try:
				self.swift.put_container(container)
			except ClientException, err:
				msg = ' '.join(str(x) for x in (err.http_status, err.http_reason))
				if err.http_response_content:
					if msg:
						msg += ': '
					msg += err.http_response_content[:60]
				print 'Error trying to create container %r: %s' % (container, msg)
			except Exception, err:
				print 'Error trying to create container %r: %s' % (container, err)
开发者ID:hjckevin,项目名称:bak,代码行数:90,代码来源:connStorage.py


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