当前位置: 首页>>代码示例>>Python>>正文


Python ElementTree.tostring方法代码示例

本文整理汇总了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
开发者ID:hulu,项目名称:salt,代码行数:62,代码来源:parallels.py

示例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
开发者ID:DaveQB,项目名称:salt,代码行数:86,代码来源:parallels.py


注:本文中的salt._compat.ElementTree.tostring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。