1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
6
# Copyright (c) 2010 Citrix Systems, Inc.
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9
# not use this file except in compliance with the License. You may obtain
10
# a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
# License for the specific language governing permissions and limitations
20
from nova import flags
21
from nova.virt import fake
22
from nova.virt import libvirt_conn
23
from nova.virt import xenapi
29
def get_connection(read_only=False):
30
# TODO(termie): maybe lazy load after initial check for permissions
31
# TODO(termie): check whether we can be disconnected
32
t = FLAGS.connection_type
34
conn = fake.get_connection(read_only)
36
conn = libvirt_conn.get_connection(read_only)
38
conn = xenapi.get_connection(read_only)
40
raise Exception('Unknown connection type "%s"' % t)
43
logging.error('Failed to open connection to the hypervisor')