Commit 74c0691f by Diego Lima

Merge branch 'master' of git.adtsys.com.br:diego.lima/aws-price-parser

2 parents 7ce9ea44 10d0f4bf
.vscode .vscode
.vscode/settings.json
{ {
"python.pythonPath": "/usr/bin/python3" "python.pythonPath": "C:\\Users\\diego\\AppData\\Local\\Programs\\Python\\Python36\\python.exe",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
} }
\ No newline at end of file
...@@ -2,17 +2,7 @@ import urllib.request ...@@ -2,17 +2,7 @@ import urllib.request
import json import json
import sys import sys
if len(sys.argv) == 1: PRODUCT_TYPE = sys.argv[1] if len(sys.argv) == 2 else 'none'
print('You need to specify a product type', end='\n\n')
print('Supported product types are:')
print('- compute')
print('- database')
exit(1)
PRODUCT_TYPE = sys.argv[1]
if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'):
print('Product type needs to be either computer or database!')
exit(1)
TERM_ONDEMAND = 'JRTCKXETXF' #Ondemand. TODO: Find out where to get this from TERM_ONDEMAND = 'JRTCKXETXF' #Ondemand. TODO: Find out where to get this from
HOURLY_DIMENSION = '6YS6EN2CT7' #Tier1. TODO: Find out where to get this from HOURLY_DIMENSION = '6YS6EN2CT7' #Tier1. TODO: Find out where to get this from
...@@ -45,11 +35,14 @@ elif PRODUCT_TYPE == 'database': ...@@ -45,11 +35,14 @@ elif PRODUCT_TYPE == 'database':
FCATALOG = 'examples/aws_rds.json' FCATALOG = 'examples/aws_rds.json'
CATALOG = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json' CATALOG = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json'
PRODUCT_FAMILY = 'Database Instance' PRODUCT_FAMILY = 'Database Instance'
else:
print("Product type not supported")
sys.exit(1)
with urllib.request.urlopen(CATALOG) as url: #with urllib.request.urlopen(CATALOG) as url:
DATA = json.loads(url.read().decode()) # DATA = json.loads(url.read().decode())
# with open(FCATALOG) as url: with open(FCATALOG) as url:
# DATA = json.load(url) DATA = json.load(url)
for product in DATA["products"]: for product in DATA["products"]:
if DATA['products'][product].get('productFamily') == PRODUCT_FAMILY: if DATA['products'][product].get('productFamily') == PRODUCT_FAMILY:
sku = DATA['products'][product].get('sku') sku = DATA['products'][product].get('sku')
...@@ -69,10 +62,10 @@ with urllib.request.urlopen(CATALOG) as url: ...@@ -69,10 +62,10 @@ with urllib.request.urlopen(CATALOG) as url:
else: else:
sharedcores = 'nonshared' sharedcores = 'nonshared'
if DATA['products'][product]['attributes']['tenancy'] == 'Shared': if DATA['products'][product]['attributes']['tenancy'] == 'Shared':
print('aws,%s,%s,%s,%s,%s,%s,%s' % (name, cpu, memory, cost, region, os, sharedcores)) print('aws,%s,%s,%s,%s,%s,%s,%s,%s' % (name, cpu, memory, cost, region, os, sharedcores, sku))
elif PRODUCT_TYPE == 'database': elif PRODUCT_TYPE == 'database':
os = DATA['products'][product]['attributes']['databaseEngine'] os = DATA['products'][product]['attributes']['databaseEngine']
edition = DATA['products'][product]['attributes'].get('databaseEdition') edition = DATA['products'][product]['attributes'].get('databaseEdition')
licensemodel = DATA['products'][product]['attributes']['licenseModel'] licensemodel = DATA['products'][product]['attributes']['licenseModel']
deployment = DATA['products'][product]['attributes']['deploymentOption'] deployment = DATA['products'][product]['attributes']['deploymentOption']
print('aws,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (name, cpu, memory, cost, region, os, edition, licensemodel, deployment)) print('aws,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (name, cpu, memory, cost, region, os, edition, licensemodel, deployment, sku))
...@@ -2,7 +2,8 @@ import urllib.request ...@@ -2,7 +2,8 @@ import urllib.request
import json import json
import sys import sys
PRODUCT_TYPE = sys.argv[1] PRODUCT_TYPE = sys.argv[1] if len(sys.argv) == 2 else 'none'
if PRODUCT_TYPE == 'compute': if PRODUCT_TYPE == 'compute':
FCATALOG = 'examples/azure.json' FCATALOG = 'examples/azure.json'
CATALOG = 'https://azure.microsoft.com/api/v2/pricing/virtual-machines-base/calculator/?culture=pt-br&discount=mosp' CATALOG = 'https://azure.microsoft.com/api/v2/pricing/virtual-machines-base/calculator/?culture=pt-br&discount=mosp'
...@@ -48,4 +49,5 @@ with urllib.request.urlopen(CATALOG) as url: ...@@ -48,4 +49,5 @@ with urllib.request.urlopen(CATALOG) as url:
for region in REGIONS: for region in REGIONS:
cost = prod["prices"].get(region) cost = prod["prices"].get(region)
if cost: if cost:
cost = cost['value']
print("azure,%s,%s,%s,%s,%s,%s,%s" %(name, cores, memory, cost, region, os, sharedcores)) print("azure,%s,%s,%s,%s,%s,%s,%s" %(name, cores, memory, cost, region, os, sharedcores))
...@@ -3,17 +3,9 @@ import json ...@@ -3,17 +3,9 @@ import json
import sys import sys
import urllib.request import urllib.request
if len(sys.argv) == 1:
print('You need to specify a product type')
print('Supported product types are:')
print('- compute')
print('- database')
exit(1)
PRODUCT_TYPE = sys.argv[1] PRODUCT_TYPE = sys.argv[1] if len(sys.argv) == 2 else 'none'
if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'):
print('Product type needs to be either computer or database!')
exit(1)
COMPUTE_PRODUCT_FAMILY = 'CP-COMPUTEENGINE-VMIMAGE-' COMPUTE_PRODUCT_FAMILY = 'CP-COMPUTEENGINE-VMIMAGE-'
DB_PRODUCT_FAMILY = 'CP-DB-' DB_PRODUCT_FAMILY = 'CP-DB-'
if PRODUCT_TYPE == 'compute': if PRODUCT_TYPE == 'compute':
...@@ -24,6 +16,9 @@ elif PRODUCT_TYPE == 'database': ...@@ -24,6 +16,9 @@ elif PRODUCT_TYPE == 'database':
FCATALOG = 'examples/gce_pricelist.json' FCATALOG = 'examples/gce_pricelist.json'
CATALOG = 'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json' CATALOG = 'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json'
PRODUCT_FAMILY = DB_PRODUCT_FAMILY PRODUCT_FAMILY = DB_PRODUCT_FAMILY
else:
print("Product type not supported")
sys.exit(1)
GCE_REGIONS = [ GCE_REGIONS = [
'us-central1', 'us-east1', 'us-east4', 'us-west1', 'us-central1', 'us-east1', 'us-east4', 'us-west1',
...@@ -34,11 +29,10 @@ GCE_REGIONS = [ ...@@ -34,11 +29,10 @@ GCE_REGIONS = [
] ]
GCE_OS = ['linux', 'win', 'rhel', 'suse', 'suse-sap', 'sql-standard', 'sql-web', 'sql-enterprise'] GCE_OS = ['linux', 'win', 'rhel', 'suse', 'suse-sap', 'sql-standard', 'sql-web', 'sql-enterprise']
#TODO: Download & decompress the gzipped current catalog #with urllib.request.urlopen(CATALOG) as url:
with urllib.request.urlopen(CATALOG) as url: # DATA = json.loads(url.read().decode())
DATA = json.loads(url.read().decode()) with open(FCATALOG) as url:
#with open(FCATALOG) as url: DATA = json.load(url)
# DATA = json.load(url)
for product in DATA['gcp_price_list']: for product in DATA['gcp_price_list']:
if 'CUSTOM-VM-' not in product: if 'CUSTOM-VM-' not in product:
if PRODUCT_FAMILY in product: # Discard non-product entries if PRODUCT_FAMILY in product: # Discard non-product entries
...@@ -103,4 +97,5 @@ with urllib.request.urlopen(CATALOG) as url: ...@@ -103,4 +97,5 @@ with urllib.request.urlopen(CATALOG) as url:
realcpu = cpu realcpu = cpu
print('google,%s,%s,%s,%s,%s,%s,%s' % (name, realcpu, memory, cost, region, os, sharedcores)) print('google,%s,%s,%s,%s,%s,%s,%s' % (name, realcpu, memory, cost, region, os, sharedcores))
else: else:
realname = realname.replace('pg-','')
print('google,%s,%s,%s,%s,%s,%s' % (realname, cpu, memory, cost, region, os)) print('google,%s,%s,%s,%s,%s,%s' % (realname, cpu, memory, cost, region, os))
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!