-
Notifications
You must be signed in to change notification settings - Fork 1
/
splitVMData.py
executable file
·86 lines (67 loc) · 3.39 KB
/
splitVMData.py
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
#!/usr/bin/python3
import requests
import json
import datetime
import re
import os
print('###############################################################################')
print('###############################################################################')
outputFolder = 'Data' + os.path.sep
with open('AzureVMData.js') as vmsDataFile:
vmsData = json.load(vmsDataFile)
priceData = {}
for vmid, vmData in vmsData['offers'].items():
if 'prices' in vmData:
for region, prices in vmData['prices'].items():
if not region in priceData:
priceData[region] = {}
priceData[region][vmid] = prices
vmData.pop('prices')
# if 'baseOfferSlug' in vmData:
# print(vmid + ':' + vmData['baseOfferSlug'])
# else:
# print(vmid )
vmsData['refRegionPricesFiles'] = {}
for region, rData in priceData.items():
regionFilename = outputFolder + 'AzureVMPrices_' + region + '.js'
vmsData['refRegionPricesFiles'][region] = regionFilename
with open(regionFilename, 'w') as outfile:
json.dump(rData, outfile, indent = 1, sort_keys = True)
# vrite vmsData withoutPrices
with open(outputFolder + 'AzureVMDataWOPrices.js', 'w') as outfile:
json.dump(vmsData, outfile, indent = 1, sort_keys = True)
# print('###############################################################################')
# ### Debug offers lists and slug
# vmsData = { 'currencyData': {}, 'offers': {},
# 'refDatacenter': [], 'refOffers': [], 'refCores': [], 'refRam': [],
# 'sources': { 'docs': {}, 'prices': {} }, 'updateDateUtc': datetime.datetime.utcnow().isoformat() }
# def getOfferFromPricing (url, vmsData, priceSource):
# r = requests.get(url)
# data = r.json()
# vmsData['sources']['prices'][priceSource] = url
# offers = vmsData['offers']
# refDatacenter = vmsData['refDatacenter']
# refOffers = vmsData['refOffers']
# for offer in data['offers']:
# # if offer == "transactions":
# # continue
# o = data['offers'][offer]
# parts = offer.split("-")
# index = 2
# if len(parts) >= 5 and ( parts[-2] == 'v2' or parts[-2] == 'v3' ):
# # examples : windows-ds11-1-v2-standard ; rhel-sap-hana-ha-ds11-1-v2-standard ; ubuntu-advantage-advanced-e4-2s-v3-standard
# index = 4
# elif len(parts) >= 4 and re.match(r'^\d+(ms)?$', parts[-2]):
# # examples : windows-m16ms-standard : rhel-sap-hana-ha-m16ms-standard ; sql-standard-m64-16ms-standard
# index = 3
# offerid = "-".join(parts[0:-index])
# vmsize = "-".join(parts[-index:-1]).capitalize()
# tier = parts[-1].capitalize()
# slug = ''
# if 'baseOfferSlug' in o:
# slug = o['baseOfferSlug']
# # print(priceSource + '\t' + offer + '\t' + offerid + '\t' + slug + '\t' + str(index))
# print(priceSource + '\t' + str(index) + '\t' + offer + '\t' + offerid + '\t' + vmsize + '\t' + tier)
# getOfferFromPricing('https://azure.microsoft.com/api/v2/pricing/virtual-machines-software/calculator/?culture=en-us&discount=mosp', vmsData, 'software')
# getOfferFromPricing('https://azure.microsoft.com/api/v2/pricing/virtual-machines-ahb/calculator/?culture=en-us&discount=mosp', vmsData, 'ahb')
# getOfferFromPricing('https://azure.microsoft.com/api/v2/pricing/virtual-machines-base/calculator/?culture=en-us&discount=mosp', vmsData, 'base')