Ejemplo n.º 1
0
def get_adapter(adapter_id, user=None, session=None, **kwargs):
    """get adapter."""
    load_adapters()
    if adapter_id not in ADAPTER_MAPPING:
        raise exception.RecordNotExists('adpater %s does not exist' %
                                        adapter_id)
    return ADAPTER_MAPPING[adapter_id]
Ejemplo n.º 2
0
def get_db_object(session, table, exception_when_missing=True, **kwargs):
    """Get db object.

    If not exception_when_missing and the db object can not be found,
    return None instead of raising exception.
    """
    if not session:
        raise exception.DatabaseException('session param is None')
    with session.begin(subtransactions=True):
        logging.debug(
            'session %s get db object %s from table %s',
            id(session), kwargs, table.__name__)
        db_object = model_filter(
            model_query(session, table), table, **kwargs
        ).first()
        logging.debug(
            'session %s got db object %s', id(session), db_object
        )
        if db_object:
            return db_object

        if not exception_when_missing:
            return None

        raise exception.RecordNotExists(
            'Cannot find the record in table %s: %s' % (
                table.__name__, kwargs
            )
        )
Ejemplo n.º 3
0
def _get_package_metadata(adapter_id):
    """get package metadata."""
    load_metadatas()
    if adapter_id not in PACKAGE_METADATA_MAPPING:
        raise exception.RecordNotExists('adpater %s does not exist' %
                                        adapter_id)
    return _filter_metadata(PACKAGE_METADATA_MAPPING[adapter_id])
Ejemplo n.º 4
0
def _get_host_network(host_id, host_network_id, session=None, **kwargs):
    """Get hostnetwork by host id and hostnetwork id."""
    host = _get_host(host_id, session=session)
    host_network = _get_hostnetwork(host_network_id, session=session, **kwargs)
    if host_network.host_id != host.id:
        raise exception.RecordNotExists(
            'host %s does not own host network %s' %
            (host.id, host_network.id))
    return host_network
Ejemplo n.º 5
0
def _get_flavor_metadata(flavor_id):
    """get flavor metadata."""
    load_metadatas()
    if not flavor_id:
        logging.info('There is no flavor id, skipping...')
    elif flavor_id not in FLAVOR_METADATA_MAPPING:
        raise exception.RecordNotExists('flavor %s does not exist' % flavor_id)
    else:
        return _filter_metadata(FLAVOR_METADATA_MAPPING[flavor_id])
Ejemplo n.º 6
0
def get_flavor(flavor_id, user=None, session=None, **kwargs):
    """Get flavor."""
    load_flavors()
    if flavor_id not in FLAVOR_MAPPING:
        raise exception.RecordNotExists('flavor %s does not exist' % flavor_id)
    return FLAVOR_MAPPING[flavor_id]
Ejemplo n.º 7
0
def _get_flavor_metadata_ui_converter(flavor_id):
    """get flavor metadata ui converter."""
    load_metadatas()
    if flavor_id not in FLAVOR_METADATA_UI_CONVERTERS:
        raise exception.RecordNotExists('flavor %s does not exist' % flavor_id)
    return FLAVOR_METADATA_UI_CONVERTERS[flavor_id]
Ejemplo n.º 8
0
def _get_os_metadata_ui_converter(os_id):
    """get os metadata ui converter."""
    load_metadatas()
    if os_id not in OS_METADATA_UI_CONVERTERS:
        raise exception.RecordNotExists('os %s does not exist' % os_id)
    return OS_METADATA_UI_CONVERTERS[os_id]
Ejemplo n.º 9
0
def _get_os_metadata(os_id):
    """get os metadata."""
    load_metadatas()
    if os_id not in OS_METADATA_MAPPING:
        raise exception.RecordNotExists('os %s does not exist' % os_id)
    return _filter_metadata(OS_METADATA_MAPPING[os_id])