Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Diego Lima
/
aws-price-parser
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d2520957
authored
Nov 01, 2017
by
diegolima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Corrigir logica do parser do google
1 parent
6d42c356
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
gce_parser.py
gce_parser.py
View file @
d252095
...
@@ -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,19 +42,24 @@ with open(FCATALOG) as url:
...
@@ -42,19 +42,24 @@ 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
]
cost
=
DATA
[
'gcp_price_list'
][
product
][
region
]
if
PRODUCT_FAMILY
==
COMPUTE_PRODUCT_FAMILY
:
cost
=
DATA
[
'gcp_price_list'
][
product
][
region
]
for
os
in
GCE_OS
:
if
os
==
'linux'
:
if
os
==
'linux'
:
add
=
0
add
=
0
else
:
else
:
...
@@ -89,11 +94,6 @@ with open(FCATALOG) as url:
...
@@ -89,11 +94,6 @@ with open(FCATALOG) as url:
add
=
float
(
DATA
[
'gcp_price_list'
][
'CP-COMPUTEENGINE-OS'
][
'win'
][
"high"
])
*
float
(
billing_cpu
)
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
)
add
=
add
+
float
(
DATA
[
'gcp_price_list'
][
'CP-COMPUTEENGINE-OS'
][
os
][
"high"
])
*
float
(
billing_cpu
)
cost
=
float
(
cost
)
+
add
cost
=
float
(
cost
)
+
add
print
(
'google'
,
end
=
','
)
print
(
'google,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
))
print
(
name
,
end
=
','
)
else
:
print
(
cpu
,
end
=
','
)
print
(
'google,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
))
print
(
memory
,
end
=
','
)
\ No newline at end of file
print
(
cost
,
end
=
','
)
print
(
region
,
end
=
','
)
print
(
os
)
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment