def add_app_location(project_type, pkg_type, pkg_name, app_name, path, arch, build_host): """Add the location of a given application""" # Ensure the environment parameter is boolean project = PackageLocation(project_type=project_type, pkg_type=pkg_type, pkg_name=pkg_name, app_name=app_name, path=path, arch=arch, build_host=build_host, environment=False) Session.add(project) Session.flush() # Needed to get pkgLocationID generated # Transitional code to synchronize with new tables project_new = add_project(app_name) pkg_def = add_package_definition('rpm', 'matching', pkg_name, path, arch, 'jenkins', build_host) Session.add(pkg_def) Session.flush() # Needed to get pkg_def_id generated package_name = PackageName(name=pkg_name, pkg_def_id=pkg_def.id) Session.add(package_name) pkg_def.package_names.append(package_name) return project, project_new, pkg_def
def find_running_deployment(app_id, environment, hosts=None): """Find a currently running tier or host deployment (or deployments) for a given application type and environment """ tier = (Session.query( AppDeployment.user, AppDeployment.realized, AppDeployment.environment, AppDefinition.app_type).join(AppDefinition).filter( AppDeployment.app_id == app_id).filter( AppDeployment.environment == environment).filter( AppDeployment.status == 'inprogress').order_by( AppDeployment.realized.desc(), AppDeployment.id.desc()).first()) if tier: return ('tier', tier) host = (Session.query( HostDeployment.user, HostDeployment.realized, Host.hostname, Host.environment).join(Host).filter( Host.environment == environment).filter( Host.app_id == app_id).filter( HostDeployment.status == 'inprogress').all()) if host: return ('host', host) # Get here then nothing to return return None
def add_app_location(project_type, pkg_type, pkg_name, app_name, path, arch, build_host): """Add the location of a given application""" # Ensure the environment parameter is boolean project = PackageLocation( project_type=project_type, pkg_type=pkg_type, pkg_name=pkg_name, app_name=app_name, path=path, arch=arch, build_host=build_host, environment=False ) Session.add(project) Session.flush() # Needed to get pkgLocationID generated # Transitional code to synchronize with new tables project_new = add_project(app_name) pkg_def = add_package_definition('rpm', 'matching', pkg_name, path, arch, 'jenkins', build_host) Session.add(pkg_def) Session.flush() # Needed to get pkg_def_id generated package_name = PackageName(name=pkg_name, pkg_def_id=pkg_def.id) Session.add(package_name) pkg_def.package_names.append(package_name) return project, project_new, pkg_def
def add_app_packages_mapping(project_new, pkg_def, app_types): """Add the mappings of the app types for a given project""" existing_apptypes = [x.name for x in project_new.applications] if AppDefinition.dummy not in (existing_apptypes + app_types): app_types.append(AppDefinition.dummy) for app_type in list(app_types): if app_type in existing_apptypes: if app_type == AppDefinition.dummy: app_types.remove(app_type) else: raise Exception('"%s" is already a part of "%s"', app_type, project_new.name) for app_type in app_types: try: app_def = (Session.query(AppDefinition).filter_by( app_type=app_type).one()) except sqlalchemy.orm.exc.NoResultFound: raise RepoException('App type "%s" is not found in the ' 'Application table' % app_type) package_loc = PackageLocation.get(app_name=pkg_def.name) if package_loc is not None: package_loc.app_definitions.append(app_def) # Transitional code to synchronize with new tables proj_pkg = ProjectPackage() proj_pkg.project = project_new proj_pkg.package_definition = pkg_def proj_pkg.app_definition = app_def Session.add(proj_pkg)
def find_running_deployment(app_id, environment, hosts=None): """Find a currently running tier or host deployment (or deployments) for a given application type and environment """ tier = (Session.query(AppDeployment.user, AppDeployment.realized, AppDeployment.environment, AppDefinition.app_type) .join(AppDefinition) .filter(AppDeployment.app_id==app_id) .filter(AppDeployment.environment==environment) .filter(AppDeployment.status=='inprogress') .order_by(AppDeployment.realized.desc(), AppDeployment.id.desc()) .first()) if tier: return ('tier', tier) host = (Session.query(HostDeployment.user, HostDeployment.realized, Host.hostname, Host.environment) .join(Host) .filter(Host.environment==environment) .filter(Host.app_id==app_id) .filter(HostDeployment.status=='inprogress') .all()) if host: return ('host', host) # Get here then nothing to return return None
def find_app_deployment(pkg_id, app_ids, environment): """Find specific tier deployment(s) based on package ID and application ID(s) """ subq = (Session.query(AppDeployment.app_id, AppDefinition.app_type, AppDeployment.id) .join(Package) .join(AppDefinition) .filter(Package.id == pkg_id)) if app_ids: subq = subq.filter(AppDeployment.app_id.in_(app_ids)) subq = (subq.filter(AppDeployment.environment == environment) .order_by(AppDeployment.realized.desc(), AppDeployment.id.desc()) .subquery(name='t_ordered')) return (Session.query(AppDeployment, AppDefinition.app_type, Package) .join(AppDefinition) .join(Package) .join(subq, AppDeployment.id == subq.c.AppDeploymentID) .group_by(subq.c.AppID) .all())
def find_unvalidated_versions(time_delta, environment): """Find the latest deployments that are not validated in a given environment for a given amount of time """ subq = (Session.query(Package.pkg_name, Package.version, Package.revision, AppDefinition.app_type, AppDeployment.environment, AppDeployment.realized, AppDeployment.user, AppDeployment.status) .join(AppDeployment) .join(AppDefinition) .filter(AppDeployment.status!='invalidated') .filter(AppDeployment.environment==environment) .order_by(AppDeployment.realized.desc(), AppDeployment.id.desc()) .subquery(name='t_ordered')) return (Session.query(subq.c.pkg_name, subq.c.version, subq.c.revision, subq.c.appType, subq.c.environment, subq.c.realized, subq.c.user, subq.c.status) .group_by(subq.c.appType, subq.c.environment, subq.c.pkg_name) .having(and_(subq.c.status.like('%complete'), func.unix_timestamp(subq.c.realized) < func.unix_timestamp(func.now()) - time_delta)) .all())
def add_project(name): """Add a new project to the database""" project = Project(name=name) Session.add(project) Session.flush() # Needed to get project_id generated return project
def find_deployed_version(package_name, environment, version=None, revision=None, apptypes=None, apptier=False): """Find a given deployed version for a given package in a given environment for all related app types; search for full tier or host only deployment specifically """ if apptier: subq = ( Session.query( Package.pkg_name, Package.version, Package.revision, AppDefinition.app_type, AppDeployment.environment ).join(AppDeployment) .join(AppDefinition) .filter(Package.pkg_name == package_name) .filter(AppDeployment.environment == environment) .filter(AppDeployment.status != 'invalidated')) if apptypes is not None: subq = subq.filter(AppDefinition.app_type.in_(apptypes)) if version is not None: subq = subq.filter(Package.version == version) if revision is not None: subq = subq.filter(Package.revision == revision) subq = (subq.order_by(AppDeployment.realized.desc(), AppDeployment.id.desc()) .subquery(name='t_ordered')) # The actual column name must be used in the subquery # usage below; DB itself should be corrected versions = (Session.query(subq.c.appType, subq.c.version, subq.c.revision) .group_by(subq.c.appType, subq.c.environment) .all()) else: hostsq = (Session.query(Host.hostname, Host.app_id, Package.version, Package.revision) .join(AppDefinition) .join(HostDeployment) .join(Package) .filter(Package.pkg_name == package_name) .filter(Host.environment == environment)) if apptypes is not None: hostsq = hostsq.filter(AppDefinition.app_type.in_(apptypes)) versions = (hostsq.all()) return versions
def delete_host_deployments(package_name, app_id, environment): """ """ host_deps = (Session.query(HostDeployment).join(Host).join(Package).filter( Package.pkg_name == package_name).filter(Host.app_id == app_id).filter( Host.environment == environment).all()) for host_dep in host_deps: # Commit to DB immediately Session.delete(host_dep) Session.commit()
def delete_host_deployment(hostname, package_name): """ """ host_deps = (Session.query(HostDeployment).join(Host).join(Package).filter( Package.pkg_name == package_name).filter( Host.hostname == hostname).all()) # Allow this to silently do nothing if there are no matching rows for host_dep in host_deps: # Commit to DB immediately Session.delete(host_dep) Session.commit()
def find_deployed_version(package_name, environment, version=None, revision=None, apptypes=None, apptier=False): """Find a given deployed version for a given package in a given environment for all related app types; search for full tier or host only deployment specifically """ if apptier: subq = (Session.query( Package.pkg_name, Package.version, Package.revision, AppDefinition.app_type, AppDeployment.environment).join(AppDeployment).join( AppDefinition).filter(Package.pkg_name == package_name).filter( AppDeployment.environment == environment).filter( AppDeployment.status != 'invalidated')) if apptypes is not None: subq = subq.filter(AppDefinition.app_type.in_(apptypes)) if version is not None: subq = subq.filter(Package.version == version) if revision is not None: subq = subq.filter(Package.revision == revision) subq = (subq.order_by( AppDeployment.realized.desc(), AppDeployment.id.desc()).subquery(name='t_ordered')) # The actual column name must be used in the subquery # usage below; DB itself should be corrected versions = (Session.query(subq.c.appType, subq.c.version, subq.c.revision).group_by( subq.c.appType, subq.c.environment).all()) else: hostsq = (Session.query( Host.hostname, Host.app_id, Package.version, Package.revision).join(AppDefinition).join(HostDeployment).join( Package).filter(Package.pkg_name == package_name).filter( Host.environment == environment)) if apptypes is not None: hostsq = hostsq.filter(AppDefinition.app_type.in_(apptypes)) versions = (hostsq.all()) return versions
def add_project_package_mapping(project, application, app_types): """Add the mappings for a given project, application and one or more app types """ # Note: eventually an 'application' may have multiple # package definitions related to it; to be decided at # a later date for app_type in app_types: proj_pkg = ProjectPackage(project_id=project.id, pkg_def_id=application.id, app_id=app_type.id) Session.add(proj_pkg)
def delete_host_deployment(hostname, package_name): """ """ host_deps = (Session.query(HostDeployment) .join(Host) .join(Package) .filter(Package.pkg_name == package_name) .filter(Host.hostname == hostname) .all()) # Allow this to silently do nothing if there are no matching rows for host_dep in host_deps: # Commit to DB immediately Session.delete(host_dep) Session.commit()
def delete_host_deployments(package_name, app_id, environment): """ """ host_deps = (Session.query(HostDeployment) .join(Host) .join(Package) .filter(Package.pkg_name == package_name) .filter(Host.app_id == app_id) .filter(Host.environment == environment) .all()) for host_dep in host_deps: # Commit to DB immediately Session.delete(host_dep) Session.commit()
def add_project_package_mapping(project, application, app_types): """Add the mappings for a given project, application and one or more app types """ # Note: eventually an 'application' may have multiple # package definitions related to it; to be decided at # a later date for app_type in app_types: proj_pkg = ProjectPackage( project_id=project.id, pkg_def_id=application.id, app_id=app_type.id ) Session.add(proj_pkg)
def find_app_by_apptype(apptype): """Find a given application by app type""" try: return (Session.query(AppDefinition).filter_by(app_type=apptype).one()) except sqlalchemy.orm.exc.NoResultFound: return None
def find_current_host_deployments(package_name, environment, apptype, version=None): """Temporary workaround method for 'show' command to find the current host deployments for a given tier. """ # NOTE: unable to easily join PackageDefinition in here, # so the filtering on the package name will fail once # some upcoming DB schema changes are made; this will # need to be fixed or replaced host_deps = ( Session.query(HostDeployment) .join(Package) .join(HostDeployment) .join(Host) .join(AppDefinition) .filter(Package.pkg_name == package_name) .filter(Host.environment == environment) .filter(AppDefinition.id == apptype.id) ) if version is not None: host_deps = host_deps.filter(Package.version == version) return ( host_deps.order_by(Host.hostname, HostDeployment.realized.asc()).all() )
def list_host_deployment_info(package_name, environment, version=None, revision=None, apptypes=None): """Give all deployment information for a given package deployed to hosts for given (or all) application types and in given environment """ dep_info = (Session.query(Deployment, HostDeployment, Host.hostname, Package).join(Package).join(HostDeployment).join( Host).join(AppDefinition)) if version is not None: dep_info = dep_info.filter(Package.version == version) if revision is not None: dep_info = dep_info.filter(Package.revision == revision) if apptypes is not None: dep_info = dep_info.filter(AppDefinition.app_type.in_(apptypes)) return (dep_info.filter(Package.pkg_name == package_name).filter( Host.environment == environment).order_by( Host.hostname, HostDeployment.realized.asc()).all())
def list_host_deployment_info(package_name, environment, version=None, revision=None, apptypes=None): """Give all deployment information for a given package deployed to hosts for given (or all) application types and in given environment """ dep_info = (Session.query(Deployment, HostDeployment, Host.hostname, Package) .join(Package) .join(HostDeployment) .join(Host) .join(AppDefinition)) if version is not None: dep_info = dep_info.filter(Package.version == version) if revision is not None: dep_info = dep_info.filter(Package.revision == revision) if apptypes is not None: dep_info = dep_info.filter(AppDefinition.app_type.in_(apptypes)) return (dep_info.filter(Package.pkg_name == package_name) .filter(Host.environment == environment) .order_by(Host.hostname, HostDeployment.realized.asc()) .all())
def find_deployment_by_id(dep_id): """Find deployment for a given ID""" try: return (Session.query(Deployment).filter_by(id=dep_id).one()) except sqlalchemy.orm.exc.NoResultFound: raise DeployException('No deployment with deploy ID "%s" found ' 'in the deployments table' % dep_id)
def find_hosts_for_app(app_id, environment): """Find the hosts for a given application and environment""" return (Session.query(Host) .join(AppDefinition) .filter(AppDefinition.id==app_id) .filter(Host.environment==environment) .all())
def find_project(name): """Find a given project""" try: return (Session.query(Project).filter_by(name=name).one()) except sqlalchemy.orm.exc.NoResultFound: raise RepoException('No entry found for project "%s" in ' 'the Project table' % name)
def add_package_definition(deploy_type, validation_type, name, path, arch, build_type, build_host): """Add base definition for a package""" pkg_def = PackageDefinition(deploy_type=deploy_type, validation_type=validation_type, pkg_name=name, path=path, arch=arch, build_type=build_type, build_host=build_host, created=func.current_timestamp()) Session.add(pkg_def) Session.flush() # Needed to get pkg_ef_id generated return pkg_def
def add_host_deployment(dep_id, host_id, user, status, package_id): """Add host deployment for a given host and deployment""" host_dep = HostDeployment( deployment_id=dep_id, host_id=host_id, user=user, status=status, realized=func.current_timestamp(), package_id=package_id, ) # Commit to DB immediately Session.add(host_dep) Session.commit() return host_dep
def find_host_by_hostname(hostname): """Find host for a given hostname""" try: return (Session.query(Host).filter_by(hostname=hostname).one()) except sqlalchemy.orm.exc.NoResultFound: raise DeployException('No host with hostname "%s" found in ' 'the hosts table' % hostname)
def find_project_type(project): """Determine the project type for a given project""" try: return (Session.query( PackageLocation.project_type).filter_by(app_name=project).one()) except sqlalchemy.orm.exc.NoResultFound: raise RepoException('No project "%s" found in the ' 'package_locations table' % project)
def find_app_by_apptype(apptype): """Find a given application by app type""" try: return (Session.query(AppDefinition) .filter_by(app_type=apptype) .one()) except sqlalchemy.orm.exc.NoResultFound: return None
def find_apptype_by_appid(app_id): """Find the app type for a given ID""" try: app_def = (Session.query(AppDefinition).filter_by(id=app_id).one()) return app_def.app_type except sqlalchemy.orm.exc.NoResultFound: raise DeployException('No app type with AppID "%s" was found ' 'in the app_definitions table' % app_id)
def find_host_deployments_by_package_name(package_name, dep_hosts): """Find host deployments for a given package and a given set of hosts """ return (Session.query(HostDeployment, Host.hostname, Host.app_id, Package.version).join(Host).join(Package).filter( Package.pkg_name == package_name).filter( Host.hostname.in_(dep_hosts)).all())
def find_host_deployments_by_pkgid(pkg_id, dep_hosts): """Find host deployments for a given package ID and a given set of hosts """ return (Session.query(HostDeployment, Host.hostname, Host.app_id).join(Host).join(Package).filter( Package.id == pkg_id).filter( Host.hostname.in_(dep_hosts)).all())
def find_app_packages_mapping(app_name): """Find all app types related to a given package""" app_defs = (Session.query(AppDefinition).filter( AppDefinition.package_locations.any(pkg_name=app_name)).all()) if not app_defs: return [] return app_defs
def add_package(app_name, version, revision, user): """Add the requested version for the package of a given application""" pkg_def = find_package_definition(app_name) if find_package(app_name, version, revision): raise PackageException('Current version of application "%s" ' 'already found in Package table' % app_name) pkg = Package(pkg_def_id=pkg_def.id, pkg_name=app_name, version=version, revision=revision, status='pending', created=func.current_timestamp(), creator=user, builder=pkg_def.build_type, project_type='application') Session.add(pkg)
def find_host_deployments_not_ok(pkg_id, app_id, environment): """Find host deployments that are not in 'ok' state for a given package ID, app ID and environment (may return none) """ return (Session.query(HostDeployment, Host.hostname).join(Host).filter( HostDeployment.package_id == pkg_id).filter( Host.app_id == app_id).filter( Host.environment == environment).filter( HostDeployment.status != 'ok').all())
def list_app_locations(app_names): """ """ list_query = Session.query(PackageLocation) if app_names is not None: list_query = \ list_query.filter(PackageLocation.app_name.in_(app_names)) return list_query.order_by(PackageLocation.app_name).all()
def find_all_app_deployments_by_apptype(package_name, apptype, environment): """Find all tier deployments for a given application type and specific environment """ return ( Session.query(AppDeployment).join(Package).join(AppDefinition).filter( Package.pkg_name == package_name).filter( AppDefinition.app_type == apptype).filter( AppDeployment.environment == environment).all())
def find_project_type(project): """Determine the project type for a given project""" try: return (Session.query(PackageLocation.project_type) .filter_by(app_name=project) .one()) except sqlalchemy.orm.exc.NoResultFound: raise RepoException('No project "%s" found in the ' 'package_locations table' % project)
def find_project(name): """Find a given project""" try: return (Session.query(Project) .filter_by(name=name) .one()) except sqlalchemy.orm.exc.NoResultFound: raise RepoException('No entry found for project "%s" in ' 'the Project table' % name)
def add_package_definition(deploy_type, validation_type, name, path, arch, build_type, build_host): """Add base definition for a package""" pkg_def = PackageDefinition( deploy_type=deploy_type, validation_type=validation_type, pkg_name=name, path=path, arch=arch, build_type=build_type, build_host=build_host, created=func.current_timestamp() ) Session.add(pkg_def) Session.flush() # Needed to get pkg_ef_id generated return pkg_def
def find_host_deployment_by_depid(dep_id, dep_host): """Find host deployment (if exists) for a given deployment ID""" try: return (Session.query(HostDeployment).join(Host).filter( HostDeployment.deployment_id == dep_id).filter( Host.hostname == dep_host).one()) except sqlalchemy.orm.exc.NoResultFound: # Currently this shouldn't be a fatal error return None
def find_host_by_hostname(hostname): """Find host for a given hostname""" try: return (Session.query(Host) .filter_by(hostname=hostname) .one()) except sqlalchemy.orm.exc.NoResultFound: raise DeployException('No host with hostname "%s" found in ' 'the hosts table' % hostname)
def find_deployment_by_id(dep_id): """Find deployment for a given ID""" try: return (Session.query(Deployment) .filter_by(id=dep_id) .one()) except sqlalchemy.orm.exc.NoResultFound: raise DeployException('No deployment with deploy ID "%s" found ' 'in the deployments table' % dep_id)
def find_host_deployments_by_pkgid(pkg_id, dep_hosts): """Find host deployments for a given package ID and a given set of hosts """ return (Session.query(HostDeployment, Host.hostname, Host.app_id) .join(Host) .join(Package) .filter(Package.id==pkg_id) .filter(Host.hostname.in_(dep_hosts)) .all())
def find_unvalidated_deployments(environment): """Find the latest deployments that are not validated in a given environment (simplified version of find_unvalidated_versions) """ subq = (Session.query( Package.pkg_name, AppDefinition.app_type, AppDeployment.environment, AppDeployment.status, AppDeployment).join(AppDeployment).join(AppDefinition).filter( AppDefinition.status == 'active').filter( AppDeployment.status != 'invalidated').filter( AppDeployment.environment == environment).order_by( AppDeployment.realized.desc(), AppDeployment.id.desc()).subquery(name='t_ordered')) appdep_alias = aliased(AppDeployment, subq) return (Session.query(appdep_alias).group_by( subq.c.appType, subq.c.environment, subq.c.pkg_name).having(subq.c.status.like('%complete')).all())
def find_latest_validated_deployment(package_name, app_id, environment): """Find the most recent deployment that was validated for a given package, application type and environment. """ return (Session.query(AppDeployment, Package.id).join(Package).filter( Package.pkg_name == package_name).filter( AppDeployment.environment == environment).filter( AppDeployment.status == 'validated').order_by( AppDeployment.realized.desc(), AppDeployment.id.desc()).first())
def find_apptype_by_appid(app_id): """Find the app type for a given ID""" try: app_def = (Session.query(AppDefinition) .filter_by(id=app_id) .one()) return app_def.app_type except sqlalchemy.orm.exc.NoResultFound: raise DeployException('No app type with AppID "%s" was found ' 'in the app_definitions table' % app_id)
def list_packages(app_names): """Return all available packages in the repository""" if app_names is None: return None return (Session.query(Package).join(PackageDefinition).filter( PackageDefinition.pkg_name == Package.pkg_name).filter( PackageDefinition.pkg_name.in_(app_names)).filter( Package.status == 'completed').order_by( Package.pkg_name, Package.version, Package.revision).all())
def add_app_deployment(dep_id, app_id, user, status, environment, package_id): """Add a tier deployment for a given deployment ID""" environment_id = _calculate_environment_id(environment) app_dep = AppDeployment( deployment_id=dep_id, app_id=app_id, user=user, status=status, environment_id=environment_id, realized=func.current_timestamp(), package_id=package_id, ) # Commit to DB immediately Session.add(app_dep) Session.commit() return app_dep
def add_package(app_name, version, revision, user): """Add the requested version for the package of a given application""" pkg_def = find_package_definition(app_name) if find_package(app_name, version, revision): raise PackageException('Current version of application "%s" ' 'already found in Package table' % app_name) pkg = Package( pkg_def_id=pkg_def.id, pkg_name=app_name, version=version, revision=revision, status='pending', created=func.current_timestamp(), creator=user, builder=pkg_def.build_type, project_type='application' ) Session.add(pkg)
def find_app_packages_mapping(app_name): """Find all app types related to a given package""" app_defs = (Session.query(AppDefinition) .filter(AppDefinition.package_locations.any( pkg_name=app_name)) .all()) if not app_defs: return [] return app_defs
def find_all_app_deployments_by_apptype(package_name, apptype, environment): """Find all tier deployments for a given application type and specific environment """ return (Session.query(AppDeployment) .join(Package) .join(AppDefinition) .filter(Package.pkg_name == package_name) .filter(AppDefinition.app_type == apptype) .filter(AppDeployment.environment == environment) .all())
def find_host_deployment_by_depid(dep_id, dep_host): """Find host deployment (if exists) for a given deployment ID""" try: return (Session.query(HostDeployment) .join(Host) .filter(HostDeployment.deployment_id==dep_id) .filter(Host.hostname==dep_host) .one()) except sqlalchemy.orm.exc.NoResultFound: # Currently this shouldn't be a fatal error return None
def find_latest_validated_deployment(package_name, app_id, environment): """Find the most recent deployment that was validated for a given package, application type and environment. """ return (Session.query(AppDeployment, Package.id) .join(Package) .filter(Package.pkg_name==package_name) .filter(AppDeployment.environment==environment) .filter(AppDeployment.status=='validated') .order_by(AppDeployment.realized.desc(), AppDeployment.id.desc()) .first())
def find_host_deployments_by_package_name(package_name, dep_hosts): """Find host deployments for a given package and a given set of hosts """ return (Session.query(HostDeployment, Host.hostname, Host.app_id, Package.version) .join(Host) .join(Package) .filter(Package.pkg_name==package_name) .filter(Host.hostname.in_(dep_hosts)) .all())
def find_host_deployments_not_ok(pkg_id, app_id, environment): """Find host deployments that are not in 'ok' state for a given package ID, app ID and environment (may return none) """ return (Session.query(HostDeployment, Host.hostname) .join(Host) .filter(HostDeployment.package_id==pkg_id) .filter(Host.app_id==app_id) .filter(Host.environment==environment) .filter(HostDeployment.status!='ok') .all())
def find_package_definition(app_name): """Find package definition for a given package""" try: # Note: can there be multiple package definitions # with the same pkg_name? pkg_def = (Session.query(PackageDefinition).filter_by( pkg_name=app_name).first()) except sqlalchemy.orm.exc.NoResultFound: raise PackageException('Entry for application "%s" not found in ' 'PackageDefinition table' % app_name) return pkg_def