def _validate_common(cls, data, instance=None): d = cls.validate_json(data) release_id = d.get("release", d.get("release_id")) if release_id: if not Release.get_by_uid(release_id): raise errors.InvalidData( "Invalid release ID", log_message=True) pend_release_id = d.get("pending_release_id") if pend_release_id: pend_release = Release.get_by_uid(pend_release_id, fail_if_not_found=True) if not release_id: if not instance: raise errors.InvalidData( "Cannot set pending release when " "there is no current release", log_message=True ) release_id = instance.release_id curr_release = Release.get_by_uid(release_id) if not cls._can_update_release(curr_release, pend_release): raise errors.InvalidData( "Cannot set pending release as " "it cannot update current release", log_message=True ) return d
def _validate_common(cls, data, instance=None): d = cls.validate_json(data) release_id = d.get("release", d.get("release_id")) if release_id: if not Release.get_by_uid(release_id): raise errors.InvalidData("Invalid release ID", log_message=True) pend_release_id = d.get("pending_release_id") if pend_release_id: pend_release = Release.get_by_uid(pend_release_id, fail_if_not_found=True) if not release_id: if not instance: raise errors.InvalidData( "Cannot set pending release when " "there is no current release", log_message=True) release_id = instance.release_id curr_release = Release.get_by_uid(release_id) if not cls._can_update_release(curr_release, pend_release): raise errors.InvalidData( "Cannot set pending release as " "it cannot update current release", log_message=True) return d
def get_all_by_release(cls, release_id): """Get all components for specific release. :param release_id: release ID :type release_id: int :returns: list -- list of components """ components = [] release = Release.get_by_uid(release_id) release_os = release.operating_system.lower() release_version = release.version db_components = db().query(cls.single.model).options( joinedload(cls.single.model.releases), joinedload(cls.single.model.plugin)).all() for db_component in db_components: if db_component.releases: for db_release in db_component.releases: if db_release.id == release.id: components.append(db_component) elif db_component.plugin: for plugin_release in db_component.plugin.releases: if (release_os == plugin_release.get('os') and release_version == plugin_release.get('version')): components.append(db_component) return components
def _validate_common(cls, data): d = cls.validate_json(data) release_id = d.get("release", d.get("release_id", None)) if release_id: release = Release.get_by_uid(release_id) if not release: raise errors.InvalidData( "Invalid release ID", log_message=True) return d
def _validate_common(cls, data): d = cls.validate_json(data) if d.get("name"): if ClusterCollection.filter_by(None, name=d["name"]).first(): raise errors.AlreadyExists( "Environment with this name already exists", log_message=True) release_id = d.get("release", d.get("release_id", None)) if release_id: release = Release.get_by_uid(release_id) if not release: raise errors.InvalidData("Invalid release ID", log_message=True) return d
def get_cluster_attributes_by_components(cls, components, release_id): """Enable cluster attributes by given components :param components: list of component names :type components: list of strings :param release_id: Release model id :type release_id: str :returns: dict -- objects with enabled attributes for cluster """ def _update_attributes_dict_by_binds_exp(bind_exp, value): """Update cluster and attributes data with bound values :param bind_exp: path to specific attribute for model in format model:some.attribute.value. Model can be settings|cluster :type bind_exp: str :param value: value for specific attribute :type value: bool|str|int :returns: None """ model, attr_expr = bind_exp.split(':') if model not in ('settings', 'cluster'): return path_items = attr_expr.split('.') path_items.insert(0, model) attributes = cluster_attributes for i in six.moves.range(0, len(path_items) - 1): attributes = attributes.setdefault(path_items[i], {}) attributes[path_items[-1]] = value release = Release.get_by_uid(release_id) cluster_attributes = {} for component in Release.get_all_components(release): if component['name'] in components: for bind_item in component.get('bind', []): if isinstance(bind_item, six.string_types): _update_attributes_dict_by_binds_exp(bind_item, True) elif isinstance(bind_item, list): _update_attributes_dict_by_binds_exp(bind_item[0], bind_item[1]) return { 'editable': cluster_attributes.get('settings', {}), 'cluster': cluster_attributes.get('cluster', {}) }
def _validate_common(cls, data): d = cls.validate_json(data) if d.get("name"): if ClusterCollection.filter_by( query=None, name=d["name"] ).first(): raise errors.AlreadyExists( "Environment with this name already exists", log_message=True ) release_id = d.get("release", d.get("release_id", None)) if release_id: release = Release.get_by_uid(release_id) if not release: raise errors.InvalidData( "Invalid release ID", log_message=True ) return d