当前位置: 首页>>代码示例>>Python>>正文


Python session.get_session函数代码示例

本文整理汇总了Python中murano.db.session.get_session函数的典型用法代码示例。如果您正苦于以下问题:Python get_session函数的具体用法?Python get_session怎么用?Python get_session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_missing_blob

 def test_missing_blob(self):
     """Fake a package with NULL supplier JSON blob to test bug 1342306"""
     con = session.get_session().connection()
     con.execute("INSERT INTO package(id, fully_qualified_name, "
                 "owner_id, name, description, created, updated, type, "
                 "supplier) "
                 "VALUES (1, 'blob.test', 1, 'blob test', 'Desc', "
                 "'2014-07-15 00:00:00', '2014-07-15 00:00:00', "
                 "'Application', NULL)")
     loaded_e = session.get_session().query(models.Package).get(1)
     self.assertEqual(None, loaded_e.supplier)
开发者ID:ativelkov,项目名称:murano-api,代码行数:11,代码来源:test_models.py

示例2: __inner

    def __inner(self, request, *args, **kwargs):
        if hasattr(request, 'context') and not request.context.session:
            msg = _('X-Configuration-Session header which indicates'
                    ' to the session is missed')
            LOG.error(msg)
            raise exc.HTTPBadRequest(explanation=msg)

        session_id = request.context.session

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        if session is None:
            msg = _('Session <SessionId {0}> is not found').format(session_id)
            LOG.error(msg)
            raise exc.HTTPNotFound(explanation=msg)

        if not sessions.SessionServices.validate(session):
            msg = _('Session <SessionId {0}> '
                    'is invalid: environment has been updated or '
                    'updating right now with other session').format(session_id)
            LOG.error(msg)
            raise exc.HTTPForbidden(explanation=msg)

        if session.state == states.SessionState.DEPLOYING:
            msg = _('Session <SessionId {0}> is already in deployment state'
                    ).format(session_id)
            raise exc.HTTPForbidden(explanation=msg)
        return func(self, request, *args, **kwargs)
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:29,代码来源:utils.py

示例3: validate

    def validate(session):
        """
        Session is valid only if no other session for same
        environment was already deployed on in deploying state,

        :param session: Session for validation
        """

        #if other session is deploying now current session is invalid
        unit = db_session.get_session()

        #if environment version is higher then version on which current session
        #is created then other session was already deployed
        current_env = unit.query(models.Environment).\
            get(session.environment_id)
        if current_env.version > session.version:
            return False

        #if other session is deploying now current session is invalid
        other_is_deploying = unit.query(models.Session).filter_by(
            environment_id=session.environment_id, state=SessionState.deploying
        ).count() > 0
        if session.state == SessionState.open and other_is_deploying:
            return False

        return True
开发者ID:ativelkov,项目名称:murano-api,代码行数:26,代码来源:sessions.py

示例4: create

    def create(environment_id, user_id):
        """
        Creates session object for specific environment for specified user.

        :param environment_id: Environment Id
        :param user_id: User Id
        :return: Created session
        """
        unit = db_session.get_session()
        environment = unit.query(models.Environment).get(environment_id)

        session = models.Session()
        session.environment_id = environment.id
        session.user_id = user_id
        session.state = SessionState.open
        # used for checking if other sessions was deployed before this one
        session.version = environment.version
        # all changes to environment is stored here, and translated to
        # environment only after deployment completed
        session.description = environment.description

        with unit.begin():
            unit.add(session)

        return session
开发者ID:ativelkov,项目名称:murano-api,代码行数:25,代码来源:sessions.py

示例5: show

    def show(self, request, environment_id):
        LOG.debug('Environments:Show <Id: {id}>'.format(id=environment_id))
        target = {"environment_id": environment_id}
        policy.check('show_environment', request.context, target)

        session = db_session.get_session()
        environment = session.query(models.Environment).get(environment_id)
        env = environment.to_dict()
        env['status'] = envs.EnvironmentServices.get_status(env['id'])

        # if env is currently being deployed we can provide information about
        # the session right away
        env['acquired_by'] = None
        if env['status'] == states.EnvironmentStatus.DEPLOYING:
            session_list = session_services.SessionServices.get_sessions(
                environment_id, state=states.SessionState.DEPLOYING)
            if session_list:
                env['acquired_by'] = session_list[0].id

        session_id = None
        if hasattr(request, 'context') and request.context.session:
            session_id = request.context.session
        if session_id:
            env_session = session.query(models.Session).get(session_id)
            check_session(request, environment_id, env_session, session_id)

        # add services to env
        get_data = core_services.CoreServices.get_data
        env['services'] = get_data(environment_id, '/services', session_id)

        return env
开发者ID:AleptNamrata,项目名称:murano,代码行数:31,代码来源:environments.py

示例6: show

    def show(self, request, environment_id, session_id):
        LOG.debug('Session:Show <SessionId: {id}>'.format(id=session_id))

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        check_session(request, environment_id, session, session_id)

        user_id = request.context.user

        if session.user_id != user_id:
            msg = _('User <UserId {usr_id}> is not authorized to access'
                    'session <SessionId {s_id}>.').format(usr_id=user_id,
                                                          s_id=session_id)
            LOG.error(msg)
            raise exc.HTTPUnauthorized(explanation=msg)

        if not sessions.SessionServices.validate(session):
            msg = _('Session <SessionId {0}> is invalid: environment has been'
                    ' updated or updating right now with other session'
                    ).format(session_id)
            LOG.error(msg)
            raise exc.HTTPForbidden(explanation=msg)

        return session.to_dict()
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:25,代码来源:sessions.py

示例7: execute

    def execute(self, request, environment_id, action_id, body):
        policy.check("execute_action", request.context, {})

        LOG.debug("Action:Execute <ActionId: {0}>".format(action_id))

        unit = db_session.get_session()

        # no new session can be opened if environment has deploying status
        env_status = envs.EnvironmentServices.get_status(environment_id)
        if env_status in (states.EnvironmentStatus.DEPLOYING, states.EnvironmentStatus.DELETING):
            LOG.info(
                _LI(
                    "Could not open session for environment <EnvId: {0}>," "environment has deploying " "status."
                ).format(environment_id)
            )
            raise exc.HTTPForbidden()

        user_id = request.context.user
        session = sessions.SessionServices.create(environment_id, user_id)

        if not sessions.SessionServices.validate(session):
            LOG.error(_LE("Session <SessionId {0}> " "is invalid").format(session.id))
            raise exc.HTTPForbidden()

        task_id = actions.ActionServices.execute(action_id, session, unit, request.context.auth_token, body or {})
        return {"task_id": task_id}
开发者ID:sajuptpm,项目名称:murano,代码行数:26,代码来源:actions.py

示例8: delete

    def delete(self, request, environment_id, session_id):
        LOG.debug('Session:Delete <SessionId: {0}>'.format(session_id))

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        self._check_session(request, environment_id, session, session_id)

        user_id = request.context.user
        if session.user_id != user_id:
            msg = _('User <UserId {0}> is not authorized to access session'
                    '<SessionId {1}>.').format(user_id, session_id)
            LOG.error(msg)
            raise exc.HTTPUnauthorized(explanation=msg)

        if session.state == states.SessionState.DEPLOYING:
            msg = _('Session <SessionId: {0}> is in deploying state and '
                    'could not be deleted').format(session_id)
            LOG.error(msg)
            raise exc.HTTPForbidden(explanation=msg)

        with unit.begin():
            unit.delete(session)

        return None
开发者ID:aawm,项目名称:murano,代码行数:25,代码来源:sessions.py

示例9: update

    def update(self, request, environment_id, body):
        LOG.debug('Environments:Update <Id: {0}, '
                  'Body: {1}>'.format(environment_id, body))
        target = {"environment_id": environment_id}
        policy.check('update_environment', request.context, target)

        session = db_session.get_session()
        environment = session.query(models.Environment).get(environment_id)

        if environment is None:
            LOG.info(_('Environment <EnvId {0}> is not '
                       'found').format(environment_id))
            raise exc.HTTPNotFound

        if environment.tenant_id != request.context.tenant:
            LOG.info(_('User is not authorized to access '
                       'this tenant resources.'))
            raise exc.HTTPUnauthorized

        LOG.debug('ENV NAME: {0}>'.format(body['name']))
        if VALID_NAME_REGEX.match(str(body['name'])):
            environment.update(body)
            environment.save(session)
        else:
            msg = _('Environment name must contain only alphanumeric '
                    'or "_-." characters, must start with alpha')
            LOG.exception(msg)
            raise exc.HTTPClientError(msg)

        return environment.to_dict()
开发者ID:alex-docker,项目名称:murano,代码行数:30,代码来源:environments.py

示例10: show

    def show(self, request, environment_id):
        LOG.debug('Environments:Show <Id: {0}>'.format(environment_id))
        target = {"environment_id": environment_id}
        policy.check('show_environment', request.context, target)

        session = db_session.get_session()
        environment = session.query(models.Environment).get(environment_id)

        if environment is None:
            LOG.info(_('Environment <EnvId {0}> is not found').format(
                environment_id))
            raise exc.HTTPNotFound

        if environment.tenant_id != request.context.tenant:
            LOG.info(_('User is not authorized to access '
                       'this tenant resources.'))
            raise exc.HTTPUnauthorized

        env = environment.to_dict()
        env['status'] = envs.EnvironmentServices.get_status(env['id'])

        session_id = None
        if hasattr(request, 'context') and request.context.session:
            session_id = request.context.session

        #add services to env
        get_data = core_services.CoreServices.get_data
        env['services'] = get_data(environment_id, '/services', session_id)

        return env
开发者ID:alex-docker,项目名称:murano,代码行数:30,代码来源:environments.py

示例11: configure

    def configure(self, request, environment_id):
        LOG.debug('Session:Configure <EnvId: {0}>'.format(environment_id))

        unit = db_session.get_session()
        environment = unit.query(models.Environment).get(environment_id)

        if environment is None:
            msg = _('Environment <EnvId {0}>'
                    ' is not found').format(environment_id)
            LOG.error(msg)
            raise exc.HTTPNotFound(explanation=msg)

        if environment.tenant_id != request.context.tenant:
            msg = _('User is not authorized to access '
                    'this tenant resources.')
            LOG.error(msg)
            raise exc.HTTPUnauthorized(explanation=msg)

        # no new session can be opened if environment has deploying status
        env_status = envs.EnvironmentServices.get_status(environment_id)
        if env_status in (states.EnvironmentStatus.DEPLOYING,
                          states.EnvironmentStatus.DELETING):
            msg = _('Could not open session for environment <EnvId: {0}>,'
                    'environment has deploying status.').format(environment_id)
            LOG.error(msg)
            raise exc.HTTPForbidden(explanation=msg)

        user_id = request.context.user
        session = sessions.SessionServices.create(environment_id, user_id)

        return session.to_dict()
开发者ID:OndrejVojta,项目名称:murano,代码行数:31,代码来源:sessions.py

示例12: create

    def create(environment_params, tenant_id):
        #tagging environment by tenant_id for later checks
        """
        Creates environment with specified params, in particular - name
        :param environment_params: Dict, e.g. {'name': 'env-name'}
        :param tenant_id: Tenant Id
        :return: Created Environment
        """

        objects = {'?': {
            'id': uuidutils.generate_uuid(),
        }}
        objects.update(environment_params)
        objects.update(
            EnvironmentServices.generate_default_networks(objects['name']))
        objects['?']['type'] = 'io.murano.Environment'
        environment_params['tenant_id'] = tenant_id

        data = {
            'Objects': objects,
            'Attributes': []
        }

        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        #saving environment as Json to itself
        environment.update({'description': data})
        environment.save(unit)

        return environment
开发者ID:ativelkov,项目名称:murano-api,代码行数:35,代码来源:environments.py

示例13: create

    def create(environment_params, context):
        # tagging environment by tenant_id for later checks
        """Creates environment with specified params, in particular - name

           :param environment_params: Dict, e.g. {'name': 'env-name'}
           :param context: request context to get the tenant id and the token
           :return: Created Environment
        """
        objects = {"?": {"id": uuidutils.generate_uuid()}}
        network_driver = EnvironmentServices.get_network_driver(context)
        objects.update(environment_params)
        if not objects.get("defaultNetworks"):
            objects["defaultNetworks"] = EnvironmentServices.generate_default_networks(objects["name"], network_driver)
        objects["?"]["type"] = "io.murano.Environment"
        environment_params["tenant_id"] = context.tenant

        data = {"Objects": objects, "Attributes": []}

        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        # saving environment as Json to itself
        environment.update({"description": data})
        environment.save(unit)

        return environment
开发者ID:schaertelr,项目名称:murano,代码行数:30,代码来源:environments.py

示例14: get_environment_description

    def get_environment_description(environment_id, session_id=None, inner=True):
        """Returns environment description for specified environment.

           If session is specified and not in deploying state function
           returns modified environment description,
           otherwise returns actual environment desc.

           :param environment_id: Environment Id
           :param session_id: Session Id
           :param inner: return contents of environment rather than whole
            Object Model structure
           :return: Environment Description Object
        """
        unit = db_session.get_session()

        if session_id:
            session = unit.query(models.Session).get(session_id)
            if sessions.SessionServices.validate(session):
                if session.state != states.SessionState.DEPLOYED:
                    env_description = session.description
                else:
                    env = unit.query(models.Environment).get(session.environment_id)
                    env_description = env.description
            else:
                env = unit.query(models.Environment).get(session.environment_id)
                env_description = env.description
        else:
            env = unit.query(models.Environment).get(environment_id)
            env_description = env.description

        if not inner:
            return env_description
        else:
            return env_description["Objects"]
开发者ID:schaertelr,项目名称:murano,代码行数:34,代码来源:environments.py

示例15: update

    def update(self, request, environment_id, body):
        LOG.debug('Environments:Update <Id: {id}, '
                  'Body: {body}>'.format(id=environment_id, body=body))
        target = {"environment_id": environment_id}
        policy.check('update_environment', request.context, target)

        session = db_session.get_session()
        environment = session.query(models.Environment).get(environment_id)
        new_name = six.text_type(body['name'])
        if new_name.strip():
            if len(new_name) > 255:
                msg = _('Environment name should be 255 characters maximum')
                LOG.error(msg)
                raise exc.HTTPBadRequest(explanation=msg)
            try:
                environment.update(body)
                environment.save(session)
            except db_exc.DBDuplicateEntry:
                msg = _('Environment with specified name already exists')
                LOG.error(msg)
                raise exc.HTTPConflict(explanation=msg)
        else:
            msg = _('Environment name must contain at least one '
                    'non-white space symbol')
            LOG.error(msg)
            raise exc.HTTPClientError(explanation=msg)

        return environment.to_dict()
开发者ID:AleptNamrata,项目名称:murano,代码行数:28,代码来源:environments.py


注:本文中的murano.db.session.get_session函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。