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


Python jsonutils.loads方法代码示例

本文整理汇总了Python中oslo_serialization.jsonutils.loads方法的典型用法代码示例。如果您正苦于以下问题:Python jsonutils.loads方法的具体用法?Python jsonutils.loads怎么用?Python jsonutils.loads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_serialization.jsonutils的用法示例。


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

示例1: update_devices_from_compute_resources

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def update_devices_from_compute_resources(self, devices_json):
        """Sync the pci device tracker with compute node information.

        To support pci device hot plug, we sync with the compute node
        periodically, fetching all devices information from compute node,
        update the tracker and sync the DB information.

        Devices should not be hot-plugged when assigned to a container,
        but possibly the compute node has no such guarantee. The best
        we can do is to give a warning if a device is changed
        or removed while assigned.

        :param devices_json: The JSON-ified string of device information
                             that is returned from the compute node.
        """

        devices = []
        for dev in jsonutils.loads(devices_json):
            if self.dev_filter.device_assignable(dev):
                devices.append(dev)
        self._set_hvdevs(devices) 
开发者ID:openstack,项目名称:zun,代码行数:23,代码来源:manager.py

示例2: from_pci_stats

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def from_pci_stats(pci_stats):
    """Create and return a PciDevicePoolList from the data stored in the db,

    which can be either the serialized object, or, prior to the creation of the
    device pool objects, a simple dict or a list of such dicts.
    """
    pools = []
    if isinstance(pci_stats, str):
        try:
            pci_stats = jsonutils.loads(pci_stats)
        except (ValueError, TypeError):
            pci_stats = None
    if pci_stats:
        # Check for object-ness, or old-style storage format.
        if 'zun_object.namespace' in pci_stats:
            return PciDevicePoolList.obj_from_primitive(pci_stats)
        else:
            # This can be either a dict or a list of dicts
            if isinstance(pci_stats, list):
                pools = [PciDevicePool.from_dict(stat)
                         for stat in pci_stats]
            else:
                pools = [PciDevicePool.from_dict(pci_stats)]
    return PciDevicePoolList(objects=pools) 
开发者ID:openstack,项目名称:zun,代码行数:26,代码来源:pci_device_pool.py

示例3: __call__

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def __call__(self, environ, start_response):
        for err_str in self.app_iter:
            err = {}
            try:
                err = json.loads(err_str.decode('utf-8'))
            except ValueError:
                pass

            links = {'rel': 'help', 'href': 'https://docs.openstack.org'
                     '/api-guide/compute/microversions.html'}

            err['max_version'] = self.max_version
            err['min_version'] = self.min_version
            err['code'] = "zun.microversion-unsupported"
            err['links'] = [links]
            err['title'] = "Requested microversion is unsupported"

        self.app_iter = [json.dump_as_bytes(err).encode("latin-1")]
        self.headers['Content-Length'] = str(len(self.app_iter[0]))

        return super(HTTPNotAcceptableAPIVersion, self).__call__(
            environ, start_response) 
开发者ID:openstack,项目名称:zun,代码行数:24,代码来源:http_error.py

示例4: detach_volume

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def detach_volume(self, context, volmap):
        volume_id = volmap.cinder_volume_id
        try:
            self.cinder_api.begin_detaching(volume_id)
        except cinder_exception.BadRequest as e:
            raise exception.Invalid(_("Invalid volume: %s") %
                                    str(e))

        conn_info = jsonutils.loads(volmap.connection_info)
        if not self._volume_connection_keep(context, volume_id):
            try:
                self._disconnect_volume(conn_info)
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.exception('Failed to disconnect volume %(volume_id)s',
                                  {'volume_id': volume_id})
                    self.cinder_api.roll_detaching(volume_id)

            self.cinder_api.terminate_connection(
                volume_id, get_volume_connector_properties())
        self.cinder_api.detach(volmap) 
开发者ID:openstack,项目名称:zun,代码行数:23,代码来源:cinder_workflow.py

示例5: _update_next_hop_details

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def _update_next_hop_details(self, flow_rule, port_detail, detail):
        # Update detail with next-hop node_type and the correlation of
        # port-pair of next-hop
        for node in port_detail['path_nodes']:
            _node = self.get_path_node(node['pathnode_id'])
            if flow_rule['fwd_path'] == _node['fwd_path']:
                detail['nsi'], detail['nsp'] = _node['nsi'], _node['nsp']
                if _node['next_hop']:
                    next_hops = jsonutils.loads(_node['next_hop'])
                    for next_hop in next_hops:
                        pp = self.get_port_detail(next_hop['portpair_id'])
                        detail['pp_corr_tap_nh'] = pp['correlation']
                        for pp_node in pp['path_nodes']:
                            pp_node_detail = self.get_path_node(
                                pp_node['pathnode_id'])
                            detail['tap_nh_node_type'] = pp_node_detail[
                                'node_type']
                            return 
开发者ID:openstack,项目名称:networking-sfc,代码行数:20,代码来源:driver.py

示例6: _make_port_chain_dict

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def _make_port_chain_dict(self, port_chain, fields=None):
        res = {
            'id': port_chain['id'],
            'name': port_chain['name'],
            'project_id': port_chain['project_id'],
            'description': port_chain['description'],
            'port_pair_groups': [
                assoc['portpairgroup_id']
                for assoc in port_chain['chain_group_associations']
            ],
            'flow_classifiers': [
                assoc['flowclassifier_id']
                for assoc in port_chain['chain_classifier_associations']
            ],
            'chain_parameters': {
                param['keyword']: jsonutils.loads(param['value'])
                for k, param in port_chain['chain_parameters'].items()
            },
            'chain_id': port_chain['chain_id'],
        }
        return db_utils.resource_fields(res, fields) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:23,代码来源:sfc_db.py

示例7: _make_port_pair_dict

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def _make_port_pair_dict(self, port_pair, fields=None):
        res = {
            'id': port_pair['id'],
            'name': port_pair['name'],
            'description': port_pair['description'],
            'project_id': port_pair['project_id'],
            'ingress': port_pair['ingress'],
            'egress': port_pair['egress'],
            'service_function_parameters': {
                param['keyword']: jsonutils.loads(param['value'])
                for k, param in
                port_pair['service_function_parameters'].items()
            }
        }

        return db_utils.resource_fields(res, fields) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:18,代码来源:sfc_db.py

示例8: test_playbook_treeview

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def test_playbook_treeview(self):
        ctx = ansible_run()
        treeview = jsonutils.loads(u.playbook_treeview(ctx['playbook'].id))

        # ansible_run provides two fake files:
        # /some/path/main.yml and /playbook.yml
        for f in treeview:
            if f['text'] == 'some':
                self.assertEqual(f['text'], 'some')
                child = f['nodes'][0]
                self.assertEqual(child['text'], 'path')
                child = child['nodes'][0]
                self.assertEqual(child['text'], 'main.yml')
                self.assertEqual(child['dataAttr']['load'],
                                 ctx['task_file'].id)
            else:
                self.assertEqual(f['text'], 'playbook.yml')
                self.assertEqual(f['dataAttr']['load'], ctx['pb_file'].id) 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:20,代码来源:test_utils.py

示例9: test_params_for_keystone_call

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def test_params_for_keystone_call(self, mock_request):
        req = wsgi.Request.blank('/test')
        req.GET['Signature'] = 'test-signature'
        req.GET['AWSAccessKeyId'] = 'test-key-id'
        self.kauth(req)
        mock_request.assert_called_with(
            'POST', CONF.keystone_ec2_tokens_url,
            data=mock.ANY, headers=mock.ANY)

        data = jsonutils.loads(mock_request.call_args[1]['data'])
        expected_data = {
            'ec2Credentials': {
                'access': 'test-key-id',
                'headers': {'Host': 'localhost:80'},
                'host': 'localhost:80',
                'verb': 'GET',
                'params': {'AWSAccessKeyId': 'test-key-id'},
                'signature': 'test-signature',
                'path': '/test',
                'body_hash': 'e3b0c44298fc1c149afbf4c8996fb924'
                             '27ae41e4649b934ca495991b7852b855'}}
        self.assertEqual(expected_data, data) 
开发者ID:openstack,项目名称:ec2-api,代码行数:24,代码来源:test_middleware.py

示例10: _get_in_use_ports

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def _get_in_use_ports(self):
        kubernetes = clients.get_kubernetes_client()
        in_use_ports = []
        running_pods = kubernetes.get(constants.K8S_API_BASE + '/pods')
        for pod in running_pods['items']:
            try:
                annotations = jsonutils.loads(pod['metadata']['annotations'][
                    constants.K8S_ANNOTATION_VIF])
                pod_state = utils.extract_pod_annotation(annotations)
            except KeyError:
                LOG.debug("Skipping pod without kuryr VIF annotation: %s",
                          pod)
            else:
                for vif in pod_state.vifs.values():
                    in_use_ports.append(vif.id)
        return in_use_ports 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:18,代码来源:vif_pool.py

示例11: get_port_annot_pci_info

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def get_port_annot_pci_info(nodename, neutron_port):
    k8s = clients.get_kubernetes_client()
    annot_name = constants.K8S_ANNOTATION_NODE_PCI_DEVICE_INFO
    annot_name = annot_name + '-' + neutron_port

    node_info = k8s.get('/api/v1/nodes/{}'.format(nodename))
    annotations = node_info['metadata']['annotations']
    try:
        json_pci_info = annotations[annot_name]
        pci_info = jsonutils.loads(json_pci_info)
    except KeyError:
        pci_info = {}
    except Exception:
        LOG.exception('Exception when reading annotations '
                      '%s and converting from json', annot_name)
    return pci_info 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:18,代码来源:utils.py

示例12: _get_pod_details

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def _get_pod_details(self, selflink):
        k8s = clients.get_kubernetes_client()
        pod = k8s.get(selflink)
        annotations = pod['metadata']['annotations']
        resource_version = pod['metadata']['resourceVersion']
        labels = pod['metadata'].get('labels')
        try:
            annotations = annotations[constants.K8S_ANNOTATION_VIF]
            state_annotation = jsonutils.loads(annotations)
            state = utils.extract_pod_annotation(state_annotation)
        except KeyError:
            LOG.exception("No annotations %s", constants.K8S_ANNOTATION_VIF)
            raise
        except ValueError:
            LOG.exception("Unable encode annotations")
            raise
        LOG.info("Got VIFs from annotation: %s", state.vifs)
        return state, labels, resource_version 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:20,代码来源:dpdk.py

示例13: update_server

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def update_server(self, server_id, **kwargs):
        """Update server.

        Available params: see http://developer.openstack.org/
                              api-ref-compute-v2.1.html#updateServer

        Most parameters except the following are passed to the API without
        any changes.
        :param disk_config: The name is changed to OS-DCF:diskConfig
        """
        if kwargs.get('disk_config'):
            kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')

        post_body = json.dumps({'server': kwargs})
        resp, body = self.put("servers/%s" % server_id, post_body)
        body = json.loads(body)
        self.validate_response(schema.update_server, resp, body)
        return rest_client.ResponseBody(resp, body) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:20,代码来源:servers_client.py

示例14: list_servers

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def list_servers(self, detail=False, **params):
        """List servers.

        Available params: see http://developer.openstack.org/
                              api-ref-compute-v2.1.html#listServers
                          and http://developer.openstack.org/
                              api-ref-compute-v2.1.html#listDetailServers
        """

        url = 'servers'
        _schema = schema.list_servers

        if detail:
            url += '/detail'
            _schema = schema.list_servers_detail
        if params:
            url += '?%s' % urllib.urlencode(params)

        resp, body = self.get(url)
        body = json.loads(body)
        self.validate_response(_schema, resp, body)
        return rest_client.ResponseBody(resp, body) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:24,代码来源:servers_client.py

示例15: list_images

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import loads [as 别名]
def list_images(self, detail=False, **params):
        """Return a list of all images filtered by any parameter.

        Available params: see http://developer.openstack.org/
                              api-ref-compute-v2.1.html#listImages
        """
        url = 'images'
        _schema = schema.list_images
        if detail:
            url += '/detail'
            _schema = schema.list_images_details

        if params:
            url += '?%s' % urllib.urlencode(params)

        resp, body = self.get(url)
        body = json.loads(body)
        self.validate_response(_schema, resp, body)
        return rest_client.ResponseBody(resp, body) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:21,代码来源:images_client.py


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