本文整理汇总了Python中salt._compat.ElementTree.tostring方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.tostring方法的具体用法?Python ElementTree.tostring怎么用?Python ElementTree.tostring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt._compat.ElementTree
的用法示例。
在下文中一共展示了ElementTree.tostring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_node
# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import tostring [as 别名]
def create_node(vm_):
"""
Build and submit the XML to create a node
"""
# Start the tree
content = ET.Element("ve")
# Name of the instance
name = ET.SubElement(content, "name")
name.text = vm_["name"]
# Description, defaults to name
desc = ET.SubElement(content, "description")
desc.text = config.get_config_value("desc", vm_, __opts__, default=vm_["name"], search_global=False)
# How many CPU cores, and how fast they are
cpu = ET.SubElement(content, "cpu")
cpu.attrib["number"] = config.get_config_value("cpu_number", vm_, __opts__, default="1", search_global=False)
cpu.attrib["power"] = config.get_config_value("cpu_power", vm_, __opts__, default="1000", search_global=False)
# How many megabytes of RAM
ram = ET.SubElement(content, "ram-size")
ram.text = config.get_config_value("ram", vm_, __opts__, default="256", search_global=False)
# Bandwidth available, in kbps
bandwidth = ET.SubElement(content, "bandwidth")
bandwidth.text = config.get_config_value("bandwidth", vm_, __opts__, default="100", search_global=False)
# How many public IPs will be assigned to this instance
ip_num = ET.SubElement(content, "no-of-public-ip")
ip_num.text = config.get_config_value("ip_num", vm_, __opts__, default="1", search_global=False)
# Size of the instance disk
disk = ET.SubElement(content, "ve-disk")
disk.attrib["local"] = "true"
disk.attrib["size"] = config.get_config_value("disk_size", vm_, __opts__, default="10", search_global=False)
# Attributes for the image
vm_image = config.get_config_value("image", vm_, __opts__, search_global=False)
image = show_image({"image": vm_image}, call="function")
platform = ET.SubElement(content, "platform")
template = ET.SubElement(platform, "template-info")
template.attrib["name"] = vm_image
os_info = ET.SubElement(platform, "os-info")
os_info.attrib["technology"] = image[vm_image]["technology"]
os_info.attrib["type"] = image[vm_image]["osType"]
# Username and password
admin = ET.SubElement(content, "admin")
admin.attrib["login"] = config.get_config_value("ssh_username", vm_, __opts__, default="root")
admin.attrib["password"] = config.get_config_value("password", vm_, __opts__, search_global=False)
data = ET.tostring(content, encoding="UTF-8")
salt.cloud.utils.fire_event(
"event", "requesting instance", "salt/cloud/{0}/requesting".format(vm_["name"]), {"kwargs": data}
)
node = query(action="ve", method="POST", data=data)
return node
示例2: create_node
# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import tostring [as 别名]
def create_node(vm_):
'''
Build and submit the XML to create a node
'''
# Start the tree
content = ET.Element('ve')
# Name of the instance
name = ET.SubElement(content, 'name')
name.text = vm_['name']
# Description, defaults to name
desc = ET.SubElement(content, 'description')
desc.text = config.get_cloud_config_value(
'desc', vm_, __opts__, default=vm_['name'], search_global=False
)
# How many CPU cores, and how fast they are
cpu = ET.SubElement(content, 'cpu')
cpu.attrib['number'] = config.get_cloud_config_value(
'cpu_number', vm_, __opts__, default='1', search_global=False
)
cpu.attrib['power'] = config.get_cloud_config_value(
'cpu_power', vm_, __opts__, default='1000', search_global=False
)
# How many megabytes of RAM
ram = ET.SubElement(content, 'ram-size')
ram.text = config.get_cloud_config_value(
'ram', vm_, __opts__, default='256', search_global=False
)
# Bandwidth available, in kbps
bandwidth = ET.SubElement(content, 'bandwidth')
bandwidth.text = config.get_cloud_config_value(
'bandwidth', vm_, __opts__, default='100', search_global=False
)
# How many public IPs will be assigned to this instance
ip_num = ET.SubElement(content, 'no-of-public-ip')
ip_num.text = config.get_cloud_config_value(
'ip_num', vm_, __opts__, default='1', search_global=False
)
# Size of the instance disk
disk = ET.SubElement(content, 've-disk')
disk.attrib['local'] = 'true'
disk.attrib['size'] = config.get_cloud_config_value(
'disk_size', vm_, __opts__, default='10', search_global=False
)
# Attributes for the image
vm_image = config.get_cloud_config_value(
'image', vm_, __opts__, search_global=False
)
image = show_image({'image': vm_image}, call='function')
platform = ET.SubElement(content, 'platform')
template = ET.SubElement(platform, 'template-info')
template.attrib['name'] = vm_image
os_info = ET.SubElement(platform, 'os-info')
os_info.attrib['technology'] = image[vm_image]['technology']
os_info.attrib['type'] = image[vm_image]['osType']
# Username and password
admin = ET.SubElement(content, 'admin')
admin.attrib['login'] = config.get_cloud_config_value(
'ssh_username', vm_, __opts__, default='root'
)
admin.attrib['password'] = config.get_cloud_config_value(
'password', vm_, __opts__, search_global=False
)
data = ET.tostring(content, encoding='UTF-8')
salt.utils.cloud.fire_event(
'event',
'requesting instance',
'salt/cloud/{0}/requesting'.format(vm_['name']),
{'kwargs': data},
transport=__opts__['transport']
)
node = query(action='ve', method='POST', data=data)
return node