Exemplo n.º 1
0
def get_connection(read_only=False):
    """
    Returns an object representing the connection to a virtualization
    platform, or to an on-demand bare-metal provisioning platform.

    This could be :mod:`nova.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`. Other platforms are
    also supported.

    Any object returned here must conform to the interface documented by
    :mod:`FakeConnection`.

    **Related flags**

    :connection_type:  A string literal that falls through an if/elif structure
                       to determine what virtualization mechanism to use.
                       Values may be

                            * fake
                            * libvirt
                            * xenapi
                            * vmwareapi
                            * baremetal

    """
    # 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 == 'vmwareapi':
        conn = vmwareapi_conn.get_connection(read_only)
    elif t == 'baremetal':
        conn = proxy.get_connection(read_only)
    else:
        raise Exception('Unknown connection type "%s"' % t)

    if conn is None:
        LOG.error(_('Failed to open connection to underlying virt platform'))
        sys.exit(1)
    return utils.check_isinstance(conn, driver.ComputeDriver)
Exemplo n.º 2
0
def get_connection(read_only=False):
    """
    Returns an object representing the connection to a virtualization
    platform.

    This could be :mod:`nova.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
                            * vmwareapi
    """
    # 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 == 'vmwareapi':
        conn = vmwareapi_conn.get_connection(read_only)
    elif t == 'baremetal':
        conn = proxy.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)
Exemplo n.º 3
0
    def test_get_info(self):
        # Create the mock objects
        self.mox.StubOutWithMock(dom, 'read_domains')
        self.mox.StubOutWithMock(dom, 'write_domains')

        # Expected calls
        dom.read_domains('/tftpboot/test_fake_dom_file')\
            .AndReturn(fake_domains)
        dom.write_domains('/tftpboot/test_fake_dom_file', fake_domains)

        self.mox.ReplayAll()

        # Code under test
        conn = proxy.get_connection(True)
        info = conn.get_info('instance-00000001')

        # Expected values
        self.assertEquals(info['mem'], 16777216)
        self.assertEquals(info['state'], 1)
        self.assertEquals(info['num_cpu'], 1)
        self.assertEquals(info['cpu_time'], 100)
        self.assertEquals(info['max_mem'], 16777216)
Exemplo n.º 4
0
    def test_get_info(self):
        # Create the mock objects
        self.mox.StubOutWithMock(dom, 'read_domains')
        self.mox.StubOutWithMock(dom, 'write_domains')

        # Expected calls
        dom.read_domains('/tftpboot/'
                         'test_fake_dom_file').AndReturn(fake_domains)
        dom.write_domains('/tftpboot/test_fake_dom_file', fake_domains)

        self.mox.ReplayAll()

        # Code under test
        conn = proxy.get_connection(True)
        # TODO(mikalstill): this is not a very good fake instance
        info = conn.get_info({'name': 'instance-00000001'})

        # Expected values
        self.assertEquals(info['mem'], 16777216)
        self.assertEquals(info['state'], 1)
        self.assertEquals(info['num_cpu'], 1)
        self.assertEquals(info['cpu_time'], 100)
        self.assertEquals(info['max_mem'], 16777216)