本文整理汇总了Python中swift.common.ring.Ring类的典型用法代码示例。如果您正苦于以下问题:Python Ring类的具体用法?Python Ring怎么用?Python Ring使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ring类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, app, conf):
self.app = app
self.logger = get_logger(conf, log_route='endpoints')
self.swift_dir = conf.get('swift_dir', '/etc/swift')
self.account_ring = Ring(self.swift_dir, ring_name='account')
self.container_ring = Ring(self.swift_dir, ring_name='container')
self.endpoints_path = conf.get('list_endpoints_path', '/endpoints/')
if not self.endpoints_path.endswith('/'):
self.endpoints_path += '/'
示例2: __call__
def __call__(self, env, start_response):
req = Request(env)
if env.get('REQUEST_METHOD') == "PUT" and env.get("HTTP_X_OBJECT_META_LXC_DEPLOY"):
ring = Ring(self.object_ring_path)
raw_path = env.get("RAW_PATH_INFO").split("/")
node_data = ring.get_nodes(raw_path[2],raw_path[3],raw_path[4])
deploy_host = node_data[1][0]["ip"]
req.headers["X-Object-Meta-LXC-HOST"] = deploy_host
req.headers["REMOTE_USER"] = raw_path[2]
return self.app(env, start_response)
示例3: create_account
def create_account(act):
ts = utils.normalize_timestamp(time())
account_ring = Ring(_testdir, ring_name='account')
partition, nodes = account_ring.get_nodes(act)
for node in nodes:
# Note: we are just using the http_connect method in the object
# controller here to talk to the account server nodes.
conn = swift.proxy.controllers.obj.http_connect(
node['ip'], node['port'], node['device'], partition, 'PUT',
'/' + act, {'X-Timestamp': ts, 'x-trans-id': act})
resp = conn.getresponse()
assert(resp.status == 201)
示例4: __init__
def __init__(self, app, conf):
self.app = app
self.logger = get_logger(conf, log_route='endpoints')
self.swift_dir = conf.get('swift_dir', '/etc/swift')
self.account_ring = Ring(self.swift_dir, ring_name='account')
self.container_ring = Ring(self.swift_dir, ring_name='container')
self.endpoints_path = conf.get('list_endpoints_path', '/endpoints/')
if not self.endpoints_path.endswith('/'):
self.endpoints_path += '/'
self.default_response_version = 1.0
self.response_map = {
1.0: self.v1_format_response,
2.0: self.v2_format_response,
}
示例5: is_valid_ring
def is_valid_ring(ring_file):
"""Check if a ring file is 'valid'
- make sure it has more than one device
- make sure get_part_nodes works
:returns: True or False if ring is valid
"""
try:
ring = Ring(ring_file)
if len(ring.devs) < 1:
return False
if not ring.get_part_nodes(1):
return False
except Exception:
return False
return True
示例6: SwiftUsageInput
class SwiftUsageInput(IDataSource):
def __init__(self, project, username, password, auth_url, ring_location="/etc/swift/account.ring.gz"):
self.__project=project
self.__username=username
self.__password=password
self.__auth_url=auth_url
self.__ring_location=ring_location
self.__ring=None
def get_data(self, **kwargs):
query_id=str(uuid.uuid4())
data_list=[]
from keystoneclient.v2_0 import client
from swift.common.ring import Ring
keystone=client.Client(username=self.__username, password=self.__password, tenant_name=self.__project, auth_url=self.__auth_url)
self.__ring = Ring(self.__ring_location)
tenants = [tenant.id for tenant in keystone.tenants.list()]
random.shuffle(tenants)
data=init_message()
data["swift"] = {}
for tenant, stats in zip(tenants, ThreadPool().map(self.fetch, tenants)):
if stats is not None:
data["swift"][tenant] = stats
return data
def fetch(self, tenant):
account = "AUTH_%s" % tenant
partition = self.__ring.get_part(account, None, None)
nodes = self.__ring.get_part_nodes(partition)
random.shuffle(nodes)
for node in nodes:
url = "http://%s:%s/%s/%s/%s" % (node["ip"], node["port"], node["device"], partition, account)
try:
response = requests.head(url, timeout=5)
if response.status_code == 204:
return {
"containers" : int(response.headers["x-account-container-count"]),
"objects" : int(response.headers["x-account-object-count"]),
"bytes" : int(response.headers["x-account-bytes-used"]),
"quota" : int(response.headers["x-account-meta-quota-bytes"]) if "x-account-meta-quota-bytes" in response.headers else None
}
elif response.status_code == 404:
return None
else:
log.warning("error fetching %s [HTTP %s]", url, response.status_code)
except:
log.warning("error fetching %s", url, exc_info=True)
log.error("failed to fetch info for tenant %s", tenant)
return None
示例7: __init__
def __init__(self, conf):
"""
:param conf: configuration object obtained from ConfigParser
:param logger: logging object
"""
self.conf = conf
self.logger = get_logger(conf, log_route='object-replicator')
self.devices_dir = conf.get('devices', '/srv/node')
self.mount_check = conf.get('mount_check', 'true').lower() in \
('true', 't', '1', 'on', 'yes', 'y')
self.vm_test_mode = conf.get(
'vm_test_mode', 'no').lower() in ('yes', 'true', 'on', '1')
self.swift_dir = conf.get('swift_dir', '/etc/swift')
self.port = int(conf.get('bind_port', 6000))
self.concurrency = int(conf.get('concurrency', 1))
self.stats_interval = int(conf.get('stats_interval', '300'))
self.object_ring = Ring(self.swift_dir, ring_name='object')
self.ring_check_interval = int(conf.get('ring_check_interval', 15))
self.next_check = time.time() + self.ring_check_interval
self.reclaim_age = int(conf.get('reclaim_age', 86400 * 7))
self.partition_times = []
self.run_pause = int(conf.get('run_pause', 30))
self.rsync_timeout = int(conf.get('rsync_timeout', 900))
self.rsync_io_timeout = conf.get('rsync_io_timeout', '30')
self.http_timeout = int(conf.get('http_timeout', 60))
self.lockup_timeout = int(conf.get('lockup_timeout', 1800))
self.recon_enable = conf.get(
'recon_enable', 'no').lower() in TRUE_VALUES
self.recon_cache_path = conf.get(
'recon_cache_path', '/var/cache/swift')
self.recon_object = os.path.join(self.recon_cache_path, "object.recon")
示例8: __init__
def __init__(self, conf):
self.conf = conf
self.logger = get_logger(conf, log_route='utilization-aggregator')
self.interval = int(conf.get('interval') or 60)
self.aggregate_account = '.utilization'
self.sample_account = '.transfer_record'
conf_path = conf.get('__file__') or \
'/etc/swift/swift-utilization-aggregator.conf'
request_tries = int(conf.get('request_tries') or 3)
self.swift = InternalClient(conf_path,
'Swift Utilization Aggregator',
request_tries)
self.report_interval = int(conf.get('report_interval') or 60)
self.report_first_time = self.report_last_time = time()
self.report_containers = 0
self.report_objects = 0
self.recon_cache_path = conf.get('recon_cache_path',
'/var/cache/swift')
self.rcache = join(self.recon_cache_path, 'object.recon')
self.concurrency = int(conf.get('concurrency', 1))
if self.concurrency < 1:
raise ValueError("concurrency must be set to at least 1")
self.processes = int(self.conf.get('processes', 0))
self.process = int(self.conf.get('process', 0))
self.container_ring = Ring('/etc/swift', ring_name='container')
self.sample_rate = int(self.conf.get('sample_rate', 600))
self.last_chk = iso8601_to_timestamp(self.conf.get(
'service_start'))
self.kinx_api_url = self.conf.get('kinx_api_url')
示例9: __init__
def __init__(self, app, conf, *args, **kwargs):
self.app = app
self.conf = conf
self.logger = get_logger(self.conf, log_route='transition')
self.container_ring = Ring('/etc/swift', ring_name='container')
self.glacier_account_prefix = '.glacier_'
self.temp_path = conf.get('temp_path', '/var/cache/s3/')
示例10: __init__
def __init__(self, conf):
self.conf = conf
self.container_ring = Ring('/etc/swift', ring_name='container')
self.logger = get_logger(conf, log_route='object-restorer')
self.logger.set_statsd_prefix('s3-object-restorer')
self.interval = int(conf.get('interval') or 300)
self.restoring_object_account = '.s3_restoring_objects'
self.expiring_restored_account = '.s3_expiring_restored_objects'
self.glacier_account_prefix = '.glacier_'
self.todo_container = 'todo'
self.restoring_container = 'restoring'
conf_path = '/etc/swift/s3-object-restorer.conf'
request_tries = int(conf.get('request_tries') or 3)
self.glacier = self._init_glacier()
self.glacier_tmpdir = conf.get('temp_path', '/var/cache/s3/')
self.swift = InternalClient(conf_path,
'Swift Object Restorer',
request_tries)
self.report_interval = int(conf.get('report_interval') or 300)
self.report_first_time = self.report_last_time = time()
self.report_objects = 0
self.recon_cache_path = conf.get('recon_cache_path',
'/var/cache/swift')
self.rcache = join(self.recon_cache_path, 'object.recon')
self.concurrency = int(conf.get('concurrency', 1))
if self.concurrency < 1:
raise ValueError("concurrency must be set to at least 1")
self.processes = int(self.conf.get('processes', 0))
self.process = int(self.conf.get('process', 0))
self.client = Client(self.conf.get('sentry_sdn', ''))
示例11: __init__
def __init__(self, conf):
"""
:param conf: configuration object obtained from ConfigParser
:param logger: logging object
"""
self.conf = conf
self.logger = get_logger(conf, log_route='object-replicator')
self.devices_dir = conf.get('devices', '/srv/node')
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
self.vm_test_mode = config_true_value(conf.get('vm_test_mode', 'no'))
self.swift_dir = conf.get('swift_dir', '/etc/swift')
self.port = int(conf.get('bind_port', 6000))
self.concurrency = int(conf.get('concurrency', 1))
self.stats_interval = int(conf.get('stats_interval', '300'))
self.object_ring = Ring(self.swift_dir, ring_name='object')
self.ring_check_interval = int(conf.get('ring_check_interval', 15))
self.next_check = time.time() + self.ring_check_interval
self.reclaim_age = int(conf.get('reclaim_age', 86400 * 7))
self.partition_times = []
self.run_pause = int(conf.get('run_pause', 30))
self.rsync_timeout = int(conf.get('rsync_timeout', 900))
self.rsync_io_timeout = conf.get('rsync_io_timeout', '30')
self.rsync_bwlimit = conf.get('rsync_bwlimit', '0')
self.http_timeout = int(conf.get('http_timeout', 60))
self.lockup_timeout = int(conf.get('lockup_timeout', 1800))
self.recon_cache_path = conf.get('recon_cache_path',
'/var/cache/swift')
self.rcache = os.path.join(self.recon_cache_path, "object.recon")
self.headers = {
'Content-Length': '0',
'user-agent': 'obj-replicator %s' % os.getpid()}
self.rsync_error_log_line_length = \
int(conf.get('rsync_error_log_line_length', 0))
示例12: __init__
def __init__(self, conf):
"""
:param conf: configuration object obtained from ConfigParser
:param logger: logging object
"""
self.conf = conf
self.logger = get_logger(conf, log_route="object-replicator")
self.devices_dir = conf.get("devices", "/srv/node")
self.mount_check = conf.get("mount_check", "true").lower() in ("true", "t", "1", "on", "yes", "y")
self.vm_test_mode = conf.get("vm_test_mode", "no").lower() in ("yes", "true", "on", "1")
self.swift_dir = conf.get("swift_dir", "/etc/swift")
self.port = int(conf.get("bind_port", 6000))
self.concurrency = int(conf.get("concurrency", 1))
self.stats_interval = int(conf.get("stats_interval", "300"))
self.object_ring = Ring(self.swift_dir, ring_name="object")
self.ring_check_interval = int(conf.get("ring_check_interval", 15))
self.next_check = time.time() + self.ring_check_interval
self.reclaim_age = int(conf.get("reclaim_age", 86400 * 7))
self.partition_times = []
self.run_pause = int(conf.get("run_pause", 30))
self.rsync_timeout = int(conf.get("rsync_timeout", 900))
self.rsync_io_timeout = conf.get("rsync_io_timeout", "30")
self.http_timeout = int(conf.get("http_timeout", 60))
self.lockup_timeout = int(conf.get("lockup_timeout", 1800))
self.recon_cache_path = conf.get("recon_cache_path", "/var/cache/swift")
self.rcache = os.path.join(self.recon_cache_path, "object.recon")
示例13: __init__
def __init__(self, app, conf, *args, **kwargs):
self.app = app
self.conf = conf
self.sample_account = '.transfer_record'
self.aggregate_account = '.utilization'
self.logger = get_logger(self.conf, log_route='utilization')
self.container_ring = Ring('/etc/swift', ring_name='container')
self.sample_rate = int(self.conf.get('sample_rate', 600))
示例14: create_account
def create_account(act):
ts = utils.normalize_timestamp(time())
account_ring = Ring(_testdir, ring_name="account")
partition, nodes = account_ring.get_nodes(act)
for node in nodes:
# Note: we are just using the http_connect method in the object
# controller here to talk to the account server nodes.
conn = swift.proxy.controllers.obj.http_connect(
node["ip"],
node["port"],
node["device"],
partition,
"PUT",
"/" + act,
{"X-Timestamp": ts, "x-trans-id": act},
)
resp = conn.getresponse()
assert resp.status == 201
示例15: get_container_list
def get_container_list(account):
#Require a account eg. AUTH_ss
#Return a list of containers within this account
account_ring = Ring(swift_dir, ring_name="account")
container_ring = Ring(swift_dir, ring_name="container")
object_ring = Ring(swift_dir, ring_name="object")
part, nodes = account_ring.get_nodes(account)
URL="http://%s:%s/%s/%s/%s" % (nodes[0]['ip'], nodes[0]['port'], nodes[0]['device'],
part, account)
r = requests.get(URL)
if r.status_code == 404:
logger.warning("Account not existing yet")
content = str(r.text)
req = urllib2.Request(URL)
container_list_hash = hashlib.md5(content).hexdigest()
content = content.split("\n")
content.remove('')
return content, container_list_hash