Example #1
0
def add_user_repository(user_id, service_group_id, name, type):
    try:
        Users.get(user_id)
    except DoesNotExist:
        raise

    try:
        ServiceGroupDatabase.get(service_group_id)
    except DoesNotExist:
        raise

    try:
        RepositoryDatabase.query().filter(RepositoryDatabase.service_group_id == service_group_id and RepositoryDatabase.name == name and RepositoryDatabase.type == type).one()
    except NoResultFound:
        pass
    except Exception as e:
        raise AlreadyExist("Repository name=%s type=%s service_group_id=%s already exists" % (name, type, service_group_id))

    repository = RepositoryDatabase()
    repository.user_id = int(user_id)
    repository.service_group_id = int(service_group_id)
    repository.name = name
    repository.type = type
    repository.save()

    return repository
Example #2
0
def add_user_port(user_id, service_group_id):
    try:
        Users.get(user_id)
    except DoesNotExist:
        raise

    try:
        ServiceGroupDatabase.get(service_group_id)
    except DoesNotExist:
        raise

    try:
        query = (
            dbsession.query(func.max(PortDatabase.port))
            .filter(PortDatabase.service_group_id == service_group_id)
            .group_by(PortDatabase.service_group_id)
        )
        portNumber = int(query.one()[0]) + 1
    except NoResultFound:
        portNumber = 1337

    port = PortDatabase()
    port.user_id = int(user_id)
    port.service_group_id = int(service_group_id)
    port.port = int(portNumber)
    port.save()

    return port
Example #3
0
def add_user_port(user_id, service_group_id):
    try:
        Users.get(user_id)
    except DoesNotExist:
        raise

    try:
        ServiceGroupDatabase.get(service_group_id)
    except DoesNotExist:
        raise

    try:
        query = dbsession.query(func.max(PortDatabase.port)).filter(
            PortDatabase.service_group_id == service_group_id).group_by(
                PortDatabase.service_group_id)
        portNumber = int(query.one()[0]) + 1
    except NoResultFound:
        portNumber = 1337

    port = PortDatabase()
    port.user_id = int(user_id)
    port.service_group_id = int(service_group_id)
    port.port = int(portNumber)
    port.save()

    return port