def neutron_backend_delete(self, req, id): """Registers a new neutron_backend with the registry. :param req: wsgi Request object :param body: Dictionary of information about the template :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ if id and not utils.is_uuid_like(id): msg = _LI("Rejecting neutron_backend delete " "request for invalid neutron_backend " "id '%(bad_id)s'") % {'bad_id': id} LOG.info(msg) msg = _("Invalid neutron_backend id format") return exc.HTTPBadRequest(explanation=msg) try: neutron_backend_data = self.db_api.neutron_backend_destroy( req.context, id) msg = (_LI("Successfully deleted neutron_backend %s") % id) LOG.info(msg) if 'neutron_backend' not in neutron_backend_data: neutron_backend_data = dict( neutron_backend=neutron_backend_data) return neutron_backend_data except exception.Invalid as e: msg = (_("Failed to delete neutron_backend metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to delete neutron_backend %s"), id) raise
def detail(self, req, id): """Registers a new hwm with the registry. :param req: wsgi Request object :param body: Dictionary of information about the template :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ if id and not utils.is_uuid_like(id): msg = _LI("Rejecting hwm delete request for invalid hwm " "id '%(bad_id)s'") % {'bad_id': id} LOG.info(msg) msg = _("Invalid hwm id format") return exc.HTTPBadRequest(explanation=msg) try: hwm_data = self.db_api.hwm_get(req.context, id) msg = (_LI("Successfully get hwm information:%s") % id) LOG.info(msg) if 'hwm' not in hwm_data: hwm_data = dict(hwm=hwm_data) return hwm_data except exception.Invalid as e: msg = (_("Failed to get hwm metadata. Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to get hwm %s"), id) raise
def template_delete(self, req, template_id): """Registers a new template with the registry. :param req: wsgi Request object :param body: Dictionary of information about the template :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ if template_id and not utils.is_uuid_like(template_id): msg = _LI("Rejecting template delete request for invalid template " "id '%(bad_id)s'") % { 'bad_id': template_id } LOG.info(msg) msg = _("Invalid template id format") return exc.HTTPBadRequest(explanation=msg) try: template_data = self.db_api.template_destroy( req.context, template_id) msg = (_LI("Successfully deleted template %s") % template_id) LOG.info(msg) if 'template' not in template_data: template_data = dict(template=template_data) return template_data except exception.Invalid as e: msg = (_("Failed to delete template metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to delete template %s"), template_id) raise
def host_template_detail(self, req, template_id): """Registers a new service_disk with the registry. :param req: wsgi Request object :param body: Dictionary of information about the service_disk :retval Returns the newly-created service_disk information as a mapping, which will include the newly-created service_disk's internal id in the 'id' field """ if template_id and not utils.is_uuid_like(template_id): msg = _LI("Rejecting template delete request for invalid template " "id '%(bad_id)s'") % {'bad_id': template_id} LOG.info(msg) msg = _("Invalid template id format") return exc.HTTPBadRequest(explanation=msg) try: template_data = self.db_api.host_template_get(req.context, template_id) #service_disk_data = dict(service_disk=make_image_dict(service_disk_data)) msg = (_LI("Successfully get template information:%s") % template_id) LOG.info(msg) if 'template' not in template_data: template_data = dict(host_template=template_data) return template_data except exception.Invalid as e: msg = (_("Failed to get template metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to get template %s"), template_id) raise
def _get_marker(self, req): """Parse a marker query param into something usable.""" marker = req.params.get('marker', None) if marker and not utils.is_uuid_like(marker): msg = _('Invalid marker format') raise exc.HTTPBadRequest(explanation=msg) return marker
def cinder_volume_add(self, req, body): """Registers a new cinder_volume with the registry. :param req: wsgi Request object :param body: Dictionary of information about the cinder_volume :retval Returns the newly-created cinder_volume information as a mapping, which will include the newly-created cinder_volume's internal id in the 'id' field """ cinder_volume_data = body["cinder_volume"] id = cinder_volume_data.get('id') # role = service_disk_data.get('role') # add id and role # if role # self.db_api.get_role(req.context,role) if id and not utils.is_uuid_like(id): msg = _LI("Rejecting cinder_volume creation request for " "invalid cinder_volume " "id '%(bad_id)s'") % {'bad_id': id} LOG.info(msg) msg = _("Invalid cinder_volume id format") return exc.HTTPBadRequest(explanation=msg) try: cinder_volume_data = self.db_api.cinder_volume_add( req.context, cinder_volume_data) msg = (_LI("Successfully created cinder_volume %s") % cinder_volume_data["id"]) LOG.info(msg) if 'cinder_volume' not in cinder_volume_data: cinder_volume_data = dict(cinder_volume=cinder_volume_data) return cinder_volume_data except exception.Duplicate: msg = _("cinder_volume with identifier %s already exists!") % id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add cinder_volume metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create cinder_volume %s"), id) raise
def create(self, req, body): """Registers a new image with the registry. :param req: wsgi Request object :param body: Dictionary of information about the image :retval Returns the newly-created image information as a mapping, which will include the newly-created image's internal id in the 'id' field """ image_data = body['image'] # Ensure the image has a status set image_data.setdefault('status', 'active') # Set up the image owner if not req.context.is_admin or 'owner' not in image_data: image_data['owner'] = req.context.owner image_id = image_data.get('id') if image_id and not utils.is_uuid_like(image_id): msg = _LI("Rejecting image creation request for invalid image " "id '%(bad_id)s'") % {'bad_id': image_id} LOG.info(msg) msg = _("Invalid image id format") return exc.HTTPBadRequest(explanation=msg) if 'location' in image_data: image_data['locations'] = [image_data.pop('location')] try: image_data = _normalize_image_location_for_db(image_data) image_data = self.db_api.image_create(req.context, image_data) image_data = dict(image=make_image_dict(image_data)) msg = (_LI("Successfully created image %(id)s") % image_data['image']) LOG.info(msg) return image_data except exception.Duplicate: msg = _("Image with identifier %s already exists!") % image_id LOG.warn(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add image metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create image %s"), image_id) raise
def add_network(self, req, body): """Registers a new network with the registry. :param req: wsgi Request object :param body: Dictionary of information about the network :retval Returns the newly-created network information as a mapping, which will include the newly-created network's internal id in the 'id' field """ network_data = body["network"] network_id = network_data.get('id') # role = network_data.get('role') # add network_id and role # if role # self.db_api.get_role(req.context,role) if network_id and not utils.is_uuid_like(network_id): msg = _LI("Rejecting network creation request for invalid network " "id '%(bad_id)s'") % {'bad_id': network_id} LOG.info(msg) msg = _("Invalid network id format") return exc.HTTPBadRequest(explanation=msg) try: network_data = self.db_api.network_add(req.context, network_data) #network_data = dict(network=make_image_dict(network_data)) msg = (_LI("Successfully created node %s") % network_data["id"]) LOG.info(msg) if 'network' not in network_data: network_data = dict(network=network_data) return network_data except exception.Duplicate: msg = _("node with identifier %s already exists!") % image_id LOG.warn(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add node metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create node %s"), network_id) raise
def add_network(self, req, body): """Registers a new network with the registry. :param req: wsgi Request object :param body: Dictionary of information about the network :retval Returns the newly-created network information as a mapping, which will include the newly-created network's internal id in the 'id' field """ network_data = body["network"] network_id = network_data.get('id') # role = network_data.get('role') # add network_id and role # if role # self.db_api.get_role(req.context,role) if network_id and not utils.is_uuid_like(network_id): msg = _LI("Rejecting network creation request for invalid network " "id '%(bad_id)s'") % { 'bad_id': network_id } LOG.info(msg) msg = _("Invalid network id format") return exc.HTTPBadRequest(explanation=msg) try: network_data = self.db_api.network_add(req.context, network_data) msg = (_LI("Successfully created node %s") % network_data["id"]) LOG.info(msg) if 'network' not in network_data: network_data = dict(network=network_data) return network_data except exception.Duplicate: msg = _("node with identifier %s already exists!") % network_id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add node metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create node %s"), network_id) raise
def add_config_set(self, req, body): """Registers a new config_set with the registry. :param req: wsgi Request object :param body: Dictionary of information about the config_set :retval Returns the newly-created config_set information as a mapping, which will include the newly-created config_set's internal id in the 'id' field """ config_set_data = body["config_set"] config_set_id = config_set_data.get('id') if config_set_id and not utils.is_uuid_like(config_set_id): msg = _LI("Rejecting config_set creation request for " "invalid config_set " "id '%(bad_id)s'") % { 'bad_id': config_set_id } LOG.info(msg) msg = _("Invalid config_set id format") return exc.HTTPBadRequest(explanation=msg) try: config_set_data = self.db_api.config_set_add( req.context, config_set_data) msg = (_LI("Successfully created config_set %s") % config_set_data["id"]) LOG.info(msg) if 'config_set' not in config_set_data: config_set_data = dict(config_set=config_set_data) return config_set_data except exception.Duplicate: msg = _("config_set with identifier %s already exists!") % \ config_set_id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add config_set metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create config_set %s"), config_set_id) raise
def add_config_set(self, req, body): """Registers a new config_set with the registry. :param req: wsgi Request object :param body: Dictionary of information about the config_set :retval Returns the newly-created config_set information as a mapping, which will include the newly-created config_set's internal id in the 'id' field """ config_set_data = body["config_set"] config_set_id = config_set_data.get('id') if config_set_id and not utils.is_uuid_like(config_set_id): msg = _LI("Rejecting config_set creation request for " "invalid config_set " "id '%(bad_id)s'") % {'bad_id': config_set_id} LOG.info(msg) msg = _("Invalid config_set id format") return exc.HTTPBadRequest(explanation=msg) try: config_set_data = self.db_api.config_set_add( req.context, config_set_data) msg = (_LI("Successfully created config_set %s") % config_set_data["id"]) LOG.info(msg) if 'config_set' not in config_set_data: config_set_data = dict(config_set=config_set_data) return config_set_data except exception.Duplicate: msg = _("config_set with identifier %s already exists!") % \ config_set_id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add config_set metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create config_set %s"), config_set_id) raise
def neutron_backend_add(self, req, body): """Registers a new neutron_backend with the registry. :param req: wsgi Request object :param body: Dictionary of information about the templatae :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ neutron_backend_data = body["neutron_backend"] id = neutron_backend_data.get('id') if id and not utils.is_uuid_like(id): msg = _LI("Rejecting neutron_backend creation " "request for invalid neutron_backend " "id '%(bad_id)s'") % { 'bad_id': id } LOG.info(msg) msg = _("Invalid neutron_backend id format") return exc.HTTPBadRequest(explanation=msg) try: neutron_backend_data = self.db_api.neutron_backend_add( req.context, neutron_backend_data) msg = (_LI("Successfully created neutron_backend %s") % neutron_backend_data["id"]) LOG.info(msg) if 'neutron_backend' not in neutron_backend_data: neutron_backend_data = dict( neutron_backend=neutron_backend_data) return neutron_backend_data except exception.Duplicate: msg = _("neutron_backend with identifier %s already exists!") % id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add neutron_backend metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create neutron_backend %s"), id) raise
def host_template_update(self, req, template_id, body): """Registers a new service_disk with the registry. :param req: wsgi Request object :param body: Dictionary of information about the service_disk :retval Returns the newly-created service_disk information as a mapping, which will include the newly-created service_disk's internal id in the 'id' field """ template_data = body["template"] # template_id = template_data.get('template_id') if template_id and not utils.is_uuid_like(template_id): msg = _LI("Rejecting cluster template creation request for " "invalid template " "id '%(bad_id)s'") % { 'bad_id': template_id } LOG.info(msg) msg = _("Invalid template id format") return exc.HTTPBadRequest(explanation=msg) try: template_data = self.db_api.host_template_update( req.context, template_id, template_data) msg = (_LI("Successfully updated template %s") % template_data["id"]) LOG.info(msg) if 'template' not in template_data: template_data = dict(host_template=template_data) return template_data except exception.Duplicate: msg = _("template with identifier %s already exists!") % \ template_id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to update template metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to update template %s"), template_id) raise
def add_version_patch(self, req, body): """Registers a new version with the registry. :param req: wsgi Request object :param body: Dictionary of information about the version :retval Returns the newly-created version information as a mapping, which will include the newly-created version's internal id in the 'id' field """ version_patch_data = body["version_patch"] version_patch_id = version_patch_data.get('id') if version_patch_id and not utils.is_uuid_like(version_patch_id): msg = _LI("Rejecting version creation request for invalid version " "id '%(bad_id)s'") % { 'bad_id': version_patch_id } LOG.info(msg) msg = _("Invalid version id format") return exc.HTTPBadRequest(explanation=msg) try: version_patch_data = self.db_api.version_patch_add( req.context, version_patch_data) msg = (_LI("Successfully created node %s") % version_patch_data["id"]) LOG.info(msg) if 'version_patch' not in version_patch_data: version_patch_data = dict(version_patch=version_patch_data) return version_patch_data except exception.Duplicate: msg = (_("version patch with identifier %s" " already exists!") % version_patch_id) LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add version patch metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create node %s"), version_patch_id) raise
def _walk_all_locations(self, remove=False): """Returns a list of image id and location tuple from scrub queue. :param remove: Whether remove location from queue or not after walk :retval a list of image id, location id and uri tuple from scrub queue """ if not os.path.exists(self.scrubber_datadir): LOG.warn(_LW("%s directory does not exist.") % self.scrubber_datadir) return [] ret = [] for root, dirs, files in os.walk(self.scrubber_datadir): for image_id in files: if not utils.is_uuid_like(image_id): continue with lockutils.lock("scrubber-%s" % image_id, lock_file_prefix='daisy-', external=True): file_path = os.path.join(self.scrubber_datadir, image_id) records = self._read_queue_file(file_path) loc_ids, uris, delete_times = records remove_record_idxs = [] skipped = False for (record_idx, delete_time) in enumerate(delete_times): if delete_time > time.time(): skipped = True continue else: ret.append((image_id, loc_ids[record_idx], uris[record_idx])) remove_record_idxs.append(record_idx) if remove: if skipped: # NOTE(zhiyan): remove location records from # the queue file. self._update_queue_file(file_path, remove_record_idxs) else: utils.safe_remove(file_path) return ret
def add_version_patch(self, req, body): """Registers a new version with the registry. :param req: wsgi Request object :param body: Dictionary of information about the version :retval Returns the newly-created version information as a mapping, which will include the newly-created version's internal id in the 'id' field """ version_patch_data = body["version_patch"] version_patch_id = version_patch_data.get('id') if version_patch_id and not utils.is_uuid_like(version_patch_id): msg = _LI("Rejecting version creation request for invalid version " "id '%(bad_id)s'") % {'bad_id': version_patch_id} LOG.info(msg) msg = _("Invalid version id format") return exc.HTTPBadRequest(explanation=msg) try: version_patch_data = self.db_api.version_patch_add( req.context, version_patch_data) msg = (_LI("Successfully created node %s") % version_patch_data["id"]) LOG.info(msg) if 'version_patch' not in version_patch_data: version_patch_data = dict(version_patch=version_patch_data) return version_patch_data except exception.Duplicate: msg = (_("version patch with identifier %s" " already exists!") % version_patch_id) LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add version patch metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create node %s"), version_patch_id) raise
def host_template_update(self, req, template_id, body): """Registers a new service_disk with the registry. :param req: wsgi Request object :param body: Dictionary of information about the service_disk :retval Returns the newly-created service_disk information as a mapping, which will include the newly-created service_disk's internal id in the 'id' field """ template_data = body["template"] # template_id = template_data.get('template_id') if template_id and not utils.is_uuid_like(template_id): msg = _LI("Rejecting cluster template creation request for " "invalid template " "id '%(bad_id)s'") % {'bad_id': template_id} LOG.info(msg) msg = _("Invalid template id format") return exc.HTTPBadRequest(explanation=msg) try: template_data = self.db_api.host_template_update( req.context, template_id, template_data) msg = (_LI("Successfully updated template %s") % template_data["id"]) LOG.info(msg) if 'template' not in template_data: template_data = dict(host_template=template_data) return template_data except exception.Duplicate: msg = _("template with identifier %s already exists!") % \ template_id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to update template metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to update template %s"), template_id) raise
def neutron_backend_update(self, req, id, body): """Registers a new neutron_backend with the registry. :param req: wsgi Request object :param body: Dictionary of information about the template :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ neutron_backend_data = body["neutron_backend"] if id and not utils.is_uuid_like(id): msg = _LI("Rejecting cluster neutron_backend " "creation request for invalid " "neutron_backend id '%(bad_id)s'") % {'bad_id': id} LOG.info(msg) msg = _("Invalid neutron_backend id format") return exc.HTTPBadRequest(explanation=msg) try: neutron_backend_data = self.db_api.neutron_backend_update( req.context, id, neutron_backend_data) msg = (_LI("Successfully updated neutron_backend %s") % neutron_backend_data["id"]) LOG.info(msg) if 'neutron_backend' not in neutron_backend_data: neutron_backend_data = dict( neutron_backend=neutron_backend_data) return neutron_backend_data except exception.Duplicate: msg = _("neutron_backend with identifier %s already exists!") % id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to update neutron_backend " "metadata.Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to update neutron_backend %s"), id) raise
def add_hwm(self, req, body): """Registers a new hwm with the registry. :param req: wsgi Request object :param body: Dictionary of information about the templatae :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ hwm_data = body["hwm"] id = hwm_data.get('id') if id and not utils.is_uuid_like(id): msg = _LI("Rejecting hwm creation request for invalid hwm " "id '%(bad_id)s'") % {'bad_id': id} LOG.info(msg) msg = _("Invalid hwm id format") return exc.HTTPBadRequest(explanation=msg) try: hwm_data = self.db_api.hwm_add(req.context, hwm_data) msg = (_LI("Successfully created hwm %s") % hwm_data["id"]) LOG.info(msg) if 'hwm' not in hwm_data: hwm_data = dict(hwm=hwm_data) return hwm_data except exception.Duplicate: msg = _("hwm with identifier %s already exists!") % id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to add hwm metadata. " "Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to create hwm %s"), id) raise
def update_hwm(self, req, id, body): """Registers a new hwm with the registry. :param req: wsgi Request object :param body: Dictionary of information about the template :retval Returns the newly-created template information as a mapping, which will include the newly-created template's internal id in the 'id' field """ hwm_data = body["hwm"] if id and not utils.is_uuid_like(id): msg = _LI("Rejecting cluster hwm creation request for invalid " "hwm id '%(bad_id)s'") % {'bad_id': id} LOG.info(msg) msg = _("Invalid hwm id format") return exc.HTTPBadRequest(explanation=msg) try: hwm_data = self.db_api.hwm_update(req.context, id, hwm_data) msg = (_LI("Successfully updated hwm %s") % hwm_data["id"]) LOG.info(msg) if 'hwm' not in hwm_data: hwm_data = dict(hwm=hwm_data) return hwm_data except exception.Duplicate: msg = _("hwm with identifier %s already exists!") % id LOG.warning(msg) return exc.HTTPConflict(msg) except exception.Invalid as e: msg = (_("Failed to update hwm metadata.Got error: %s") % utils.exception_to_str(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except Exception: LOG.exception(_LE("Unable to update hwm %s"), id) raise
def replication_load(options, args): """%(prog)s load <server:port> <path> Load the contents of a local directory into daisy. server:port: the location of the glance instance. path: a directory on disk containing the data. """ # Make sure server and path are provided if len(args) < 2: raise TypeError(_("Too few arguments.")) path = args.pop() server, port = utils.parse_valid_host_port(args.pop()) imageservice = get_image_service() client = imageservice(httplib.HTTPConnection(server, port), options.slavetoken) updated = [] for ent in os.listdir(path): if utils.is_uuid_like(ent): image_uuid = ent LOG.info(_LI('Considering: %s') % image_uuid) meta_file_name = os.path.join(path, image_uuid) with open(meta_file_name) as meta_file: meta = jsonutils.loads(meta_file.read()) # Remove keys which don't make sense for replication for key in options.dontreplicate.split(' '): if key in meta: LOG.debug('Stripping %(header)s from saved ' 'metadata', {'header': key}) del meta[key] if _image_present(client, image_uuid): # NOTE(mikal): Perhaps we just need to update the metadata? # Note that we don't attempt to change an image file once it # has been uploaded. LOG.debug('Image %s already present', image_uuid) headers = client.get_image_meta(image_uuid) for key in options.dontreplicate.split(' '): if key in headers: LOG.debug('Stripping %(header)s from slave ' 'metadata', {'header': key}) del headers[key] if _dict_diff(meta, headers): LOG.info(_LI('Image %s metadata has changed') % image_uuid) headers, body = client.add_image_meta(meta) _check_upload_response_headers(headers, body) updated.append(meta['id']) else: if not os.path.exists(os.path.join(path, image_uuid + '.img')): LOG.debug('%s dump is missing image data, skipping' % image_uuid) continue # Upload the image itself with open(os.path.join(path, image_uuid + '.img')) as img_file: try: headers, body = client.add_image(meta, img_file) _check_upload_response_headers(headers, body) updated.append(meta['id']) except exc.HTTPConflict: LOG.error(_LE(IMAGE_ALREADY_PRESENT_MESSAGE) % image_uuid) # noqa return updated
def _validate_marker(self, marker): if marker and not utils.is_uuid_like(marker): msg = _('Invalid marker format') raise webob.exc.HTTPBadRequest(explanation=msg) return marker