本文整理汇总了Python中turbolift.ARGS.get方法的典型用法代码示例。如果您正苦于以下问题:Python ARGS.get方法的具体用法?Python ARGS.get怎么用?Python ARGS.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turbolift.ARGS
的用法示例。
在下文中一共展示了ARGS.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _obj_index
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def _obj_index(b_path, m_path):
f_list = []
l_obj = None
while True:
resp = http.get_request(url=url, rpath=m_path, headers=fheaders)
self.resp_exception(resp=resp)
return_list = resp.json()
for obj in return_list:
time_offset = ARGS.get("time_offset")
if time_offset is not None:
# Get the last_modified data from the Object.
if cloud.time_delta(lmobj=time_offset) is True:
f_list.append(obj)
else:
f_list.append(obj)
last_obj_in_list = f_list[-1].get("name")
if ARGS.get("max_jobs", ARGS.get("object_index")) is not None:
max_jobs = ARGS.get("max_jobs", ARGS.get("object_index"))
if max_jobs <= len(f_list):
return f_list[:max_jobs]
elif l_obj is last_obj_in_list:
return f_list
else:
l_obj = last_obj_in_list
m_path = _marker_type(base=b_path, last=last_obj_in_list)
else:
if l_obj is last_obj_in_list:
return f_list
else:
l_obj = last_obj_in_list
m_path = _marker_type(base=b_path, last=last_obj_in_list)
示例2: parse_region
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def parse_region():
"""Pull region/auth url information from context."""
base_auth_url = 'identity.api.rackspacecloud.com/v2.0/tokens'
if ARGS.get('os_region'):
region = ARGS.get('os_region')
elif ARGS.get('os_rax_auth'):
region = ARGS.get('os_rax_auth')
else:
raise turbo.SystemProblem('You Are required to specify a REGION')
if region is 'LON':
return ARGS.get('os_auth_url', 'lon.%s' % base_auth_url), True
elif region.lower() in info.__rax_regions__:
return ARGS.get('os_auth_url', '%s' % base_auth_url), True
else:
if ARGS.get('os_auth_url'):
if 'racksapce' in ARGS.get('os_auth_url'):
return ARGS.get('os_auth_url', '%s' % base_auth_url), True
else:
return ARGS.get('os_auth_url'), False
else:
LOG.error('FAILURE: No Region Found. ARGS DUMP:\t %s', ARGS)
raise turbo.AuthenticationProblem('You Are required to specify a'
' REGION and an AUTHURL')
示例3: time_delta
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def time_delta(lmobj, compare_time=None):
"""Check to see if a date delta exists based on filter for an object.
:param lmobj:
:param compare_time:
:return True|False:
"""
fmt, date, delta, now = basic.time_stamp()
# Set time objects
odate = date.strptime(lmobj, fmt)
if not compare_time:
# Time Options
time_factor = ARGS.get('time_factor', 1)
offset = ARGS.get('time_offset')
if (odate + delta(**{offset: time_factor})) > now:
return False
else:
return True
else:
if date.strptime(compare_time, fmt) > odate:
return True
else:
return False
示例4: cdn_toggle
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def cdn_toggle(headers):
"""Set headers to Enable or Disable the CDN."""
enable_or_disable = ARGS.get('enabled', ARGS.get('disable', False))
return headers.update({'X-CDN-Enabled': enable_or_disable,
'X-TTL': ARGS.get('cdn_ttl'),
'X-Log-Retention': ARGS.get('cdn_logs')})
示例5: get_authversion
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def get_authversion():
"""Get or infer the auth version."""
authversion = ARGS.get('auth_version')
authversion = AUTH_VERSION_MAP.get(authversion) or authversion
if authversion:
supported = ['v1.0', 'v2.0']
if authversion not in supported:
raise ValueError("Auth Version must be one of %s."
% supported)
else:
# infer version if possible else v2.0
if any((ARGS.get(s) for s in ('st_auth', 'st_user', 'st_key'))):
authversion = 'v1.0'
elif '/v1.0' in ARGS.get('os_auth_url'):
raise ValueError("Specify v1 auth endpoint with 'st_auth'"
"instead of 'os_auth_url'")
elif '/v2.0' in ARGS.get('st_auth'):
raise ValueError("Specify v2 auth endpoint with 'os_auth_url'"
"instead of 'st_auth'")
else:
authversion = 'v2.0'
if authversion == 'v1.0':
if not ARGS.get('st_auth'):
# TODO(samstav): automatically determine this for rax & hp
raise AttributeError("Specify the v1 auth endpoint "
"with 'st_auth'")
ARGS['auth_version'] = authversion
return authversion
示例6: cdn_toggle
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def cdn_toggle(headers):
"""Set headers to Enable or Disable the CDN."""
enable_or_disable = ARGS.get("enabled", ARGS.get("disable", False))
return headers.update(
{"X-CDN-Enabled": enable_or_disable, "X-TTL": ARGS.get("cdn_ttl"), "X-Log-Retention": ARGS.get("cdn_logs")}
)
示例7: start
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def start(self):
"""Return a list of objects from the API for a container."""
def _check_list(list_object):
if list_object:
return list_object
else:
return None, None, None
def _list(payload, go, last_obj):
"""Retrieve a long list of all files in a container.
:return final_list, list_count, last_obj:
"""
if ARGS.get("all_containers") is None:
return _check_list(
list_object=go.object_lister(url=payload["url"], container=payload["c_name"], last_obj=last_obj)
)
else:
return _check_list(list_object=go.container_lister(url=payload["url"], last_obj=last_obj))
# Package up the Payload
payload = http.prep_payload(auth=self.auth, container=ARGS.get("container"), source=None, args=ARGS)
# Prep Actions.
self.go = actions.CloudActions(payload=payload)
report.reporter(msg="API Access for a list of Objects in %s" % payload["c_name"], log=True)
report.reporter(msg='PAYLOAD\t: "%s"' % payload, log=True, lvl="debug", prt=False)
last_obj = None
with multi.spinner():
objects, list_count, last_obj = _list(payload=payload, go=self.go, last_obj=last_obj)
if ARGS.get("pattern_match"):
objects = basic.match_filter(idx_list=objects, pattern=ARGS["pattern_match"], dict_type=True)
if ARGS.get("filter") is not None:
objects = [obj for obj in objects if ARGS.get("filter") in obj.get("name")]
# Count the number of objects returned.
if objects is False:
report.reporter(msg="Nothing found.")
elif objects is not None:
num_files = len(objects)
if num_files < 1:
report.reporter(msg="Nothing found.")
else:
return_objects = []
for obj in objects:
for item in ["hash", "last_modified", "content_type"]:
if item in obj:
obj.pop(item)
return_objects.append(obj)
report.reporter(msg=report.print_horiz_table(return_objects))
report.reporter(msg='I found "%d" Item(s).' % num_files)
else:
report.reporter(msg="Nothing found.")
示例8: _deleterator
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def _deleterator(payload):
"""Multipass Object Delete."""
report.reporter(msg='Getting file list')
with multi.spinner():
# Get all objects in a Container
objects, list_count, last_obj = self.action(
url=payload['url'],
container=payload['c_name']
)
if ARGS.get('pattern_match'):
objects = basic.match_filter(
idx_list=objects,
pattern=ARGS['pattern_match'],
dict_type=True
)
# Count the number of objects returned.
if objects is False:
report.reporter(msg='No Container found.')
return
elif objects is not None:
# Load the queue
obj_list = [obj['name'] for obj in objects]
num_files = len(obj_list)
if num_files < 1:
report.reporter(msg='No Objects found.')
return
else:
report.reporter(msg='Nothing found.')
return
# Get The rate of concurrency
concurrency = multi.set_concurrency(args=ARGS,
file_count=num_files)
if ARGS.get('object'):
obj_names = ARGS.get('object')
obj_list = [obj for obj in obj_list if obj in obj_names]
if not obj_list:
return 'Nothing Found to Delete.'
num_files = len(obj_list)
report.reporter(
msg=('Performing Object Delete for "%s" object(s)...'
% num_files)
)
kwargs = {'url': payload['url'],
'container': payload['c_name'],
'cf_job': getattr(self.go, 'object_deleter')}
multi.job_processer(
num_jobs=num_files,
objects=obj_list,
job_action=multi.doerator,
concur=concurrency,
kwargs=kwargs
)
_deleterator(payload=payload)
示例9: start
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def start(self):
"""This is the upload method.
Uses file_upload is to simply upload all files and folders to a
specified container.
"""
# Index Local Files for Upload
with multi.spinner():
f_indexed = methods.get_local_files()
if ARGS.get('pattern_match'):
f_indexed = basic.match_filter(
idx_list=f_indexed, pattern=ARGS['pattern_match']
)
num_files = len(f_indexed)
# Get The rate of concurrency
concurrency = multi.set_concurrency(args=ARGS, file_count=num_files)
# Package up the Payload
payload = multi.manager_dict(
http.prep_payload(
auth=self.auth,
container=ARGS.get('container', basic.rand_string()),
source=basic.get_local_source(),
args=ARGS
)
)
LOG.info('MESSAGE\t: "%s" Files have been found.', num_files)
LOG.debug('PAYLOAD\t: "%s"', payload)
# Set the actions class up
self.go = actions.CloudActions(payload=payload)
kwargs = {'url': payload['url'],
'container': payload['c_name']}
# get that the container exists if not create it.
self.go.container_create(**kwargs)
kwargs['source'] = payload['source']
kwargs['cf_job'] = getattr(self.go, 'object_putter')
multi.job_processer(
num_jobs=num_files,
objects=f_indexed,
job_action=multi.doerator,
concur=concurrency,
kwargs=kwargs
)
if ARGS.get('delete_remote') is True:
self.remote_delete(payload=payload,
f_indexed=f_indexed)
示例10: start
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def start(self):
"""This is the archive method.
Uses archive (TAR) feature to compress files and then upload the
TAR Ball to a specified container.
"""
# Index Local Files for Upload
f_indexed = methods.get_local_files()
if ARGS.get('pattern_match'):
f_indexed = basic.match_filter(
idx_list=f_indexed, pattern=ARGS['pattern_match']
)
num_files = len(f_indexed)
report.reporter(msg='MESSAGE: "%s" Files have been found.' % num_files)
# Package up the Payload
payload = http.prep_payload(
auth=self.auth,
container=ARGS.get('container', basic.rand_string()),
source=None,
args=ARGS
)
report.reporter(
msg='PAYLOAD\t: "%s"' % payload,
log=True,
lvl='debug',
prt=False
)
# Set the actions class up
self.go = actions.CloudActions(payload=payload)
self.go.container_create(
url=payload['url'], container=payload['c_name']
)
self.action = getattr(self.go, 'object_putter')
with multi.spinner():
# Compression Job
wfile = methods.compress_files(file_list=f_indexed)
source, name = os.path.split(wfile)
report.reporter(msg='MESSAGE: "%s" is being uploaded.' % name)
# Perform the upload
self.action(url=payload['url'],
container=payload['c_name'],
source=source,
u_file=wfile)
# Remove the archive unless instructed not too.
if ARGS.get('no_cleanup') is None:
basic.remove_file(wfile)
示例11: parse_region
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def parse_region():
"""Pull region/auth url information from context."""
if ARGS.get('os_rax_auth'):
region = ARGS.get('os_rax_auth')
auth_url = 'identity.api.rackspacecloud.com/v2.0/tokens'
if region is 'LON':
return ARGS.get('os_auth_url', 'https://lon.%s' % auth_url)
elif region.lower() in info.__rax_regions__:
return ARGS.get('os_auth_url', 'https://%s' % auth_url)
else:
raise turbo.SystemProblem('No Known RAX Region Was Specified')
elif ARGS.get('os_hp_auth'):
region = ARGS.get('os_hp_auth')
auth_url = 'https://%s.identity.hpcloudsvc.com:35357/v2.0/tokens'
if region.lower() in info.__hpc_regions__:
return ARGS.get('os_auth_url', auth_url % region)
else:
raise turbo.SystemProblem('No Known HP Region Was Specified')
elif ARGS.get('os_auth_url'):
return ARGS.get('os_auth_url')
else:
raise turbo.SystemProblem(
'You Are required to specify an Auth URL, Region or Plugin'
)
示例12: parse_reqtype
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def parse_reqtype():
"""Setup our Authentication POST.
username and setup are only used in APIKEY/PASSWORD Authentication
"""
setup = {'username': ARGS.get('os_user')}
if ARGS.get('os_token') is not None:
auth_body = {'auth': {'token': {'id': ARGS.get('os_token')}}}
elif ARGS.get('os_password') is not None:
prefix = 'passwordCredentials'
setup['password'] = ARGS.get('os_password')
auth_body = {'auth': {prefix: setup}}
elif ARGS.get('os_apikey') is not None:
prefix = 'RAX-KSKEY:apiKeyCredentials'
setup['apiKey'] = ARGS.get('os_apikey')
auth_body = {'auth': {prefix: setup}}
else:
LOG.error(traceback.format_exc())
raise AttributeError('No Password, APIKey, or Token Specified')
if ARGS.get('os_tenant'):
auth_body['auth']['tenantName'] = ARGS.get('os_tenant')
LOG.debug('AUTH Request Type > %s', auth_body)
return auth_body
示例13: set_headers
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def set_headers(headers):
"""Set the headers used in the Cloud Files Request.
:return headers:
"""
# Set the headers if some custom ones were specified
if ARGS.get('base_headers'):
headers.update(ARGS.get('base_headers'))
return headers
示例14: start
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def start(self):
"""This is the upload method.
Uses file_upload is to simply upload all files and folders to a
specified container.
"""
f_indexed = self._index_local_files()
num_files = len(f_indexed)
# Get The rate of concurrency
concurrency = multi.set_concurrency(args=ARGS, file_count=num_files)
# Package up the Payload
payload = multi.manager_dict(
http.prep_payload(
auth=self.auth,
container=ARGS.get('container', basic.rand_string()),
source=basic.get_local_source(),
args=ARGS
)
)
report.reporter(msg='MESSAGE : "%s" Files found.' % num_files)
report.reporter(
msg='PAYLOAD : [ %s ]' % payload,
prt=False,
lvl='debug'
)
# Set the actions class up
self.go = actions.CloudActions(payload=payload)
kwargs = {'url': payload['url'], 'container': payload['c_name']}
# get that the container exists if not create it.
self.go.container_create(**kwargs)
kwargs['source'] = payload['source']
kwargs['cf_job'] = getattr(self.go, 'object_putter')
multi.job_processer(
num_jobs=num_files,
objects=f_indexed,
job_action=multi.doerator,
concur=concurrency,
kwargs=kwargs
)
if ARGS.get('delete_remote') is True:
self.remote_delete(payload=payload)
示例15: object_lister
# 需要导入模块: from turbolift import ARGS [as 别名]
# 或者: from turbolift.ARGS import get [as 别名]
def object_lister(self, url, container, object_count=None, last_obj=None):
"""Builds a long list of objects found in a container.
NOTE: This could be millions of Objects.
:param url:
:param container:
:param object_count:
:param last_obj:
:return None | list:
"""
for retry in basic.retryloop(attempts=ARGS.get("error_retry"), obj="Object List"):
fheaders = self.payload["headers"]
fpath = http.quoter(url=url.path, cont=container)
with meth.operation(retry, obj="%s %s" % (fheaders, fpath)):
resp = self._header_getter(url=url, rpath=fpath, fheaders=fheaders)
if resp.status_code == 404:
report.reporter(msg="Not found. %s | %s" % (resp.status_code, resp.request))
return None, None, None
else:
if object_count is None:
object_count = resp.headers.get("x-container-object-count")
if object_count:
object_count = int(object_count)
if not object_count > 0:
return None, None, None
else:
return None, None, None
# Set the number of loops that we are going to do
return self._list_getter(url=url, filepath=fpath, fheaders=fheaders, last_obj=last_obj)