コード例 #1
0
ファイル: api.py プロジェクト: priya2417/nova
    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)
コード例 #2
0
ファイル: api.py プロジェクト: B-Rich/gantt
    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)
コード例 #3
0
ファイル: api.py プロジェクト: whitekid/nova
    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)
コード例 #4
0
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)
コード例 #5
0
ファイル: api.py プロジェクト: MVillari/nova
    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)
コード例 #6
0
ファイル: driver.py プロジェクト: DavidYan/nova
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)
コード例 #7
0
ファイル: manager.py プロジェクト: jessegonzalez/healthnmon
 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)
コード例 #8
0
ファイル: __init__.py プロジェクト: dblundell/veta
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)
コード例 #9
0
 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
コード例 #10
0
 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
コード例 #11
0
ファイル: connection.py プロジェクト: pulchart/nova
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)
コード例 #12
0
ファイル: connection.py プロジェクト: tomchill/reddwarf
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)
コード例 #13
0
ファイル: connection.py プロジェクト: soniafr/nova
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)
コード例 #14
0
ファイル: connection.py プロジェクト: Nesrine85/nova
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)
コード例 #15
0
ファイル: connection.py プロジェクト: emonty/healthnmon
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)
コード例 #16
0
ファイル: fake.py プロジェクト: rajatkhanduja/nova
 def _map_to_instance_info(self, instance):
     instance = utils.check_isinstance(instance, FakeInstance)
     info = driver.InstanceInfo(instance.name, instance.state)
     return info
コード例 #17
0
ファイル: fake.py プロジェクト: bopopescu/extra-specs-1
 def _map_to_instance_info(self, instance):
     instance = utils.check_isinstance(instance, FakeInstance)
     info = driver.InstanceInfo(instance.name, instance.state)
     return info