Commit a42411b4 by diegolima

Corrigir parse de banco de dados

1 parent 97ea0b5b
Showing with 59 additions and 49 deletions
......@@ -15,14 +15,16 @@ 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-'
DB_PRODUCT_FAMILY = 'CP-DB-'
if PRODUCT_TYPE == 'compute':
FCATALOG = 'examples/gce_pricelist.json'
CATALOG = 'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json'
PRODUCT_FAMILY = 'CP-COMPUTEENGINE-VMIMAGE-'
PRODUCT_FAMILY = COMPUTE_PRODUCT_FAMILY
elif PRODUCT_TYPE == 'database':
FCATALOG = 'examples/gce_pricelist.json'
CATALOG = 'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json'
PRODUCT_FAMILY = 'CP-DB-'
PRODUCT_FAMILY = DB_PRODUCT_FAMILY
GCE_REGIONS = [
'us-central1', 'us-east1', 'us-east4', 'us-west1',
......@@ -39,52 +41,59 @@ GCE_OS = ['linux', 'win', 'rhel', 'suse', 'suse-sap', 'sql-standard', 'sql-web',
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:
if 'CUSTOM-VM-' not in product:
if PRODUCT_FAMILY in product:
name = product[len(PRODUCT_FAMILY):].lower()
if PRODUCT_FAMILY == DB_PRODUCT_FAMILY:
match = COMPUTE_PRODUCT_FAMILY+name.upper()
match = match.replace('PG-','')
else:
match = product
memory = DATA['gcp_price_list'][match]["memory"] + ' GB'
cpu = DATA['gcp_price_list'][match]["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-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)
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!