本文整理汇总了Python中pyrax.connect_to_cloudfiles函数的典型用法代码示例。如果您正苦于以下问题:Python connect_to_cloudfiles函数的具体用法?Python connect_to_cloudfiles怎么用?Python connect_to_cloudfiles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect_to_cloudfiles函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
pyrax.connect_to_cloudservers = Mock()
pyrax.connect_to_cloud_loadbalancers = Mock()
pyrax.connect_to_cloud_databases = Mock()
pyrax.connect_to_cloud_blockstorage = Mock()
pyrax.identity = FakeIdentity()
pyrax.set_credentials("fakeuser", "fakeapikey", region="FAKE")
pyrax.connect_to_cloudfiles(region="FAKE")
self.client = pyrax.cloudfiles
self.client._container_cache = {}
self.cont_name = utils.random_name()
self.obj_name = utils.random_name()
self.fake_object = FakeStorageObject(self.client, self.cont_name, self.obj_name)
开发者ID:piecommerce,项目名称:pyrax,代码行数:13,代码来源:test_cf_client.py
示例2: setUp
def setUp(self):
pyrax.connect_to_cloudservers = Mock()
pyrax.connect_to_cloud_loadbalancers = Mock()
pyrax.connect_to_cloud_databases = Mock()
pyrax.connect_to_cloud_blockstorage = Mock()
pyrax.connect_to_cloudfiles()
self.client = pyrax.cloudfiles
self.client.connection.head_container = Mock()
self.cont_name = utils.random_name()
self.container = self.client.get_container(self.cont_name)
self.obj_name = utils.random_name()
self.fake_object = FakeStorageObject(self.client, self.cont_name,
self.obj_name)
self.client._container_cache = {}
self.container.object_cache = {}
开发者ID:jirwin,项目名称:pyrax,代码行数:15,代码来源:test_cf_container.py
示例3: listdir
def listdir(self):
for ent in self.shalist.keys():
if ent in self.remote_files:
yield ent
# Directories don't appear in shalists
conn = pyrax.connect_to_cloudfiles(region=self.region.upper())
container = conn.create_container(self.container_name)
dirs = {}
marker = None
prefix = remote_filename(self.path) + '~'
while True:
results = container.get_objects(prefix=prefix, marker=marker)
if not results:
break
for f in results:
marker = f.name
if f.name.endswith('.shalist'):
subdir = f.name[len(prefix):]
if subdir and subdir != '.shalist':
dirs[subdir.split('~')[0]] = True
for d in dirs:
yield d
开发者ID:mikalstill,项目名称:cloudfiles-tools,代码行数:25,代码来源:remote_pyrax.py
示例4: _get_connection
def _get_connection(self):
if not hasattr(self.local_cache, "connection"):
public = not self.use_snet # invert
connection = pyrax.connect_to_cloudfiles(region=self.region, public=public)
self.local_cache.connection = connection
return self.local_cache.connection
开发者ID:bennylope,项目名称:django-cumulus,代码行数:7,代码来源:storage.py
示例5: __init__
def __init__(self, name):
self.region, name = name.split('://')
self.basename = os.path.basename(name)
pyrax.set_setting('identity_type', 'rackspace')
with open(os.path.expanduser('~/.cloudfiles'), 'r') as f:
self.conf = json.loads(f.read())
pyrax.set_credentials(self.conf['access_key'],
self.conf['secret_key'],
region=self.region)
conn = pyrax.connect_to_cloudfiles(region=self.region.upper())
if self.region == 'dfw':
self.container_name = remote_filename(name)
else:
self.container_name = remote_filename('%s/%s' %(self.region, name))
container = conn.create_container(self.container_name)
for i in range(3):
try:
container.log_retention(True)
break
except:
pass
for info in conn.list_containers_info():
if info['name'] == self.container_name:
remote_total = info['bytes']
print ('%s Remote store %s contains %s in %d objects'
%(datetime.datetime.now(), self.region,
utility.DisplayFriendlySize(remote_total),
info['count']))
开发者ID:mikalstill,项目名称:cloudfiles-tools,代码行数:33,代码来源:remote_pyrax.py
示例6: login
def login(self):
"""
Logs into cloud files. Note that this is on the main thread.
init_thread is responsible for initializing individual threads.
:return: True on success, false on failure
"""
try:
pyrax.set_credentials(username=self.username,
api_key=self.api_key)
self.rax = pyrax.connect_to_cloudfiles(self.region, True)
if self.rax is None:
ThreadedDeleter.output('Unknown error occured while connecting'
' to CloudFiles.')
return False
except pyrax.exceptions.AuthenticationFailed as e:
ThreadedDeleter.output('Authentication failed: {msg}'.format(
msg=str(e)))
return False
except pyrax.exceptions.PyraxException as e:
ThreadedDeleter.output('Unknown error occurred: {msg}'.format(
msg=str(e)))
return False
return True
开发者ID:curquhart,项目名称:threadedobjectdeleter,代码行数:25,代码来源:cloudfiles.py
示例7: connect_container
def connect_container(self):
"""
Connects to a container using the swiftclient api.
The container will be created and/or made public using the
pyrax api if not already so.
"""
self.conn = swiftclient.Connection(authurl=CUMULUS["AUTH_URL"],
user=CUMULUS["USERNAME"],
key=CUMULUS["API_KEY"],
snet=CUMULUS["SERVICENET"],
auth_version=CUMULUS["AUTH_VERSION"],
tenant_name=CUMULUS["AUTH_TENANT_NAME"])
try:
self.conn.head_container(self.container_name)
except swiftclient.client.ClientException as exception:
if exception.msg == "Container HEAD failed":
call_command("container_create", self.container_name)
else:
raise
if CUMULUS["USE_PYRAX"]:
public = not CUMULUS["SERVICENET"]
pyrax.set_credentials(CUMULUS["USERNAME"], CUMULUS["API_KEY"])
connection = pyrax.connect_to_cloudfiles(region=CUMULUS["REGION"],
public=public)
container = connection.get_container(self.container_name)
if not container.cdn_enabled:
container.make_public(ttl=CUMULUS["TTL"])
else:
headers = {"X-Container-Read": ".r:*"}
self.conn.post_container(self.container_name, headers=headers)
self.container = self.conn.get_container(self.container_name)
开发者ID:ZG-Tennis,项目名称:django-cumulus,代码行数:34,代码来源:syncstatic.py
示例8: get_link
def get_link(jsonresp):
foo = jsonresp["access"]["serviceCatalog"]
for i in foo:
for value in i.values():
if value == "cloudFiles":
bar = i
regions = [
{ str(bar["endpoints"][0]["region"]) : str(bar["endpoints"][0]["publicURL"]) },
{ str(bar["endpoints"][1]["region"]) : str(bar["endpoints"][1]["publicURL"]) },
{ str(bar["endpoints"][2]["region"]) : str(bar["endpoints"][2]["publicURL"]) },
{ str(bar["endpoints"][3]["region"]) : str(bar["endpoints"][3]["publicURL"])}]
sys.stdout.write("\x1b[2J\x1b[H")
print "Regions/URLs:"
for i, item in enumerate(regions):
for value in item.values():
j=str(i+1)
print "%s) %s" % (j, value)
value = raw_input("Please enter choice: ")
value = int(value)-1
while True:
try:
link = regions[value].values()[0]+"/"
region = regions[value].keys()[0]
break
except IndexError:
"Wrong value!"
cf = pyrax.connect_to_cloudfiles(region=region)
return cf, link
开发者ID:dman777,项目名称:rackspace-cloud-files-tools,代码行数:31,代码来源:add_header_util_api_key.py
示例9: main
def main(username, project, list):
pyrax.set_setting('identity_type', 'rackspace')
with open(os.path.expanduser('~/.bugminion'), 'r') as f:
conf = json.loads(f.read())
pyrax.set_credentials(conf['access_key'],
conf['secret_key'],
region=conf['region'].upper())
conn = pyrax.connect_to_cloudfiles(region=conf['region'].upper())
container = conn.create_container(conf['container'])
# Prioritize a list of bugs from an input file
now = datetime.datetime.now()
datestamp = '%04d%02d%02d' %(now.year, now.month, now.day)
with open(list) as f:
for bug in f.readlines():
bug = bug.rstrip()
triage = {'reviewer': username,
'osic': 'y'}
common.clobber_object(container,
'%s-bug/%s-%s' %(project, bug, datestamp),
json.dumps(triage, indent=4, sort_keys=True))
print 'Done!'
开发者ID:neillc,项目名称:bugminion,代码行数:25,代码来源:prioritize_list.py
示例10: load
def load(context, path, callback):
key = (
context.config.RACKSPACE_PYRAX_REGION,
context.config.get('RACKSPACE_PYRAX_IDENTITY_TYPE','rackspace'),
context.config.RACKSPACE_PYRAX_CFG,
context.config.RACKSPACE_PYRAX_PUBLIC,
context.config.RACKSPACE_LOADER_CONTAINER
)
if key not in CONNECTIONS:
if(context.config.RACKSPACE_PYRAX_REGION):
pyrax.set_default_region(context.config.RACKSPACE_PYRAX_REGION)
pyrax.set_setting('identity_type', context.config.get('RACKSPACE_PYRAX_IDENTITY_TYPE','rackspace'))
pyrax.set_credential_file(expanduser(context.config.RACKSPACE_PYRAX_CFG))
cf = pyrax.connect_to_cloudfiles(public=context.config.RACKSPACE_PYRAX_PUBLIC)
CONNECTIONS[key] = cf.get_container(context.config.RACKSPACE_LOADER_CONTAINER)
cont = CONNECTIONS[key]
file_abspath = normalize_path(context, path)
logger.debug("[LOADER] getting from %s/%s" % (context.config.RACKSPACE_LOADER_CONTAINER, file_abspath))
try:
obj = cont.get_object(file_abspath)
if obj:
logger.debug("[LOADER] Found object at %s/%s" % (context.config.RACKSPACE_LOADER_CONTAINER, file_abspath))
else:
logger.warning("[LOADER] Unable to find object %s/%s" % (context.config.RACKSPACE_LOADER_CONTAINER, file_abspath ))
except:
callback(None)
else:
callback(obj.get())
开发者ID:Superbalist,项目名称:thumbor_rackspace,代码行数:30,代码来源:cloudfiles_loader.py
示例11: deleteFile
def deleteFile(username, userid, userkey, userenabled, lid, lname, fp, date,**kw):
if userenabled:
print format('Access CloudFiles for user id %s : user name %s' %
(pyrax.identity.user['id'], pyrax.identity.user['name']))
filename = genRemoteFileName(lid, lname, date)
gencname = genContName(lid, lname, date)
if gencname in deleted_containers:
print "container %s already deleted"%gencname
return
cf = pyrax.connect_to_cloudfiles(region=getRegion())
try:
print format('Deleteing... \n Remote File Name: %s size(%i) as %s, Container Name: %s' % (fp,os.stat(fp).st_size,filename, gencname))
print format('WARNING DELETING Container and files from %s' % gencname)
delcont = cf.get_container(gencname)
print format('Retrieved container to delete is %s' % delcont.name)
cf.delete_container(gencname,del_objects=True)
deleted_containers.add(gencname)
print format("Successfully deleted file/container for: LBID: %s" % lid)
except Exception, e:
print 'DELETING failed for %s %s. Exception: %s' % (userid, username, e)
return
except KeyboardInterrupt:
print "Skipping this entry"
time.sleep(1.0)
开发者ID:carriercomm,项目名称:atlas-lb,代码行数:27,代码来源:delcontainers.py
示例12: main
def main(username, project, list):
pyrax.set_setting('identity_type', 'rackspace')
with open(os.path.expanduser('~/.bugminion'), 'r') as f:
conf = json.loads(f.read())
pyrax.set_credentials(conf['access_key'],
conf['secret_key'],
region=conf['region'].upper())
conn = pyrax.connect_to_cloudfiles(region=conf['region'].upper())
container = conn.create_container(conf['container'])
now = datetime.datetime.now()
datestamp = '%04d%02d%02d' %(now.year, now.month, now.day)
with open(list) as f:
with open('%s.csv' % list, 'w') as csvfile:
csvwriter = csv.writer(csvfile, dialect='excel')
for bug in f.readlines():
bug = bug.rstrip()
try:
data = json.loads(container.get_object(
'%s-bug/%s' %(project, bug)).get())
except pyrax.exceptions.NoSuchObject:
data = {}
csvwriter.writerow([
'https://bugs.launchpad.net/nova/+bug/%s' % bug,
data.get('title', 'unknown'),
data.get('status', 'unknown'),
username])
print 'Done!'
开发者ID:neillc,项目名称:bugminion,代码行数:32,代码来源:spreadsheetize_list.py
示例13: uploadFile
def uploadFile(username, userid, userkey, userenabled, lid, lname, fp, date,**kw):
upenabled = kw.pop('upenabled','true')
cleardirs = kw.pop('cleardirs','true')
if upenabled == 'false':
print "Not uploading files, option disabled!"
print format('Files will not be uploaded: %s for userId: %s' % (fp, userid))
return
if userenabled:
print format('Access CloudFiles for user id %s : user name %s' %
(pyrax.identity.user['id'], pyrax.identity.user['name']))
cf = pyrax.connect_to_cloudfiles(region=getRegion())
try:
cf.create_container(genContName(lid, lname, date))
chksum = pyrax.utils.get_checksum(fp)
filename = genRemoteFileName(lid, lname, date)
gencname = genContName(lid, lname, date)
print format('Uploading... \n Remote File Name: %s size(%i) as %s, Container Name: %s' % (fp,os.stat(fp).st_size,filename, gencname))
ucont = cf.upload_file(gencname, fp, obj_name=filename, etag=chksum)
print "Chksum valid: ", chksum == ucont.etag
print format("Successfully uploaded file for: LBID: %s" % lid)
print "DELETING UPLOADED FILE:",fp
removeLocalFile(fp)
except exc.UploadFailed, e:
print 'Upload failed for %s %s. Exception: %s' % (userid, username, e)
return
except KeyboardInterrupt:
print "Skipping this entry"
time.sleep(1.0)
开发者ID:carriercomm,项目名称:atlas-lb,代码行数:29,代码来源:logsup.py
示例14: connect_container
def connect_container(self):
"""
Connects to a container using the swiftclient api.
The container will be created and/or made public using the
pyrax api if not already so.
"""
if CUMULUS["USE_PYRAX"]:
public = not self.use_snet # invert
self.conn = pyrax.connect_to_cloudfiles(region=self.region,
public=public)
else:
self.conn = swiftclient.Connection(authurl=CUMULUS["AUTH_URL"],
user=CUMULUS["USERNAME"],
key=CUMULUS["API_KEY"],
snet=CUMULUS["SERVICENET"],
auth_version=CUMULUS["AUTH_VERSION"],
tenant_name=CUMULUS["AUTH_TENANT_NAME"])
#try:
# self.conn.head_container(self.container_name)
#except swiftclient.client.ClientException as exception:
# if exception.msg == "Container HEAD failed":
# call_command("container_create", self.container_name)
# else:
# raise
self.container = self.conn.get_container(self.container_name)
开发者ID:Rhombik,项目名称:rhombik-django-cumulus,代码行数:28,代码来源:syncfiles.py
示例15: cache_clean
def cache_clean(folder, extension):
# NOTE: Manually install gevent & pyrax, no need for it to be depenency just for this method.
from gevent import monkey
from gevent.pool import Pool
from gevent import Timeout
monkey.patch_all()
import six
import pyrax
import logging
from mfr.server import settings
# Monkey patch pyrax for python 3 compatibility.
def _add_details(self, info):
"""
Takes the dict returned by the API call and sets the
corresponding attributes on the object.
"""
for (key, val) in six.iteritems(info):
if six.PY2 and isinstance(key, six.text_type):
key = key.encode(pyrax.get_encoding())
elif isinstance(key, bytes):
key = key.decode("utf-8")
setattr(self, key, val)
pyrax.resource.BaseResource._add_details = _add_details
# WARNING: We are using provider specific functions to enumerate files to quickly
# purge the cache, which can contain hundreds of thousands of objects. Thus
# asserting the provider, we will need to update if we move providers.
assert settings.CACHE_PROVIDER_NAME == 'cloudfiles'
logging.captureWarnings(True)
pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_setting('verify_ssl', True)
pyrax.set_credentials(settings.CACHE_PROVIDER_CREDENTIALS['username'], settings.CACHE_PROVIDER_CREDENTIALS['token'])
cf = pyrax.connect_to_cloudfiles(region=settings.CACHE_PROVIDER_CREDENTIALS['region'].upper(), public=True)
container = cf.get_container(settings.CACHE_PROVIDER_SETTINGS['container'])
def delete_object(obj):
# added timeout of 5 seconds just in case
with Timeout(5, False):
try:
print(obj)
obj.delete()
except Exception as ex:
print(ex)
pool = Pool(100)
objects = container.get_objects(prefix=folder, limit=5000, marker='')
while objects:
for obj in objects:
if obj.name.endswith(extension):
pool.spawn(delete_object, obj)
objects = container.get_objects(prefix=folder, limit=5000, marker=objects[-1].name)
pool.join()
开发者ID:CenterForOpenScience,项目名称:modular-file-renderer,代码行数:59,代码来源:tasks.py
示例16: __init__
def __init__(self, context):
self.context = context
if(self.context.config.RACKSPACE_PYRAX_REGION):
pyrax.set_default_region(self.context.config.RACKSPACE_PYRAX_REGION)
pyrax.set_credential_file(expanduser(self.context.config.RACKSPACE_PYRAX_CFG))
self.cloudfiles = pyrax.connect_to_cloudfiles(public=self.context.config.RACKSPACE_PYRAX_PUBLIC)
开发者ID:ettoredn,项目名称:thumbor_rackspace,代码行数:8,代码来源:cloudfile_storage.py
示例17: connection
def connection(self):
if not hasattr(self, '_connection'):
pyrax.set_credentials(self.username, self.api_key)
# For some reason pyrax.encoding doesn't get set by default.
pyrax.encoding = "utf-8"
self._connection = pyrax.connect_to_cloudfiles(
region=self.region)
return self._connection
开发者ID:dustinfarris,项目名称:django-rax,代码行数:8,代码来源:mixin.py
示例18: setUp
def setUp(self):
pyrax.connect_to_cloudservers = Mock()
pyrax.connect_to_cloud_loadbalancers = Mock()
pyrax.connect_to_cloud_databases = Mock()
pyrax.connect_to_cloud_blockstorage = Mock()
pyrax.clear_credentials()
pyrax.identity = FakeIdentity()
pyrax.set_credentials("fakeuser", "fakeapikey")
pyrax.connect_to_cloudfiles()
self.client = pyrax.cloudfiles
self.container = FakeContainer(self.client, self.container_name, 0, 0)
self.container.name = self.container_name
self.client.get_container = Mock(return_value=self.container)
self.client.connection.get_container = Mock()
self.client.connection.head_object = Mock(return_value=fake_attdict)
self.storage_object = self.client.get_object(self.container, "testobj")
self.client._container_cache = {}
self.container.object_cache = {}
开发者ID:datalogics-kam,项目名称:pyrax,代码行数:18,代码来源:test_cf_storage_object.py
示例19: isdir
def isdir(self):
conn = pyrax.connect_to_cloudfiles(region=self.region.upper())
container = conn.create_container(self.container_name)
prefix = remote_filename(self.path) + '~'
results = container.get_objects(prefix=prefix)
if not results:
return False
return True
开发者ID:mikalstill,项目名称:cloudfiles-tools,代码行数:9,代码来源:remote_pyrax.py
示例20: main
def main(username, project):
pyrax.set_setting('identity_type', 'rackspace')
with open(os.path.expanduser('~/.bugminion'), 'r') as f:
conf = json.loads(f.read())
pyrax.set_credentials(conf['access_key'],
conf['secret_key'],
region=conf['region'].upper())
conn = pyrax.connect_to_cloudfiles(region=conf['region'].upper())
container = conn.create_container(conf['container'])
# Read the most recent bug dump
most_recent = common.get_most_recent_dump(container, project)
most_recent_datestamp = most_recent.split('/')[1]
print 'Using the dump from %s' % most_recent
bug_list = json.loads(container.get_objects(prefix=most_recent)[0].get())
for priority in common.PRIORITIES:
targets = bug_list.get(priority, [])
random.shuffle(targets)
for bug in targets:
triages = common.triages(container, project, bug)
if not common.recently_triaged(triages):
print 'Bug %s (%s) is not triaged' %(bug, priority)
print 'Triages: %s' % triages
data = json.loads(container.get_object('%s-bug/%s'
%(project, bug)).get())
for field in common.DISPLAY_ORDER:
print '%s: %s' %(field, data.get(field, ''))
print 'tags: %s' % ' '.join(data.get('tags', []))
print
print 'Description:'
print
print data.get('description')
print
triage = {'reviewer': username}
sys.stdout.write('OSIC (y/n)? ')
triage['osic'] = sys.stdin.readline().rstrip()
if triage['osic'] == 'y':
for question in common.QUESTIONS:
sys.stdout.write('%s? ' % question)
answer = sys.stdin.readline().rstrip()
triage[question] = answer
common.clobber_object(container,
'%s-bug/%s-%s' %(project, bug,
most_recent_datestamp),
json.dumps(triage, indent=4,
sort_keys=True))
print
print
print 'Done!'
开发者ID:neillc,项目名称:bugminion,代码行数:57,代码来源:triage.py
注:本文中的pyrax.connect_to_cloudfiles函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论