File size: 3,799 Bytes
ba1757b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# import boto3
# from azure.identity import DefaultAzureCredential
# from azure.mgmt.compute import ComputeManagementClient
# from google.cloud import compute_v1

# def get_aws_instances():
#     ec2 = boto3.client('ec2')
#     response = ec2.describe_instance_types()
#     return [instance['InstanceType'] for instance in response['InstanceTypes']]

# def get_azure_instances():
#     credential = DefaultAzureCredential()
#     compute_client = ComputeManagementClient(credential, "9591eed5-316a-4f40-8ea2-430e161ee367")
#     vm_sizes = compute_client.virtual_machine_sizes.list(location='eastus')
#     return [size.name for size in vm_sizes]

# def get_gcp_instances():
#     client = compute_v1.InstanceTypesClient()
#     request = compute_v1.ListInstanceTypesRequest(
#         project='mage-test-1234',
#         zone='us-central1-a'
#     )
#     instance_types = client.list(request=request)
#     return [instance.name for instance in instance_types]

# # Call the functions to get instance lists
# aws_instances = get_aws_instances()
# print("AWS Instances:", aws_instances)
# azure_instances = get_azure_instances()
# print("Azure Instances:", azure_instances)
# gcp_instances = get_gcp_instances()



# print("GCP Instances:", gcp_instances)

import boto3
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
from google.cloud import compute_v1
from concurrent.futures import ThreadPoolExecutor
import csv

def get_aws_instances():
    ec2 = boto3.client('ec2')
    response = ec2.describe_instance_types()
    instances = []
    for instance in response['InstanceTypes']:
        instances.append({
            'name': instance['InstanceType'],
            'vCPU': instance['VCpuInfo']['DefaultVCpus'],
            'MemoryMiB': instance['MemoryInfo']['SizeInMiB']
        })
    return instances

def get_azure_instances():
    credential = DefaultAzureCredential()
    compute_client = ComputeManagementClient(credential, "9591eed5-316a-4f40-8ea2-430e161ee367")
    vm_sizes = compute_client.virtual_machine_sizes.list(location='eastus')
    instances = []
    for size in vm_sizes:
        instances.append({
            'name': size.name,
            'vCPU': size.number_of_cores,
            'MemoryMiB': size.memory_in_mb
        })
    return instances

def get_gcp_instances():
    client = compute_v1.MachineTypesClient()
    request = compute_v1.ListMachineTypesRequest(
        project='mage-test-1234',
        zone='us-central1-a'
    )
    instance_types = client.list(request=request)
    instances = []
    for instance in instance_types:
        instances.append({
            'name': instance.name,
            'vCPU': instance.guest_cpus,
            'MemoryMiB': instance.memory_mb
        })
    return instances

def save_instances_to_csv(instances, filename):
    with open(filename, 'w', newline='') as csvfile:
        fieldnames = ['Cloud', 'Name', 'vCPU', 'MemoryMiB']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        
        writer.writeheader()
        for cloud, cloud_instances in instances.items():
            for instance in cloud_instances:
                writer.writerow({
                    'Cloud': cloud,
                    'Name': instance['name'],
                    'vCPU': instance['vCPU'],
                    'MemoryMiB': instance['MemoryMiB']
                })

# Call the functions to get instance lists
aws_instances = get_aws_instances()
azure_instances = get_azure_instances()
gcp_instances = get_gcp_instances()

# Combine all instances into a dictionary
all_instances = {
    'AWS': aws_instances,
    'Azure': azure_instances,
    'GCP': gcp_instances
}

# Save the instances to a CSV file
save_instances_to_csv(all_instances, 'cloud_instances.csv')