Ejemplo n.º 1
0
    def get_flavor_next_provider(self, context, flavor_id,
                                 filters=None, fields=None,
                                 sorts=None, limit=None,
                                 marker=None, page_reverse=False):
        """From flavor, choose service profile and find provider for driver."""

        objs = obj_flavor.FlavorServiceProfileBinding.get_objects(context,
            flavor_id=flavor_id)
        if not objs:
            raise ext_flavors.FlavorServiceProfileBindingNotFound(
                sp_id='', fl_id=flavor_id)
        # Get the service profile from the first binding
        # TODO(jwarendt) Should become a scheduling framework instead
        sp_obj = self._get_service_profile(context, objs[0].service_profile_id)

        if not sp_obj.enabled:
            raise ext_flavors.ServiceProfileDisabled()

        LOG.debug("Found driver %s.", sp_obj.driver)

        service_type_manager = sdb.ServiceTypeManager.get_instance()
        providers = service_type_manager.get_service_providers(
            context,
            filters={'driver': sp_obj.driver})

        if not providers:
            raise ext_flavors.ServiceProfileDriverNotFound(
                driver=sp_obj.driver)

        LOG.debug("Found providers %s.", providers)

        res = {'driver': sp_obj.driver,
               'provider': providers[0].get('name')}

        return [db_utils.resource_fields(res, fields)]
Ejemplo n.º 2
0
    def get_flavor_next_provider(self,
                                 context,
                                 flavor_id,
                                 filters=None,
                                 fields=None,
                                 sorts=None,
                                 limit=None,
                                 marker=None,
                                 page_reverse=False):
        """From flavor, choose service profile and find provider for driver."""

        with context.session.begin(subtransactions=True):
            bind_qry = context.session.query(
                flavor_models.FlavorServiceProfileBinding)
            binding = bind_qry.filter_by(flavor_id=flavor_id).first()
            if not binding:
                raise ext_flavors.FlavorServiceProfileBindingNotFound(
                    sp_id='', fl_id=flavor_id)

        # Get the service profile from the first binding
        # TODO(jwarendt) Should become a scheduling framework instead
        sp_db = self._get_service_profile(context,
                                          binding['service_profile_id'])

        if not sp_db.enabled:
            raise ext_flavors.ServiceProfileDisabled()

        LOG.debug("Found driver %s.", sp_db.driver)

        service_type_manager = sdb.ServiceTypeManager.get_instance()
        providers = service_type_manager.get_service_providers(
            context, filters={'driver': sp_db.driver})

        if not providers:
            raise ext_flavors.ServiceProfileDriverNotFound(driver=sp_db.driver)

        LOG.debug("Found providers %s.", providers)

        res = {'driver': sp_db.driver, 'provider': providers[0].get('name')}

        return [db_utils.resource_fields(res, fields)]