def get_connection(read_only=False): """ Returns an object representing the connection to a virtualization platform. This could be :mod:`engine.virt.fake.FakeConnection` in test mode, a connection to KVM, QEMU, or UML via :mod:`libvirt_conn`, or a connection to XenServer or Xen Cloud Platform via :mod:`xenapi`. Any object returned here must conform to the interface documented by :mod:`FakeConnection`. **Related flags** :connection_type: A string literal that falls through a if/elif structure to determine what virtualization mechanism to use. Values may be * fake * libvirt * xenapi """ # TODO(termie): maybe lazy load after initial check for permissions # TODO(termie): check whether we can be disconnected t = FLAGS.connection_type if t == 'fake': conn = fake.get_connection(read_only) elif t == 'libvirt': conn = libvirt_conn.get_connection(read_only) elif t == 'xenapi': conn = xenapi_conn.get_connection(read_only) elif t == 'hyperv': conn = hyperv.get_connection(read_only) elif t == 'vmwareapi': conn = vmwareapi_conn.get_connection(read_only) else: raise Exception('Unknown connection type "%s"' % t) if conn is None: LOG.error(_('Failed to open connection to the hypervisor')) sys.exit(1) return utils.check_isinstance(conn, driver.ComputeDriver)
def test_create_destroy(self): """Create a VM and destroy it""" instance = { "internal_id": random.randint(1, 1000000), "memory_mb": "1024", "mac_address": "02:12:34:46:56:67", "vcpus": 2, "project_id": "fake", "instance_type": "m1.small", } instance_ref = db.instance_create(self.context, instance) conn = hyperv.get_connection(False) conn._create_vm(instance_ref) # pylint: disable=W0212 found = [n for n in conn.list_instances() if n == instance_ref["name"]] self.assertTrue(len(found) == 1) info = conn.get_info(instance_ref["name"]) # Unfortunately since the vm is not running at this point, # we cannot obtain memory information from get_info self.assertEquals(info["num_cpu"], instance_ref["vcpus"]) conn.destroy(instance_ref) found = [n for n in conn.list_instances() if n == instance_ref["name"]] self.assertTrue(len(found) == 0)
def test_create_destroy(self): """Create a VM and destroy it""" instance = { 'internal_id': random.randint(1, 1000000), 'memory_mb': '1024', 'mac_address': '02:12:34:46:56:67', 'vcpus': 2, 'project_id': 'fake', 'instance_type': 'm1.small' } instance_ref = db.instance_create(self.context, instance) conn = hyperv.get_connection(False) conn._create_vm(instance_ref) # pylint: disable=W0212 found = [n for n in conn.list_instances() if n == instance_ref['name']] self.assertTrue(len(found) == 1) info = conn.get_info(instance_ref['name']) #Unfortunately since the vm is not running at this point, #we cannot obtain memory information from get_info self.assertEquals(info['num_cpu'], instance_ref['vcpus']) conn.destroy(instance_ref) found = [n for n in conn.list_instances() if n == instance_ref['name']] self.assertTrue(len(found) == 0)