本文整理汇总了Python中boto.cloudfront.CloudFrontConnection.create_invalidation_request方法的典型用法代码示例。如果您正苦于以下问题:Python CloudFrontConnection.create_invalidation_request方法的具体用法?Python CloudFrontConnection.create_invalidation_request怎么用?Python CloudFrontConnection.create_invalidation_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.cloudfront.CloudFrontConnection
的用法示例。
在下文中一共展示了CloudFrontConnection.create_invalidation_request方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invalidate
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def invalidate(paths):
try:
print("Invalidating...")
conn = CloudFrontConnection()
conn.create_invalidation_request(AWS_CF_DISTRIBUTION_ID, paths)
return True
except:
return False
示例2: handle_noargs
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def handle_noargs(self, **options):
try:
access_key = settings.AWS_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
distribution = settings.AWS_CF_DISTRIBUTION_ID
static_url = settings.STATIC_URL
except AttributeError:
raise ImproperlyConfigured(
'Please specify AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,'
' AWS_CF_DISTRIBUTION_ID in settings\n')
super(Command, self).handle_noargs(**options)
invalid_files = self.copied_files + self.symlinked_files
if not len(invalid_files):
self.stdout.write('Nothing to invalidate\n')
return
self.stdout.write('Invalidating files...\n')
# we need add static prefix to each address
static_prefix = urlsplit(static_url).path
invalid_files = \
[urljoin(static_prefix, path) for path in invalid_files if path]
invalidation_step = 1000
invalication_max_num = 3
invalidation_max_files = invalidation_step * invalication_max_num
def dump(invalid_files):
import tempfile
from django.utils import simplejson
dump = tempfile.NamedTemporaryFile(delete=False)
dump.write(simplejson.dumps(invalid_files, indent=2))
dump.close()
return dump.name
if len(invalid_files) > invalidation_max_files:
raise AssertionError(
"There are more than %s files to invalidate, "
"AWS doesn't support it at the moment.\n"
"File names to be invalidated dumped to JSON file %s, "
"please invalidate manually\n"""
% (invalidation_max_files, dump(invalid_files)))
conn = CloudFrontConnection(access_key, secret_key)
try:
for i in xrange(invalication_max_num):
thousand = invalid_files[i:i + invalidation_step]
if not thousand: break
conn.create_invalidation_request(distribution, thousand)
except exception.CloudFrontServerError, message:
self.stderr.write('Error while processing:\n\n%s\n\n'
'Unprocessed files dumped to JSON file %s, '
'please invalidate manually\n'
% (message, dump(invalid_files)))
示例3: invalidate_paths
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def invalidate_paths(deploy_type, paths, *args, **kwargs):
"""
Helper function, create an invalidation request for CloudFront distribution
:param deploy_type: The deploy type
:param paths: The paths array
"""
from boto.cloudfront import CloudFrontConnection
# TODO chunking invalidation to prevent error
distributions = get_conf('AWS_DISTRIBUTION_ID', deploy_type=deploy_type)
if isinstance(distributions, list):
distributions = distributions
else:
distributions = [distributions]
for distribution in distributions:
conn_cf = CloudFrontConnection(get_conf('AWS_ACCESS_KEY_ID', deploy_type=deploy_type),
get_conf('AWS_SECRET_ACCESS_KEY', deploy_type=deploy_type))
conn_cf.create_invalidation_request(distribution, paths)
示例4: invalidate_cache
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def invalidate_cache(ec2, env, source):
""" Invalidate CloudFront cache for each machine with a Cloudfront Distribution ID"""
# NOTE: Creating distributions is not yet supported, only cache invalidation
cfc = CloudFrontConnection(ec2.access_key,ec2.secret_key)
for machine in env:
if 'cloudfront' in machine.keys():
print 'Invalidating cache for %s' % machine['name']
cloudfront = machine['cloudfront'] # Cloudfront Distribution ID
media_files = []
static_dir = os.path.join(source,'project','static')
for root, dirs, files in os.walk(static_dir):
if '.svn' in dirs: dirs.remove('.svn')
key_root = root.split('static')[1]
for file in files:
filename = os.path.join(root,file)
if os.path.isfile(filename):
media_files.append(os.path.join(key_root,file))
cfc.create_invalidation_request(cloudfront, media_files)
示例5: do_invalidate
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def do_invalidate(distrib_id, inval_keys, creds):
'''
Send a CloudFront invalidation request for the given objects.
'''
cf = CloudFrontConnection(**creds.as_dict())
distrib = get_distribution(cf, distrib_id)
req = cf.create_invalidation_request(distrib.id, inval_keys)
pbar = s3pub.progress.InvalidationProgressBar(req.id)
for _ in pbar(Monitor(cf, distrib_id, req.id)):
pass
print('Done.')
示例6: do_invalidation
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def do_invalidation(self):
files = sys.argv[1:]
if len(files) > 0:
print 'Sending invalidation request for the following files:'
for f in files:
print f
conn = CloudFrontConnection(settings.AWS_ACCESS_KEY, settings.AWS_SECRET_ACCESS_KEY)
req = conn.create_invalidation_request(settings.AWS_CF_DISTRIBUTION_ID, files)
print req.status
else:
self.help()
sys.exit()
示例7: Level3Service
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
import sys, datetime, settings
from level3client import Level3Service
from boto.cloudfront import CloudFrontConnection
urls = sys.argv
urls.remove('invcache.py')
scope = settings.level3scope
key_id = settings.level3key
secret = settings.level3secret
service = Level3Service(key_id, secret, method='POST')
result = service('invalidations/%s' % scope, post_data="""
<paths>
%s
</paths>
""" % ('\n'.join(['<path>%s</path>' % url for url in urls]))
)
conn = CloudFrontConnection( settings.awscfkey, settings.awscfsecret )
invreq = conn.create_invalidation_request( settings.awscfdistribution, urls)
print "Level3 Invalidation Request:"
print result.dom.toprettyxml()
print "CloudFront Invalidation Status:"
print invreq.status
示例8: CloudFrontConnection
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
#!/usr/bin/env python
__author__ = "Stamped ([email protected])"
__version__ = "1.0"
__copyright__ = "Copyright (c) 2011-2012 Stamped.com"
__license__ = "TODO"
import Globals
import datetime, os, sys, urllib2, utils
import keys.aws
from boto.cloudfront import CloudFrontConnection
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
args = parser.parse_args()
files = [ '/assets/css/screen.css', '/assets/css/styles.css' ]
conn = CloudFrontConnection(keys.aws.AWS_ACCESS_KEY_ID, keys.aws.AWS_SECRET_KEY)
# NOTE: this cloudfront distribution id is hardcoded to the static.stamped.com distro
distribution_id = 'E17S1XTPOFC1EQ'
print conn.create_invalidation_request(distribution_id, files)
示例9: invalidate_all
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def invalidate_all(aws_access_key, aws_secret_key, cloudfront_distribution):
print("Invalidating all")
cloudfront_connection = CloudFrontConnection(aws_access_key, aws_secret_key)
cloudfront_connection.create_invalidation_request(cloudfront_distribution, "/*")
示例10: CloudFrontConnection
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
files = ['/css/style.css',
'/favicon.ico',
'/images/harper_6.jpg',
'/images/glider.png',
'/js/scripts.js',
'/css/style.css',
'/images/DateHeaderIco.png',
'/images/PostComLeft.png',
'/images/PostComRight.png',
'/images/PostDetailsTagsIco.png',
'/images/RelatedPostsHeading.png',
'/images/RelatedPostsLi.png',
'/images/CommentsListHeading.png',
'/images/CommentsFormHeading.png',
'/images/SubmitComment.png',
'/images/SubmitComment.png',
'/images/SubmitComment.png',
'/images/CategIco.png',
'/images/tr.png',
'/images/tl.png',
'/images/br.png',
'/images/bl.png',
'/images/SRLBkg',
'/images/SRRBkg',
'/images/close2.png',]
conn = CloudFrontConnection()
print conn.create_invalidation_request(AWS_CF_DISTRIBUTION_ID, files)
示例11: create_invalidation
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def create_invalidation(article, settings):
cloudfront = CloudFrontConnection(settings.aws_access_key_id, settings.aws_secret_access_key)
inval_req = cloudfront.create_invalidation_request(settings.cloudfront_distribution_id_cdn,
["/articles/" + article + "/*"])
assert isinstance(inval_req, InvalidationBatch), \
"Invalidation request did not return expected object."
示例12: invalidate_cloudfront
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def invalidate_cloudfront():
conn = CloudFrontConnection(env.cdn['aws_access_key'], env.cdn['aws_secret_key'])
print conn.create_invalidation_request(env.cdn['aws_cloudfront_id'], env.cdn['files'])
print 'Invalidated cloudfront cache for ...%s' % '\n\t '.join(env.cdn['files'])
env.cdn['files'] = []
示例13: clear_cloudfront_cache
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import create_invalidation_request [as 别名]
def clear_cloudfront_cache(base_dir,index_file,dir_prefix='',passn=0):
base_dir = os.path.abspath(base_dir)
all_files = get_files_from_dir(base_dir)
if(os.path.exists(index_file)):
data = file(index_file).read()
os.unlink(index_file+'.back')
file(index_file+'.back','w').write(data)
else:
data = ''
file(index_file+'.back','w').write('')
index = {}
data = data.split('\n')
for line in data:
if not line:
continue
path,md5 = line.split('\t#\t')
index[path] = md5
new_files,new_files_raw = get_modified_files(base_dir,all_files,index,dir_prefix)
for filename in index.iterkeys():
if filename not in all_files:
next = False
for it in IGNORE:
if it in filename:
next = True
if next:
continue
new_files.append(os.path.join(dir_prefix,filename.strip('/')))
new_files_raw.append(filename)
if new_files:
for filename in new_files:
print 'Modified: %s' % filename
else:
print 'No files were modified.\n'
sys.exit()
print '\nUploading %s files\n' % len(new_files)
inp = ''
while (inp != 'y' and inp != 'n'):
inp = raw_input('Upload changes to CloudFront(y/n): ')
if inp == 'y':
try:
conn = CloudFrontConnection(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY)
k = 0
for i in xrange(0,len(new_files),800):
if k < passn:
k += 1
continue
res = True
res = conn.create_invalidation_request(AWS_CF_DISTRIBUTION_ID, new_files[i:i+900])
if res:
print '\nInvalidation request created'
for filename in new_files_raw[i:i+800]:
fc = file(base_dir+filename).read()
index[filename] = hashlib.md5(fc).hexdigest()
if k >= (passn+2):
print '\nToo many files. Repeat update after 15 minutes.'
break
k += 1
except Exception,e:
save_index(index_file,index)
sys.exit('\nError: %s' % e)
save_index(index_file,index)