diff --git a/S3/CloudFront.py b/S3/CloudFront.py index d04ffee45..62f8b7b1b 100644 --- a/S3/CloudFront.py +++ b/S3/CloudFront.py @@ -91,6 +91,9 @@ def parse(self, tree): self.info['IsTruncated'] = (self.info['IsTruncated'].lower() == "true") self.dist_summs = [] + self.marker = self.info.get('Marker') + self.next_marker = self.info.get('NextMarker') + self.max_items = self.info.get('MaxItems') for dist_summ in tree.findall(".//DistributionSummary"): self.dist_summs.append(DistributionSummary(dist_summ)) @@ -297,7 +300,7 @@ class CloudFront(object): operations = { "CreateDist" : { 'method' : "POST", 'resource' : "" }, "DeleteDist" : { 'method' : "DELETE", 'resource' : "/%(dist_id)s" }, - "GetList" : { 'method' : "GET", 'resource' : "" }, + "GetList" : { 'method' : "GET", 'resource' : "?Marker=%(Marker)s" }, "GetDistInfo" : { 'method' : "GET", 'resource' : "/%(dist_id)s" }, "GetDistConfig" : { 'method' : "GET", 'resource' : "/%(dist_id)s/config" }, "SetDistConfig" : { 'method' : "PUT", 'resource' : "/%(dist_id)s/config" }, @@ -317,12 +320,9 @@ def __init__(self, config): ## Methods implementing CloudFront API ## -------------------------------------------------- - def GetList(self): - response = self.send_request("GetList") + def GetList(self, marker = ''): + response = self.send_request("GetList", marker = marker) response['dist_list'] = DistributionList(response['data']) - if response['dist_list'].info['IsTruncated']: - raise NotImplementedError("List is truncated. Ask s3cmd author to add support.") - ## TODO: handle Truncated return response def CreateDistribution(self, uri, cnames_add = [], comment = None, logging = None, default_root_object = None): @@ -490,11 +490,11 @@ def GetInvalInfo(self, cfuri): ## Low-level methods for handling CloudFront requests ## -------------------------------------------------- - def send_request(self, op_name, dist_id = None, request_id = None, body = None, headers = {}, retries = _max_retries): + def send_request(self, op_name, dist_id = None, request_id = None, body = None, headers = {}, retries = _max_retries, marker = None): operation = self.operations[op_name] if body: headers['content-type'] = 'text/plain' - request = self.create_request(operation, dist_id, request_id, headers) + request = self.create_request(operation, dist_id, request_id, headers, marker) conn = self.get_connection() debug("send_request(): %s %s" % (request['method'], request['resource'])) conn.c.request(request['method'], request['resource'], body, request['headers']) @@ -524,9 +524,9 @@ def send_request(self, op_name, dist_id = None, request_id = None, body = None, return response - def create_request(self, operation, dist_id = None, request_id = None, headers = None): + def create_request(self, operation, dist_id = None, request_id = None, headers = None, marker = ''): resource = cloudfront_resource + ( - operation['resource'] % { 'dist_id' : dist_id, 'request_id' : request_id }) + operation['resource'] % { 'dist_id' : dist_id, 'request_id' : request_id, 'Marker': marker}) if not headers: headers = {} @@ -605,6 +605,7 @@ class Cmd(object): class Options(object): cf_cnames_add = [] + cf_marker = '' cf_cnames_remove = [] cf_comment = None cf_enable = None @@ -632,7 +633,13 @@ def _parse_args(args): def info(args): cf = CloudFront(Config()) if not args: - response = cf.GetList() + response = cf.GetList( marker=Cmd.options.cf_marker ) + pretty_output("Current Marker", response['dist_list'].marker) + pretty_output("Next Marker", response['dist_list'].next_marker) + pretty_output("Max Items", response['dist_list'].max_items) + pretty_output("Items", len(response['dist_list'].dist_summs)) + output("") + for d in response['dist_list'].dist_summs: if d.info.has_key("S3Origin"): origin = S3UriS3.httpurl_to_s3uri(d.info['S3Origin']['DNSName']) diff --git a/s3cmd b/s3cmd index d6aa9945a..65253cad1 100755 --- a/s3cmd +++ b/s3cmd @@ -2596,6 +2596,7 @@ def main(): optparser.add_option( "--cf-remove-cname", dest="cf_cnames_remove", action="append", metavar="CNAME", help="Remove given CNAME from a CloudFront distribution (only for [cfmodify] command)") optparser.add_option( "--cf-comment", dest="cf_comment", action="store", metavar="COMMENT", help="Set COMMENT for a given CloudFront distribution (only for [cfcreate] and [cfmodify] commands)") optparser.add_option( "--cf-default-root-object", dest="cf_default_root_object", action="store", metavar="DEFAULT_ROOT_OBJECT", help="Set the default root object to return when no object is specified in the URL. Use a relative path, i.e. default/index.html instead of /default/index.html or s3://bucket/default/index.html (only for [cfcreate] and [cfmodify] commands)") + optparser.add_option( "--cf-marker", dest="cf_marker", action="store", metavar="MARKER", help="Get next page when list of cloudfront distributions is a multilist list (only for [cflist] command)") optparser.add_option("-v", "--verbose", dest="verbosity", action="store_const", const=logging.INFO, help="Enable verbose output.") optparser.add_option("-d", "--debug", dest="verbosity", action="store_const", const=logging.DEBUG, help="Enable debug output.") optparser.add_option( "--version", dest="show_version", action="store_true", help="Show s3cmd version (%s) and exit." % (PkgInfo.version))