def set_boot_device(self, bootdevice): LOG.debug( 'Set boot device called for %(domain)s with boot ' 'device "%(bootdev)s"', { 'domain': self.domain_name, 'bootdev': bootdevice }) device = SET_BOOT_DEVICES_MAP.get(bootdevice) if device is None: return 0xd5 with utils.libvirt_open(**self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) tree = ET.fromstring(domain.XMLDesc()) for os_element in tree.findall('os'): # Remove all "boot" elements for boot_element in os_element.findall('boot'): os_element.remove(boot_element) # Add a new boot element with the request boot device boot_element = ET.SubElement(os_element, 'boot') boot_element.set('dev', device) try: conn.defineXML(ET.tostring(tree)) except libvirt.libvirtError as e: LOG.error( 'Failed setting the boot device %(bootdev)s for ' 'domain %(domain)s', { 'bootdev': device, 'domain': self.domain_name })
def set_boot_device(self, bootdevice): LOG.debug('Set boot device called for %(domain)s with boot ' 'device "%(bootdev)s"', {'domain': self.domain_name, 'bootdev': bootdevice}) device = SET_BOOT_DEVICES_MAP.get(bootdevice) if device is None: return 0xd5 with utils.libvirt_open(**self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) tree = ET.fromstring(domain.XMLDesc()) for os_element in tree.findall('os'): # Remove all "boot" elements for boot_element in os_element.findall('boot'): os_element.remove(boot_element) # Add a new boot element with the request boot device boot_element = ET.SubElement(os_element, 'boot') boot_element.set('dev', device) try: conn.defineXML(ET.tostring(tree)) except libvirt.libvirtError as e: LOG.error('Failed setting the boot device %(bootdev)s for ' 'domain %(domain)s', {'bootdev': device, 'domain': self.domain_name})
def get_boot_device(self): LOG.debug('Get boot device called for %s', self.domain_name) with utils.libvirt_open(readonly=True, **self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) boot_element = ET.fromstring(domain.XMLDesc()).find('.//os/boot') boot_dev = None if boot_element is not None: boot_dev = boot_element.attrib.get('dev') return GET_BOOT_DEVICES_MAP.get(boot_dev, 0)
def power_on(self): LOG.debug('Power on called for domain %s', self.domain_name) try: with utils.libvirt_open(**self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) if not domain.isActive(): domain.create() except libvirt.libvirtError as e: LOG.error('Error powering on the domain %(domain)s. ' 'Error: %(error)s' % {'domain': self.domain_name, 'error': e}) return
def power_on(self): LOG.debug('Power on called for domain %s', self.domain_name) try: with utils.libvirt_open(**self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) if not domain.isActive(): domain.create() except libvirt.libvirtError as e: LOG.error('Error powering on the domain %(domain)s. ' 'Error: %(error)s' % { 'domain': self.domain_name, 'error': e }) return
def get_power_state(self): LOG.debug('Get power state called for domain %s', self.domain_name) try: with utils.libvirt_open(readonly=True, **self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): return POWERON except libvirt.libvirtError as e: LOG.error('Error getting the power state of domain %(domain)s. ' 'Error: %(error)s', {'domain': self.domain_name, 'error': e}) return return POWEROFF
def get_power_state(self): LOG.debug('Get power state called for domain %s', self.domain_name) try: with utils.libvirt_open(readonly=True, **self._conn_args) as conn: domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): return POWERON except libvirt.libvirtError as e: LOG.error( 'Error getting the power state of domain %(domain)s. ' 'Error: %(error)s', { 'domain': self.domain_name, 'error': e }) return return POWEROFF