-
Notifications
You must be signed in to change notification settings - Fork 0
/
2Q
43 lines (31 loc) · 1.05 KB
/
2Q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
import platform
def get_azure_instance_metadata():
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
subscription_id = 'YOUR_AZURE_SUBSCRIPTION_ID'
compute_client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id=subscription_id
)
vm_list = list(compute_client.virtual_machines.list_all())
if vm_list:
vm = vm_list[0].as_dict()
return vm
return None
def main():
cloud_provider = platform.system().lower()
if cloud_provider == 'linux':
cloud_provider = platform.linux_distribution()[0].lower()
if cloud_provider == 'azure':
instance_metadata = get_azure_instance_metadata()
else:
print("Unsupported cloud provider.")
return
if instance_metadata:
json_output = json.dumps(instance_metadata, indent=2)
print(json_output)
else:
print(f"No instance metadata found on {cloud_provider}.")
if _name_ == "_main_":
main()