def create_standard_config(self, uuid, name, mem_kb, vcpus, disk, mac): # First, populate the XML with the appropriate values. boot_params = { 'name' : name, 'mem_kb' : mem_kb, 'vcpus' : vcpus, 'uuid' : hyphenize_uuid(uuid), 'disk' : disk, 'mac' : mac } xml = STANDARD_CONFIG_TEMPLATE % boot_params self.__write_xml_file(uuid, xml)
def _get_domain(uuid): """ Lookup the domain by its UUID. If not found, raise an exception. """ conn = libvirt.open(None) domain = None hyphenized_uuid = hyphenize_uuid(uuid) try: domain = conn.lookupByUUIDString(hyphenized_uuid) except libvirt.libvirtError, lve: raise VirtualizationException, \ "Domain UUID '%s' not found: %s" (hyphenized_uuid, str(lve)), sys.exc_info()[2]
def _get_domain(uuid): """ Lookup the domain by its UUID. If not found, raise an exception. """ conn = libvirt.open(None) domain = None hyphenized_uuid = hyphenize_uuid(uuid) try: domain = conn.lookupByUUIDString(hyphenized_uuid) except libvirt.libvirtError, lve: raise VirtualizationException, \ "Domain UUID '%s' not found: %s", (hyphenized_uuid, str(lve))
def _get_domain(uuid): """ Lookup the domain by its UUID. If not found, raise an exception. """ conn = libvirt.open(None) domain = None hyphenized_uuid = hyphenize_uuid(uuid) try: domain = conn.lookupByUUIDString(hyphenized_uuid) except libvirt.libvirtError: lve = sys.exc_info()[1] raise_with_tb(VirtualizationException("Domain UUID '%s' not found: %s" % (hyphenized_uuid, str(lve))), sys.exc_info()[2]) return (conn, domain)
def create_standard_config(self, uuid, name, mem_kb, vcpus, disk, mac): # First, populate the XML with the appropriate values. boot_params = { "name": name, "mem_kb": mem_kb, "vcpus": vcpus, "uuid": hyphenize_uuid(uuid), "disk": disk, "mac": mac, } xml = STANDARD_CONFIG_TEMPLATE % boot_params self.__write_xml_file(uuid, xml)
def poll_state(uuid): """ Polls just the state of the guest with the provided UUID. This state is returned. """ conn = libvirt.openReadOnly(None) if not conn: raise VirtualizationException, \ "Failed to open connection to hypervisor." # Attempt to connect to the domain. Since there is technically no # "stopped" state, we will assume that if we cannot connect the domain is # not running. Unfortunately, we can't really determine if the domain # actually exists. domain = None try: domain = conn.lookupByUUIDString(hyphenize_uuid(uuid)) except libvirt.libvirtError, lve: # Can't find domain. Return stopped state. return State(None)
def _begin_domain_installation(connection, name, install_kernel_path, install_initrd_path, extra_append, mem_kb, vcpus, uuid, disk_image_path, disk_image_type, mac): """ Creates and begins installation of the Xen instance. """ syslog = 'syslog=%s:%s' % (socket.gethostname(), SYSLOG_PORT) if DEBUG: syslog = '' create_params = { 'name' : name, 'install_kernel' : install_kernel_path, 'install_initrd' : install_initrd_path, 'extra' : extra_append, 'mem_kb' : mem_kb, 'vcpus' : vcpus, 'uuid' : hyphenize_uuid(uuid), 'disk' : disk_image_path, 'mac' : mac, 'syslog' : syslog} create_xml = XEN_CREATE_TEMPLATE % create_params # Now actually create the domain. domain = None try: domain = connection.createLinux(create_xml, 0) except Exception, e: raise VirtualizationKickstartException, \ "Error occurred while attempting to create domain %s: %s" % \ (name, str(e)), sys.exc_info()[2]