本文整理汇总了Python中tempest.services.compute.xml.common.Document类的典型用法代码示例。如果您正苦于以下问题:Python Document类的具体用法?Python Document怎么用?Python Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_interface
def create_interface(self, server, port_id=None, network_id=None,
fixed_ip=None):
doc = Document()
iface = Element('interfaceAttachment')
if port_id:
_port_id = Element('port_id')
_port_id.append(Text(port_id))
iface.append(_port_id)
if network_id:
_network_id = Element('net_id')
_network_id.append(Text(network_id))
iface.append(_network_id)
if fixed_ip:
_fixed_ips = Element('fixed_ips')
_fixed_ip = Element('fixed_ip')
_ip_address = Element('ip_address')
_ip_address.append(Text(fixed_ip))
_fixed_ip.append(_ip_address)
_fixed_ips.append(_fixed_ip)
iface.append(_fixed_ips)
doc.append(iface)
resp, body = self.post('servers/%s/os-interface' % server,
body=str(doc))
body = self._process_xml_interface(etree.fromstring(body))
return resp, body
示例2: update_server
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))
示例3: _metadata_body
def _metadata_body(image_id, meta):
post_body = Document("metadata")
for k, v in meta:
text = Text(v)
metadata = Element("meta", text, key=k)
post_body.append(metadata)
return post_body
示例4: update_server
def update_server(self, server_id, name=None, meta=None, access_ip_v4=None,
access_ip_v6=None, disk_config=None):
doc = Document()
server = Element("server")
doc.append(server)
if name is not None:
server.add_attr("name", name)
if access_ip_v4 or access_ip_v6:
server.add_attr('xmlns:os-access-ips',
"http://docs.openstack.org/compute/ext/"
"os-access-ips/api/v3")
if access_ip_v4 is not None:
server.add_attr("os-access-ips:access_ip_v4", access_ip_v4)
if access_ip_v6 is not None:
server.add_attr("os-access-ips:access_ip_v6", access_ip_v6)
if disk_config is not None:
server.add_attr('xmlns:os-disk-config', "http://docs.openstack.org"
"/compute/ext/disk_config/api/v3")
server.add_attr("os-disk-config:disk_config", 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), self.headers)
return resp, xml_to_json(etree.fromstring(body))
示例5: set_server_metadata_item
def set_server_metadata_item(self, server_id, key, meta):
doc = Document()
for k, v in meta.items():
meta_element = Element("meta", key=k)
meta_element.append(Text(v))
doc.append(meta_element)
resp, body = self.put("servers/%s/metadata/%s" % (str(server_id), key), str(doc), self.headers)
return resp, xml_to_json(etree.fromstring(body))
示例6: disassociate_floating_ip_from_server
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
示例7: remove_flavor_access
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
示例8: associate_floating_ip_to_server
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
示例9: add_flavor_access
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
示例10: set_server_metadata
def set_server_metadata(self, server_id, meta, no_metadata_field=False):
doc = Document()
if not no_metadata_field:
metadata = Element("metadata")
doc.append(metadata)
for k, v in meta.items():
meta_element = Element("meta", key=k)
meta_element.append(Text(v))
metadata.append(meta_element)
resp, body = self.put('servers/%s/metadata' % str(server_id), str(doc))
return resp, xml_to_json(etree.fromstring(body))
示例11: update_server_metadata
def update_server_metadata(self, server_id, meta):
doc = Document()
metadata = Element("metadata")
doc.append(metadata)
for k, v in meta.items():
meta_element = Element("meta", key=k)
meta_element.append(Text(v))
metadata.append(meta_element)
resp, body = self.post("/servers/%s/metadata" % str(server_id), str(doc), headers=self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
示例12: update_flavor_extra_spec
def update_flavor_extra_spec(self, flavor_id, key, **kwargs):
"""Update extra Specs details of the mentioned flavor and key."""
doc = Document()
for (k, v) in kwargs.items():
element = Element(k)
doc.append(element)
value = Text(v)
element.append(value)
resp, body = self.put("flavors/%s/flavor-extra-specs/%s" % (flavor_id, key), str(doc), self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, {key: body}
示例13: create_floating_ip
def create_floating_ip(self, pool_name=None):
"""Allocate a floating IP to the project."""
url = 'os-floating-ips'
if pool_name:
doc = Document()
pool = Element("pool")
pool.append(Text(pool_name))
doc.append(pool)
resp, body = self.post(url, str(doc), self.headers)
else:
resp, body = self.post(url, None, self.headers)
body = self._parse_floating_ip(etree.fromstring(body))
return resp, body
示例14: update_endpoint
def update_endpoint(self, endpoint_id, service_id=None, interface=None, url=None, region=None, enabled=None):
"""Updates an endpoint with given parameters."""
doc = Document()
endpoint = Element("endpoint")
doc.append(endpoint)
if service_id:
endpoint.add_attr("service_id", service_id)
if interface:
endpoint.add_attr("interface", interface)
if url:
endpoint.add_attr("url", url)
if region:
endpoint.add_attr("region", region)
if enabled is not None:
endpoint.add_attr("enabled", enabled)
resp, body = self.patch("endpoints/%s" % str(endpoint_id), str(doc), self.headers)
body = self._parse_body(etree.fromstring(body))
return resp, body
示例15: create_keypair
def create_keypair(self, name, pub_key=None):
doc = Document()
keypair_element = Element("keypair")
if pub_key:
public_key_element = Element("public_key")
public_key_text = Text(pub_key)
public_key_element.append(public_key_text)
keypair_element.append(public_key_element)
name_element = Element("name")
name_text = Text(name)
name_element.append(name_text)
keypair_element.append(name_element)
doc.append(keypair_element)
resp, body = self.post("os-keypairs", body=str(doc))
body = xml_to_json(etree.fromstring(body))
return resp, body