def index_connect(local_config: LocalConfig = None, application_name: str = None, validate_connection: bool = True) -> Index: """ Create a Data Cube Index that can connect to a PostgreSQL server It contains all the required connection parameters, but doesn't actually check that the server is available. :param application_name: A short, alphanumeric name to identify this application. :param local_config: Config object to use. (optional) :param validate_connection: Validate database connection and schema immediately :raises datacube.index.Exceptions.IndexSetupError: """ if local_config is None: local_config = LocalConfig.find() driver_name = local_config.get('index_driver', 'default') index_driver = index_driver_by_name(driver_name) if not index_driver: raise RuntimeError( "No index driver found for %r. %s available: %s" % (driver_name, len(index_drivers()), ', '.join(index_drivers()))) return index_driver.connect_to_index( local_config, application_name=application_name, validate_connection=validate_connection)
def index_connect(local_config=None, application_name=None, validate_connection=True): # type: (LocalConfig, str, bool) -> Index """ Create a Data Cube Index that can connect to a PostgreSQL server It contains all the required connection parameters, but doesn't actually check that the server is available. :param application_name: A short, alphanumeric name to identify this application. :param local_config: Config object to use. :type local_config: :py:class:`datacube.config.LocalConfig`, optional :param validate_connection: Validate database connection and schema immediately :raises datacube.index.postgres._api.EnvironmentError: :rtype: datacube.index.index.Index """ if local_config is None: local_config = LocalConfig.find() index_driver = index_driver_by_name( local_config.get('index_driver', 'default')) return index_driver.connect_to_index( local_config, application_name=application_name, validate_connection=validate_connection)
def test_metadata_type_from_doc(): metadata_doc = yaml.safe_load(''' name: minimal description: minimal metadata definition dataset: id: [id] sources: [lineage, source_datasets] label: [label] creation_dt: [creation_dt] search_fields: some_custom_field: description: some custom field offset: [a,b,c,custom] ''') for name in index_drivers(): driver = index_driver_by_name(name) metadata = driver.metadata_type_from_doc(metadata_doc) assert isinstance(metadata, MetadataType) assert metadata.id is None assert metadata.name == 'minimal' assert 'some_custom_field' in metadata.dataset_fields