本文整理汇总了Python中stratuslab.Util.etree_from_text方法的典型用法代码示例。如果您正苦于以下问题:Python Util.etree_from_text方法的具体用法?Python Util.etree_from_text怎么用?Python Util.etree_from_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stratuslab.Util
的用法示例。
在下文中一共展示了Util.etree_from_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doWork
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def doWork(self):
# checking marketplace endpoint URL
url_is_ok = Util.checkUrlExists(ENDPOINT_MKP, 30)
if url_is_ok is True:
req = urllib2.Request(ENDPOINT_MKP)
response = urllib2.urlopen(req)
content = response.read()
xml = Util.etree_from_text(content)
desc_nodes = xml.iter("{" + RDF + "}Description")
all_desc = []
desc = {}
for desc_node in desc_nodes:
desc["description"] = desc_node.find('{' + DCTERMS + '}description').text
desc["identifier"] = desc_node.find('{' + DCTERMS + '}identifier').text
desc["creator"] = desc_node.find('{' + DCTERMS + '}creator').text
desc["created"] = desc_node.find('{' + DCTERMS + '}created').text
desc["os"] = desc_node.find('{' + SLTERMS + '}os').text
desc["os-version"] = desc_node.find('{' + SLTERMS + '}os-version').text
desc["os-arch"] = desc_node.find('{' + SLTERMS + '}os-arch').text
# cast in str for NoneType object (otherwise, we should use try/Except)
print "Description: " + str(desc["description"])
print "ID: " + str(desc["identifier"])
print "OS: " + str(desc["os"]), str(desc["os-version"]), "| Arch: " + str(desc["os-arch"])
print "Creator: " + str(desc["creator"])
print "Created at: " + str(desc["created"].replace("Z", "").split('T'))
print "####\n"
all_desc.append(desc)
示例2: parseManifest
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def parseManifest(self, manifest):
try:
xml_tree = Util.etree_from_text(manifest)
except SyntaxError, ex:
raise ExecutionException('Unable to parse manifest: %s\nMANIFEST:\n%s' %
(str(ex), manifest))
示例3: listVms
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def listVms(self, showVmsFromAllUsers=False):
fromAllUsers = -2
currentUserOnly = -3
if showVmsFromAllUsers:
visibilitySwitch = fromAllUsers
else:
visibilitySwitch = currentUserOnly
# Hack to retry on SSL errors.
maxRetries = 3
retries = 0
while True:
try:
ret, info, _ = self._rpc.one.vmpool.info(self._sessionString, visibilitySwitch, -1, -1, -1)
break
except ssl.SSLError as e:
retries += 1
t = strftime("%Y-%m-%d %H:%M:%S", gmtime())
Util.printDetail('SSL ERROR ENCOUNTERED (%s): %s' % (t, str(e)))
if retries >= maxRetries:
raise e
if not ret:
raise OneException(info)
vmlist = Util.etree_from_text(info)
for xml in vmlist.findall('VM'):
self._addStateSummary(xml)
return etree.tostring(vmlist)
示例4: _getVmInfoAsXml
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def _getVmInfoAsXml(self, vmId):
info = self._vmInfo(vmId)
xml = Util.etree_from_text(info)
self._addStateSummary(xml)
return xml
示例5: getCreateImageInfo
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def getCreateImageInfo(self, vmId):
info = self._vmInfo(vmId)
dom = Util.etree_from_text(info)
createImage_dom = dom.find('TEMPLATE/CREATE_IMAGE')
infos = {}
for elem in createImage_dom:
value = elem.text or ''
infos[elem.tag] = value.strip().strip('"')
return infos
示例6: _vmDetail
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def _vmDetail(self, vmId):
res = self.cloud.getVmInfo(int(vmId))
vm = Util.etree_from_text(res)
if self.portTranslationClient:
self.portTranslationClient.addPortTranslationToSingleVmInfo(vm)
info = CloudInfo()
info.populate(vm)
self._addHostnameElement(info)
return info
示例7: listNodes
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def listNodes(self):
nodes = self.cloud.listHosts()
correct_nodes = []
for node in self._iterate(Util.etree_from_text(nodes)):
# FIXME: remove this later.
try:
node.attribs['template_usedcpu'] = round(float(node.attribs['template_usedcpu']), 2)
except:
pass
correct_nodes.append(node)
return correct_nodes
示例8: listVms
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def listVms(self, showVmsFromAllUsers=False):
res = self.cloud.listVms(showVmsFromAllUsers)
vms = Util.etree_from_text(res)
self._addHostnameToVmsInfo(vms)
if self.portTranslationClient:
self.portTranslationClient.addPortTranslationToVmsInfo(vms)
correct_vms = []
for vm in self._iterate(vms):
self._addHostnameElement(vm)
if vm.attribs['uname'].startswith('CN'):
vm.attribs['uname'] = vm.attribs['uname'].replace("CN%3D", "") \
.replace("%2COU%3D", " OrgUnit:").replace("%2CO%3D", " Org:").replace("%2CC%3D", " Country:") \
.replace("+", " ")
correct_vms.append(vm)
return correct_vms
示例9: _getVnetIdFromVnetName
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def _getVnetIdFromVnetName(self, vnet_name):
vnet_info = self._getVnetInfoXml(vnet_name)
try:
vnet_tree = Util.etree_from_text(vnet_info)
except SyntaxError, ex:
raise ExecutionException("Unable to parse vnet %s info: %s" % (vnet_name, str(ex)))
示例10: _getVmStateSummary
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def _getVmStateSummary(self, vmId):
info = self._vmInfo(vmId)
xml = Util.etree_from_text(info)
return self._getOneVmStateFromXml(xml)
示例11: getVmSource
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def getVmSource(self, vmId):
info = self._vmInfo(vmId)
xml = Util.etree_from_text(info)
return xml.find('TEMPLATE/DISK/DISK_ID=0/../SOURCE').text
示例12: getVmDiskSource
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def getVmDiskSource(self, vmId, diskId):
info = self._vmInfo(vmId)
xml = Util.etree_from_text(info)
sources = [x.find('SOURCE').text for x in xml.findall('TEMPLATE/DISK')
if x.find('DISK_ID').text == str(diskId)]
return sources[0]
示例13: getVmInfo
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def getVmInfo(self, vmId):
info = self._vmInfo(vmId)
xml = Util.etree_from_text(info)
self._addStateSummary(xml)
return etree.tostring(xml)
示例14: _parseXml
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def _parseXml(xmlAsString):
return Util.etree_from_text(xmlAsString)
示例15: doWork
# 需要导入模块: from stratuslab import Util [as 别名]
# 或者: from stratuslab.Util import etree_from_text [as 别名]
def doWork(self):
id = self.options.image
# checking marketplace endpoint URL
url_is_ok = Util.checkUrlExists(ENDPOINT_MKP, 30)
if url_is_ok is True and id is not False:
req = urllib2.Request(ENDPOINT_MKP)
response = urllib2.urlopen(req)
content = response.read()
xml = Util.etree_from_text(content)
desc_nodes = xml.iter("{" + RDF + "}Description")
desc = {}
for desc_node in desc_nodes:
desc["identifier"] = desc_node.find('{' + DCTERMS + '}identifier').text
if id == desc["identifier"]:
desc["checksum"] = {}
desc["checksum"]["val"] = []
desc["checksum"]["algo"] = []
desc["description"] = desc_node.find('{' + DCTERMS + '}description').text
desc["creator"] = desc_node.find('{' + DCTERMS + '}creator').text
desc["created"] = desc_node.find('{' + DCTERMS + '}created').text
desc["valid"] = desc_node.find('{' + DCTERMS + '}valid').text
desc["os"] = desc_node.find('{' + SLTERMS + '}os').text
desc["os-version"] = desc_node.find('{' + SLTERMS + '}os-version').text
desc["os-arch"] = desc_node.find('{' + SLTERMS + '}os-arch').text
desc["version"] = desc_node.find('{' + SLTERMS + '}version').text
desc["compression"] = desc_node.find('{' + DCTERMS + '}compression').text
desc["location"] = desc_node.find('{' + SLTERMS + '}location').text
desc["location"] = desc_node.find('{' + SLTERMS + '}location').text
desc["format"] = desc_node.find('{' + DCTERMS + '}format').text
desc["publisher"] = desc_node.find('{' + DCTERMS + '}publisher').text
desc["hypervisor"] = desc_node.find('{' + SLTERMS + '}hypervisor').text
for check in desc_node.findall('{' + SLREQ + '}checksum'):
desc["checksum"]["algo"].append(check.find('{' + SLREQ + '}algorithm').text)
desc["checksum"]["val"].append(check.find('{' + SLREQ + '}value').text)
for endorsement in desc_node.findall('{' + SLREQ + '}endorsement'):
for endorser in endorsement.findall('{' + SLREQ + '}endorser'):
desc["email"] = endorser.find('{' + SLREQ + '}email').text
# cast in str for None object (otherwise, I should use try/Except)
print "Description: " + str(desc["description"])
print "ID: " + str(desc["identifier"])
print "Creator: " + str(desc["creator"])
print "Created at: " + str(desc["created"].replace("Z", "").split('T'))
print "Validity: " + str(desc["valid"].replace("Z", "").split('T'))
print "OS: " + str(desc["os"]), str(desc["os-version"]), "| Arch: " + str(desc["os-arch"])
print "Version: " + str(desc["version"])
print "Compression: " + str(desc["compression"])
print "Location: " + str(desc["location"])
print "Format: " + str(desc["format"])
print "Publisher: " + str(desc["publisher"])
print "Hypervisor: " + str(desc["hypervisor"])
print "Endorser: " + str(desc["email"])
for i in range(len(desc["checksum"]["algo"])):
print str(desc["checksum"]["algo"][i]), str(desc["checksum"]["val"][i])
print "####\n"