예제 #1
0
파일: api.py 프로젝트: YongchaoTIAN/sahara
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs={kwargs}".format(kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                ctx = context.Context(
                    flask.request.headers["X-User-Id"],
                    flask.request.headers["X-Tenant-Id"],
                    flask.request.headers["X-Auth-Token"],
                    flask.request.headers["X-Service-Catalog"],
                    flask.request.headers["X-User-Name"],
                    flask.request.headers["X-Tenant-Name"],
                    flask.request.headers["X-Roles"].split(","),
                )
                context.set_ctx(ctx)

                if flask.request.method in ["POST", "PUT"]:
                    kwargs["data"] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, "Internal Server Error", e)
예제 #2
0
파일: main.py 프로젝트: Mimansa04/sahara
def admin_context():
    ctx = context.get_admin_context()
    context.set_ctx(ctx)
    try:
        yield
    finally:
        context.set_ctx(None)
예제 #3
0
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs={kwargs}"
                          .format(kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','))
                context.set_ctx(ctx)

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
예제 #4
0
 def version_list():
     context.set_ctx(None)
     return api_utils.render(
         {"versions": [{
             "id": "v1.0",
             "status": "CURRENT"
         }]})
예제 #5
0
파일: periodic.py 프로젝트: RogerFed/sahara
    def terminate_unneeded_clusters(self, ctx):
        LOG.debug('Terminating unneeded clusters')
        ctx = context.get_admin_context()
        context.set_ctx(ctx)
        for cluster in conductor.cluster_get_all(ctx, status='Active'):
            if not cluster.is_transient:
                continue

            jc = conductor.job_execution_count(ctx,
                                               end_time=None,
                                               cluster_id=cluster.id)

            if jc > 0:
                continue

            cluster_updated_at = timeutils.normalize_time(
                timeutils.parse_isotime(cluster.updated_at))
            current_time = timeutils.utcnow()
            spacing = timeutils.delta_seconds(cluster_updated_at, current_time)
            if spacing < CONF.min_transient_cluster_active_time:
                continue

            if CONF.use_identity_api_v3:
                trusts.use_os_admin_auth_token(cluster)
                api.terminate_cluster(cluster.id)
                LOG.debug('Terminated cluster %s with id %s' %
                          (cluster.name, cluster.id))
            else:
                if cluster.status != 'AwaitingTermination':
                    conductor.cluster_update(
                        ctx,
                        cluster,
                        {'status': 'AwaitingTermination'})
        context.set_ctx(None)
예제 #6
0
파일: main.py 프로젝트: openstack/sahara
def admin_context():
    ctx = context.get_admin_context()
    context.set_ctx(ctx)
    try:
        yield
    finally:
        context.set_ctx(None)
예제 #7
0
파일: api.py 프로젝트: lhcxx/sahara
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs={kwargs}"
                          .format(kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                req_id = flask.request.environ.get(oslo_req_id.ENV_REQUEST_ID)
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','),
                    request_id=req_id)
                context.set_ctx(ctx)
                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
예제 #8
0
파일: main.py 프로젝트: COSHPC/sahara
 def version_list():
     context.set_ctx(None)
     return api_utils.render({
         "versions": [
             {"id": "v1.0", "status": "CURRENT"}
         ]
     })
예제 #9
0
파일: api.py 프로젝트: qinweiwei/sahara
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','))
                context.set_ctx(ctx)

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()
                #add args 
                else:
                    kwargs.update(flask.request.args.to_dict())
                try:
                    return func(**kwargs)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
예제 #10
0
 def test_is_auth_capable_for_user_ctx(self):
     existing_ctx = context.ctx()
     try:
         ctx = context.Context('test_user', 'tenant_1', 'test_auth_token',
                               {"network": "aURL"}, remote_semaphore='123')
         self.assertTrue(ctx.is_auth_capable())
     finally:
         context.set_ctx(existing_ctx)
예제 #11
0
 def test_is_auth_capable_for_user_ctx(self):
     existing_ctx = context.ctx()
     try:
         ctx = context.Context('test_user', 'tenant_1', 'test_auth_token',
                               {"network": "aURL"}, remote_semaphore='123')
         self.assertTrue(ctx.is_auth_capable())
     finally:
         context.set_ctx(existing_ctx)
예제 #12
0
 def setUp(self):
     super(ContextTest, self).setUp()
     self.useFixture(fixtures.FakeLogger('sahara'))
     ctx = context.Context('test_user',
                           'tenant_1',
                           'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
예제 #13
0
파일: base.py 프로젝트: COSHPC/sahara
 def setup_context(self, username="******", tenant_id="tenant_1",
                   token="test_auth_token", tenant_name='test_tenant',
                   **kwargs):
     self.addCleanup(context.set_ctx,
                     context.ctx() if context.has_ctx() else None)
     context.set_ctx(context.Context(
         username=username, tenant_id=tenant_id,
         token=token, service_catalog={},
         tenant_name=tenant_name, **kwargs))
예제 #14
0
파일: base.py 프로젝트: xinw1012/sahara
    def setup_context(self, username="******", tenant_id="tenant_1",
                      auth_token="test_auth_token", tenant_name='test_tenant',
                      service_catalog=None, **kwargs):
        self.addCleanup(context.set_ctx,
                        context.ctx() if context.has_ctx() else None)

        context.set_ctx(context.Context(
            username=username, tenant_id=tenant_id,
            auth_token=auth_token, service_catalog=service_catalog or {},
            tenant_name=tenant_name, **kwargs))
예제 #15
0
 def check_for_zombie_proxy_users(self, ctx):
     ctx = context.get_admin_context()
     context.set_ctx(ctx)
     for user in p.proxy_domain_users_list():
         if user.name.startswith('job_'):
             je_id = user.name[4:]
             je = conductor.job_execution_get(ctx, je_id)
             if je is None or (je.info['status'] in
                               edp.JOB_STATUSES_TERMINATED):
                 LOG.debug('Found zombie proxy user {username}'.format(
                     username=user.name))
                 p.proxy_user_delete(user_id=user.id)
     context.set_ctx(None)
예제 #16
0
        def terminate_unneeded_clusters(self, ctx):
            LOG.debug('Terminating unneeded transient clusters')
            ctx = context.get_admin_context()
            context.set_ctx(ctx)
            for cluster in conductor.cluster_get_all(ctx, status='Active'):
                if not cluster.is_transient:
                    continue

                jc = conductor.job_execution_count(ctx,
                                                   end_time=None,
                                                   cluster_id=cluster.id)

                if jc > 0:
                    continue

                cluster_updated_at = timeutils.normalize_time(
                    timeutils.parse_isotime(cluster.updated_at))
                current_time = timeutils.utcnow()
                spacing = timeutils.delta_seconds(cluster_updated_at,
                                                  current_time)
                if spacing < CONF.min_transient_cluster_active_time:
                    continue

                if CONF.use_identity_api_v3:
                    trusts.use_os_admin_auth_token(cluster)

                    LOG.info(
                        _LI('Terminating transient cluster %(cluster)s '
                            'with id %(id)s'), {
                                'cluster': cluster.name,
                                'id': cluster.id
                            })

                    try:
                        ops.terminate_cluster(cluster.id)
                    except Exception as e:
                        LOG.info(
                            _LI('Failed to terminate transient cluster '
                                '%(cluster)s with id %(id)s: %(error)s.'), {
                                    'cluster': cluster.name,
                                    'id': cluster.id,
                                    'error': six.text_type(e)
                                })

                else:
                    if cluster.status != 'AwaitingTermination':
                        conductor.cluster_update(
                            ctx, cluster, {'status': 'AwaitingTermination'})
            context.set_ctx(None)
예제 #17
0
파일: periodic.py 프로젝트: a9261/sahara
        def terminate_unneeded_clusters(self, ctx):
            LOG.debug('Terminating unneeded transient clusters')
            ctx = context.get_admin_context()
            context.set_ctx(ctx)
            for cluster in conductor.cluster_get_all(ctx, status='Active'):
                if not cluster.is_transient:
                    continue

                jc = conductor.job_execution_count(ctx,
                                                   end_time=None,
                                                   cluster_id=cluster.id)

                if jc > 0:
                    continue

                cluster_updated_at = timeutils.normalize_time(
                    timeutils.parse_isotime(cluster.updated_at))
                current_time = timeutils.utcnow()
                spacing = timeutils.delta_seconds(cluster_updated_at,
                                                  current_time)
                if spacing < CONF.min_transient_cluster_active_time:
                    continue

                if CONF.use_identity_api_v3:
                    trusts.use_os_admin_auth_token(cluster)

                    LOG.info(_LI('Terminating transient cluster %(cluster)s '
                                 'with id %(id)s'),
                             {'cluster': cluster.name, 'id': cluster.id})

                    try:
                        ops.terminate_cluster(cluster.id)
                    except Exception as e:
                        LOG.info(_LI('Failed to terminate transient cluster '
                                 '%(cluster)s with id %(id)s: %(error)s.'),
                                 {'cluster': cluster.name,
                                  'id': cluster.id,
                                  'error': six.text_type(e)})

                else:
                    if cluster.status != 'AwaitingTermination':
                        conductor.cluster_update(
                            ctx,
                            cluster,
                            {'status': 'AwaitingTermination'})
            context.set_ctx(None)
예제 #18
0
        def terminate_unneeded_transient_clusters(self, ctx):
            LOG.debug('Terminating unneeded transient clusters')
            ctx = context.get_admin_context()
            context.set_ctx(ctx)
            for cluster in conductor.cluster_get_all(ctx, status='Active'):
                if not cluster.is_transient:
                    continue

                jc = conductor.job_execution_count(ctx,
                                                   end_time=None,
                                                   cluster_id=cluster.id)

                if jc > 0:
                    continue

                spacing = get_time_since_last_update(cluster)
                if spacing < CONF.min_transient_cluster_active_time:
                    continue

                terminate_cluster(ctx, cluster, description='transient')
            context.set_ctx(None)
예제 #19
0
        def terminate_incomplete_clusters(self, ctx):
            if CONF.cleanup_time_for_incomplete_clusters <= 0:
                return

            LOG.debug('Terminating old clusters in non-final state')
            ctx = context.get_admin_context()

            context.set_ctx(ctx)
            # NOTE(alazarev) Retrieving all clusters once in hour for now.
            # Criteria support need to be implemented in sahara db API to
            # have SQL filtering.
            for cluster in conductor.cluster_get_all(ctx):
                if cluster.status in ['Active', 'Error', 'Deleting']:
                    continue

                spacing = get_time_since_last_update(cluster)
                if spacing < CONF.cleanup_time_for_incomplete_clusters * 3600:
                    continue

                terminate_cluster(ctx, cluster, description='incomplete')

            context.set_ctx(None)
예제 #20
0
        def terminate_unneeded_transient_clusters(self, ctx):
            LOG.debug('Terminating unneeded transient clusters')
            ctx = context.get_admin_context()
            context.set_ctx(ctx)
            for cluster in conductor.cluster_get_all(ctx, status='Active'):
                if not cluster.is_transient:
                    continue

                jc = conductor.job_execution_count(ctx,
                                                   end_time=None,
                                                   cluster_id=cluster.id)

                if jc > 0:
                    continue

                spacing = get_time_since_last_update(cluster)
                if spacing < CONF.min_transient_cluster_active_time:
                    continue

                terminate_cluster(ctx, cluster, description='transient')
                # Add event log info cleanup
                context.ctx().current_instance_info = context.InstanceInfo()
            context.set_ctx(None)
예제 #21
0
        def terminate_incomplete_clusters(self, ctx):
            if CONF.cleanup_time_for_incomplete_clusters <= 0:
                return

            LOG.debug('Terminating old clusters in non-final state')
            ctx = context.get_admin_context()

            context.set_ctx(ctx)
            # NOTE(alazarev) Retrieving all clusters once in hour for now.
            # Criteria support need to be implemented in sahara db API to
            # have SQL filtering.
            for cluster in conductor.cluster_get_all(ctx):
                if cluster.status in ['Active', 'Error', 'Deleting']:
                    continue

                spacing = get_time_since_last_update(cluster)
                if spacing < CONF.cleanup_time_for_incomplete_clusters * 3600:
                    continue

                terminate_cluster(ctx, cluster, description='incomplete')
                # Add event log info cleanup
                context.ctx().current_instance_info = context.InstanceInfo()
            context.set_ctx(None)
예제 #22
0
파일: api.py 프로젝트: yonglehou/sahara
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug(
                    "Rest.route.decorator.handler, kwargs={kwargs}".format(
                        kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                req_id = flask.request.environ.get(oslo_req_id.ENV_REQUEST_ID)
                auth_plugin = flask.request.environ.get('keystone.token_auth')
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','),
                    auth_plugin=auth_plugin,
                    request_id=req_id)
                context.set_ctx(ctx)
                if flask.request.method in ['POST', 'PUT', 'PATCH']:
                    kwargs['data'] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
예제 #23
0
파일: rpc.py 프로젝트: a9261/sahara
 def run_method(ctx, **kwargs):
     context.set_ctx(context.Context(**ctx))
     try:
         return method(**kwargs)
     finally:
         context.set_ctx(None)
예제 #24
0
 def wrapped(self, ctx, *args, **kwargs):
     context.set_ctx(context.Context(**ctx))
     return func(self, *args, **kwargs)
예제 #25
0
 def update_job_statuses(self, ctx):
     LOG.debug('Updating job statuses')
     ctx = context.get_admin_context()
     context.set_ctx(ctx)
     job_manager.update_job_statuses()
     context.set_ctx(None)
예제 #26
0
 def run_method(ctx, **kwargs):
     context.set_ctx(context.Context(**ctx))
     try:
         return method(**kwargs)
     finally:
         context.set_ctx(None)
예제 #27
0
파일: context.py 프로젝트: openstack/sahara
def set_ctx(new_ctx, **kwargs):
    context.set_ctx(new_ctx)
예제 #28
0
 def teardown_request(_ex=None):
     context.set_ctx(None)
예제 #29
0
 def version_list():
     context.set_ctx(None)
     return api_utils.render(version_response)
예제 #30
0
 def setUp(self):
     context.set_ctx(context.Context(None, None, None, None))
예제 #31
0
 def setUp(self):
     context.set_ctx(context.Context(None, None, None, None))
예제 #32
0
 def version_list():
     context.set_ctx(None)
     return api_utils.render(version_response)
예제 #33
0
 def setUp(self):
     ctx = context.Context('test_user', 'tenant_1', 'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
예제 #34
0
 def setUp(self):
     super(TopologyTestCase, self).setUp()
     context.set_ctx(context.Context(None, None, None, None))
예제 #35
0
 def handler(self, ctx):
     ctx = context.get_admin_context()
     context.set_ctx(ctx)
     func(self, ctx)
     context.set_ctx(None)
예제 #36
0
 def setUp(self):
     super(TopologyTestCase, self).setUp()
     context.set_ctx(context.Context(None, None, None, None))
예제 #37
0
파일: ops.py 프로젝트: openstack/sahara
 def wrapped(self, ctx, *args, **kwargs):
     context.set_ctx(context.Context(**ctx))
     return func(self, *args, **kwargs)
예제 #38
0
 def setUp(self):
     super(ContextTest, self).setUp()
     self.useFixture(fixtures.FakeLogger('sahara'))
     ctx = context.Context('test_user', 'tenant_1', 'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
예제 #39
0
 def setUp(self):
     ctx = context.Context('test_user',
                           'tenant_1',
                           'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
예제 #40
0
파일: main.py 프로젝트: COSHPC/sahara
 def teardown_request(_ex=None):
     context.set_ctx(None)
예제 #41
0
파일: periodic.py 프로젝트: lhcxx/sahara
 def handler(self, ctx):
     ctx = context.get_admin_context()
     context.set_ctx(ctx)
     func(self, ctx)
     context.set_ctx(None)