本文整理汇总了Python中libvirt.VIR_DOMAIN_AFFECT_LIVE属性的典型用法代码示例。如果您正苦于以下问题:Python libvirt.VIR_DOMAIN_AFFECT_LIVE属性的具体用法?Python libvirt.VIR_DOMAIN_AFFECT_LIVE怎么用?Python libvirt.VIR_DOMAIN_AFFECT_LIVE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类libvirt
的用法示例。
在下文中一共展示了libvirt.VIR_DOMAIN_AFFECT_LIVE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach_iso
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def attach_iso(self, iso_object, live=False):
"""Attaches an ISO image to the disk drive of the VM."""
iso_object = self.po__convert_remote_object(iso_object)
# Ensure that the user has permissions to modifiy the VM
self.po__get_registered_object('auth').assert_permission(
PERMISSIONS.MODIFY_VM,
self.vm_object
)
# Import cdrom XML template
cdrom_xml = ET.parse(DirectoryLocation.TEMPLATE_DIR + '/cdrom.xml')
# Add iso image path to cdrom XML
cdrom_xml.find('source').set('file', iso_object.get_path())
cdrom_xml_string = ET.tostring(cdrom_xml.getroot(), encoding='utf8', method='xml')
flags = libvirt.VIR_DOMAIN_AFFECT_LIVE if live else 0
# Update the libvirt cdrom device
libvirt_object = self.vm_object._get_libvirt_domain_object()
if libvirt_object.updateDeviceFlags(cdrom_xml_string, flags):
raise LibvirtException('An error occurred whilst attaching ISO')
示例2: remove_iso
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def remove_iso(self, live=False):
"""Removes ISO attached to the disk drive of a VM."""
# Import cdrom XML template
cdrom_xml = ET.parse(DirectoryLocation.TEMPLATE_DIR + '/cdrom.xml')
# Add iso image path to cdrom XML
cdrom_xml = cdrom_xml.getroot()
source_xml = cdrom_xml.find('source')
if source_xml is not None:
cdrom_xml.remove(source_xml)
cdrom_xml_string = ET.tostring(cdrom_xml, encoding='utf8', method='xml')
flags = libvirt.VIR_DOMAIN_AFFECT_LIVE if live else 0
# Update the libvirt cdrom device
if self.vm_object._get_libvirt_domain_object().updateDeviceFlags(
cdrom_xml_string, flags):
raise LibvirtException('An error occurred whilst detaching ISO')
示例3: update_memory
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def update_memory(self, name, memory):
conn = self.conn
memory = str(int(memory) * 1024)
try:
vm = conn.lookupByName(name)
except:
print("VM %s not found" % name)
return {'result': 'failure', 'reason': "VM %s not found" % name}
xml = vm.XMLDesc(0)
root = ET.fromstring(xml)
memorynode = list(root.getiterator('memory'))[0]
memorynode.text = memory
currentmemory = list(root.getiterator('currentMemory'))[0]
maxmemory = list(root.getiterator('maxMemory'))
if maxmemory:
diff = int(memory) - int(currentmemory.text)
if diff > 0:
xml = "<memory model='dimm'><target><size unit='KiB'>%s</size><node>0</node></target></memory>" % diff
vm.attachDeviceFlags(xml, VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)
elif vm.isActive():
common.pprint("Note this will only be effective upon next start", color='blue')
currentmemory.text = memory
newxml = ET.tostring(root)
conn.defineXML(newxml.decode("utf-8"))
return {'result': 'success'}
示例4: attach
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def attach(self):
"""Attach the USB device to the libvirt domain."""
if not self.virtual_machine.is_running:
raise VmStoppedException('VM is stopped. '
'Can only attached USB device to running VM')
# TO ADD PERMISSION CHECKING
libvirt_object = self.virtual_machine._get_libvirt_domain_object()
libvirt_object.attachDeviceFlags(
self._generate_libvirt_xml(),
(libvirt.VIR_DOMAIN_AFFECT_LIVE |
libvirt.VIR_DOMAIN_AFFECT_CURRENT |
libvirt.VIR_DOMAIN_AFFECT_CONFIG))
示例5: detach
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def detach(self):
"""Detach the USB device from the libvirt domain."""
if not self.virtual_machine.is_running:
raise VmStoppedException('VM is stopped. '
'Can only attached USB device to running VM')
# TO ADD PERMISSION CHECKING
libvirt_object = self.virtual_machine._get_libvirt_domain_object()
libvirt_object.detachDeviceFlags(
self._generate_libvirt_xml(),
(libvirt.VIR_DOMAIN_AFFECT_LIVE |
libvirt.VIR_DOMAIN_AFFECT_CURRENT |
libvirt.VIR_DOMAIN_AFFECT_CONFIG))
示例6: add_nic
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def add_nic(self, name, network):
conn = self.conn
networks = {}
for interface in conn.listInterfaces():
networks[interface] = 'bridge'
for net in conn.listAllNetworks():
networks[net.name()] = 'network'
try:
vm = conn.lookupByName(name)
except:
common.pprint("VM %s not found" % name, color='red')
return {'result': 'failure', 'reason': "VM %s not found" % name}
if network not in networks:
common.pprint("Network %s not found" % network, color='red')
return {'result': 'failure', 'reason': "Network %s not found" % network}
else:
networktype = networks[network]
source = "<source %s='%s'/>" % (networktype, network)
nicxml = """<interface type='%s'>
%s
<model type='virtio'/>
</interface>""" % (networktype, source)
if vm.isActive() == 1:
vm.attachDeviceFlags(nicxml, VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)
else:
vm.attachDeviceFlags(nicxml, VIR_DOMAIN_AFFECT_CONFIG)
vm = conn.lookupByName(name)
vmxml = vm.XMLDesc(0)
conn.defineXML(vmxml)
return {'result': 'success'}
示例7: parse_flag
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def parse_flag(logger, params):
flag = params.get('flags', 'current')
ret = 0
logger.info("metadata with flag %s" % flag)
if flag == 'current':
return libvirt.VIR_DOMAIN_AFFECT_CURRENT
for flag in flag.split('|'):
if flag == 'live':
ret = ret | libvirt.VIR_DOMAIN_AFFECT_LIVE
elif flag == 'config':
ret = ret | libvirt.VIR_DOMAIN_AFFECT_CONFIG
else:
logger.error('illegal flag %s' % flag)
return -1
return ret
示例8: check_events
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def check_events(events, event_list, guestname, flags, domstate, dom, logger):
values = {}
if ((domstate == libvirt.VIR_DOMAIN_RUNNING) and
((flags == libvirt.VIR_DOMAIN_AFFECT_CURRENT) or
(flags == libvirt.VIR_DOMAIN_AFFECT_LIVE))):
xmlstr = minidom.parse("%s%s.xml" % (XML_PATH, guestname))
else:
guestxml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
xmlstr = minidom.parseString(guestxml)
perf = xmlstr.getElementsByTagName('perf')
if perf:
perf = xmlstr.getElementsByTagName('perf')[0]
for item in perf.getElementsByTagName('event'):
for i in event_list:
if item.getAttribute('name') == i:
if item.getAttribute('enabled') == "yes":
values[i] = True
elif item.getAttribute('enabled') == "no":
values[i] = False
logger.info("values: %s" % values)
for i in event_list:
if i in list(values.keys()) and i in list(events.keys()):
if values[i] != events[i]:
return 1
return 0
示例9: parse_flag
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def parse_flag(params, logger):
flags = params.get('flags', 'current')
logger.info("Flag: %s" % flags)
if flags == "current":
return libvirt.VIR_DOMAIN_AFFECT_CURRENT
elif flags == "live":
return libvirt.VIR_DOMAIN_AFFECT_LIVE
elif flags == "config":
return libvirt.VIR_DOMAIN_AFFECT_CONFIG
else:
logger.error("Not support flag: %s" % flags)
return -1
示例10: parse_flag
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def parse_flag(logger, params):
flag = params.get('flags', 'current')
ret = 0
logger.info("setMetadata with flag %s" % flag)
if flag == 'current':
return libvirt.VIR_DOMAIN_AFFECT_CURRENT
for flag in flag.split('|'):
if flag == 'live':
ret = ret | libvirt.VIR_DOMAIN_AFFECT_LIVE
elif flag == 'config':
ret = ret | libvirt.VIR_DOMAIN_AFFECT_CONFIG
else:
logger.error('illegal flag %s' % flag)
return -1
return ret
示例11: del_iothread
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def del_iothread(params):
"""
test API for delIOThread in class virDomain
"""
logger = params['logger']
id = int(params['id'])
try:
conn = libvirt.open(params['conn'])
logger.info("get connection to libvirtd")
guest = params['guestname']
vm = conn.lookupByName(guest)
logger.info("test guest name: %s" % guest)
""" test effect guest running XML """
if vm.isActive() == 1:
logger.info("guest is running test with running guest")
if find_iothreadid_fromxml(vm, 1, id):
vm.delIOThread(id, libvirt.VIR_DOMAIN_AFFECT_LIVE)
if find_iothreadid_fromxml(vm, 1, id):
logger.info("FAIL: still can find iothread id in XML")
return 1
else:
""" test effect guest config"""
logger.info("test with guest inactive XML")
if find_iothreadid_fromxml(vm, 0, id):
vm.delIOThread(id, libvirt.VIR_DOMAIN_AFFECT_CONFIG)
if find_iothreadid_fromxml(vm, 0, id):
logger.info("FAIL: still can find iothread id in XML")
return 1
logger.info("PASS: delete iothread successful.")
except libvirtError as e:
logger.error("API error message: %s" % e.get_error_message())
return 1
return 0
示例12: mount_cdrom
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def mount_cdrom(self, cdrom_path):
logging.info('Mounting CDROM image')
dom_elem = tree.fromstring(self.domain.XMLDesc())
# find cdrom
cdrom_elem = dom_elem.find("./devices/disk[@device='cdrom']")
# find source
source_elem = cdrom_elem.find('./source')
if source_elem is None:
tree.SubElement(cdrom_elem, 'source')
source_elem = cdrom_elem.find('./source')
source_elem.set('file', cdrom_path)
new_xml = tree.tostring(cdrom_elem).decode('utf-8')
result = self.domain.updateDeviceFlags(new_xml, libvirt.VIR_DOMAIN_AFFECT_LIVE)
logging.debug("updateDeviceFlags returned %s", result)
示例13: edit_iface
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def edit_iface(self, port_id, old_net, new_net):
#This action imply remove and insert interface to put proper parameters
if self.test:
time.sleep(1)
else:
#get iface details
self.db_lock.acquire()
r,c = self.db.get_table(FROM='ports as p join resources_port as rp on p.uuid=rp.port_id',
WHERE={'port_id': port_id})
self.db_lock.release()
if r<0:
print self.name, ": edit_iface(",port_id,") DDBB error:", c
return
elif r==0:
print self.name, ": edit_iface(",port_id,") por not found"
return
port=c[0]
if port["model"]!="VF":
print self.name, ": edit_iface(",port_id,") ERROR model must be VF"
return
#create xml detach file
xml=[]
self.xml_level = 2
xml.append("<interface type='hostdev' managed='yes'>")
xml.append(" <mac address='" +port['mac']+ "'/>")
xml.append(" <source>"+ self.pci2xml(port['pci'])+"\n </source>")
xml.append('</interface>')
try:
conn=None
conn = libvirt.open("qemu+ssh://"+self.user+"@"+self.host+"/system")
dom = conn.lookupByUUIDString(port["instance_id"])
if old_net:
text="\n".join(xml)
print self.name, ": edit_iface detaching SRIOV interface", text
dom.detachDeviceFlags(text, flags=libvirt.VIR_DOMAIN_AFFECT_LIVE)
if new_net:
xml[-1] =" <vlan> <tag id='" + str(port['vlan']) + "'/> </vlan>"
self.xml_level = 1
xml.append(self.pci2xml(port.get('vpci',None)) )
xml.append('</interface>')
text="\n".join(xml)
print self.name, ": edit_iface attaching SRIOV interface", text
dom.attachDeviceFlags(text, flags=libvirt.VIR_DOMAIN_AFFECT_LIVE)
except libvirt.libvirtError as e:
text = e.get_error_message()
print self.name, ": edit_iface(",port["instance_id"],") libvirt exception:", text
finally:
if conn is not None: conn.close
示例14: add_disk
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def add_disk(self, name, size=1, pool=None, thin=True, image=None, shareable=False, existing=None,
interface='virtio'):
conn = self.conn
diskformat = 'qcow2'
diskbus = interface
if size < 1:
common.pprint("Incorrect size.Leaving...", color='red')
return {'result': 'failure', 'reason': "Incorrect size"}
if not thin:
diskformat = 'raw'
try:
vm = conn.lookupByName(name)
xml = vm.XMLDesc(0)
root = ET.fromstring(xml)
except:
common.pprint("VM %s not found" % name, color='red')
return {'result': 'failure', 'reason': "VM %s not found" % name}
currentdisk = 0
diskpaths = []
virtio_index, scsi_index, ide_index = 0, 0, 0
for element in list(root.getiterator('disk')):
disktype = element.get('device')
device = element.find('target').get('dev')
imagefiles = [element.find('source').get('file'), element.find('source').get('dev'),
element.find('source').get('volume')]
path = next(item for item in imagefiles if item is not None)
diskpaths.append(path)
if disktype == 'cdrom':
continue
elif device.startswith('sd'):
scsi_index += 1
elif device.startswith('hd'):
ide_index += 1
else:
virtio_index += 1
currentdisk += 1
diskindex = currentdisk
if interface == 'scsi':
diskdev = "sd%s" % string.ascii_lowercase[scsi_index]
elif interface == 'ide':
diskdev = "hd%s" % string.ascii_lowercase[ide_index]
else:
diskdev = "vd%s" % string.ascii_lowercase[virtio_index]
if existing is None:
storagename = "%s_%d.img" % (name, diskindex)
diskpath = self.create_disk(name=storagename, size=size, pool=pool, thin=thin, image=image)
elif existing in diskpaths:
common.pprint("Disk %s already in VM %s" % (existing, name), color='blue')
return {'result': 'success'}
else:
diskpath = existing
diskxml = self._xmldisk(diskpath=diskpath, diskdev=diskdev, diskbus=diskbus, diskformat=diskformat,
shareable=shareable)
if vm.isActive() == 1:
vm.attachDeviceFlags(diskxml, VIR_DOMAIN_AFFECT_LIVE)
vm = conn.lookupByName(name)
vmxml = vm.XMLDesc(0)
conn.defineXML(vmxml)
else:
vm.attachDeviceFlags(diskxml, VIR_DOMAIN_AFFECT_CONFIG)
return {'result': 'success'}
示例15: delete_nic
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_AFFECT_LIVE [as 别名]
def delete_nic(self, name, interface):
conn = self.conn
networks = {}
nicnumber = 0
for n in conn.listInterfaces():
networks[n.name()] = 'bridge'
for n in conn.listAllNetworks():
networks[n.name()] = 'network'
try:
vm = conn.lookupByName(name)
xml = vm.XMLDesc(0)
root = ET.fromstring(xml)
except:
common.pprint("VM %s not found" % name, color='red')
return {'result': 'failure', 'reason': "VM %s not found" % name}
networktype, mac, source = None, None, None
for element in list(root.getiterator('interface')):
device = "eth%s" % nicnumber
if device == interface:
mac = element.find('mac').get('address')
networktype = element.get('type')
if networktype == 'bridge':
network = element.find('source').get('bridge')
source = "<source %s='%s'/>" % (networktype, network)
else:
network = element.find('source').get('network')
source = "<source %s='%s'/>" % (networktype, network)
break
else:
nicnumber += 1
if networktype is None or mac is None or source is None:
common.pprint("Interface %s not found" % interface, color='red')
return {'result': 'failure', 'reason': "Interface %s not found" % interface}
nicxml = """<interface type='%s'>
<mac address='%s'/>
%s
<model type='virtio'/>
</interface>""" % (networktype, mac, source)
if self.debug:
print(nicxml)
# vm.detachDevice(nicxml)
if vm.isActive() == 1:
vm.detachDeviceFlags(nicxml, VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)
else:
vm.detachDeviceFlags(nicxml, VIR_DOMAIN_AFFECT_CONFIG)
vm = conn.lookupByName(name)
vmxml = vm.XMLDesc(0)
conn.defineXML(vmxml)
return {'result': 'success'}