• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python context.get_admin_context函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: update_vnf_with_alarm

 def update_vnf_with_alarm(self, vnf, policy_name, policy_dict):
     params = dict()
     params['vnf_id'] = vnf['id']
     params['mon_policy_name'] = policy_name
     driver = policy_dict['triggers']['resize_compute'][
         'event_type']['implementation']
     policy_action = policy_dict['triggers']['resize_compute'].get('action')
     if not policy_action:
         _log_monitor_events(t_context.get_admin_context(),
                             vnf,
                             "Alarm not set: policy action missing")
         return
     alarm_action_name = policy_action['resize_compute'].get('action_name')
     if not alarm_action_name:
         _log_monitor_events(t_context.get_admin_context(),
                             vnf,
                             "Alarm not set: alarm action name missing")
         return
     params['mon_policy_action'] = alarm_action_name
     alarm_url = self.call_alarm_url(driver, vnf, params)
     details = "Alarm URL set successfully: %s" % alarm_url
     _log_monitor_events(t_context.get_admin_context(),
                         vnf,
                         details)
     return alarm_url
开发者ID:pineunity,项目名称:tacker,代码行数:25,代码来源:monitor.py


示例2: execute_action

 def execute_action(cls, plugin, vnf_dict):
     _log_monitor_events(t_context.get_admin_context(),
                         vnf_dict,
                         "ActionLogAndKill invoked")
     vnf_id = vnf_dict['id']
     if plugin._mark_vnf_dead(vnf_dict['id']):
         if vnf_dict['attributes'].get('monitoring_policy'):
             plugin._vnf_monitor.mark_dead(vnf_dict['id'])
         plugin.delete_vnf(t_context.get_admin_context(), vnf_id)
     LOG.error(_('vnf %s dead'), vnf_id)
开发者ID:pineunity,项目名称:tacker,代码行数:10,代码来源:monitor.py


示例3: test_enforce_admin_only_subattribute

 def test_enforce_admin_only_subattribute(self):
     action = "create_something"
     target = {'tenant_id': 'fake', 'attr': {'sub_attr_1': 'x',
                                             'sub_attr_2': 'y'}}
     result = policy.enforce(context.get_admin_context(),
                             action, target, None)
     self.assertEqual(True, result)
开发者ID:K-OpenNet,项目名称:OPNFV-StateMon,代码行数:7,代码来源:test_policy.py


示例4: setUp

 def setUp(self):
     super(TestCommonServicesPlugin, self).setUp()
     self.addCleanup(mock.patch.stopall)
     self.context = context.get_admin_context()
     self.event_db_plugin =\
         common_services_db_plugin.CommonServicesPluginDb()
     self.coreutil_plugin = common_services_plugin.CommonServicesPlugin()
开发者ID:openstack,项目名称:tacker,代码行数:7,代码来源:test_common_services.py


示例5: create_alarm_action

        def create_alarm_action(action, action_list, scaling_type):
            params = dict()
            params['vnf_id'] = vnf['id']
            params['mon_policy_name'] = action
            driver = 'ceilometer'

            def _refactor_backend_policy(bk_policy_name, bk_action_name):
                policy = '%(policy_name)s%(action_name)s' % {
                    'policy_name': bk_policy_name,
                    'action_name': bk_action_name}
                return policy

            for index, policy_action_name in enumerate(action_list):
                filters = {'name': policy_action_name}
                bkend_policies = \
                    plugin.get_vnf_policies(context, vnf['id'], filters)
                if bkend_policies:
                    if constants.POLICY_SCALING in str(bkend_policies[0]):
                        action_list[index] = _refactor_backend_policy(
                            policy_action_name, scaling_type)

                # Support multiple action. Ex: respawn % notify
                action_name = '%'.join(action_list)
                params['mon_policy_action'] = action_name
                alarm_url[action] = \
                    self.call_alarm_url(driver, vnf, params)
                details = "Alarm URL set successfully: %s" % alarm_url
                vnfm_utils.log_events(t_context.get_admin_context(), vnf,
                                      constants.RES_EVT_MONITOR,
                                      details)
开发者ID:openstack,项目名称:tacker,代码行数:30,代码来源:monitor.py


示例6: execute_action

    def execute_action(cls, plugin, device_dict):
        LOG.error(_('device %s dead'), device_dict['id'])
        if plugin._mark_device_dead(device_dict['id']):
            plugin._vnf_monitor.mark_dead(device_dict['id'])

            attributes = device_dict['attributes'].copy()
            attributes['dead_device_id'] = device_dict['id']
            new_device = {'attributes': attributes}
            for key in ('tenant_id', 'template_id', 'name'):
                new_device[key] = device_dict[key]
            LOG.debug(_('new_device %s'), new_device)

            # keystone v2.0 specific
            authtoken = CONF.keystone_authtoken
            token = clients.OpenstackClients().auth_token

            context = t_context.get_admin_context()
            context.tenant_name = authtoken.project_name
            context.user_name = authtoken.username
            context.auth_token = token['id']
            context.tenant_id = token['tenant_id']
            context.user_id = token['user_id']
            new_device_dict = plugin.create_device(context,
                                                   {'device': new_device})
            LOG.info(_('respawned new device %s'), new_device_dict['id'])
开发者ID:srics,项目名称:tacker,代码行数:25,代码来源:monitor.py


示例7: on_failure

    def on_failure(cls, plugin, device_dict):
        LOG.error(_('device %s dead'), device_dict['id'])
        attributes = device_dict['attributes'].copy()
        attributes['dead_device_id'] = device_dict['id']
        new_device = {'attributes': attributes}
        for key in ('tenant_id', 'template_id', 'name'):
            new_device[key] = device_dict[key]
        LOG.debug(_('new_device %s'), new_device)

        # keystone v2.0 specific
        auth_url = CONF.keystone_authtoken.auth_uri + '/v2.0'
        authtoken = CONF.keystone_authtoken
        kc = ks_client.Client(
            tenant_name=authtoken.project_name,
            username=authtoken.username,
            password=authtoken.password,
            auth_url=auth_url)
        token = kc.service_catalog.get_token()

        context = t_context.get_admin_context()
        context.tenant_name = authtoken.project_name
        context.user_name = authtoken.username
        context.auth_token = token['id']
        context.tenant_id = token['tenant_id']
        context.user_id = token['user_id']
        new_device_dict = plugin.create_device(context, {'device': new_device})
        LOG.info(_('respawned new device %s'), new_device_dict['id'])
开发者ID:SripriyaSeetharam,项目名称:tacker,代码行数:27,代码来源:monitor.py


示例8: setUp

 def setUp(self):
     super(TestNfvoPlugin, self).setUp()
     self.addCleanup(mock.patch.stopall)
     self.context = context.get_admin_context()
     self._mock_driver_manager()
     mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin.__run__').start()
     self.nfvo_plugin = nfvo_plugin.NfvoPlugin()
开发者ID:bharaththiruveedula,项目名称:tacker,代码行数:7,代码来源:test_nfvo_plugin.py


示例9: update_vnf_with_alarm

    def update_vnf_with_alarm(self, plugin, context, vnf, policy_dict):
        triggers = policy_dict['triggers']
        alarm_url = dict()
        for trigger_name, trigger_dict in triggers.items():
            params = dict()
            params['vnf_id'] = vnf['id']
            params['mon_policy_name'] = trigger_name
            driver = trigger_dict['event_type']['implementation']
            # TODO(Tung Doan) trigger_dict.get('actions') needs to be used
            policy_action = trigger_dict.get('action')
            if len(policy_action) == 0:
                vnfm_utils.log_events(t_context.get_admin_context(), vnf,
                                      constants.RES_EVT_MONITOR,
                                      "Alarm not set: policy action missing")
                return
            # Other backend policies with the construct (policy, action)
            # ex: (SP1, in), (SP1, out)

            def _refactor_backend_policy(bk_policy_name, bk_action_name):
                policy = '%(policy_name)s-%(action_name)s' % {
                    'policy_name': bk_policy_name,
                    'action_name': bk_action_name}
                return policy

            for index, policy_action_name in enumerate(policy_action):
                filters = {'name': policy_action_name}
                bkend_policies =\
                    plugin.get_vnf_policies(context, vnf['id'], filters)
                if bkend_policies:
                    bkend_policy = bkend_policies[0]
                    if bkend_policy['type'] == constants.POLICY_SCALING:
                        cp = trigger_dict['condition'].\
                            get('comparison_operator')
                        scaling_type = 'out' if cp == 'gt' else 'in'
                        policy_action[index] = _refactor_backend_policy(
                            policy_action_name, scaling_type)

            # Support multiple action. Ex: respawn % notify
            action_name = '%'.join(policy_action)

            params['mon_policy_action'] = action_name
            alarm_url[trigger_name] =\
                self.call_alarm_url(driver, vnf, params)
            details = "Alarm URL set successfully: %s" % alarm_url
            vnfm_utils.log_events(t_context.get_admin_context(), vnf,
                                  constants.RES_EVT_MONITOR, details)
        return alarm_url
开发者ID:openstack,项目名称:tacker,代码行数:47,代码来源:monitor.py


示例10: _init_monitoring

 def _init_monitoring(self):
     context = t_context.get_admin_context()
     vnfs = self.get_vnfs(context)
     for vnf in vnfs:
         # Add tenant_id in context object as it is required
         # to get VIM in monitoring.
         context.tenant_id = vnf['tenant_id']
         self.add_vnf_to_monitor(context, vnf)
开发者ID:openstack,项目名称:tacker,代码行数:8,代码来源:plugin.py


示例11: test_tacker_context_admin_to_dict

 def test_tacker_context_admin_to_dict(self):
     self.db_api_session.return_value = 'fakesession'
     ctx = context.get_admin_context()
     ctx_dict = ctx.to_dict()
     self.assertIsNone(ctx_dict['user_id'])
     self.assertIsNone(ctx_dict['tenant_id'])
     self.assertIsNotNone(ctx.session)
     self.assertNotIn('session', ctx_dict)
开发者ID:openstack,项目名称:tacker,代码行数:8,代码来源:test_context.py


示例12: setUp

 def setUp(self):
     super(VNFActionRespawn, self).setUp()
     self.context = context.get_admin_context()
     mock.patch('tacker.db.common_services.common_services_db_plugin.'
                'CommonServicesPluginDb.create_event'
                ).start()
     self._cos_db_plugin =\
         common_services_db_plugin.CommonServicesPluginDb()
开发者ID:openstack,项目名称:tacker,代码行数:8,代码来源:test_respawn.py


示例13: test_tacker_context_get_admin_context_not_update_local_store

    def test_tacker_context_get_admin_context_not_update_local_store(self):
        ctx = context.Context('user_id', 'tenant_id')
        req_id_before = local.store.context.request_id
        self.assertEqual(ctx.request_id, req_id_before)

        ctx_admin = context.get_admin_context()
        self.assertEqual(req_id_before, local.store.context.request_id)
        self.assertNotEqual(req_id_before, ctx_admin.request_id)
开发者ID:DorChen,项目名称:tacker,代码行数:8,代码来源:test_neutron_context.py


示例14: setUp

 def setUp(self):
     super(TestVNFMPlugin, self).setUp()
     self.addCleanup(mock.patch.stopall)
     self.context = context.get_admin_context()
     self._mock_device_manager()
     self._mock_vnf_monitor()
     self._mock_green_pool()
     self.vnfm_plugin = plugin.VNFMPlugin()
开发者ID:liujyg,项目名称:tacker,代码行数:8,代码来源:test_plugin.py


示例15: setUp

 def setUp(self):
     super(TestVNFActionVduAutoheal, self).setUp()
     self.context = context.get_admin_context()
     self._mock_device_manager()
     self._mock_vnf_monitor()
     self._insert_dummy_vim()
     self.vnfm_plugin = plugin.VNFMPlugin()
     self.vdu_autoheal = vdu_autoheal.VNFActionVduAutoheal()
     self.addCleanup(mock.patch.stopall)
开发者ID:openstack,项目名称:tacker,代码行数:9,代码来源:test_vdu_autoheal.py


示例16: test_tacker_context_get_admin_context_not_update_local_store

    def test_tacker_context_get_admin_context_not_update_local_store(self):
        ctx = context.Context('user_id', 'tenant_id')
        req_id_before = oslo_context.get_current().request_id
        self.assertEqual(req_id_before, ctx.request_id)

        ctx_admin = context.get_admin_context()
        self.assertEqual(req_id_before,
                         oslo_context.get_current().request_id)
        self.assertNotEqual(req_id_before, ctx_admin.request_id)
开发者ID:openstack,项目名称:tacker,代码行数:9,代码来源:test_context.py


示例17: down_cb

 def down_cb(hosting_device_):
     if self._mark_device_dead(device_id):
         self._device_status.mark_dead(device_id)
         device_dict_ = self.get_device(
             t_context.get_admin_context(), device_id)
         failure_cls = monitor.FailurePolicy.get_policy(
             device_dict_['attributes'].get('failure_policy'),
             device_dict_)
         if failure_cls:
             failure_cls.on_failure(self, device_dict_)
开发者ID:SripriyaSeetharam,项目名称:tacker,代码行数:10,代码来源:plugin.py


示例18: setUp

 def setUp(self):
     super(TestOpenStack, self).setUp()
     self.context = context.get_admin_context()
     self.infra_driver = openstack.OpenStack()
     self._mock_heat_client()
     mock.patch('tacker.db.common_services.common_services_db_plugin.'
                'CommonServicesPluginDb.create_event'
                ).start()
     self._cos_db_plugin = \
         common_services_db_plugin.CommonServicesPluginDb()
     self.addCleanup(mock.patch.stopall)
开发者ID:openstack,项目名称:tacker,代码行数:11,代码来源:test_openstack.py


示例19: __init__

 def __init__(self):
     super(NfvoPlugin, self).__init__()
     self._vim_drivers = driver_manager.DriverManager(
         'tacker.nfvo.vim.drivers',
         cfg.CONF.nfvo_vim.vim_drivers)
     self._created_vims = dict()
     context = t_context.get_admin_context()
     vims = self.get_vims(context)
     for vim in vims:
         self._created_vims[vim["id"]] = vim
     self._monitor_interval = cfg.CONF.nfvo_vim.monitor_interval
     threading.Thread(target=self.__run__).start()
开发者ID:bharaththiruveedula,项目名称:tacker,代码行数:12,代码来源:nfvo_plugin.py


示例20: setUp

 def setUp(self):
     super(TestNfvoPlugin, self).setUp()
     self.addCleanup(mock.patch.stopall)
     self.context = context.get_admin_context()
     self._mock_driver_manager()
     mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin.__run__').start()
     mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf',
                side_effect=dummy_get_vim).start()
     self.nfvo_plugin = nfvo_plugin.NfvoPlugin()
     mock.patch('tacker.db.common_services.common_services_db.'
                'CommonServicesPluginDb.create_event'
                ).start()
     self._cos_db_plugin = common_services_db.CommonServicesPluginDb()
开发者ID:pineunity,项目名称:tacker,代码行数:13,代码来源:test_nfvo_plugin.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python policy.enforce函数代码示例发布时间:2022-05-27
下一篇:
Python _i18n._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap