本文整理汇总了Python中Utils.XmlUtil类的典型用法代码示例。如果您正苦于以下问题:Python XmlUtil类的具体用法?Python XmlUtil怎么用?Python XmlUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_perf_counters_settings
def _update_perf_counters_settings(self, omi_queries, for_app_insights=False):
"""
Update the mdsd XML tree with the OMI queries provided.
:param omi_queries: List of dictionaries specifying OMI queries and destination tables. E.g.:
[
{"query":"SELECT PercentAvailableMemory, AvailableMemory, UsedMemory, PercentUsedSwap FROM SCX_MemoryStatisticalInformation","table":"LinuxMemory"},
{"query":"SELECT PercentProcessorTime, PercentIOWaitTime, PercentIdleTime FROM SCX_ProcessorStatisticalInformation WHERE Name='_TOTAL'","table":"LinuxCpu"},
{"query":"SELECT AverageWriteTime,AverageReadTime,ReadBytesPerSecond,WriteBytesPerSecond FROM SCX_DiskDriveStatisticalInformation WHERE Name='_TOTAL'","table":"LinuxDisk"}
]
:param for_app_insights: Indicates whether we are updating perf counters settings for AppInsights.
AppInsights requires specific names, so we need this.
:return: None. The mdsd XML tree member is updated accordingly.
"""
assert self._mdsd_config_xml_tree is not None
if not omi_queries:
return
mdsd_omi_query_schema = """
<OMIQuery cqlQuery="" dontUsePerNDayTable="true" eventName="" omiNamespace="" priority="High" sampleRateInSeconds="" />
"""
for omi_query in omi_queries:
mdsd_omi_query_element = XmlUtil.createElement(mdsd_omi_query_schema)
mdsd_omi_query_element.set('cqlQuery', omi_query['query'])
mdsd_omi_query_element.set('eventName', omi_query['table'])
namespace = omi_query['namespace'] if 'namespace' in omi_query else 'root/scx'
mdsd_omi_query_element.set('omiNamespace', namespace)
if for_app_insights:
AIUtil.updateOMIQueryElement(mdsd_omi_query_element)
XmlUtil.addElement(xml=self._mdsd_config_xml_tree, path='Events/OMI', el=mdsd_omi_query_element, addOnlyOnce=True)
示例2: configSettings
def configSettings():
mdsdCfgstr = readPublicConfig('mdsdCfg')
if not mdsdCfgstr :
with open (os.path.join(WorkDir, './mdsdConfig.xml.template'),"r") as defaulCfg:
mdsdCfgstr = defaulCfg.read()
else:
mdsdCfgstr = base64.b64decode(mdsdCfgstr)
mdsdCfg = ET.ElementTree()
mdsdCfg._setroot(XmlUtil.createElement(mdsdCfgstr))
# update deployment id
deployment_id = get_deployment_id()
XmlUtil.setXmlValue(mdsdCfg, "Management/Identity/IdentityComponent", "", deployment_id, ["name", "DeploymentId"])
try:
resourceId = getResourceId()
if resourceId:
createPortalSettings(mdsdCfg,escape(resourceId))
instanceID=""
if resourceId.find("providers/Microsoft.Compute/virtualMachineScaleSets") >=0:
instanceID = readUUID();
config(mdsdCfg,"instanceID",instanceID,"Events/DerivedEvents/DerivedEvent/LADQuery")
except Exception, e:
hutil.error("Failed to create portal config error:{0} {1}".format(e,traceback.format_exc()))
示例3: _add_element_from_element
def _add_element_from_element(self, path, xml_elem, add_only_once=True):
"""
Add an XML fragment to the mdsd config document in accordance with path
:param str path: Where to add the fragment
:param ElementTree xml_elem: An ElementTree object XML fragment that should be added to the path.
:param bool add_only_once: Indicates whether to perform the addition only to the first match of the path.
"""
XmlUtil.addElement(xml=self._mdsd_config_xml_tree, path=path, el=xml_elem, addOnlyOnce=add_only_once)
示例4: _add_element_from_string
def _add_element_from_string(self, path, xml_string, add_only_once=True):
"""
Add an XML fragment to the mdsd config document in accordance with path
:param str path: Where to add the fragment
:param str xml_string: A string containing the XML element to add
:param bool add_only_once: Indicates whether to perform the addition only to the first match of the path.
"""
XmlUtil.addElement(xml=self._mdsd_config_xml_tree, path=path, el=ET.fromstring(xml_string),
addOnlyOnce=add_only_once)
示例5: getResourceId
def getResourceId():
ladCfg = readPublicConfig('ladCfg')
resourceId = LadUtil.getResourceIdFromLadCfg(ladCfg)
if not resourceId:
encodedXmlCfg = readPublicConfig('xmlCfg').strip()
if encodedXmlCfg:
xmlCfg = base64.b64decode(encodedXmlCfg)
resourceId = XmlUtil.getXmlValue(XmlUtil.createElement(xmlCfg),'diagnosticMonitorConfiguration/metrics','resourceId')
# Azure portal uses xmlCfg which contains WadCfg which is pascal case, Currently we will support both casing and deprecate one later
if not resourceId:
resourceId = XmlUtil.getXmlValue(XmlUtil.createElement(xmlCfg),'DiagnosticMonitorConfiguration/Metrics','resourceId')
return resourceId
示例6: setEventVolume
def setEventVolume(mdsdCfg,ladCfg):
eventVolume = LadUtil.getEventVolumeFromLadCfg(ladCfg)
if eventVolume:
hutil.log("Event volume found in ladCfg: " + eventVolume)
else:
eventVolume = readPublicConfig("eventVolume")
if eventVolume:
hutil.log("Event volume found in public config: " + eventVolume)
else:
eventVolume = "Medium"
hutil.log("Event volume not found in config. Using default value: " + eventVolume)
XmlUtil.setXmlValue(mdsdCfg,"Management","eventVolume",eventVolume)
示例7: _add_derived_event
def _add_derived_event(self, interval, source, event_name, store_type, add_lad_query=False):
"""
Add a <DerivedEvent> element to the configuration
:param str interval: Interval at which this DerivedEvent should be run
:param str source: Local table from which this DerivedEvent should pull
:param str event_name: Destination table to which this DerivedEvent should push
:param str store_type: The storage type of the destination table, e.g. Local, Central, JsonBlob
:param bool add_lad_query: True if a <LadQuery> subelement should be added to this <DerivedEvent> element
"""
derived_event = mxt.derived_event.format(interval=interval, source=source, target=event_name, type=store_type)
element = ET.fromstring(derived_event)
if add_lad_query:
XmlUtil.addElement(element, ".", ET.fromstring(mxt.lad_query))
self._add_element_from_element('Events/DerivedEvents', element)
示例8: createPerfSettngs
def createPerfSettngs(tree, perfs, forAI=False):
if not perfs:
return
for perf in perfs:
perfElement = XmlUtil.createElement(perfSchema)
perfElement.set("cqlQuery", perf["query"])
perfElement.set("eventName", perf["table"])
namespace = "root/scx"
if perf.has_key("namespace"):
namespace = perf["namespace"]
perfElement.set("omiNamespace", namespace)
if forAI:
AIUtil.updateOMIQueryElement(perfElement)
XmlUtil.addElement(tree, "Events/OMI", perfElement, ["omitag", "perf"])
示例9: createPerfSettngs
def createPerfSettngs(tree,perfs,forAI=False):
if not perfs:
return
for perf in perfs:
perfElement = XmlUtil.createElement(perfSchema)
perfElement.set('cqlQuery',perf['query'])
perfElement.set('eventName',perf['table'])
namespace="root/scx"
if perf.has_key('namespace'):
namespace=perf['namespace']
perfElement.set('omiNamespace',namespace)
if forAI:
AIUtil.updateOMIQueryElement(perfElement)
XmlUtil.addElement(tree,'Events/OMI',perfElement,["omitag","perf"])
示例10: _set_xml_attr
def _set_xml_attr(self, key, value, xml_path, selector=[]):
"""
Set XML attribute on the element specified with xml_path.
:param key: The attribute name to set on the XML element.
:param value: The default value to be set, if there's no public config for that attribute.
:param xml_path: The path of the XML element(s) to which the attribute is applied.
:param selector: Selector for finding the actual XML element (see XmlUtil.setXmlValue)
:return: None. Change is directly applied to mdsd_config_xml_tree XML member object.
"""
assert self._mdsd_config_xml_tree is not None
v = self._ext_settings.read_public_config(key)
if not v:
v = value
XmlUtil.setXmlValue(self._mdsd_config_xml_tree, xml_path, key, v, selector)
示例11: _update_and_get_file_monitoring_settings
def _update_and_get_file_monitoring_settings(self, files):
"""
Update mdsd config's file monitoring config. Also creates/returns rsyslog imfile config.
All the operations are based on the input param files, which is a Json-deserialized dictionary
corresponding the following Json array example:
[
{"file":"/var/log/a.log", "table":"aLog"},
{"file":"/var/log/b.log", "table":"bLog"}
]
:param files: Array of dictionaries deserialized from the 'fileCfg' Json config (example as above)
:return: rsyslog omfile module config file content
"""
assert self._mdsd_config_xml_tree is not None
if not files:
return ''
file_id = 0
imfile_config = """
$ModLoad imfile
"""
mdsd_event_source_schema = """
<MdsdEventSource source="ladfile">
<RouteEvent dontUsePerNDayTable="true" eventName="" priority="High"/>
</MdsdEventSource>
"""
mdsd_source_schema = """
<Source name="ladfile1" schema="ladfile" />
"""
imfile_per_file_config_template = """
$InputFileName #FILE#
$InputFileTag #FILETAG#
$InputFileFacility local6
$InputFileStateFile syslog-stat#STATFILE#
$InputFileSeverity debug
$InputRunFileMonitor
"""
for item in files:
file_id += 1
mdsd_event_source_element = XmlUtil.createElement(mdsd_event_source_schema)
XmlUtil.setXmlValue(mdsd_event_source_element, 'RouteEvent', 'eventName', item["table"])
mdsd_event_source_element.set('source', 'ladfile'+str(file_id))
XmlUtil.addElement(self._mdsd_config_xml_tree, 'Events/MdsdEvents', mdsd_event_source_element)
mdsd_source_element = XmlUtil.createElement(mdsd_source_schema)
mdsd_source_element.set('name', 'ladfile'+str(file_id))
XmlUtil.addElement(self._mdsd_config_xml_tree, 'Sources', mdsd_source_element)
imfile_per_file_config = imfile_per_file_config_template.replace('#FILE#', item['file'])
imfile_per_file_config = imfile_per_file_config.replace('#STATFILE#', item['file'].replace("/","-"))
imfile_per_file_config = imfile_per_file_config.replace('#FILETAG#', 'ladfile'+str(file_id))
imfile_config += imfile_per_file_config
return imfile_config
示例12: get_resource_id
def get_resource_id(self):
"""
Try to get resourceId from LadCfg. If not present, try to fetch from xmlCfg.
"""
lad_cfg = self.read_public_config('ladCfg')
resource_id = LadUtil.getResourceIdFromLadCfg(lad_cfg)
if not resource_id:
encoded_xml_cfg = self.read_public_config('xmlCfg').strip()
if encoded_xml_cfg:
xml_cfg = base64.b64decode(encoded_xml_cfg)
resource_id = XmlUtil.getXmlValue(XmlUtil.createElement(xml_cfg),
'diagnosticMonitorConfiguration/metrics', 'resourceId')
# Azure portal uses xmlCfg which contains WadCfg which is pascal case
# Currently we will support both casing and deprecate one later
if not resource_id:
resource_id = XmlUtil.getXmlValue(XmlUtil.createElement(xml_cfg),
'DiagnosticMonitorConfiguration/Metrics', 'resourceId')
return resource_id
示例13: _set_event_volume
def _set_event_volume(self, lad_cfg):
"""
Set event volume in mdsd config. Check if desired event volume is specified,
first in ladCfg then in public config. If in neither then default to Medium.
:param lad_cfg: 'ladCfg' Json object to look up for the event volume setting.
:return: None. The mdsd config XML tree's eventVolume attribute is directly updated.
:rtype: str
"""
assert self._mdsd_config_xml_tree is not None
event_volume = LadUtil.getEventVolumeFromLadCfg(lad_cfg)
if event_volume:
self._logger_log("Event volume found in ladCfg: " + event_volume)
else:
event_volume = self._ext_settings.read_public_config("eventVolume")
if event_volume:
self._logger_log("Event volume found in public config: " + event_volume)
else:
event_volume = "Medium"
self._logger_log("Event volume not found in config. Using default value: " + event_volume)
XmlUtil.setXmlValue(self._mdsd_config_xml_tree, "Management", "eventVolume", event_volume)
示例14: UpdateXML
def UpdateXML(doc):
"""
Add to the mdsd XML the minimal set of OMI queries which will retrieve the metrics requested via AddMetric(). This
provider doesn't need any configuration external to mdsd; if it did, that would be generated here as well.
:param doc: XML document object to be updated
:return: None
"""
global _metrics, _eventNames, _omiClassName
for group in _metrics:
(class_name, condition_clause, sample_rate) = group
if not condition_clause:
condition_clause = default_condition(class_name)
columns = []
mappings = []
for metric in _metrics[group]:
omi_name = metric.counter_name()
scale = _scaling[class_name][omi_name]
columns.append(omi_name)
mappings.append('<MapName name="{0}" {1}>{2}</MapName>'.format(omi_name, scale, metric.label()))
column_string = ','.join(columns)
if condition_clause:
cql_query = quoteattr("SELECT {0} FROM {1} WHERE {2}".format(column_string,
_omiClassName[class_name], condition_clause))
else:
cql_query = quoteattr("SELECT {0} FROM {1}".format(column_string, _omiClassName[class_name]))
query = '''
<OMIQuery cqlQuery={qry} eventName={evname} omiNamespace="root/scx" sampleRateInSeconds="{rate}" storeType="local">
<Unpivot columnName="CounterName" columnValue="Value" columns={columns}>
{mappings}
</Unpivot>
</OMIQuery>'''.format(
qry=cql_query,
evname=quoteattr(_eventNames[group]),
columns=quoteattr(column_string),
rate=sample_rate,
mappings='\n '.join(mappings)
)
XmlUtil.addElement(doc, 'Events/OMI', ET.fromstring(query))
return
示例15: createAccountSettings
def createAccountSettings(tree,account,key,endpoint,aikey=None):
XmlUtil.setXmlValue(tree,'Accounts/Account',"account",account,['isDefault','true'])
XmlUtil.setXmlValue(tree,'Accounts/Account',"key",key,['isDefault','true'])
XmlUtil.setXmlValue(tree,'Accounts/Account',"tableEndpoint",endpoint,['isDefault','true'])
if aikey:
AIUtil.createAccountElement(tree,aikey)