cloud-metadata 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cloud_metadata/__init__.py +176 -0
- cloud_metadata/_http.py +103 -0
- cloud_metadata/cli.py +192 -0
- cloud_metadata/detect.py +187 -0
- cloud_metadata/engine.py +333 -0
- cloud_metadata/errors.py +65 -0
- cloud_metadata/functions.py +211 -0
- cloud_metadata/providers/__init__.py +20 -0
- cloud_metadata/providers/_loader.py +260 -0
- cloud_metadata/providers/_spec.py +194 -0
- cloud_metadata/providers/data/alibaba.json +113 -0
- cloud_metadata/providers/data/amazon.json +97 -0
- cloud_metadata/providers/data/google.json +78 -0
- cloud_metadata/providers/data/index.json +9 -0
- cloud_metadata/providers/data/microsoft.json +77 -0
- cloud_metadata/providers/data/oracle.json +73 -0
- cloud_metadata/py.typed +0 -0
- cloud_metadata/registry.py +125 -0
- cloud_metadata-1.1.0.dist-info/METADATA +379 -0
- cloud_metadata-1.1.0.dist-info/RECORD +23 -0
- cloud_metadata-1.1.0.dist-info/WHEEL +4 -0
- cloud_metadata-1.1.0.dist-info/entry_points.txt +3 -0
- cloud_metadata-1.1.0.dist-info/licenses/LICENSE +618 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "google",
|
|
3
|
+
"notes": [
|
|
4
|
+
"Google Compute Engine metadata server.",
|
|
5
|
+
"Detection values (base URLs, probe path, header) come from provider.py in cloud-registration-engine. The instance document is the recursive JSON view of /computeMetadata/v1/instance/; see https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys",
|
|
6
|
+
"Machine type and zone are full resource paths, so the mappings use the basename and strip_zone_suffix helpers.",
|
|
7
|
+
"Google reports IPv6 addresses in ipv6s of the network interface, for both internal (unique local, fd20::/20) and external (global, 2600:1900::/24) subnets, so the address is classified by range with the ipv6_private and ipv6_public helpers. The JSON shape of ipv6s is not confirmed on a real instance. The helpers accept a string or a list, with or without a prefix length."
|
|
8
|
+
],
|
|
9
|
+
"dmi_match": [
|
|
10
|
+
"google"
|
|
11
|
+
],
|
|
12
|
+
"probes": [
|
|
13
|
+
{
|
|
14
|
+
"path": "/computeMetadata/v1/"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"base_urls": [
|
|
18
|
+
"http://metadata.google.internal",
|
|
19
|
+
"http://169.254.169.254",
|
|
20
|
+
"http://[::ffff:169.254.169.254]"
|
|
21
|
+
],
|
|
22
|
+
"request_headers": {
|
|
23
|
+
"Metadata-Flavor": "Google"
|
|
24
|
+
},
|
|
25
|
+
"documents": [
|
|
26
|
+
{
|
|
27
|
+
"name": "instance",
|
|
28
|
+
"path": "/computeMetadata/v1/instance/?recursive=true",
|
|
29
|
+
"format": "json"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"keys": {
|
|
33
|
+
"instance-id": {
|
|
34
|
+
"document": "instance",
|
|
35
|
+
"expression": "id"
|
|
36
|
+
},
|
|
37
|
+
"instance-type": {
|
|
38
|
+
"document": "instance",
|
|
39
|
+
"expression": "basename(machineType)"
|
|
40
|
+
},
|
|
41
|
+
"region": {
|
|
42
|
+
"document": "instance",
|
|
43
|
+
"expression": "strip_zone_suffix(basename(zone))"
|
|
44
|
+
},
|
|
45
|
+
"zone": {
|
|
46
|
+
"document": "instance",
|
|
47
|
+
"expression": "basename(zone)"
|
|
48
|
+
},
|
|
49
|
+
"private-ipv4": {
|
|
50
|
+
"document": "instance",
|
|
51
|
+
"expression": "networkInterfaces[0].ip"
|
|
52
|
+
},
|
|
53
|
+
"private-ipv6": {
|
|
54
|
+
"document": "instance",
|
|
55
|
+
"expression": "ipv6_private(networkInterfaces[0].ipv6s)"
|
|
56
|
+
},
|
|
57
|
+
"public-ipv4": {
|
|
58
|
+
"document": "instance",
|
|
59
|
+
"expression": "networkInterfaces[0].accessConfigs[0].externalIp"
|
|
60
|
+
},
|
|
61
|
+
"public-ipv6": {
|
|
62
|
+
"document": "instance",
|
|
63
|
+
"expression": "ipv6_public(networkInterfaces[0].ipv6s)"
|
|
64
|
+
},
|
|
65
|
+
"ipv6": {
|
|
66
|
+
"document": "instance",
|
|
67
|
+
"expression": "first_ipv6(networkInterfaces[0].ipv6s)"
|
|
68
|
+
},
|
|
69
|
+
"hostname": {
|
|
70
|
+
"document": "instance",
|
|
71
|
+
"expression": "hostname"
|
|
72
|
+
},
|
|
73
|
+
"image-id": {
|
|
74
|
+
"document": "instance",
|
|
75
|
+
"expression": "image"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "microsoft",
|
|
3
|
+
"notes": [
|
|
4
|
+
"Microsoft Azure Instance Metadata Service.",
|
|
5
|
+
"Detection values (base URLs, probe path, header) come from provider.py in cloud-registration-engine. Key mappings follow https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service",
|
|
6
|
+
"The image-id key is storageProfile.imageReference.id for images that are addressed by resource ID (for example a custom or gallery image). Marketplace images have an empty ID, so image-id is then the publisher:offer:sku:version URN from image_urn(), with exactVersion (API version 2023-07-01 or later) as the version, or version if that is empty. The probe stays on api-version 2021-02-01, which only has to confirm the service."
|
|
7
|
+
],
|
|
8
|
+
"dmi_match": [
|
|
9
|
+
"microsoft",
|
|
10
|
+
"azure"
|
|
11
|
+
],
|
|
12
|
+
"probes": [
|
|
13
|
+
{
|
|
14
|
+
"path": "/metadata/instance?api-version=2021-02-01"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"base_urls": [
|
|
18
|
+
"http://169.254.169.254",
|
|
19
|
+
"http://[::ffff:169.254.169.254]"
|
|
20
|
+
],
|
|
21
|
+
"request_headers": {
|
|
22
|
+
"Metadata": "true"
|
|
23
|
+
},
|
|
24
|
+
"documents": [
|
|
25
|
+
{
|
|
26
|
+
"name": "instance",
|
|
27
|
+
"path": "/metadata/instance?api-version=2025-04-07",
|
|
28
|
+
"format": "json"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"keys": {
|
|
32
|
+
"instance-id": {
|
|
33
|
+
"document": "instance",
|
|
34
|
+
"expression": "compute.vmId"
|
|
35
|
+
},
|
|
36
|
+
"instance-type": {
|
|
37
|
+
"document": "instance",
|
|
38
|
+
"expression": "compute.vmSize"
|
|
39
|
+
},
|
|
40
|
+
"region": {
|
|
41
|
+
"document": "instance",
|
|
42
|
+
"expression": "compute.location"
|
|
43
|
+
},
|
|
44
|
+
"zone": {
|
|
45
|
+
"document": "instance",
|
|
46
|
+
"expression": "compute.zone"
|
|
47
|
+
},
|
|
48
|
+
"private-ipv4": {
|
|
49
|
+
"document": "instance",
|
|
50
|
+
"expression": "network.interface[0].ipv4.ipAddress[0].privateIpAddress"
|
|
51
|
+
},
|
|
52
|
+
"private-ipv6": {
|
|
53
|
+
"document": "instance",
|
|
54
|
+
"expression": "network.interface[0].ipv6.ipAddress[0].privateIpAddress"
|
|
55
|
+
},
|
|
56
|
+
"public-ipv4": {
|
|
57
|
+
"document": "instance",
|
|
58
|
+
"expression": "network.interface[0].ipv4.ipAddress[0].publicIpAddress"
|
|
59
|
+
},
|
|
60
|
+
"public-ipv6": {
|
|
61
|
+
"document": "instance",
|
|
62
|
+
"expression": "network.interface[0].ipv6.ipAddress[0].publicIpAddress"
|
|
63
|
+
},
|
|
64
|
+
"ipv6": {
|
|
65
|
+
"document": "instance",
|
|
66
|
+
"expression": "first_ipv6([network.interface[0].ipv6.ipAddress[0].privateIpAddress, network.interface[0].ipv6.ipAddress[0].publicIpAddress])"
|
|
67
|
+
},
|
|
68
|
+
"hostname": {
|
|
69
|
+
"document": "instance",
|
|
70
|
+
"expression": "compute.osProfile.computerName"
|
|
71
|
+
},
|
|
72
|
+
"image-id": {
|
|
73
|
+
"document": "instance",
|
|
74
|
+
"expression": "compute.storageProfile.imageReference.id || image_urn(compute.storageProfile.imageReference)"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "oracle",
|
|
3
|
+
"notes": [
|
|
4
|
+
"Oracle Cloud Infrastructure instance metadata service (IMDS v2).",
|
|
5
|
+
"Endpoints, header and field names follow https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/gettingmetadata.htm The instance and its VNICs are separate documents. IPv4 and dual stack VNICs use 169.254.169.254; IPv6-only VNICs use [fd00:c1::a9fe:a9fe].",
|
|
6
|
+
"OCI does not expose a public IP address through IMDS, so public-ipv4 and public-ipv6 are not mapped and are unavailable. The VNIC's ipv6Addresses are documented as private IPv6 addresses, so they map to private-ipv6. No external service is called to work around the missing public addresses."
|
|
7
|
+
],
|
|
8
|
+
"dmi_match": [
|
|
9
|
+
"oraclecloud"
|
|
10
|
+
],
|
|
11
|
+
"probes": [
|
|
12
|
+
{
|
|
13
|
+
"path": "/opc/v2/instance/"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"base_urls": [
|
|
17
|
+
"http://169.254.169.254",
|
|
18
|
+
"http://[fd00:c1::a9fe:a9fe]"
|
|
19
|
+
],
|
|
20
|
+
"request_headers": {
|
|
21
|
+
"Authorization": "Bearer Oracle"
|
|
22
|
+
},
|
|
23
|
+
"documents": [
|
|
24
|
+
{
|
|
25
|
+
"name": "instance",
|
|
26
|
+
"path": "/opc/v2/instance/",
|
|
27
|
+
"format": "json"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "vnics",
|
|
31
|
+
"path": "/opc/v2/vnics/",
|
|
32
|
+
"format": "json"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"keys": {
|
|
36
|
+
"instance-id": {
|
|
37
|
+
"document": "instance",
|
|
38
|
+
"expression": "id"
|
|
39
|
+
},
|
|
40
|
+
"instance-type": {
|
|
41
|
+
"document": "instance",
|
|
42
|
+
"expression": "shape"
|
|
43
|
+
},
|
|
44
|
+
"region": {
|
|
45
|
+
"document": "instance",
|
|
46
|
+
"expression": "canonicalRegionName"
|
|
47
|
+
},
|
|
48
|
+
"zone": {
|
|
49
|
+
"document": "instance",
|
|
50
|
+
"expression": "availabilityDomain"
|
|
51
|
+
},
|
|
52
|
+
"private-ipv4": {
|
|
53
|
+
"document": "vnics",
|
|
54
|
+
"expression": "[0].privateIp"
|
|
55
|
+
},
|
|
56
|
+
"private-ipv6": {
|
|
57
|
+
"document": "vnics",
|
|
58
|
+
"expression": "[0].ipv6Addresses[0]"
|
|
59
|
+
},
|
|
60
|
+
"ipv6": {
|
|
61
|
+
"document": "vnics",
|
|
62
|
+
"expression": "[0].ipv6Addresses[0]"
|
|
63
|
+
},
|
|
64
|
+
"hostname": {
|
|
65
|
+
"document": "instance",
|
|
66
|
+
"expression": "hostname"
|
|
67
|
+
},
|
|
68
|
+
"image-id": {
|
|
69
|
+
"document": "instance",
|
|
70
|
+
"expression": "image"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
cloud_metadata/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Copyright (c) 2026 SUSE LLC. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# This file is part of cloud-metadata. cloud-metadata provides one command
|
|
4
|
+
# and one Python API that return the same standard instance metadata on every
|
|
5
|
+
# supported public cloud.
|
|
6
|
+
#
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
#
|
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
# GNU General Public License for more details.
|
|
16
|
+
#
|
|
17
|
+
# You should have received a copy of the GNU General Public License
|
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
|
|
20
|
+
"""The ordered registry of cloud providers.
|
|
21
|
+
|
|
22
|
+
Built-in providers are registered at import time in a fixed order. Providers
|
|
23
|
+
registered later follow in registration order.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from collections.abc import Callable
|
|
27
|
+
|
|
28
|
+
from cloud_metadata.errors import ProviderNotDetected
|
|
29
|
+
from cloud_metadata.providers._spec import ProviderSpec
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"ProviderSpec",
|
|
33
|
+
"add_change_callback",
|
|
34
|
+
"get_spec",
|
|
35
|
+
"names",
|
|
36
|
+
"register",
|
|
37
|
+
"specs",
|
|
38
|
+
"unregister",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
# Insertion ordered: built-in providers first, then runtime registrations.
|
|
42
|
+
_registry: dict[str, ProviderSpec] = {}
|
|
43
|
+
_callbacks: list[Callable[[], None]] = []
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def add_change_callback(callback: Callable[[], None]) -> None:
|
|
47
|
+
"""Call ``callback`` whenever a provider is registered or removed.
|
|
48
|
+
|
|
49
|
+
Modules that cache provider data use this to drop their caches without the
|
|
50
|
+
registry importing them.
|
|
51
|
+
"""
|
|
52
|
+
if callback not in _callbacks:
|
|
53
|
+
_callbacks.append(callback)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _notify() -> None:
|
|
57
|
+
for callback in _callbacks:
|
|
58
|
+
callback()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def register(spec: ProviderSpec, *, replace: bool = False) -> None:
|
|
62
|
+
"""Add a provider.
|
|
63
|
+
|
|
64
|
+
A replaced provider keeps its position in the registry.
|
|
65
|
+
|
|
66
|
+
Raises:
|
|
67
|
+
TypeError: If ``spec`` is not a ``ProviderSpec``.
|
|
68
|
+
ValueError: If the name is already registered and ``replace`` is false.
|
|
69
|
+
"""
|
|
70
|
+
if not isinstance(spec, ProviderSpec):
|
|
71
|
+
msg = f"spec: expected ProviderSpec, got {type(spec).__name__}"
|
|
72
|
+
raise TypeError(msg)
|
|
73
|
+
if spec.name in _registry and not replace:
|
|
74
|
+
msg = f"name: provider {spec.name!r} is already registered"
|
|
75
|
+
raise ValueError(msg)
|
|
76
|
+
_registry[spec.name] = spec
|
|
77
|
+
_notify()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def unregister(name: str) -> None:
|
|
81
|
+
"""Remove a provider.
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
ProviderNotDetected: If no provider has that name.
|
|
85
|
+
"""
|
|
86
|
+
if name not in _registry:
|
|
87
|
+
msg = f"unknown provider {name!r}"
|
|
88
|
+
raise ProviderNotDetected(msg)
|
|
89
|
+
del _registry[name]
|
|
90
|
+
_notify()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def names() -> tuple[str, ...]:
|
|
94
|
+
"""Return the registered provider names in registry order."""
|
|
95
|
+
return tuple(_registry)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def specs() -> tuple[ProviderSpec, ...]:
|
|
99
|
+
"""Return the registered provider specs in registry order."""
|
|
100
|
+
return tuple(_registry.values())
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def get_spec(name: str) -> ProviderSpec:
|
|
104
|
+
"""Return the spec registered under ``name``.
|
|
105
|
+
|
|
106
|
+
Raises:
|
|
107
|
+
ProviderNotDetected: If no provider has that name.
|
|
108
|
+
"""
|
|
109
|
+
try:
|
|
110
|
+
return _registry[name]
|
|
111
|
+
except KeyError:
|
|
112
|
+
known = ", ".join(_registry) or "none"
|
|
113
|
+
msg = f"unknown provider {name!r} (registered: {known})"
|
|
114
|
+
raise ProviderNotDetected(msg) from None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _register_builtins() -> None:
|
|
118
|
+
"""Register the built-in providers, in the order of the data index."""
|
|
119
|
+
from cloud_metadata.providers._loader import load_builtins # noqa: PLC0415
|
|
120
|
+
|
|
121
|
+
for spec in load_builtins():
|
|
122
|
+
register(spec)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
_register_builtins()
|