本文整理汇总了Python中tempest.common.xml_utils.xml_to_json函数的典型用法代码示例。如果您正苦于以下问题:Python xml_to_json函数的具体用法?Python xml_to_json怎么用?Python xml_to_json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml_to_json函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_volume
def create_volume(self, size, display_name=None, metadata=None):
"""Creates a new Volume.
:param size: Size of volume in GB. (Required)
:param display_name: Optional Volume Name.
:param metadata: An optional dictionary of values for metadata.
"""
volume = xml_utils.Element("volume",
xmlns=xml_utils.XMLNS_11,
size=size)
if display_name:
volume.add_attr('display_name', display_name)
if metadata:
_metadata = xml_utils.Element('metadata')
volume.append(_metadata)
for key, value in metadata.items():
meta = xml_utils.Element('meta')
meta.add_attr('key', key)
meta.append(xml_utils.Text(value))
_metadata.append(meta)
resp, body = self.post('os-volumes', str(xml_utils.Document(volume)))
body = xml_utils.xml_to_json(etree.fromstring(body))
return resp, body
开发者ID:AminaMseddi,项目名称:tempest,代码行数:25,代码来源:volumes_extensions_client.py
示例2: create_flavor
def create_flavor(self, name, ram, vcpus, disk, flavor_id, **kwargs):
"""Creates a new flavor or instance type."""
flavor = xml_utils.Element("flavor",
xmlns=xml_utils.XMLNS_11,
ram=ram,
vcpus=vcpus,
disk=disk,
id=flavor_id,
name=name)
if kwargs.get('rxtx'):
flavor.add_attr('rxtx_factor', kwargs.get('rxtx'))
if kwargs.get('swap'):
flavor.add_attr('swap', kwargs.get('swap'))
if kwargs.get('ephemeral'):
flavor.add_attr('OS-FLV-EXT-DATA:ephemeral',
kwargs.get('ephemeral'))
if kwargs.get('is_public'):
flavor.add_attr('os-flavor-access:is_public',
kwargs.get('is_public'))
flavor.add_attr('xmlns:OS-FLV-EXT-DATA', XMLNS_OS_FLV_EXT_DATA)
flavor.add_attr('xmlns:os-flavor-access', XMLNS_OS_FLV_ACCESS)
resp, body = self.post('flavors', str(xml_utils.Document(flavor)))
body = xml_utils.xml_to_json(etree.fromstring(body))
flavor = self._format_flavor(body)
return resp, flavor
开发者ID:AminaMseddi,项目名称:tempest,代码行数:25,代码来源:flavors_client.py
示例3: create_volume
def create_volume(self, size, **kwargs):
"""Creates a new Volume.
:param size: Size of volume in GB. (Required)
:param display_name: Optional Volume Name.
:param metadata: An optional dictionary of values for metadata.
:param volume_type: Optional Name of volume_type for the volume
:param snapshot_id: When specified the volume is created from
this snapshot
:param imageRef: When specified the volume is created from this
image
"""
# NOTE(afazekas): it should use a volume namespace
volume = common.Element("volume", xmlns=common.XMLNS_11, size=size)
if "metadata" in kwargs:
_metadata = common.Element("metadata")
volume.append(_metadata)
for key, value in kwargs["metadata"].items():
meta = common.Element("meta")
meta.add_attr("key", key)
meta.append(common.Text(value))
_metadata.append(meta)
attr_to_add = kwargs.copy()
del attr_to_add["metadata"]
else:
attr_to_add = kwargs
for key, value in attr_to_add.items():
volume.add_attr(key, value)
resp, body = self.post("volumes", str(common.Document(volume)))
body = common.xml_to_json(etree.fromstring(body))
return resp, body
开发者ID:javacruft,项目名称:tempest,代码行数:34,代码来源:volumes_client.py
示例4: _parse_array
def _parse_array(self, node):
array = []
for child in node.getchildren():
tag_list = child.tag.split('}', 1)
if tag_list[1] == "endpoint":
array.append(common.xml_to_json(child))
return array
开发者ID:adkerr,项目名称:tempest,代码行数:7,代码来源:endpoints_client.py
示例5: create_volume_type
def create_volume_type(self, name, **kwargs):
"""
Creates a new Volume_type.
name(Required): Name of volume_type.
Following optional keyword arguments are accepted:
extra_specs: A dictionary of values to be used as extra_specs.
"""
vol_type = common.Element("volume_type", xmlns=common.XMLNS_11)
if name:
vol_type.add_attr("name", name)
extra_specs = kwargs.get("extra_specs")
if extra_specs:
_extra_specs = common.Element("extra_specs")
vol_type.append(_extra_specs)
for key, value in extra_specs.items():
spec = common.Element("extra_spec")
spec.add_attr("key", key)
spec.append(common.Text(value))
_extra_specs.append(spec)
resp, body = self.post("types", str(common.Document(vol_type)))
body = common.xml_to_json(etree.fromstring(body))
self.expected_success(200, resp.status)
return resp, body
开发者ID:yanheven,项目名称:OpenStackInAction,代码行数:25,代码来源:volume_types_client.py
示例6: update_image_metadata_item
def update_image_metadata_item(self, image_id, key, meta):
"""Sets the value for a specific image metadata key."""
post_body = xml_utils.Document('meta', xml_utils.Text(meta), key=key)
resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key),
post_body)
body = xml_utils.xml_to_json(etree.fromstring(body))
return resp, body['meta']
开发者ID:snowsun,项目名称:tempest,代码行数:7,代码来源:images_client.py
示例7: _parse_image
def _parse_image(self, node):
"""Parses detailed XML image information into dictionary."""
data = xml_utils.xml_to_json(node)
self._parse_links(node, data)
# parse all metadata
if 'metadata' in data:
tag = node.find('{%s}metadata' % xml_utils.XMLNS_11)
data['metadata'] = dict((x.get('key'), x.text)
for x in tag.getchildren())
# parse server information
if 'server' in data:
tag = node.find('{%s}server' % xml_utils.XMLNS_11)
data['server'] = self._parse_server(tag)
# parse extended attributes
diskConfig = ('{http://docs.openstack.org'
'/compute/ext/disk_config/api/v1.1}diskConfig')
image_size = ('{http://docs.openstack.org'
'/compute/ext/image_size/api/v1.1}size')
if diskConfig in data:
data['OS-DCF:diskConfig'] = data.pop(diskConfig)
if image_size in data:
data['OS-EXT-IMG-SIZE:size'] = data.pop(image_size)
return data
开发者ID:snowsun,项目名称:tempest,代码行数:29,代码来源:images_client.py
示例8: show_host_detail
def show_host_detail(self, hostname):
"""Show detail information for the host."""
resp, body = self.get("os-hosts/%s" % str(hostname))
node = etree.fromstring(body)
body = [xml_utils.xml_to_json(node)]
return resp, body
开发者ID:cloudbase,项目名称:lis-tempest,代码行数:7,代码来源:hosts_client.py
示例9: get_snapshot
def get_snapshot(self, snapshot_id):
"""Returns the details of a single snapshot."""
url = "snapshots/%s" % str(snapshot_id)
resp, body = self.get(url)
body = etree.fromstring(body)
self.expected_success(200, resp.status)
return resp, common.xml_to_json(body)
开发者ID:armando-migliaccio,项目名称:tempest-1,代码行数:7,代码来源:snapshots_client.py
示例10: upload_volume
def upload_volume(self, volume_id, image_name, disk_format):
"""Uploads a volume in Glance."""
post_body = common.Element("os-volume_upload_image", image_name=image_name, disk_format=disk_format)
url = "volumes/%s/action" % str(volume_id)
resp, body = self.post(url, str(common.Document(post_body)))
volume = common.xml_to_json(etree.fromstring(body))
return resp, volume
开发者ID:javacruft,项目名称:tempest,代码行数:7,代码来源:volumes_client.py
示例11: update_server
def update_server(self, server_id, name=None, meta=None, accessIPv4=None,
accessIPv6=None, disk_config=None):
doc = xml_utils.Document()
server = xml_utils.Element("server")
doc.append(server)
if name is not None:
server.add_attr("name", name)
if accessIPv4 is not None:
server.add_attr("accessIPv4", accessIPv4)
if accessIPv6 is not None:
server.add_attr("accessIPv6", accessIPv6)
if disk_config is not None:
server.add_attr('xmlns:OS-DCF', "http://docs.openstack.org/"
"compute/ext/disk_config/api/v1.1")
server.add_attr("OS-DCF:diskConfig", disk_config)
if meta is not None:
metadata = xml_utils.Element("metadata")
server.append(metadata)
for k, v in meta:
meta = xml_utils.Element("meta", key=k)
meta.append(xml_utils.Text(v))
metadata.append(meta)
resp, body = self.put('servers/%s' % str(server_id), str(doc))
return resp, xml_utils.xml_to_json(etree.fromstring(body))
开发者ID:javacruft,项目名称:tempest,代码行数:26,代码来源:servers_client.py
示例12: accept_volume_transfer
def accept_volume_transfer(self, transfer_id, transfer_auth_key):
"""Accept a volume transfer."""
post_body = common.Element("accept", auth_key=transfer_auth_key)
url = "os-volume-transfer/%s/accept" % transfer_id
resp, body = self.post(url, str(common.Document(post_body)))
volume = common.xml_to_json(etree.fromstring(body))
return resp, volume
开发者ID:javacruft,项目名称:tempest,代码行数:7,代码来源:volumes_client.py
示例13: reboot_host
def reboot_host(self, hostname):
"""Reboot a host."""
resp, body = self.get("os-hosts/%s/reboot" % str(hostname))
node = etree.fromstring(body)
body = [xml_utils.xml_to_json(x) for x in node.getchildren()]
return resp, body
开发者ID:cloudbase,项目名称:lis-tempest,代码行数:7,代码来源:hosts_client.py
示例14: shutdown_host
def shutdown_host(self, hostname):
"""Shutdown a host."""
resp, body = self.get("os-hosts/%s/shutdown" % str(hostname))
node = etree.fromstring(body)
body = [xml_utils.xml_to_json(x) for x in node.getchildren()]
return resp, body
开发者ID:cloudbase,项目名称:lis-tempest,代码行数:7,代码来源:hosts_client.py
示例15: update_volume
def update_volume(self, volume_id, **kwargs):
"""Updates the Specified Volume."""
put_body = common.Element("volume", xmlns=common.XMLNS_11, **kwargs)
resp, body = self.put("volumes/%s" % volume_id, str(common.Document(put_body)))
body = common.xml_to_json(etree.fromstring(body))
return resp, body
开发者ID:javacruft,项目名称:tempest,代码行数:7,代码来源:volumes_client.py
示例16: get_volume_transfer
def get_volume_transfer(self, transfer_id):
"""Returns the details of a volume transfer."""
url = "os-volume-transfer/%s" % str(transfer_id)
resp, body = self.get(url)
volume = common.xml_to_json(etree.fromstring(body))
self.expected_success(200, resp.status)
return resp, volume
开发者ID:armando-migliaccio,项目名称:tempest-1,代码行数:7,代码来源:volumes_client.py
示例17: update_quota_set
def update_quota_set(self, tenant_id, force=None,
injected_file_content_bytes=None,
metadata_items=None, ram=None, floating_ips=None,
fixed_ips=None, key_pairs=None, instances=None,
security_group_rules=None, injected_files=None,
cores=None, injected_file_path_bytes=None,
security_groups=None):
"""
Updates the tenant's quota limits for one or more resources
"""
post_body = xml_utils.Element("quota_set",
xmlns=xml_utils.XMLNS_11)
if force is not None:
post_body.add_attr('force', force)
if injected_file_content_bytes is not None:
post_body.add_attr('injected_file_content_bytes',
injected_file_content_bytes)
if metadata_items is not None:
post_body.add_attr('metadata_items', metadata_items)
if ram is not None:
post_body.add_attr('ram', ram)
if floating_ips is not None:
post_body.add_attr('floating_ips', floating_ips)
if fixed_ips is not None:
post_body.add_attr('fixed_ips', fixed_ips)
if key_pairs is not None:
post_body.add_attr('key_pairs', key_pairs)
if instances is not None:
post_body.add_attr('instances', instances)
if security_group_rules is not None:
post_body.add_attr('security_group_rules', security_group_rules)
if injected_files is not None:
post_body.add_attr('injected_files', injected_files)
if cores is not None:
post_body.add_attr('cores', cores)
if injected_file_path_bytes is not None:
post_body.add_attr('injected_file_path_bytes',
injected_file_path_bytes)
if security_groups is not None:
post_body.add_attr('security_groups', security_groups)
resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
str(xml_utils.Document(post_body)))
body = xml_utils.xml_to_json(etree.fromstring(body))
body = self._format_quota(body)
return resp, body
开发者ID:adkerr,项目名称:tempest,代码行数:59,代码来源:quotas_client.py
示例18: force_delete_volume
def force_delete_volume(self, volume_id):
"""Force Delete Volume."""
post_body = common.Element("os-force_delete")
url = "volumes/%s/action" % str(volume_id)
resp, body = self.post(url, str(common.Document(post_body)))
if body:
body = common.xml_to_json(etree.fromstring(body))
return resp, body
开发者ID:javacruft,项目名称:tempest,代码行数:8,代码来源:volumes_client.py
示例19: attach_volume
def attach_volume(self, volume_id, instance_uuid, mountpoint):
"""Attaches a volume to a given instance on a given mountpoint."""
post_body = common.Element("os-attach", instance_uuid=instance_uuid, mountpoint=mountpoint)
url = "volumes/%s/action" % str(volume_id)
resp, body = self.post(url, str(common.Document(post_body)))
if body:
body = common.xml_to_json(etree.fromstring(body))
return resp, body
开发者ID:javacruft,项目名称:tempest,代码行数:8,代码来源:volumes_client.py
示例20: force_delete_snapshot
def force_delete_snapshot(self, snapshot_id):
"""Force Delete Snapshot."""
post_body = common.Element("os-force_delete")
url = 'snapshots/%s/action' % str(snapshot_id)
resp, body = self.post(url, str(common.Document(post_body)))
if body:
body = common.xml_to_json(etree.fromstring(body))
return resp, body
开发者ID:AminaMseddi,项目名称:tempest,代码行数:8,代码来源:snapshots_client.py
注:本文中的tempest.common.xml_utils.xml_to_json函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论