本文整理汇总了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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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)