def validate_delete(cls, data, instance): if instance.is_default: raise errors.CannotDelete("Default node group cannot be deleted.") if instance.nodes and not all( node.status == consts.NODE_STATUSES.discover for node in instance.nodes): raise errors.CannotDelete( "Node group can be deleted only when all its nodes " "are in bootstrap state.")
def validate_delete(cls, release, role_name): clusters = [cluster.id for cluster in release.clusters] node = db().query(models.Node).filter( models.Node.cluster_id.in_(clusters)).filter( sa.or_(models.Node.roles.any(role_name), models.Node.pending_roles.any(role_name))).first() if node: raise errors.CannotDelete( "Can't delete roles that is assigned to some node.")
def validate_update(cls, data, instance): d = cls.validate_json(data) cls._validate_common(d, instance) if db().query(models.Release).filter_by( name=d.get("name", instance.name), version=d.get("version", instance.version)).filter( sa.not_(models.Release.id == instance.id)).first(): raise errors.AlreadyExists( "Release with the same name " "and version already exists", log_message=True) if 'roles_metadata' in d: deleted_roles = (set(instance.roles_metadata) - set(d['roles_metadata'])) clusters_ids = (cluster.id for cluster in instance.clusters) deleted_roles_array = sa.cast( psql.array(deleted_roles), psql.ARRAY(sa.String(consts.ROLE_NAME_MAX_SIZE))) node = db().query(models.Node).filter( models.Node.cluster_id.in_(clusters_ids)).filter( sa.or_( models.Node.roles.overlap(deleted_roles_array), models.Node.pending_roles.overlap( deleted_roles_array))).first() if node: used_role = set(node.roles + node.pending_roles) used_role = used_role.intersection(deleted_roles) raise errors.CannotDelete( "The following roles: {0} cannot be deleted " "since they are already assigned " "to nodes.".format(','.join(used_role))) return d
def validate_update(cls, data, instance): d = cls.validate_json(data) cls._validate_common(d) if db().query(models.Release).filter_by( name=d.get("name", instance.name), version=d.get("version", instance.version)).filter( sa.not_(models.Release.id == instance.id)).first(): raise errors.AlreadyExists( "Release with the same name " "and version already exists", log_message=True) if 'roles_metadata' in d: new_roles = set(d['roles_metadata']) clusters = [cluster.id for cluster in instance.clusters] new_roles_array = sa.cast( psql.array(new_roles), psql.ARRAY(sa.String(consts.ROLE_NAME_MAX_SIZE))) node = db().query(models.Node).filter( models.Node.cluster_id.in_(clusters)).filter( sa.not_( sa.and_( models.Node.roles.contained_by(new_roles_array), models.Node.pending_roles.contained_by( new_roles_array)))).first() if node: used_role = set(node.roles + node.pending_roles) used_role -= new_roles raise errors.CannotDelete( "Cannot delete roles already assigned " "to nodes: {0}".format(','.join(used_role))) return d
def validate_delete(cls, data, instance): if instance.read_only: raise errors.CannotDelete("Read-only tags cannot be deleted.")
def validate_delete(cls, data, instance): if ClusterPlugin.is_plugin_used(instance.id): raise errors.CannotDelete("Can't delete plugin which is enabled " "for some environment.")
def validate_delete(cls, data, instance): if instance.clusters: raise errors.CannotDelete("Can't delete release with " "clusters assigned")
def validate_delete(cls, data, instance, force=False): if instance.status not in (consts.TASK_STATUSES.ready, consts.TASK_STATUSES.error) and not force: raise errors.CannotDelete( "You cannot delete running task manually")
def validate_delete(cls, instance_cls, instance, role_name): node = instance_cls.get_node_by_role(instance, role_name) if node: raise errors.CannotDelete("Can't delete role {} that is assigned " "to node {}.".format(role_name, node.id))