本文整理汇总了Python中xml.dom.minidom.Document.cloneNode方法的典型用法代码示例。如果您正苦于以下问题:Python Document.cloneNode方法的具体用法?Python Document.cloneNode怎么用?Python Document.cloneNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.cloneNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_xmlfile
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import cloneNode [as 别名]
#.........这里部分代码省略.........
StripUnitSize = doc.createElement('StripUnitSize')
StripUnitSize_text = doc.createTextNode('64')
StripUnitSize.appendChild(StripUnitSize_text)
lun.appendChild(StripUnitSize)
'''
v_WriteType = raw_input("WriteType:[1]")
if not v_WriteType:
v_WriteType = '1'
'''
WriteType = doc.createElement('WriteType')
WriteType_text = doc.createTextNode('1')
WriteType.appendChild(WriteType_text)
lun.appendChild(WriteType)
'''
v_MirrorSwitch = raw_input("MirrorSwitch:[1]")
if not v_MirrorSwitch:
v_MirrorSwitch = '1'
'''
MirrorSwitch = doc.createElement('MirrorSwitch')
MirrorSwitch_text = doc.createTextNode('1')
MirrorSwitch.appendChild(MirrorSwitch_text)
lun.appendChild(MirrorSwitch)
'''
v_Prefetch_Type = raw_input("Prefetch Type:[0]")
v_Prefetch_Value = raw_input("Prefetch Value:[0]")
if not v_Prefetch_Type:
v_Prefetch_Type = '0'
if not v_Prefetch_Value:
v_Prefetch_Value = '0'
'''
prefetch = doc.createElement('Prefetch')
prefetch.setAttribute('Type', '0')
prefetch.setAttribute('Value', '0')
lun.appendChild(prefetch)
v_StoragePool = raw_input(text_StoragePool)
if (not v_StoragePool) and (self.StoragePool):
v_StoragePool = self.StoragePool
StoragePool = doc.createElement('StoragePool')
StoragePool.setAttribute('Name', v_StoragePool)
lun.appendChild(StoragePool)
if v_Protocol == 'iSCSI':
iscsi = doc.createElement('iSCSI')
config.appendChild(iscsi)
v_DefaultTargetIP = raw_input(text_DefaultTargetIP)
if (not v_DefaultTargetIP) and (self.DefaultTargetIP):
v_DefaultTargetIP = self.DefaultTargetIP
defaulttargetip = doc.createElement('DefaultTargetIP')
defaulttargetip_text = doc.createTextNode(v_DefaultTargetIP)
defaulttargetip.appendChild(defaulttargetip_text)
iscsi.appendChild(defaulttargetip)
initiator = doc.createElement('Initiator')
initiator.setAttribute('Name', 'xxxxxx')
initiator.setAttribute('TargetIP', '192.168.100.2')
iscsi.appendChild(initiator)
initiator = doc.createElement('Initiator')
initiator.setAttribute('Name', 'xxxxxx')
initiator.setAttribute('TargetIP', 'x.x.x.x')
iscsi.appendChild(initiator)
else:
iscsi = doc.createElement('iSCSI')
config.appendChild(iscsi)
defaulttargetip = doc.createElement('DefaultTargetIP')
defaulttargetip_text = doc.createTextNode('')
defaulttargetip.appendChild(defaulttargetip_text)
iscsi.appendChild(defaulttargetip)
v_HostIP = raw_input(text_HostIP)
if (not v_HostIP) and (self.HostIP):
v_HostIP = self.HostIP
v_Host_OSType = raw_input(text_OSType)
if (not v_Host_OSType) and (self.OSType):
v_Host_OSType = self.OSType
Host = doc.createElement('Host')
Host.setAttribute('HostIP', v_HostIP)
Host.setAttribute('OSType', v_Host_OSType)
config.appendChild(Host)
doccopy = doc.cloneNode(True)
Indent(doccopy, doccopy.documentElement)
cinder_conf_file = open(self.conf_file_name, 'w')
writer = codecs.lookup('utf-8')[3](cinder_conf_file)
doccopy.writexml(writer, encoding = 'utf-8')
cinder_conf_file.close()
doccopy.unlink()
cinder_conf_file = open(self.conf_file_name, 'r')
file_content = cinder_conf_file.read()
cinder_conf_file.close()
pos = file_content.find('<config>')
file_content = file_content[:pos] + '\n' + file_content[pos:]
cinder_conf_file = open(self.conf_file_name, 'w')
cinder_conf_file.write(file_content)
cinder_conf_file.close()
print(self.message)
示例2: create_cinder_conf_file
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import cloneNode [as 别名]
#.........这里部分代码省略.........
" 1: Thin\n"
" 2: Thick\n"
"Enter your choice<1-2>:")
text_StoragePool = ("StoragePoolName:")
text_DefaultTargetIP = ("iSCSI IP:")
text_HostIP = ("HostIP(Local host ip):")
text_OSType = ("OSType:\n"
" 1: Linux\n"
" 2: Windows\n"
" 3: Solaris\n"
" 4: HP-UX\n"
" 5: AIX\n"
" 6: XenServer\n"
" 7: Mac OS\n"
" 8: VMware ESX\n"
" 9: Windows Server 2012\n"
"Enter your choice<1-9>:")
text_ControllerIP_Num = ("The number of Control ip "
"you want to cinfig:")
if self.SVP_IP:
text_SVP_IP = ("Storage IP:[%s]" % (self.SVP_IP))
else:
text_SVP_IP = ("Storage IP:")
self.create_product(text_Product)
self.create_protocol(text_Protocol, text_ControllerIP_Num)
self.create_svp_ip(text_SVP_IP)
self.create_user_password()
self.create_luntype(text_LUNType)
self.create_StoragePool(text_StoragePool)
self.create_iscsi(text_DefaultTargetIP)
self.create_host(text_HostIP, text_OSType)
doccopy = self.doc.cloneNode(True)
self.Indent(doccopy, doccopy.documentElement)
cinder_conf_file = open(self.xml_file_name, 'wb')
writer = codecs.lookup('utf-8')[3](cinder_conf_file)
doccopy.writexml(writer, encoding = 'utf-8')
cinder_conf_file.close()
doccopy.unlink()
cinder_conf_file = open(self.xml_file_name, 'rb')
file_content = cinder_conf_file.read()
cinder_conf_file.close()
pos = file_content.find('<config>')
file_content = file_content[:pos] + '\n' + file_content[pos:]
cinder_conf_file = open(self.xml_file_name, 'wb')
cinder_conf_file.write(file_content)
cinder_conf_file.close()
def create_manila_xmlfile(self):
self.doc = Document()
self.config = self.doc.createElement('config')
self.doc.appendChild(self.config)
self.storage = self.doc.createElement('Storage')
self.config.appendChild(self.storage)
if self.conf_file_exit:
text_Product = ("Product:[%s]" % (self.Product))
text_Protocol = ("Protocol:[%s]" % (self.Protocol))
text_StoragePool = ("StoragePoolName:[%s]" % (self.StoragePool))
v_Product = self.Product
v_Protocol = self.Protocol
LogicalPortIP = ("LogicalPortIP:[%s]" % (self.DefaultTargetIP))