def __new__(cls, *args, **kwargs): '''Create an instance of the servicegroup API. args and kwargs are passed down to the servicegroup driver when it gets created. No args currently exist, though. Valid kwargs are: db_allowed - Boolean. False if direct db access is not allowed and alternative data access (conductor) should be used instead. ''' if not cls._driver: LOG.debug(_('ServiceGroup driver defined as an instance of %s'), str(CONF.servicegroup_driver)) driver_name = CONF.servicegroup_driver try: driver_class = cls._driver_name_class_mapping[driver_name] except KeyError: raise TypeError( _("unknown ServiceGroup driver name: %s") % driver_name) cls._driver = importutils.import_object(driver_class, *args, **kwargs) utils.check_isinstance(cls._driver, ServiceGroupDriver) # we don't have to check that cls._driver is not NONE, # check_isinstance does it return super(API, cls).__new__(cls)
def __new__(cls, *args, **kwargs): '''Create an instance of the servicegroup API. args and kwargs are passed down to the servicegroup driver when it gets created. No args currently exist, though. Valid kwargs are: db_allowed - Boolean. False if direct db access is not allowed and alternative data access (conductor) should be used instead. ''' if not cls._driver: LOG.debug(_('ServiceGroup driver defined as an instance of %s'), str(CONF.servicegroup_driver)) driver_name = CONF.servicegroup_driver try: driver_class = cls._driver_name_class_mapping[driver_name] except KeyError: raise TypeError(_("unknown ServiceGroup driver name: %s") % driver_name) cls._driver = importutils.import_object(driver_class, *args, **kwargs) utils.check_isinstance(cls._driver, ServiceGroupDriver) # we don't have to check that cls._driver is not NONE, # check_isinstance does it return super(API, cls).__new__(cls)
def __new__(cls, *args, **kwargs): if not cls._driver: LOG.debug(_('ServiceGroup driver defined as an instance of %s'), str(CONF.servicegroup_driver)) driver_name = CONF.servicegroup_driver try: driver_class = cls._driver_name_class_mapping[driver_name] except KeyError: raise TypeError( _("unknown ServiceGroup driver name: %s") % driver_name) cls._driver = importutils.import_object(driver_class) utils.check_isinstance(cls._driver, ServiceGroupDriver) # we don't have to check that cls._driver is not NONE, # check_isinstance does it return super(API, cls).__new__(cls)
def load_compute_driver(virtapi, compute_driver=None): """Load a compute driver module. Load the compute driver module specified by the compute_driver configuration option or, if supplied, the driver name supplied as an argument. Compute drivers constructors take a VirtAPI object as their first object and this must be supplied. :param virtapi: a VirtAPI instance :param compute_driver: a compute driver name to override the config opt :returns: a ComputeDriver instance """ if not compute_driver: compute_driver = CONF.compute_driver if not compute_driver: LOG.error(_("Compute driver option required, but not specified")) sys.exit(1) LOG.info(_("Loading compute driver '%s'") % compute_driver) try: driver = importutils.import_object_ns('nova.virt', compute_driver, virtapi) return utils.check_isinstance(driver, ComputeDriver) except ImportError: LOG.exception(_("Unable to load the virtualization driver")) sys.exit(1)
def __new__(cls, *args, **kwargs): if not cls._driver: LOG.debug(_('ServiceGroup driver defined as an instance of %s'), str(CONF.servicegroup_driver)) driver_name = CONF.servicegroup_driver try: driver_class = cls._driver_name_class_mapping[driver_name] except KeyError: raise TypeError(_("unknown ServiceGroup driver name: %s") % driver_name) cls._driver = importutils.import_object(driver_class) utils.check_isinstance(cls._driver, ServiceGroupDriver) # we don't have to check that cls._driver is not NONE, # check_isinstance does it return super(API, cls).__new__(cls)
def __init__(self, healthnmon_driver=None, *args, **kwargs): if not healthnmon_driver: healthnmon_driver = CONF.healthnmon_driver LOG.info("Initializing healthnmon. Loading driver %s" % healthnmon_driver) try: self.driver = utils.check_isinstance(importutils.import_object(healthnmon_driver), driver.Healthnmon) except ImportError, e: LOG.error(_("Unable to load the healthnmon driver: %s") % e) sys.exit(1)
def load_snapshot_driver(): if not CONF.veta_snapshot_driver: LOG.error(_("Snapshot driver option required, but not specified")) sys.exit(1) LOG.info(_("Loading snapshot driver '%s'") % CONF.veta_snapshot_driver) try: driver = importutils.import_object_ns('veta.driver', CONF.veta_snapshot_driver) return utils.check_isinstance(driver, SnapshotDriver) except ImportError: LOG.exception(_("Unable to load the snapshot driver")) sys.exit(1)
def __init__(self, compute_rmcontext): self.is_active = True self.attempt = 0 self.last_seen = datetime.datetime.min self.last_exception = None self.last_exception_time = None self.compute_rmcontext = compute_rmcontext self.compute_info = {} inventory_driver = importutils.import_module(CONF._compute_inventory_driver) self.driver = utils.check_isinstance( inventory_driver.get_connection(self.compute_rmcontext.rmType), driver.ComputeInventoryDriver ) self.driver.init_rmcontext(compute_rmcontext) self.compute_id = None
def __init__(self, compute_rmcontext): self.is_active = True self.attempt = 0 self.last_seen = datetime.datetime.min self.last_exception = None self.last_exception_time = None self.compute_rmcontext = compute_rmcontext self.compute_info = {} inventory_driver = \ importutils.import_module(CONF._compute_inventory_driver) self.driver = \ utils.check_isinstance( inventory_driver.get_connection(self.compute_rmcontext.rmType), driver.ComputeInventoryDriver) self.driver.init_rmcontext(compute_rmcontext) self.compute_id = None
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)
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 """ # 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) elif t == 'openvz': conn = openvz_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 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 """ deprecated.warn( _('Specifying virt driver via connection_type is ' 'deprecated. Use compute_driver=classname instead.')) driver_name = known_drivers.get(FLAGS.connection_type) if driver_name is None: raise exception.VirtDriverNotFound(name=FLAGS.connection_type) conn = importutils.import_object_ns('nova.virt', driver_name, read_only=read_only) if conn is None: LOG.error(_('Failed to open connection to underlying virt platform')) sys.exit(1) return utils.check_isinstance(conn, driver.ComputeDriver)
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): check whether we can be disconnected # TODO(sdague): is there a better way to mark things deprecated LOG.error(_('Specifying virt driver via connection_type is deprecated')) driver_name = known_drivers.get(FLAGS.connection_type) if driver_name is None: raise Exception('Unknown virt connection type "%s"' % FLAGS.connection_type) conn = importutils.import_object(driver_name, read_only=read_only) if conn is None: LOG.error(_('Failed to open connection to underlying virt platform')) sys.exit(1) return utils.check_isinstance(conn, driver.ComputeDriver)
def get_connection(hypervisor_type, 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 """ # TODO(termie): maybe lazy load after initial check for permissions # TODO(termie): check whether we can be disconnected if hypervisor_type == 'fake': conn = fake.get_connection(read_only) elif hypervisor_type == 'QEMU': conn = libvirt_conn.get_connection(read_only) else: raise Exception('Unknown connection type "%s"' % hypervisor_type) if conn is None: LOG.error(_('Failed to open connection to the hypervisor')) sys.exit(1) return utils.check_isinstance(conn, driver.ComputeInventoryDriver)
def _map_to_instance_info(self, instance): instance = utils.check_isinstance(instance, FakeInstance) info = driver.InstanceInfo(instance.name, instance.state) return info