Commit d2520957 by diegolima

Corrigir logica do parser do google

1 parent 6d42c356
Showing with 46 additions and 46 deletions
...@@ -3,6 +3,7 @@ import math ...@@ -3,6 +3,7 @@ import math
import json import json
import sys import sys
if len(sys.argv) == 1: if len(sys.argv) == 1:
print('You need to specify a product type', end='\n\n') print('You need to specify a product type', end='\n\n')
print('Supported product types are:') print('Supported product types are:')
...@@ -14,7 +15,6 @@ PRODUCT_TYPE = sys.argv[1] ...@@ -14,7 +15,6 @@ PRODUCT_TYPE = sys.argv[1]
if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'): if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'):
print('Product type needs to be either computer or database!') print('Product type needs to be either computer or database!')
exit(1) 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':
...@@ -42,58 +42,58 @@ with open(FCATALOG) as url: ...@@ -42,58 +42,58 @@ 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: if PRODUCT_FAMILY in product: # Discard non-product entries
name = product[len(PRODUCT_FAMILY):].lower() name = product[len(PRODUCT_FAMILY):].lower()
if PRODUCT_FAMILY == DB_PRODUCT_FAMILY: if PRODUCT_FAMILY == DB_PRODUCT_FAMILY:
match = COMPUTE_PRODUCT_FAMILY+name.upper() match = COMPUTE_PRODUCT_FAMILY+name.upper()
match = match.replace('PG-','') match = match.replace('PG-','')
if 'PG-' in name.upper():
os = 'postgresql'
else:
os = 'mysql'
else: else:
match = product match = product
memory = DATA['gcp_price_list'][match]["memory"] + ' GB' memory = DATA['gcp_price_list'][match]["memory"] + ' GB'
cpu = DATA['gcp_price_list'][match]["cores"] cpu = DATA['gcp_price_list'][match]["cores"]
for region in GCE_REGIONS: for region in GCE_REGIONS:
for os in GCE_OS: cost = DATA['gcp_price_list'][product][region]
if PRODUCT_FAMILY == COMPUTE_PRODUCT_FAMILY:
cost = DATA['gcp_price_list'][product][region] cost = DATA['gcp_price_list'][product][region]
if os == 'linux': for os in GCE_OS:
add = 0 if os == 'linux':
else: add = 0
billing_cores = DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["cores"] else:
billing_cpu = cpu billing_cores = DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["cores"]
if billing_cores == 'shared': billing_cpu = cpu
billing_cores = 1 if billing_cores == 'shared':
if billing_cpu == 'shared': billing_cores = 1
billing_cpu = 1 if billing_cpu == 'shared':
#TODO: Make this logic elegant (use cores/shared logic) billing_cpu = 1
if 'win' in os: #TODO: Make this logic elegant (use cores/shared logic)
if 'f1-micro' in name or 'g1-small' in name: if 'win' in os:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"]) if 'f1-micro' in name or 'g1-small' in name:
else: add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"])
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu) else:
elif 'rhel' in os: add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu)
if float(billing_cpu) <= 4: elif 'rhel' in os:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"]) if float(billing_cpu) <= 4:
else: 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"]) add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"])
elif 'suse-sap' in os: elif 'suse' in os:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) if 'f1-micro' in name or 'g1-small' in name:
elif 'suse' in os: add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"])
if 'f1-micro' in name or 'g1-small' in name: else:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"]) add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu)
else: elif 'sql' in os:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu) if 'f1-micro' in name or 'g1-small' in name:
elif 'sql' in os: add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS']['win']["low"])
if 'f1-micro' in name or 'g1-small' in name: else:
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS']['win']["low"]) add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS']['win']["high"]) * float(billing_cpu)
else: add = add + float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu)
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS']['win']["high"]) * float(billing_cpu) cost = float(cost)+add
add = add + float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu) print('google,%s,%s,%s,%s,%s,%s' % (name, cpu, memory, cost, region, os))
cost = float(cost)+add else:
print('google', end=',') print('google,%s,%s,%s,%s,%s,%s' % (name, cpu, memory, cost, region, os))
print(name, end=',') \ No newline at end of file
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!