Skip to content

Commit a9704ac

Browse files
committed
Add initial support for Azure VM data
1 parent f9eafba commit a9704ac

File tree

10 files changed

+842371
-10
lines changed

10 files changed

+842371
-10
lines changed

Makefile

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EC2_INSTANCES_URL := "https://instances.vantage.sh/instances.json"
55
RDS_INSTANCES_URL := "https://instances.vantage.sh/rds/instances.json"
66
ELASTICACHE_INSTANCES_URL := "https://instances.vantage.sh/cache/instances.json"
77
OPENSEARCH_INSTANCES_URL := "https://instances.vantage.sh/opensearch/instances.json"
8+
AZURE_INSTANCES_URL := "https://instances.vantage.sh/azure/instances.json"
89

910
DEPS := "curl git jq"
1011

@@ -21,15 +22,20 @@ check_deps: ## Verify the system has all depende
2122

2223
data/instances.json:
2324
@mkdir -p data
24-
@curl $(EC2_INSTANCES_URL) -o data/instances.json
25-
@curl $(RDS_INSTANCES_URL) -o data/rds-instances.json
26-
@curl $(ELASTICACHE_INSTANCES_URL) -o data/elasticache-instances.json
27-
@curl $(OPENSEARCH_INSTANCES_URL) -o data/opensearch-instances.json
25+
@curl -s --compressed $(EC2_INSTANCES_URL) -o data/instances.json
26+
@curl -s --compressed $(RDS_INSTANCES_URL) -o data/rds-instances.json
27+
@curl -s --compressed $(ELASTICACHE_INSTANCES_URL) -o data/elasticache-instances.json
28+
@curl -s --compressed $(OPENSEARCH_INSTANCES_URL) -o data/opensearch-instances.json
29+
@curl -s --compressed $(AZURE_INSTANCES_URL) -o data/azure-instances.json
2830

2931
run-example:
3032
@go get ./...
3133
@go run examples/instances/instances.go | sort | tee generated_instances_data.txt | less -S
3234

35+
run-azure-example:
36+
@go get ./...
37+
@go run examples/azure/azure-vm.go | tee generated_azure_instances_data.txt | less -S
38+
3339
clean:
3440
@rm -rf data
3541
.PHONY: clean
@@ -40,7 +46,9 @@ update-data: clean data/instances.json
4046
update-data-from-local-file: all
4147
.PHONY: update-data-from-local-file
4248

43-
4449
test:
4550
@go test
4651
.PHONY: test
52+
53+
azure: data/instances.json run-azure-example
54+
.PHONY: azure

README.md

+65-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
[![Go Report Card](https://goreportcard.com/badge/github.com/LeanerCloud/ec2-instances-info)](https://goreportcard.com/report/github.com/LeanerCloud/ec2-instances-info)
55
[![GoDoc](https://godoc.org/github.com/LeanerCloud/ec2-instances-info?status.svg)](http://godoc.org/github.com/LeanerCloud/ec2-instances-info)
66

7-
Golang library providing specs and pricing information about AWS resources such as EC2 instances, RDS databases, ElastiCache and OpenSearch clusters.
7+
Golang library providing specs and pricing information about cloud resources such as:
8+
9+
- AWS EC2 instances
10+
- AWS RDS databases
11+
- AWS ElastiCache clusters
12+
- AWS OpenSearch clusters
13+
- Azure VM instances
814

915
It is based on the data that is also powering the comprehensive
1016
[www.ec2instances.info](http://www.ec2instances.info) instance comparison
@@ -34,7 +40,9 @@ go get -u github.com/LeanerCloud/ec2-instances-info/...
3440

3541
## Usage
3642

37-
### One-off usage, with static data
43+
### AWS EC2 Usage
44+
45+
#### One-off usage, with static data
3846

3947
```golang
4048
import "github.com/LeanerCloud/ec2-instances-info"
@@ -49,7 +57,7 @@ for _, i := range *data {
4957

5058
See the examples directory for a working code example.
5159

52-
### One-off usage, with updated instance type data
60+
#### One-off usage, with updated instance type data
5361

5462
```golang
5563
import "github.com/LeanerCloud/ec2-instances-info"
@@ -69,7 +77,7 @@ for _, i := range *data {
6977
}
7078
```
7179

72-
### Continuous usage, with instance type data updated every 2 days
80+
#### Continuous usage, with instance type data updated every 2 days
7381

7482
```golang
7583
import "github.com/LeanerCloud/ec2-instances-info"
@@ -85,6 +93,57 @@ for _, i := range *data {
8593
}
8694
```
8795

96+
### Azure VM Usage
97+
98+
#### Basic usage, with static data
99+
100+
```golang
101+
import "github.com/LeanerCloud/ec2-instances-info"
102+
103+
data, err := ec2instancesinfo.AzureData() // only needed once
104+
105+
// This would print all the available Azure VM instance type names:
106+
for _, i := range *data {
107+
fmt.Println("Azure VM instance type:", i.InstanceType)
108+
}
109+
```
110+
111+
#### One-off usage, with updated Azure VM data
112+
113+
```golang
114+
import "github.com/LeanerCloud/ec2-instances-info"
115+
116+
key := "API_KEY" // API keys are available upon demand from [email protected]
117+
118+
err := ec2instancesinfo.UpdateAzureData(nil, &key)
119+
if err != nil {
120+
fmt.Println("Couldn't update Azure VM data, reverting to static compile-time data", err.Error())
121+
}
122+
123+
data, err := ec2instancesinfo.AzureData() // needs to be called once after data updates
124+
125+
// This would print all the available Azure VM instance type names:
126+
for _, i := range *data {
127+
fmt.Println("Azure VM instance type:", i.InstanceType)
128+
}
129+
```
130+
131+
#### Continuous usage, with Azure VM data updated every 2 days
132+
133+
```golang
134+
import "github.com/LeanerCloud/ec2-instances-info"
135+
136+
key := "API_KEY"
137+
go ec2instancesinfo.AzureUpdater(2, nil, &key); // use 0 or negative values for weekly updates
138+
139+
data, err := ec2instancesinfo.AzureData() // only needed once
140+
141+
// This would print all the available Azure VM instance type names:
142+
for _, i := range *data {
143+
fmt.Println("Azure VM instance type:", i.InstanceType)
144+
}
145+
```
146+
88147
## Contributing
89148

90149
Pull requests and feedback are welcome.
@@ -97,4 +156,5 @@ The data can be updated for new instance type coverage by running `make`.
97156

98157
- Click on the `Terminal` then `New Terminal` in the top menu
99158
- In the terminal run `cd ~/cloudshell_open/ec2-instances-info/examples/instances/`
100-
- `go run .` will run the example code.
159+
- `go run .` will run the example EC2 code.
160+
- For Azure VM data: `cd ~/cloudshell_open/ec2-instances-info/examples/azure/` and `go run .`

azure_vm.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// azure_vm.go with updated fields
2+
package ec2instancesinfo
3+
4+
// AzureInstanceData represents data about a specific Azure VM instance type
5+
type AzureInstanceData struct {
6+
ACU int `json:"ACU"`
7+
GPU string `json:"GPU"`
8+
AcceleratedNetworking bool `json:"accelerated_networking"`
9+
Arch []string `json:"arch"`
10+
AvailabilityZones map[string]interface{} `json:"availability_zones"`
11+
CachedDisk int `json:"cached_disk"`
12+
CapacitySupport bool `json:"capacity_support"`
13+
Category string `json:"category"`
14+
Confidential interface{} `json:"confidential"` // Can be false or "SNP"
15+
Encryption bool `json:"encryption"`
16+
Family string `json:"family"`
17+
Hibernation interface{} `json:"hibernation"`
18+
HypervGenerations string `json:"hyperv_generations"`
19+
InstanceType string `json:"instance_type"`
20+
IOPS interface{} `json:"iops"`
21+
LowPriority bool `json:"low_priority"`
22+
Memory float64 `json:"memory"`
23+
MemoryMaintenance bool `json:"memory_maintenance"`
24+
PremiumIO bool `json:"premium_io"`
25+
PrettyName string `json:"pretty_name"`
26+
PrettyNameAzure string `json:"pretty_name_azure"`
27+
Pricing map[string]AzurePricing `json:"pricing"`
28+
RDMA bool `json:"rdma"`
29+
ReadIO int `json:"read_io"`
30+
Size int `json:"size"`
31+
Storage *AzureStorage `json:"storage"`
32+
TrustedLaunch interface{} `json:"trusted_launch"`
33+
UltraSSD bool `json:"ultra_ssd"`
34+
UncachedDisk int `json:"uncached_disk"`
35+
UncachedDiskIO int `json:"uncached_disk_io"`
36+
VCPU int `json:"vcpu"`
37+
VCPUsAvailable int `json:"vcpus_available"`
38+
VCPUsPerCore int `json:"vcpus_percore"`
39+
VMDeployment string `json:"vm_deployment"`
40+
WriteIO int `json:"write_io"`
41+
}
42+
43+
// AzureStorage contains Azure VM storage information
44+
type AzureStorage struct {
45+
Devices interface{} `json:"devices"`
46+
MaxWriteDisks interface{} `json:"max_write_disks"`
47+
NVMeSSD interface{} `json:"nvme_ssd"` // Can be string with numeric value or false
48+
Size int64 `json:"size"`
49+
}
50+
51+
// AzurePricing contains pricing information for a region
52+
type AzurePricing struct {
53+
Linux AzureOSPricing `json:"linux"`
54+
Windows AzureOSPricing `json:"windows"`
55+
}
56+
57+
// AzureOSPricing contains pricing details for a specific OS
58+
type AzureOSPricing struct {
59+
Basic float64 `json:"basic"`
60+
BasicSpot float64 `json:"basic-spot"`
61+
LowPriority float64 `json:"lowpriority,omitempty"`
62+
OnDemand float64 `json:"ondemand"`
63+
Reserved map[string]interface{} `json:"reserved"`
64+
SpotMin float64 `json:"spot_min"`
65+
// Windows specific
66+
HybridBenefit float64 `json:"hybridbenefit,omitempty"`
67+
}
68+
69+
// Global variables for Azure VM data
70+
var (
71+
azureDataBody []byte
72+
azureBackupDataBody []byte
73+
azureStaticDataBody = []byte(`[]`) // Will be replaced with actual embedded data
74+
azureInstancesData *[]AzureInstanceData
75+
)

0 commit comments

Comments
 (0)