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


Python context.get_admin_context函数代码示例

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


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


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