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


Python ElementTree.fromstring方法代码示例

本文整理汇总了Python中salt._compat.ElementTree.fromstring方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.fromstring方法的具体用法?Python ElementTree.fromstring怎么用?Python ElementTree.fromstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在salt._compat.ElementTree的用法示例。


在下文中一共展示了ElementTree.fromstring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def query(action=None, command=None, args=None, method="GET", data=None):
    """
    Make a web call to a Parallels provider
    """
    path = config.get_config_value("url", get_configured_provider(), __opts__, search_global=False)
    auth_handler = urllib2.HTTPBasicAuthHandler()
    auth_handler.add_password(
        realm="Parallels Instance Manager",
        uri=path,
        user=config.get_config_value("user", get_configured_provider(), __opts__, search_global=False),
        passwd=config.get_config_value("password", get_configured_provider(), __opts__, search_global=False),
    )
    opener = urllib2.build_opener(auth_handler)
    urllib2.install_opener(opener)

    if action:
        path += action

    if command:
        path += "/{0}".format(command)

    if type(args) is not dict:
        args = {}

    kwargs = {"data": data}
    if type(data) is str and "<?xml" in data:
        kwargs["headers"] = {"Content-type": "application/xml"}

    if args:
        path += "?%s"
        params = urllib.urlencode(args)
        req = urllib2.Request(url=path % params, **kwargs)
    else:
        req = urllib2.Request(url=path, **kwargs)

    req.get_method = lambda: method

    log.debug("{0} {1}".format(method, req.get_full_url()))
    if data:
        log.debug(data)

    try:
        result = urllib2.urlopen(req)
        log.debug("PARALLELS Response Status Code: {0}".format(result.getcode()))

        if "content-length" in result.headers:
            content = result.read()
            result.close()
            items = ET.fromstring(content)
            return items

        return {}
    except urllib2.URLError as exc:
        log.error("PARALLELS Response Status Code: {0} {1}".format(exc.code, exc.msg))
        root = ET.fromstring(exc.read())
        log.error(root)
        return {"error": root}
开发者ID:hulu,项目名称:salt,代码行数:59,代码来源:parallels.py

示例2: test_gen_vol_xml_for_esxi

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_gen_vol_xml_for_esxi(self):
     xml_data = virt._gen_vol_xml('vmname', 'system', 8192, 'esxi')
     root = ET.fromstring(xml_data)
     self.assertEqual(root.find('name').text, 'vmname/system.vmdk')
     self.assertEqual(root.find('key').text, 'vmname/system')
     self.assertEqual(root.find('capacity').attrib['unit'], 'KiB')
     self.assertEqual(root.find('capacity').text, str(8192 * 1024))
开发者ID:DaveQB,项目名称:salt,代码行数:9,代码来源:virt_test.py

示例3: list_users

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def list_users(order_by='id'):
    '''
    Show all users for this company.

    CLI Example:

        salt myminion bamboohr.list_users

    By default, the return data will be keyed by ID. However, it can be ordered
    by any other field. Keep in mind that if the field that is chosen contains
    duplicate values (i.e., location is used, for a company which only has one
    location), then each duplicate value will be overwritten by the previous.
    Therefore, it is advisable to only sort by fields that are guaranteed to be
    unique.

    CLI Examples:

        salt myminion bamboohr.list_users order_by=id
        salt myminion bamboohr.list_users order_by=email
    '''
    ret = {}
    status, result = _query(action='meta', command='users')
    root = ET.fromstring(result)
    users = root.getchildren()
    for user in users:
        user_id = None
        user_ret = {}
        for item in user.items():
            user_ret[item[0]] = item[1]
            if item[0] == 'id':
                user_id = item[1]
        for item in user.getchildren():
            user_ret[item.tag] = item.text
        ret[user_ret[order_by]] = user_ret
    return ret
开发者ID:DaveQB,项目名称:salt,代码行数:37,代码来源:bamboohr.py

示例4: _get_error

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def _get_error(error):
    # Converts boto exception to string that can be used to output error.
    error = '\n'.join(error.split('\n')[1:])
    error = ET.fromstring(error)
    code = error[0][1].text
    message = error[0][2].text
    return code, message
开发者ID:iquaba,项目名称:salt,代码行数:9,代码来源:boto_cfn.py

示例5: list_employees

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def list_employees(order_by='id'):
    '''
    Show all employees for this company.

    CLI Example:

        salt myminion bamboohr.list_employees

    By default, the return data will be keyed by ID. However, it can be ordered
    by any other field. Keep in mind that if the field that is chosen contains
    duplicate values (i.e., location is used, for a company which only has one
    location), then each duplicate value will be overwritten by the previous.
    Therefore, it is advisable to only sort by fields that are guaranteed to be
    unique.

    CLI Examples:

        salt myminion bamboohr.list_employees order_by=id
        salt myminion bamboohr.list_employees order_by=displayName
        salt myminion bamboohr.list_employees order_by=workEmail
    '''
    ret = {}
    status, result = _query(action='employees', command='directory')
    root = ET.fromstring(result)
    directory = root.getchildren()
    for cat in directory:
        if cat.tag != 'employees':
            continue
        for item in cat:
            emp_id = item.items()[0][1]
            emp_ret = {'id': emp_id}
            for details in item.getchildren():
                emp_ret[details.items()[0][1]] = details.text
            ret[emp_ret[order_by]] = emp_ret
    return ret
开发者ID:DaveQB,项目名称:salt,代码行数:37,代码来源:bamboohr.py

示例6: _get_artifact_metadata

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def _get_artifact_metadata(artifactory_url, repository, group_id, artifact_id, headers):
    metadata_xml = _get_artifact_metadata_xml(artifactory_url=artifactory_url, repository=repository, group_id=group_id, artifact_id=artifact_id, headers=headers)
    root = ET.fromstring(metadata_xml)

    assert group_id == root.find('groupId').text
    assert artifact_id == root.find('artifactId').text
    latest_version = root.find('versioning').find('latest').text
    return {
        'latest_version': latest_version
    }
开发者ID:iquaba,项目名称:salt,代码行数:12,代码来源:artifactory.py

示例7: mksls

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def mksls(src, dst=None):
    '''
    Convert an AutoYAST file to an SLS file
    '''
    with salt.utils.fopen(src, 'r') as fh_:
        ps_opts = xml.to_dict(ET.fromstring(fh_.read()))

    if dst is not None:
        with salt.utils.fopen(dst, 'w') as fh_:
            fh_.write(yaml.safe_dump(ps_opts, default_flow_style=False))
    else:
        return yaml.safe_dump(ps_opts, default_flow_style=False)
开发者ID:HowardMei,项目名称:saltstack,代码行数:14,代码来源:yast.py

示例8: test_boot_default_dev

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_boot_default_dev(self):
     diskp = virt._disk_profile('default', 'kvm')
     nicp = virt._nic_profile('default', 'kvm')
     xml_data = virt._gen_xml(
         'hello',
         1,
         512,
         diskp,
         nicp,
         'kvm'
         )
     root = ET.fromstring(xml_data)
     self.assertEqual(root.find('os/boot').attrib['dev'], 'hd')
开发者ID:DaveQB,项目名称:salt,代码行数:15,代码来源:virt_test.py

示例9: _get_artifact_metadata

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def _get_artifact_metadata(artifactory_url, repository, group_id, artifact_id, headers):
    metadata_xml = _get_artifact_metadata_xml(
        artifactory_url=artifactory_url,
        repository=repository,
        group_id=group_id,
        artifact_id=artifact_id,
        headers=headers,
    )
    root = ET.fromstring(metadata_xml)

    assert group_id == root.find("groupId").text
    assert artifact_id == root.find("artifactId").text
    latest_version = root.find("versioning").find("latest").text
    return {"latest_version": latest_version}
开发者ID:bryson,项目名称:salt,代码行数:16,代码来源:artifactory.py

示例10: test_boot_multiple_devs

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_boot_multiple_devs(self):
     diskp = virt._disk_profile('default', 'kvm')
     nicp = virt._nic_profile('default', 'kvm')
     xml_data = virt._gen_xml(
         'hello',
         1,
         512,
         diskp,
         nicp,
         'kvm',
         boot_dev='cdrom network'
         )
     root = ET.fromstring(xml_data)
     devs = root.findall('.//boot')
     self.assertTrue(len(devs) == 2)
开发者ID:DaveQB,项目名称:salt,代码行数:17,代码来源:virt_test.py

示例11: test_controller_for_kvm

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_controller_for_kvm(self):
     diskp = virt._disk_profile('default', 'kvm')
     nicp = virt._nic_profile('default', 'kvm')
     xml_data = virt._gen_xml(
         'hello',
         1,
         512,
         diskp,
         nicp,
         'kvm'
         )
     root = ET.fromstring(xml_data)
     controllers = root.findall('.//devices/controller')
     # There should be no controller
     self.assertTrue(len(controllers) == 0)
开发者ID:DaveQB,项目名称:salt,代码行数:17,代码来源:virt_test.py

示例12: test_gen_xml_for_serial_console

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_gen_xml_for_serial_console(self):
     diskp = virt._disk_profile('default', 'kvm')
     nicp = virt._nic_profile('default', 'kvm')
     xml_data = virt._gen_xml(
         'hello',
         1,
         512,
         diskp,
         nicp,
         'kvm',
         serial_type='pty',
         console=True
         )
     root = ET.fromstring(xml_data)
     self.assertEqual(root.find('devices/serial').attrib['type'], 'pty')
     self.assertEqual(root.find('devices/console').attrib['type'], 'pty')
开发者ID:DaveQB,项目名称:salt,代码行数:18,代码来源:virt_test.py

示例13: test_controller_for_esxi

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_controller_for_esxi(self):
     diskp = virt._disk_profile('default', 'esxi')
     nicp = virt._nic_profile('default', 'esxi')
     xml_data = virt._gen_xml(
         'hello',
         1,
         512,
         diskp,
         nicp,
         'esxi'
         )
     root = ET.fromstring(xml_data)
     controllers = root.findall('.//devices/controller')
     self.assertTrue(len(controllers) == 1)
     controller = controllers[0]
     self.assertEqual(controller.attrib['model'], 'lsilogic')
开发者ID:DaveQB,项目名称:salt,代码行数:18,代码来源:virt_test.py

示例14: get_config

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
def get_config(instance=_DEFAULT_INSTANCE):
    '''
    Determine the configuration of the provided instance.

    :param str instance: The name of the Tentacle instance.

    :return: A dictionary containing the configuration data.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' octopus_tentacle.get_config instance='Tentacle'
    '''
    ret = dict()
    name_mapping = {'Octopus.Home': 'home_path',
                    'Octopus.Communications.Squid': 'squid',
                    'Tentacle.CertificateThumbprint': 'thumbprint',
                    'Tentacle.Communication.TrustedOctopusServers': 'servers',
                    'Tentacle.Deployment.ApplicationDirectory': 'app_path',
                    'Tentacle.Services.NoListen': 'comms',
                    'Tentacle.Services.PortNumber': 'port'}

    config_path = get_config_path(instance)

    if not os.path.isfile(config_path):
        _LOG.error('Unable to get configuration file for instance: %s', instance)
        return ret

    with salt.utils.fopen(config_path, 'r') as fh_:
        config = _parse_config(ElementTree.fromstring(fh_.read()))

    for item in config:
        # Skip keys that we aren't specifically looking for.
        if item in name_mapping:
            # Convert the NoListen value to a friendly value.
            if name_mapping[item] == 'comms':
                for comms_style in _COMMS_STYLES:
                    if config[item] == _COMMS_STYLES[comms_style]:
                        ret[name_mapping[item]] = comms_style
                        break
            else:
                ret[name_mapping[item]] = config[item]

    return ret
开发者ID:beornf,项目名称:salt-contrib,代码行数:48,代码来源:octopus_tentacle.py

示例15: test_gen_xml_for_telnet_console_unspecified_port

# 需要导入模块: from salt._compat import ElementTree [as 别名]
# 或者: from salt._compat.ElementTree import fromstring [as 别名]
 def test_gen_xml_for_telnet_console_unspecified_port(self):
     diskp = virt._disk_profile('default', 'kvm')
     nicp = virt._nic_profile('default', 'kvm')
     xml_data = virt._gen_xml(
         'hello',
         1,
         512,
         diskp,
         nicp,
         'kvm',
         serial_type='tcp',
         console=True
         )
     root = ET.fromstring(xml_data)
     self.assertEqual(root.find('devices/serial').attrib['type'], 'tcp')
     self.assertEqual(root.find('devices/console').attrib['type'], 'tcp')
     self.assertIsInstance(int(root.find('devices/console/source').attrib['service']), int)
开发者ID:DaveQB,项目名称:salt,代码行数:19,代码来源:virt_test.py


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