本文整理汇总了Python中tempest.services.compute.xml.common.Element.add_attr方法的典型用法代码示例。如果您正苦于以下问题:Python Element.add_attr方法的具体用法?Python Element.add_attr怎么用?Python Element.add_attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempest.services.compute.xml.common.Element
的用法示例。
在下文中一共展示了Element.add_attr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_volume
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
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 = Element("volume", xmlns=XMLNS_11, size=size)
if "metadata" in kwargs:
_metadata = Element("metadata")
volume.append(_metadata)
for key, value in kwargs["metadata"].items():
meta = Element("meta")
meta.add_attr("key", key)
meta.append(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(Document(volume)), self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
示例2: create_volume_type
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
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 = Element("volume_type", xmlns=XMLNS_11)
if name:
vol_type.add_attr('name', name)
extra_specs = kwargs.get('extra_specs')
if extra_specs:
_extra_specs = Element('extra_specs')
vol_type.append(_extra_specs)
for key, value in extra_specs.items():
spec = Element('extra_spec')
spec.add_attr('key', key)
spec.append(Text(value))
_extra_specs.append(spec)
resp, body = self.post('types', str(Document(vol_type)),
self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
示例3: update_server
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def update_server(self, server_id, name=None, meta=None, accessIPv4=None,
accessIPv6=None, disk_config=None):
doc = Document()
server = 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 = Element("metadata")
server.append(metadata)
for k, v in meta:
meta = Element("meta", key=k)
meta.append(Text(v))
metadata.append(meta)
resp, body = self.put('servers/%s' % str(server_id), str(doc))
return resp, xml_to_json(etree.fromstring(body))
示例4: _get_element
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def _get_element(self, name, value):
if value is None:
xml_elem = Element(name)
xml_elem.add_attr("xsi:nil", "true")
return xml_elem
else:
return Element(name, value)
示例5: create_volume
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
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 = Element("volume",
xmlns=XMLNS_11,
size=size)
if display_name:
volume.add_attr('display_name', display_name)
if metadata:
_metadata = Element('metadata')
volume.append(_metadata)
for key, value in metadata.items():
meta = Element('meta')
meta.add_attr('key', key)
meta.append(Text(value))
_metadata.append(meta)
resp, body = self.post('os-volumes', str(Document(volume)),
self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
示例6: create_volume
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
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
"""
volume = Element("volume", xmlns=XMLNS_11, size=size)
if 'metadata' in kwargs:
_metadata = Element('metadata')
volume.append(_metadata)
for key, value in kwargs['metadata'].items():
meta = Element('meta')
meta.add_attr('key', key)
meta.append(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(Document(volume)),
self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
示例7: set_flavor_extra_spec
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def set_flavor_extra_spec(self, flavor_id, specs):
"""Sets extra Specs to the mentioned flavor."""
extra_specs = Element("extra_specs")
for key in specs.keys():
extra_specs.add_attr(key, specs[key])
resp, body = self.post("flavors/%s/flavor-extra-specs" % flavor_id, str(Document(extra_specs)), self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
示例8: remove_flavor_access
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def remove_flavor_access(self, flavor_id, tenant_id):
"""Remove flavor access from the specified tenant."""
doc = Document()
server = Element("removeTenantAccess")
doc.append(server)
server.add_attr("tenant", tenant_id)
resp, body = self.post('flavors/%s/action' % str(flavor_id), str(doc))
body = self._parse_array_access(etree.fromstring(body))
return resp, body
示例9: create_user
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def create_user(self, name, password, tenant_id, email, **kwargs):
"""Create a user."""
create_user = Element("user", xmlns=XMLNS, name=name, password=password, tenantId=tenant_id, email=email)
if "enabled" in kwargs:
create_user.add_attr("enabled", str(kwargs["enabled"]).lower())
resp, body = self.post("users", str(Document(create_user)), self.headers)
body = self._parse_body(etree.fromstring(body))
return resp, body
示例10: add_flavor_access
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def add_flavor_access(self, flavor_id, tenant_id):
"""Add flavor access for the specified tenant."""
doc = Document()
server = Element("add_tenant_access")
doc.append(server)
server.add_attr("tenant_id", tenant_id)
resp, body = self.post("flavors/%s/action" % str(flavor_id), str(doc), self.headers)
body = self._parse_array_access(etree.fromstring(body))
return resp, body
示例11: disassociate_floating_ip_from_server
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def disassociate_floating_ip_from_server(self, floating_ip, server_id):
"""Disassociate the provided floating IP from a specific server."""
url = "servers/%s/action" % str(server_id)
doc = Document()
server = Element("removeFloatingIp")
doc.append(server)
server.add_attr("address", floating_ip)
resp, body = self.post(url, str(doc), self.headers)
return resp, body
示例12: associate_floating_ip_to_server
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def associate_floating_ip_to_server(self, floating_ip, server_id):
"""Associate the provided floating IP to a specific server."""
url = "servers/%s/action" % str(server_id)
doc = Document()
server = Element("addFloatingIp")
doc.append(server)
server.add_attr("address", floating_ip)
resp, body = self.post(url, str(doc))
return resp, body
示例13: create_volume_transfer
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def create_volume_transfer(self, vol_id, name=None):
"""Create a volume transfer."""
post_body = Element("transfer",
volume_id=vol_id)
if name:
post_body.add_attr('name', name)
resp, body = self.post('os-volume-transfer',
str(Document(post_body)))
volume = xml_to_json(etree.fromstring(body))
return resp, volume
示例14: serialize
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def serialize(self, body):
#TODO(enikanorov): implement better json to xml conversion
# expecting the dict with single key
root = body.keys()[0]
post_body = Element(root)
post_body.add_attr('xmlns:xsi',
'http://www.w3.org/2001/XMLSchema-instance')
for name, attr in body[root].items():
elt = self._get_element(name, attr)
post_body.append(elt)
return str(Document(post_body))
示例15: enable_service
# 需要导入模块: from tempest.services.compute.xml.common import Element [as 别名]
# 或者: from tempest.services.compute.xml.common.Element import add_attr [as 别名]
def enable_service(self, host_name, binary):
"""
Enable service on a host
host_name: Name of host
binary: Service binary
"""
post_body = Element("service")
post_body.add_attr("binary", binary)
post_body.add_attr("host", host_name)
resp, body = self.put("os-services/enable", str(Document(post_body)))
body = xml_to_json(etree.fromstring(body))
return resp, body