def delete(self, request, **kwargs): appSettings = self.get_app().appsettings_set.latest() addresses = self.get_serializer().validate_whitelist(request.data.get('addresses')) unfound_addresses = set(addresses) - set(appSettings.whitelist) if len(unfound_addresses) != 0: raise UnprocessableEntity('addresses {} does not exist in whitelist'.format(unfound_addresses)) # noqa addresses = list(set(appSettings.whitelist) - set(addresses)) appSettings.new(self.request.user, whitelist=addresses) return Response(status=status.HTTP_204_NO_CONTENT)
def path(self, request, *args, **kwargs): new_path = request.data.get('path') if new_path is None: raise DryccException("path is a required field") obj = self.get_object() container_types = [ _ for _ in new_path.keys() if _ not in obj.app.types or _ not in obj.app.structure.keys() ] if container_types: raise DryccException( "process type {} is not included in profile".format( ','.join(container_types))) if set(new_path.items()).issubset(set(obj.path.items())): raise DryccException("mount path not changed") other_volumes = self.get_app().volume_set.exclude(name=obj.name) type_paths = {} # {'type1':[path1,path2], tyep2:[path3,path4]} for _ in other_volumes: for k, v in _.path.items(): if k not in type_paths: type_paths[k] = [v] else: type_paths[k].append(k) repeat_path = [ v for k, v in new_path.items() if v in type_paths.get(k, []) ] # noqa if repeat_path: raise DryccException("path {} is used by another volume".format( ','.join(repeat_path))) path = obj.path pre_path = deepcopy(path) # merge mount path # remove path keys if a null value is provided for key, value in new_path.items(): if value is None: # error if unsetting non-existing key if key not in path: raise UnprocessableEntity( '{} does not exist under {}'.format(key, "volume")) # noqa path.pop(key) else: path[key] = value obj.path = path # after merge path obj.save() self.deploy(obj, pre_path) serializer = self.get_serializer(obj, many=False) return Response(serializer.data)