def upload(self, image): """ Upload an image to pulp. This does not associate it with any repository. :param image: str, pathname """ # TODO: support a hidden repo for "no-channel" style uploads rid = self._createUploadRequest() size = int(os.path.getsize(image)) curr = 0 mb = 1024 * 1024 # 1M try: block = self.chunk_size if block == None: block = mb # chunk size is in MB, need to convert else: block = block * mb except AttributeError: # chunk size defaults to 1 MB if not set block = mb log.info('uploading a %sM image' % (size / mb,)) log.debug('using a chunk size of %sM' % (block / mb,)) with open(image) as fobj: while curr < size: data = fobj.read(block) self._put('/pulp/api/v2/content/uploads/%s/%s/' % (rid, curr), data=data) curr += len(data) log.debug('%s/%s bytes sent' % (curr, size)) log.info('content uploaded') iid = imgutils.get_id(image) data = { # type_id is from pulp_docker.common.constants.IMAGE_TYPE_ID 'unit_type_id': V1_C_TYPE, 'upload_id': rid, 'unit_key': {'image_id': iid}, 'unit_metadata': { 'checksum_type': None, 'filename': os.path.basename(image) } } log.info('adding %s to %s' % (iid, HIDDEN)) log.debug('repo import request data:') log.debug(pprint.pformat(data)) tid = self._post( '/pulp/api/v2/repositories/%s/actions/import_upload/' % HIDDEN, data=json.dumps(data)) timer = max(self.timeout, (size/mb)*2) # wait 2 seconds per megabyte, or timeout, self.watch(tid, timeout=timer) # whichever is greater self._deleteUploadRequest(rid)
def upload(self, image): """ Upload an image to pulp. This does not associate it with any repository. """ # TODO: support a hidden repo for "no-channel" style uploads rid = self._createUploadRequest() size = int(os.path.getsize(image)) curr = 0 block = 1024 * 1024 # 1M log.info('uploading a %sM image' % (size / block, )) with open(image) as fobj: while curr < size: data = fobj.read(block) self._put('/pulp/api/v2/content/uploads/%s/%s/' % (rid, curr), data=data) curr += len(data) log.debug('%s/%s bytes sent' % (curr, size)) log.info('content uploaded') iid = imgutils.get_id(image) data = { # type_id is from pulp_docker.common.constants.IMAGE_TYPE_ID 'unit_type_id': C_TYPE, 'upload_id': rid, 'unit_key': { 'image_id': iid }, 'unit_metadata': { 'checksum_type': None, 'filename': os.path.basename(image) } } log.info('adding %s to %s' % (iid, HIDDEN)) log.debug('repo import request data:') log.debug(pprint.pformat(data)) tid = self._post( '/pulp/api/v2/repositories/%s/actions/import_upload/' % HIDDEN, data=json.dumps(data)) timer = max(60, (size / block) * 2) # wait 2 seconds per megabyte, or 60, self.watch(tid, timeout=timer) # whichever is greater self._deleteUploadRequest(rid)
def upload(self, image): """ Upload an image to pulp. This does not associate it with any repository. """ # TODO: support a hidden repo for "no-channel" style uploads rid = self._createUploadRequest() size = int(os.path.getsize(image)) curr = 0 block = 1024 * 1024 # 1M log.info('uploading a %sM image' % (size / block,)) with open(image) as fobj: while curr < size: data = fobj.read(block) self._put('/pulp/api/v2/content/uploads/%s/%s/' % (rid, curr), data=data) curr += len(data) log.debug('%s/%s bytes sent' % (curr, size)) log.info('content uploaded') iid = imgutils.get_id(image) data = { # type_id is from pulp_docker.common.constants.IMAGE_TYPE_ID 'unit_type_id': C_TYPE, 'upload_id': rid, 'unit_key': {'image_id': iid}, 'unit_metadata': { 'checksum_type': None, 'filename': os.path.basename(image) } } log.info('adding %s to %s' % (iid, HIDDEN)) log.debug('repo import request data:') log.debug(pprint.pformat(data)) tid = self._post( '/pulp/api/v2/repositories/%s/actions/import_upload/' % HIDDEN, data=json.dumps(data)) timer = max(60, (size/block)*2) # wait 2 seconds per megabyte, or 60, self.watch(tid, timeout=timer) # whichever is greater self._deleteUploadRequest(rid)