diff options
| author | Zhongyue Luo <lzyeval@gmail.com> | 2012-06-03 16:36:06 +0800 |
|---|---|---|
| committer | Zhongyue Luo <lzyeval@gmail.com> | 2012-06-07 09:24:03 +0800 |
| commit | 3dce38f32559659978dd2ae69e9ffcb39c608582 (patch) | |
| tree | 7735a91c738dbd944344eb4fa3724bc9aa4dcf4b /nova/virt | |
| parent | 7b7febb02b37420c759eab59b07c7e3e2de9bab1 (diff) | |
Replace standard json module with openstack.common.jsonutils
Implements blueprint use-common-jsonutils
1. Edit openstack-common.conf and import nova/openstack/common/jsonutils.py
2. Remove json package imports and replace with jsonutils
Places where using json.load hasn't changed.
Change-Id: Ie6feab605fb0474fd505c56ef57b7a9ecfa5269d
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/disk/api.py | 4 | ||||
| -rw-r--r-- | nova/virt/libvirt/utils.py | 6 | ||||
| -rw-r--r-- | nova/virt/xenapi/fake.py | 16 | ||||
| -rw-r--r-- | nova/virt/xenapi/firewall.py | 8 | ||||
| -rw-r--r-- | nova/virt/xenapi/host.py | 8 | ||||
| -rw-r--r-- | nova/virt/xenapi/pool.py | 4 | ||||
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 4 | ||||
| -rw-r--r-- | nova/virt/xenapi/vmops.py | 12 |
8 files changed, 31 insertions, 31 deletions
diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index 5978399db..9e2e9ffa1 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -26,7 +26,6 @@ Includes injection of SSH PGP keys into authorized_keys file. """ import crypt -import json import os import random import re @@ -36,6 +35,7 @@ from nova import exception from nova import flags from nova import log as logging from nova.openstack.common import cfg +from nova.openstack.common import jsonutils from nova import utils from nova.virt.disk import guestfs from nova.virt.disk import loop @@ -320,7 +320,7 @@ def _inject_metadata_into_fs(metadata, fs, execute=None): metadata = dict([(m.key, m.value) for m in metadata]) utils.execute('tee', metadata_path, - process_input=json.dumps(metadata), run_as_root=True) + process_input=jsonutils.dumps(metadata), run_as_root=True) def _inject_key_into_fs(key, fs, execute=None): diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 40b8d98d5..735957b29 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -20,7 +20,6 @@ # under the License. import hashlib -import json import os import random import re @@ -29,6 +28,7 @@ from nova import exception from nova import flags from nova import log as logging from nova.openstack.common import cfg +from nova.openstack.common import jsonutils from nova import utils from nova.virt import images @@ -375,7 +375,7 @@ def read_stored_info(base_path, field=None): LOG.info(_('Read: %s'), serialized) try: - d = json.loads(serialized) + d = jsonutils.loads(serialized) except ValueError, e: LOG.error(_('Error reading image info file %(filename)s: ' @@ -400,7 +400,7 @@ def write_stored_info(target, field=None, value=None): d = read_stored_info(info_file) d[field] = value - serialized = json.dumps(d) + serialized = jsonutils.dumps(d) LOG.info(_('Writing image info file: %s'), info_file) LOG.info(_('Wrote: %s'), serialized) diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py index 3ccd6247d..a31307d89 100644 --- a/nova/virt/xenapi/fake.py +++ b/nova/virt/xenapi/fake.py @@ -51,7 +51,6 @@ A fake XenAPI SDK. """ -import json import random import uuid from xml.sax import saxutils @@ -60,6 +59,7 @@ import pprint from nova import exception from nova import log as logging +from nova.openstack.common import jsonutils from nova import utils @@ -337,7 +337,7 @@ def as_json(*args, **kwargs): then these are rendered as a JSON list. If it's given keyword arguments then these are rendered as a JSON dict.""" arg = args or kwargs - return json.dumps(arg) + return jsonutils.dumps(arg) class Failure(Exception): @@ -510,17 +510,17 @@ class SessionBase(object): elif (plugin, method) == ('migration', 'transfer_vhd'): return '' elif (plugin, method) == ('xenhost', 'host_data'): - return json.dumps({'host_memory': {'total': 10, - 'overhead': 20, - 'free': 30, - 'free-computed': 40}, }) + return jsonutils.dumps({'host_memory': {'total': 10, + 'overhead': 20, + 'free': 30, + 'free-computed': 40}, }) elif (plugin == 'xenhost' and method in ['host_reboot', 'host_startup', 'host_shutdown']): - return json.dumps({"power_action": method[5:]}) + return jsonutils.dumps({"power_action": method[5:]}) elif (plugin, method) == ('xenhost', 'set_host_enabled'): enabled = 'enabled' if _5.get('enabled') == 'true' else 'disabled' - return json.dumps({"status": enabled}) + return jsonutils.dumps({"status": enabled}) else: raise Exception('No simulation in host_call_plugin for %s,%s' % (plugin, method)) diff --git a/nova/virt/xenapi/firewall.py b/nova/virt/xenapi/firewall.py index f25954a4e..094da44eb 100644 --- a/nova/virt/xenapi/firewall.py +++ b/nova/virt/xenapi/firewall.py @@ -17,13 +17,11 @@ # License for the specific language governing permissions and limitations # under the License. -import json - - from nova import context from nova.db import api as db from nova import flags from nova import log as logging +from nova.openstack.common import jsonutils from nova.virt import firewall from nova.virt import netutils @@ -49,9 +47,9 @@ class Dom0IptablesFirewallDriver(firewall.IptablesFirewallDriver): # Prepare arguments for plugin call args = {} args.update(map(lambda x: (x, str(kwargs[x])), kwargs)) - args['cmd_args'] = json.dumps(cmd) + args['cmd_args'] = jsonutils.dumps(cmd) ret = self._session.call_plugin('xenhost', 'iptables_config', args) - json_ret = json.loads(ret) + json_ret = jsonutils.loads(ret) return (json_ret['out'], json_ret['err']) def __init__(self, xenapi_session=None, **kwargs): diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 044173a03..387a6b8a5 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -19,7 +19,6 @@ Management class for host-related functions (start, reboot, etc). """ -import json import logging from nova.compute import vm_states @@ -27,6 +26,7 @@ from nova import context from nova import db from nova import exception from nova import notifications +from nova.openstack.common import jsonutils from nova.virt.xenapi import vm_utils LOG = logging.getLogger(__name__) @@ -42,7 +42,7 @@ class Host(object): def host_power_action(self, _host, action): """Reboots or shuts down the host.""" - args = {"action": json.dumps(action)} + args = {"action": jsonutils.dumps(action)} methods = {"reboot": "host_reboot", "shutdown": "host_shutdown"} response = call_xenhost(self._session, methods[action], args) return response.get("power_action", response) @@ -112,7 +112,7 @@ class Host(object): def set_host_enabled(self, _host, enabled): """Sets the specified host's ability to accept new instances.""" - args = {"enabled": json.dumps(enabled)} + args = {"enabled": jsonutils.dumps(enabled)} response = call_xenhost(self._session, "set_host_enabled", args) return response.get("status", response) @@ -177,7 +177,7 @@ def call_xenhost(session, method, arg_dict): result = session.call_plugin('xenhost', method, args=arg_dict) if not result: return '' - return json.loads(result) + return jsonutils.loads(result) except ValueError: LOG.exception(_("Unable to get updated status")) return None diff --git a/nova/virt/xenapi/pool.py b/nova/virt/xenapi/pool.py index 6bf3edad4..6b12934ff 100644 --- a/nova/virt/xenapi/pool.py +++ b/nova/virt/xenapi/pool.py @@ -19,7 +19,6 @@ Management class for Pool-related functions (join, eject, etc). """ -import json import urlparse from nova.compute import aggregate_states @@ -28,6 +27,7 @@ from nova import exception from nova import flags from nova import log as logging from nova.openstack.common import cfg +from nova.openstack.common import jsonutils from nova import rpc from nova.virt.xenapi import vm_utils @@ -134,7 +134,7 @@ class ResourcePool(object): 'url': url, 'user': user, 'password': passwd, - 'force': json.dumps(FLAGS.use_join_force), + 'force': jsonutils.dumps(FLAGS.use_join_force), 'master_addr': self._host_addr, 'master_user': FLAGS.xenapi_connection_username, 'master_pass': FLAGS.xenapi_connection_password, } diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 570fccb1c..e7fc20639 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -23,7 +23,6 @@ their attributes like VDIs, VIFs, as well as their lookup functions. import contextlib import cPickle as pickle import decimal -import json import os import re import time @@ -43,6 +42,7 @@ from nova.image import glance from nova import log as logging from nova.openstack.common import cfg from nova.openstack.common import excutils +from nova.openstack.common import jsonutils from nova import utils from nova.virt.disk import api as disk from nova.virt import xenapi @@ -711,7 +711,7 @@ def _retry_glance_download_vhd(context, session, image): try: result = session.call_plugin('glance', 'download_vhd', kwargs) - return json.loads(result) + return jsonutils.loads(result) except session.XenAPI.Failure as exc: _type, _method, error = exc.details[:3] if error == 'RetryableError': diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 8ce47662d..6d90518ce 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -23,7 +23,6 @@ import base64 import binascii import cPickle as pickle import functools -import json import os import time import uuid @@ -39,6 +38,7 @@ from nova import flags from nova import log as logging from nova.openstack.common import cfg from nova.openstack.common import importutils +from nova.openstack.common import jsonutils from nova import utils from nova.virt import driver from nova.virt.xenapi import firewall @@ -517,7 +517,7 @@ class VMOps(object): # Check if this is a JSON-encoded string and convert if needed. if isinstance(injected_files, basestring): try: - injected_files = json.loads(injected_files) + injected_files = jsonutils.loads(injected_files) except ValueError: LOG.exception(_("Invalid value for injected_files: %r"), injected_files, instance=instance) @@ -1409,7 +1409,9 @@ class VMOps(object): xs_data = self._vif_xenstore_data(vif) location = ('vm-data/networking/%s' % vif['address'].replace(':', '')) - self._add_to_param_xenstore(vm_ref, location, json.dumps(xs_data)) + self._add_to_param_xenstore(vm_ref, + location, + jsonutils.dumps(xs_data)) try: self._write_to_xenstore(instance, location, xs_data, vm_ref=vm_ref) @@ -1466,7 +1468,7 @@ class VMOps(object): """ return self._make_plugin_call('xenstore.py', 'write_record', instance, vm_ref=vm_ref, path=path, - value=json.dumps(value)) + value=jsonutils.dumps(value)) def _make_agent_call(self, method, instance, args=None, vm_ref=None): """Abstracts out the interaction with the agent xenapi plugin.""" @@ -1478,7 +1480,7 @@ class VMOps(object): if isinstance(ret, dict): return ret try: - return json.loads(ret) + return jsonutils.loads(ret) except TypeError: LOG.error(_('The agent call to %(method)s returned an invalid' ' response: %(ret)r. path=%(path)s; args=%(args)r'), |
