def set_attr(self, value): if not isinstance(value, (list, StoreLocations)): reason = _('Invalid locations') raise exception.BadStoreUri(message=reason) ori_value = getattr(getattr(self, target), attr) if ori_value != value: # NOTE(flwang): If all the URL of passed-in locations are same as # current image locations, that means user would like to only # update the metadata, not the URL. ordered_value = sorted([loc['url'] for loc in value]) ordered_ori = sorted([loc['url'] for loc in ori_value]) if len(ori_value) > 0 and ordered_value != ordered_ori: raise exception.Invalid( _('Original locations is not empty: ' '%s') % ori_value) # NOTE(zhiyan): Check locations are all valid # NOTE(flwang): If all the URL of passed-in locations are same as # current image locations, then it's not necessary to verify those # locations again. Otherwise, if there is any restricted scheme in # existing locations. _check_image_location will fail. if ordered_value != ordered_ori: for loc in value: _check_image_location(self.context, self.store_api, self.store_utils, loc) loc['status'] = 'active' if _count_duplicated_locations(value, loc) > 1: raise exception.DuplicateLocation(location=loc['url']) _set_image_size(self.context, getattr(self, target), value) else: for loc in value: loc['status'] = 'active' return setattr(getattr(self, target), attr, list(value))
def new_image(self, **kwargs): locations = kwargs.get('locations', []) for loc in locations: _check_image_location(self.context, self.store_api, loc) loc['status'] = 'active' if _count_duplicated_locations(locations, loc) > 1: raise exception.DuplicateLocation(location=loc['url']) return super(ImageFactoryProxy, self).new_image(**kwargs)
def insert(self, i, location): _check_image_location(self.image_proxy.context, self.image_proxy.store_api, location) if location in self.value: raise exception.DuplicateLocation(location=location['url']) self.value.insert(i, location)
def insert(self, i, location): _check_image_location(self.image_proxy.context, self.image_proxy.store_api, location) location['status'] = 'active' if _count_duplicated_locations(self.value, location) > 0: raise exception.DuplicateLocation(location=location['url']) self.value.insert(i, location) _set_image_size(self.image_proxy.context, self.image_proxy, [location])
def new_image(self, **kwargs): locations = kwargs.get('locations', []) for l in locations: _check_image_location(self.context, self.store_api, l) if locations.count(l) > 1: raise exception.DuplicateLocation(location=l['url']) return super(ImageFactoryProxy, self).new_image(**kwargs)
def new_image(self, **kwargs): # If glance cache is enabled, we don't allow users to create images if CONF.remote_registry_region_name: raise exception.ImageOperationNotPermitted(operation='create') locations = kwargs.get('locations', []) for loc in locations: _check_image_location(self.context, self.store_api, self.store_utils, loc) loc['status'] = 'active' if _count_duplicated_locations(locations, loc) > 1: raise exception.DuplicateLocation(location=loc['url']) return super(ImageFactoryProxy, self).new_image(**kwargs)
def set_attr(self, value): if not isinstance(value, (list, StoreLocations)): raise exception.BadStoreUri(_('Invalid locations: %s') % value) ori_value = getattr(getattr(self, target), attr) if ori_value != value: # NOTE(zhiyan): Enforced locations list was previously empty list. if len(ori_value) > 0: raise exception.Invalid(_('Original locations is not empty: ' '%s') % ori_value) # NOTE(zhiyan): Check locations are all valid. for location in value: _check_image_location(self.context, self.store_api, location) if value.count(location) > 1: raise exception.DuplicateLocation(location=location['url']) _set_image_size(self.context, getattr(self, target), value) return setattr(getattr(self, target), attr, list(value))