def swift_get_container(request, container_name, with_data=True): if with_data: headers, data = swift_api(request).get_object(container_name, "") else: data = None headers = swift_api(request).head_container(container_name) timestamp = None is_public = False public_url = None try: is_public = GLOBAL_READ_ACL in headers.get('x-container-read', '') if is_public: swift_endpoint = base.url_for(request, 'object-store', endpoint_type='publicURL') parameters = urlparse.quote(container_name.encode('utf8')) public_url = swift_endpoint + '/' + parameters ts_float = float(headers.get('x-timestamp')) timestamp = timeutils.iso8601_from_timestamp(ts_float) except Exception: pass container_info = { 'name': container_name, 'container_object_count': headers.get('x-container-object-count'), 'container_bytes_used': headers.get('x-container-bytes-used'), 'timestamp': timestamp, 'data': data, 'is_public': is_public, 'public_url': public_url, } return Container(container_info)
def swift_get_object(request, container_name, object_name, with_data=True): if with_data: headers, data = swift_api(request).get_object(container_name, object_name) else: data = None headers = swift_api(request).head_object(container_name, object_name) orig_name = headers.get("x-object-meta-orig-filename") timestamp = None try: ts_float = float(headers.get('x-timestamp')) timestamp = timeutils.iso8601_from_timestamp(ts_float) except Exception: pass obj_info = { 'name': object_name, 'bytes': headers.get('content-length'), 'content_type': headers.get('content-type'), 'etag': headers.get('etag'), 'timestamp': timestamp, } return StorageObject(obj_info, container_name, orig_name=orig_name, data=data)
def swift_get_object(request, container_name, object_name, with_data=True): if with_data: headers, data = swift_api(request).get_object(container_name, object_name) else: data = None headers = swift_api(request).head_object(container_name, object_name) orig_name = headers.get("x-object-meta-orig-filename") timestamp = None try: ts_float = float(headers.get('x-timestamp')) timestamp = timeutils.iso8601_from_timestamp(ts_float) except Exception: pass obj_info = { 'name': object_name, 'bytes': headers.get('content-length'), 'content_type': headers.get('content-type'), 'etag': headers.get('etag'), 'timestamp': timestamp, } return StorageObject(obj_info, container_name, orig_name=orig_name, data=data)
def swift_get_container(request, container_name, with_data=True): if with_data: headers, data = swift_api(request).get_object(container_name, "") else: data = None headers = swift_api(request).head_container(container_name) timestamp = None is_public = False public_url = None try: is_public = GLOBAL_READ_ACL in headers.get('x-container-read', '') if is_public: swift_endpoint = base.url_for(request, 'object-store', endpoint_type='publicURL') public_url = swift_endpoint + '/' + urlparse.quote(container_name) ts_float = float(headers.get('x-timestamp')) timestamp = timeutils.iso8601_from_timestamp(ts_float) except Exception: pass container_info = { 'name': container_name, 'container_object_count': headers.get('x-container-object-count'), 'container_bytes_used': headers.get('x-container-bytes-used'), 'timestamp': timestamp, 'data': data, 'is_public': is_public, 'public_url': public_url, } return Container(container_info)
def stat_message(message, now): """Creates a stat document from the given message, relative to now.""" msg_id = message['id'] created = oid_ts(to_oid(msg_id)) age = now - created return { 'id': msg_id, 'age': int(age), 'created': timeutils.iso8601_from_timestamp(created), }
def stat_message(message, now): """Creates a stat document from the given message, relative to now.""" msg_id = message['id'] created = oid_ts(to_oid(msg_id)) age = now - created return { 'id': msg_id, 'age': int(age), 'created': timeutils.iso8601_from_timestamp(created), }
def list_cached(options, args): """%(prog)s list-cached [options] List all images currently cached. """ client = get_client(options) images = client.get_cached_images() if not images: print("No cached images.") return SUCCESS print("Found %d cached images..." % len(images)) pretty_table = utils.PrettyTable() pretty_table.add_column(36, label="ID") pretty_table.add_column(19, label="Last Accessed (UTC)") pretty_table.add_column(19, label="Last Modified (UTC)") # 1 TB takes 13 characters to display: len(str(2**40)) == 13 pretty_table.add_column(14, label="Size", just="r") pretty_table.add_column(10, label="Hits", just="r") print(pretty_table.make_header()) for image in images: last_modified = image['last_modified'] last_modified = timeutils.iso8601_from_timestamp(last_modified) last_accessed = image['last_accessed'] if last_accessed == 0: last_accessed = "N/A" else: last_accessed = timeutils.iso8601_from_timestamp(last_accessed) print(pretty_table.make_row( image['image_id'], last_accessed, last_modified, image['size'], image['hits']))
def to_basic(self, now, include_created=False): basic_msg = { 'id': self.id, 'age': now - self.created, 'ttl': self.ttl, 'body': self.body, 'claim_id': self.claim_id, } if include_created: created_iso = timeutils.iso8601_from_timestamp(self.created) basic_msg['created'] = created_iso return basic_msg
def to_basic(self, now, include_created=False): basic_msg = { 'id': self.id, 'age': now - self.created, 'ttl': self.ttl, 'body': self.body, 'claim_id': self.claim_id, } if include_created: created_iso = timeutils.iso8601_from_timestamp(self.created) basic_msg['created'] = created_iso return basic_msg
def test_iso8601_from_timestamp(self): utcnow = timeutils.utcnow() iso = timeutils.isotime(utcnow) ts = calendar.timegm(utcnow.timetuple()) self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))
def test_iso8601_from_timestamp(self): utcnow = timeutils.utcnow() iso = timeutils.isotime(utcnow) ts = calendar.timegm(utcnow.timetuple()) self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))