/usr/share/pyshared/nova/virt/connection.py is in python-nova 2012.1-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Abstraction of the underlying virtualization API."""
import sys
from nova import flags
from nova import log as logging
from nova import utils
from nova.virt import driver
from nova.virt import fake
from nova.virt.libvirt import connection as libvirt_conn
from nova.virt import vmwareapi_conn
from nova.virt import xenapi_conn
LOG = logging.getLogger(__name__)
FLAGS = flags.FLAGS
"""
In case of baremetal (FLAGS.connection_type),
specific driver is set by FLAGS.baremetal_driver
"""
if FLAGS.connection_type == 'baremetal':
from nova.virt.baremetal import proxy
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)
|