本文整理汇总了Python中salt._compat.ElementTree类的典型用法代码示例。如果您正苦于以下问题:Python ElementTree类的具体用法?Python ElementTree怎么用?Python ElementTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ElementTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_config
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,代码行数:46,代码来源:octopus_tentacle.py
示例2: query
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,代码行数:57,代码来源:parallels.py
示例3: create_node
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,代码行数:60,代码来源:parallels.py
示例4: test_gen_vol_xml_for_esxi
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,代码行数:7,代码来源:virt_test.py
示例5: list_users
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,代码行数:35,代码来源:bamboohr.py
示例6: _get_error
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,代码行数:7,代码来源:boto_cfn.py
示例7: list_employees
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,代码行数:35,代码来源:bamboohr.py
示例8: _get_artifact_metadata
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,代码行数:10,代码来源:artifactory.py
示例9: mksls
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,代码行数:12,代码来源:yast.py
示例10: test_boot_default_dev
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,代码行数:13,代码来源:virt_test.py
示例11: _get_artifact_metadata
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,代码行数:14,代码来源:artifactory.py
示例12: test_boot_multiple_devs
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,代码行数:15,代码来源:virt_test.py
示例13: test_controller_for_kvm
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,代码行数:15,代码来源:virt_test.py
示例14: test_gen_xml_for_serial_console
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,代码行数:16,代码来源:virt_test.py
示例15: test_controller_for_esxi
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,代码行数:16,代码来源:virt_test.py
示例16: test_gen_xml_for_telnet_console_unspecified_port
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,代码行数:17,代码来源:virt_test.py
示例17: _get_snapshot_version_metadata
def _get_snapshot_version_metadata(artifactory_url, repository, group_id, artifact_id, version, headers):
metadata_xml = _get_snapshot_version_metadata_xml(artifactory_url=artifactory_url, repository=repository, group_id=group_id, artifact_id=artifact_id, version=version, headers=headers)
metadata = ET.fromstring(metadata_xml)
assert group_id == metadata.find('groupId').text
assert artifact_id == metadata.find('artifactId').text
assert version == metadata.find('version').text
snapshot_versions = metadata.find('versioning').find('snapshotVersions')
extension_version_dict = {}
for snapshot_version in snapshot_versions:
extension = snapshot_version.find('extension').text
value = snapshot_version.find('value').text
extension_version_dict[extension] = value
return {
'snapshot_versions': extension_version_dict
}
开发者ID:iquaba,项目名称:salt,代码行数:18,代码来源:artifactory.py
示例18: test_gen_xml_for_esxi_custom_profile
def test_gen_xml_for_esxi_custom_profile(self, disk_profile, nic_profile):
diskp_yaml = '''
- first:
size: 8192
format: vmdk
model: scsi
pool: datastore1
- second:
size: 4096
format: vmdk # FIX remove line, currently test fails
model: scsi # FIX remove line, currently test fails
pool: datastore2
'''
nicp_yaml = '''
- type: bridge
name: eth1
source: ONENET
model: e1000
mac: '00:00:00:00:00:00'
- name: eth2
type: bridge
source: TWONET
model: e1000
mac: '00:00:00:00:00:00'
'''
disk_profile.return_value = yaml.load(diskp_yaml)
nic_profile.return_value = yaml.load(nicp_yaml)
diskp = virt._disk_profile('noeffect', 'esxi')
nicp = virt._nic_profile('noeffect', 'esxi')
xml_data = virt._gen_xml(
'hello',
1,
512,
diskp,
nicp,
'esxi',
)
root = ET.fromstring(xml_data)
self.assertEqual(root.attrib['type'], 'vmware')
self.assertEqual(root.find('vcpu').text, '1')
self.assertEqual(root.find('memory').text, str(512 * 1024))
self.assertEqual(root.find('memory').attrib['unit'], 'KiB')
self.assertTrue(len(root.findall('.//disk')) == 2)
self.assertTrue(len(root.findall('.//interface')) == 2)
开发者ID:DaveQB,项目名称:salt,代码行数:44,代码来源:virt_test.py
示例19: __execute_cmd
def __execute_cmd(name, xml):
'''
Execute ilom commands
'''
ret = {name.replace('_', ' '): {}}
id_num = 0
tmp_dir = os.path.join(__opts__['cachedir'], 'tmp')
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
with tempfile.NamedTemporaryFile(dir=tmp_dir,
prefix=name+str(os.getpid()),
suffix='.xml',
delete=False) as fh:
tmpfilename = fh.name
fh.write(xml)
cmd = __salt__['cmd.run_all']('hponcfg -f {0}'.format(tmpfilename))
# Clean up the temp file
__salt__['file.remove'](tmpfilename)
if cmd['retcode'] != 0:
for i in cmd['stderr'].splitlines():
if i.startswith(' MESSAGE='):
return {'Failed': i.split('=')[-1]}
return False
try:
for i in ET.fromstring(''.join(cmd['stdout'].splitlines()[3:-1])):
# Make sure dict keys don't collide
if ret[name.replace('_', ' ')].get(i.tag, False):
ret[name.replace('_', ' ')].update(
{i.tag + '_' + str(id_num): i.attrib}
)
id_num += 1
else:
ret[name.replace('_', ' ')].update(
{i.tag: i.attrib}
)
except SyntaxError:
return True
return ret
开发者ID:mahak,项目名称:salt,代码行数:44,代码来源:ilo.py
示例20: test_gen_xml_for_kvm_custom_profile
def test_gen_xml_for_kvm_custom_profile(self, disk_profile, nic_profile):
diskp_yaml = '''
- first:
size: 8192
format: qcow2
model: virtio
pool: /var/lib/images
- second:
size: 4096
format: qcow2 # FIX remove line, currently test fails
model: virtio # FIX remove line, currently test fails
pool: /var/lib/images
'''
nicp_yaml = '''
- type: bridge
name: eth1
source: b2
model: virtio
mac: '00:00:00:00:00:00'
- name: eth2
type: bridge
source: b2
model: virtio
mac: '00:00:00:00:00:00'
'''
disk_profile.return_value = yaml.load(diskp_yaml)
nic_profile.return_value = yaml.load(nicp_yaml)
diskp = virt._disk_profile('noeffect', 'kvm')
nicp = virt._nic_profile('noeffect', 'kvm')
xml_data = virt._gen_xml(
'hello',
1,
512,
diskp,
nicp,
'kvm',
)
root = ET.fromstring(xml_data)
self.assertEqual(root.attrib['type'], 'kvm')
self.assertEqual(root.find('vcpu').text, '1')
self.assertEqual(root.find('memory').text, str(512 * 1024))
self.assertEqual(root.find('memory').attrib['unit'], 'KiB')
self.assertTrue(len(root.findall('.//disk')) == 2)
self.assertTrue(len(root.findall('.//interface')) == 2)
开发者ID:DaveQB,项目名称:salt,代码行数:44,代码来源:virt_test.py
注:本文中的salt._compat.ElementTree类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论