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'): ...@@ -15,14 +15,16 @@ 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-'
DB_PRODUCT_FAMILY = 'CP-DB-'
if PRODUCT_TYPE == 'compute': if PRODUCT_TYPE == 'compute':
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 = 'CP-COMPUTEENGINE-VMIMAGE-' PRODUCT_FAMILY = COMPUTE_PRODUCT_FAMILY
elif PRODUCT_TYPE == 'database': 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 = 'CP-DB-' PRODUCT_FAMILY = DB_PRODUCT_FAMILY
GCE_REGIONS = [ GCE_REGIONS = [
'us-central1', 'us-east1', 'us-east4', 'us-west1', 'us-central1', 'us-east1', 'us-east4', 'us-west1',
...@@ -39,52 +41,59 @@ GCE_OS = ['linux', 'win', 'rhel', 'suse', 'suse-sap', 'sql-standard', 'sql-web', ...@@ -39,52 +41,59 @@ GCE_OS = ['linux', 'win', 'rhel', 'suse', 'suse-sap', 'sql-standard', 'sql-web',
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 PRODUCT_FAMILY in product: if 'CUSTOM-VM-' not in product:
name = product[len(PRODUCT_FAMILY):].lower() if PRODUCT_FAMILY in product:
memory = DATA['gcp_price_list'][product]["memory"] + ' GB' name = product[len(PRODUCT_FAMILY):].lower()
cpu = DATA['gcp_price_list'][product]["cores"]
for region in GCE_REGIONS: if PRODUCT_FAMILY == DB_PRODUCT_FAMILY:
for os in GCE_OS: match = COMPUTE_PRODUCT_FAMILY+name.upper()
cost = DATA['gcp_price_list'][product][region] match = match.replace('PG-','')
if os == 'linux': else:
add = 0 match = product
else: memory = DATA['gcp_price_list'][match]["memory"] + ' GB'
billing_cores = DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["cores"] cpu = DATA['gcp_price_list'][match]["cores"]
billing_cpu = cpu for region in GCE_REGIONS:
if billing_cores == 'shared': for os in GCE_OS:
billing_cores = 1 cost = DATA['gcp_price_list'][product][region]
if billing_cpu == 'shared': if os == 'linux':
billing_cpu = 1 add = 0
#TODO: Make this logic elegant (use cores/shared logic) else:
if 'win' in os: billing_cores = DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["cores"]
if 'f1-micro' in name or 'g1-small' in name: billing_cpu = cpu
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"]) if billing_cores == 'shared':
else: billing_cores = 1
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["high"]) * float(billing_cpu) if billing_cpu == 'shared':
elif 'rhel' in os: billing_cpu = 1
if float(billing_cpu) <= 4: #TODO: Make this logic elegant (use cores/shared logic)
add = float(DATA['gcp_price_list']['CP-COMPUTEENGINE-OS'][os]["low"]) if 'win' in os:
else: 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"]) 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', end=',')
cost = float(cost)+add print(name, end=',')
print('google', end=',') print(cpu, end=',')
print(name, end=',') print(memory, end=',')
print(cpu, end=',') print(cost, end=',')
print(memory, end=',') print(region, end=',')
print(cost, end=',') print(os)
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!