ec2utils.py (ec2-api-14.0.1) | : | ec2utils.py (ec2-api-15.0.0) | ||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
import datetime | import datetime | |||
import re | import re | |||
from glanceclient.common import exceptions as glance_exception | from glanceclient.common import exceptions as glance_exception | |||
from lxml import etree | from lxml import etree | |||
from oslo_config import cfg | from oslo_config import cfg | |||
from oslo_log import log as logging | from oslo_log import log as logging | |||
from oslo_serialization import jsonutils | from oslo_serialization import jsonutils | |||
from oslo_utils import timeutils | from oslo_utils import timeutils | |||
import six | ||||
from ec2api import clients | from ec2api import clients | |||
from ec2api.db import api as db_api | from ec2api.db import api as db_api | |||
from ec2api import exception | from ec2api import exception | |||
from ec2api.i18n import _ | from ec2api.i18n import _ | |||
LOG = logging.getLogger(__name__) | LOG = logging.getLogger(__name__) | |||
ec2_opts = [ | ec2_opts = [ | |||
cfg.StrOpt('external_network', | cfg.StrOpt('external_network', | |||
skipping to change at line 103 | skipping to change at line 102 | |||
EBS boot uses multi dot-separated arguments like | EBS boot uses multi dot-separated arguments like | |||
BlockDeviceMapping.1.DeviceName=snap-id | BlockDeviceMapping.1.DeviceName=snap-id | |||
Convert the above into | Convert the above into | |||
{'block_device_mapping': {'1': {'device_name': snap-id}}} | {'block_device_mapping': {'1': {'device_name': snap-id}}} | |||
""" | """ | |||
args = {} | args = {} | |||
for key, value in items: | for key, value in items: | |||
parts = key.split(".") | parts = key.split(".") | |||
key = str(camelcase_to_underscore(parts[0])) | key = str(camelcase_to_underscore(parts[0])) | |||
if isinstance(value, six.string_types): | if isinstance(value, str): | |||
# NOTE(vish): Automatically convert strings back | # NOTE(vish): Automatically convert strings back | |||
# into their respective values | # into their respective values | |||
value = _try_convert(value) | value = _try_convert(value) | |||
if len(parts) > 1: | if len(parts) > 1: | |||
d = args.get(key, {}) | d = args.get(key, {}) | |||
args[key] = d | args[key] = d | |||
for k in parts[1:-1]: | for k in parts[1:-1]: | |||
k = camelcase_to_underscore(k) | k = camelcase_to_underscore(k) | |||
v = d.get(k, {}) | v = d.get(k, {}) | |||
skipping to change at line 144 | skipping to change at line 143 | |||
sub_el = etree.SubElement(el, 'item') | sub_el = etree.SubElement(el, 'item') | |||
_render_data(sub_el, item) | _render_data(sub_el, item) | |||
elif isinstance(data, dict): | elif isinstance(data, dict): | |||
_render_dict(el, data) | _render_dict(el, data) | |||
elif hasattr(data, '__dict__'): | elif hasattr(data, '__dict__'): | |||
_render_dict(el, data.__dict__) | _render_dict(el, data.__dict__) | |||
elif isinstance(data, bool): | elif isinstance(data, bool): | |||
el.text = str(data).lower() | el.text = str(data).lower() | |||
elif isinstance(data, datetime.datetime): | elif isinstance(data, datetime.datetime): | |||
el.text = _database_to_isoformat(data) | el.text = _database_to_isoformat(data) | |||
elif isinstance(data, six.binary_type): | elif isinstance(data, bytes): | |||
el.text = data.decode("utf-8") | el.text = data.decode("utf-8") | |||
elif data is not None: | elif data is not None: | |||
el.text = six.text_type(data) | el.text = str(data) | |||
def _database_to_isoformat(datetimeobj): | def _database_to_isoformat(datetimeobj): | |||
"""Return a xs:dateTime parsable string from datatime.""" | """Return a xs:dateTime parsable string from datatime.""" | |||
return datetimeobj.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z' | return datetimeobj.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z' | |||
def dict_to_xml(data_dict, root_tag): | def dict_to_xml(data_dict, root_tag): | |||
root = etree.Element(root_tag) | root = etree.Element(root_tag) | |||
_render_dict(root, data_dict) | _render_dict(root, data_dict) | |||
return root | return root | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 3 lines changed or added |