Commit b06f5245 by diegolima

Adicionar suporte a google

1 parent b8eca7a1
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
import urllib.request
import math
import json
import sys
if len(sys.argv) == 1:
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)
if PRODUCT_TYPE == 'compute':
FCATALOG = 'examples/gce_pricelist.json'
CATALOG = 'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json'
PRODUCT_FAMILY = 'CP-COMPUTEENGINE-VMIMAGE-'
elif PRODUCT_TYPE == 'database':
FCATALOG = 'examples/gce_pricelist.json'
CATALOG = 'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json'
PRODUCT_FAMILY = 'CP-DB-'
GCE_REGIONS = [
'us-central1', 'us-east1', 'us-east4', 'us-west1',
'europe-west1', 'europe-west2', 'europe-west3',
'asia-east', 'asia-northeast', 'asia-southeast',
'australia-southeast1',
'southamerica-east1',
]
GCE_OS = ['linux', 'win', 'rhel', 'suse', 'suse-sap', 'sql-standard', 'sql-web', 'sql-enterprise']
#with urllib.request.urlopen(CATALOG) as url:
# DATA = json.loads(url.read().decode())
with open(FCATALOG) as url:
DATA = json.load(url)
for product in DATA['gcp_price_list']:
if PRODUCT_FAMILY in product:
name = product[len(PRODUCT_FAMILY):].lower()
memory = DATA['gcp_price_list'][product]["memory"] + ' GB'
cpu = DATA['gcp_price_list'][product]["cores"]
for region in GCE_REGIONS:
for os in GCE_OS:
cost = DATA['gcp_price_list'][product][region]
if os == 'linux':
add = 0
else:
billing_cores = DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["cores"]
billing_cpu = cpu
if billing_cores == 'shared':
billing_cores = 1
if billing_cpu == 'shared':
billing_cpu = 1
#TODO: Make this logic elegant (use cores/shared logic)
if 'win' in os:
if 'f1-micro' in name or 'g1-small' in name:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"])
else:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu)
elif 'rhel' in os:
if float(billing_cpu) <= 4:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"])
else:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"])
elif 'suse-sap' in os:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"])
elif 'suse' in os:
if 'f1-micro' in name or 'g1-small' in name:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"])
else:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu)
elif 'sql' in os:
if 'f1-micro' in name or 'g1-small' in name:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS']['win']["low"])
else:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS']['win']["high"]) * float(billing_cpu)
add = add + float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu)
cost = float(cost)+add
print('google', end=',')
print(name, end=',')
print(cpu, end=',')
print(memory, end=',')
print(cost, end=',')
print(region, end=',')
print(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!