MCPcopy Create free account
hub / github.com/canonical/cloud-init / read_metadata

Function read_metadata

cloudinit/sources/DataSourceLXD.py:418–455  ·  view source on GitHub ↗

Fetch metadata from the /dev/lxd/socket routes. Perform a number of HTTP GETs on known routes on the devlxd socket API. Minimally all containers must respond to /meta-data when the LXD configuration setting `security.devlxd` is true. When `security.devlxd` i

(
    api_version: str = LXD_SOCKET_API_VERSION,
    metadata_keys: MetaDataKeys = MetaDataKeys.ALL,
)

Source from the content-addressed store, hash-verified

416
417
418def read_metadata(
419 api_version: str = LXD_SOCKET_API_VERSION,
420 metadata_keys: MetaDataKeys = MetaDataKeys.ALL,
421) -> dict:
422 """Fetch metadata from the /dev/lxd/socket routes.
423
424 Perform a number of HTTP GETs on known routes on the devlxd socket API.
425 Minimally all containers must respond to <LXD_SOCKET_API_VERSION>/meta-data
426 when the LXD configuration setting `security.devlxd` is true.
427
428 When `security.devlxd` is false, no /dev/lxd/socket file exists. This
429 datasource will return False from `ds_detect` in that case.
430
431 Perform a GET of <LXD_SOCKET_API_VERSION>/config` and walk all `user.*`
432 configuration keys, storing all keys and values under a dict key
433 LXD_SOCKET_API_VERSION: config {...}.
434
435 In the presence of the following optional user config keys,
436 create top level aliases:
437 - user.user-data -> user-data
438 - user.vendor-data -> vendor-data
439 - user.network-config -> network-config
440
441 :param api_version:
442 LXD API version to operated with.
443 :param metadata_keys:
444 Instance of `MetaDataKeys` indicating what keys to fetch.
445 :return:
446 A dict with the following optional keys: meta-data, user-data,
447 vendor-data, network-config, network_mode, devices.
448
449 Below <LXD_SOCKET_API_VERSION> is a dict representation of all raw
450 configuration keys and values provided to the container surfaced by
451 the socket under the /1.0/config/ route.
452 """
453 return _MetaDataReader(api_version=api_version)(
454 metadata_keys=metadata_keys
455 )
456
457
458# Used to match classes to dependencies

Callers 3

_get_dataMethod · 0.70
check_instance_idMethod · 0.70
DataSourceLXD.pyFile · 0.70

Calls 1

_MetaDataReaderClass · 0.85

Tested by

no test coverage detected