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 74c0691f
authored
May 15, 2018
by
Diego Lima
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.adtsys.com.br:diego.lima/aws-price-parser
2 parents
7ce9ea44
10d0f4bf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
34 deletions
.gitignore
.vscode/settings.json
aws_parser.py
azure_parser.py
gce_parser.py
.gitignore
View file @
74c0691
.vscode
.vscode/settings.json
.vscode/settings.json
View file @
74c0691
{
"python.pythonPath"
:
"/usr/bin/python3"
"python.pythonPath"
:
"C:
\\
Users
\\
diego
\\
AppData
\\
Local
\\
Programs
\\
Python
\\
Python36
\\
python.exe"
,
"python.linting.pylintEnabled"
:
true
,
"python.linting.enabled"
:
true
}
\ No newline at end of file
aws_parser.py
View file @
74c0691
...
...
@@ -2,17 +2,7 @@ import urllib.request
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
)
PRODUCT_TYPE
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
==
2
else
'none'
TERM_ONDEMAND
=
'JRTCKXETXF'
#Ondemand. TODO: Find out where to get this from
HOURLY_DIMENSION
=
'6YS6EN2CT7'
#Tier1. TODO: Find out where to get this from
...
...
@@ -45,11 +35,14 @@ elif PRODUCT_TYPE == 'database':
FCATALOG
=
'examples/aws_rds.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json'
PRODUCT_FAMILY
=
'Database Instance'
else
:
print
(
"Product type not supported"
)
sys
.
exit
(
1
)
with
urllib
.
request
.
urlopen
(
CATALOG
)
as
url
:
DATA
=
json
.
loads
(
url
.
read
()
.
decode
())
#
with open(FCATALOG) as url:
#
DATA = json.load(url)
#
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
[
"products"
]:
if
DATA
[
'products'
][
product
]
.
get
(
'productFamily'
)
==
PRODUCT_FAMILY
:
sku
=
DATA
[
'products'
][
product
]
.
get
(
'sku'
)
...
...
@@ -69,10 +62,10 @@ with urllib.request.urlopen(CATALOG) as url:
else
:
sharedcores
=
'nonshared'
if
DATA
[
'products'
][
product
][
'attributes'
][
'tenancy'
]
==
'Shared'
:
print
(
'aws,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s
'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
,
sharedcores
))
print
(
'aws,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s
,
%
s'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
,
sharedcores
,
sku
))
elif
PRODUCT_TYPE
==
'database'
:
os
=
DATA
[
'products'
][
product
][
'attributes'
][
'databaseEngine'
]
edition
=
DATA
[
'products'
][
product
][
'attributes'
]
.
get
(
'databaseEdition'
)
licensemodel
=
DATA
[
'products'
][
product
][
'attributes'
][
'licenseModel'
]
deployment
=
DATA
[
'products'
][
product
][
'attributes'
][
'deploymentOption'
]
print
(
'aws,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s
'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
,
edition
,
licensemodel
,
deployment
))
print
(
'aws,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s
,
%
s'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
,
edition
,
licensemodel
,
deployment
,
sku
))
azure_parser.py
View file @
74c0691
...
...
@@ -2,7 +2,8 @@ import urllib.request
import
json
import
sys
PRODUCT_TYPE
=
sys
.
argv
[
1
]
PRODUCT_TYPE
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
==
2
else
'none'
if
PRODUCT_TYPE
==
'compute'
:
FCATALOG
=
'examples/azure.json'
CATALOG
=
'https://azure.microsoft.com/api/v2/pricing/virtual-machines-base/calculator/?culture=pt-br&discount=mosp'
...
...
@@ -48,4 +49,5 @@ with urllib.request.urlopen(CATALOG) as url:
for
region
in
REGIONS
:
cost
=
prod
[
"prices"
]
.
get
(
region
)
if
cost
:
cost
=
cost
[
'value'
]
print
(
"azure,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s"
%
(
name
,
cores
,
memory
,
cost
,
region
,
os
,
sharedcores
))
gce_parser.py
View file @
74c0691
...
...
@@ -3,17 +3,9 @@ import json
import
sys
import
urllib.request
if
len
(
sys
.
argv
)
==
1
:
print
(
'You need to specify a product type'
)
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
)
PRODUCT_TYPE
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
==
2
else
'none'
COMPUTE_PRODUCT_FAMILY
=
'CP-COMPUTEENGINE-VMIMAGE-'
DB_PRODUCT_FAMILY
=
'CP-DB-'
if
PRODUCT_TYPE
==
'compute'
:
...
...
@@ -24,6 +16,9 @@ elif PRODUCT_TYPE == 'database':
FCATALOG
=
'examples/gce_pricelist.json'
CATALOG
=
'https://cloudpricingcalculator.appspot.com/static/data/pricelist.json'
PRODUCT_FAMILY
=
DB_PRODUCT_FAMILY
else
:
print
(
"Product type not supported"
)
sys
.
exit
(
1
)
GCE_REGIONS
=
[
'us-central1'
,
'us-east1'
,
'us-east4'
,
'us-west1'
,
...
...
@@ -34,11 +29,10 @@ GCE_REGIONS = [
]
GCE_OS
=
[
'linux'
,
'win'
,
'rhel'
,
'suse'
,
'suse-sap'
,
'sql-standard'
,
'sql-web'
,
'sql-enterprise'
]
#TODO: Download & decompress the gzipped current catalog
with
urllib
.
request
.
urlopen
(
CATALOG
)
as
url
:
DATA
=
json
.
loads
(
url
.
read
()
.
decode
())
#with open(FCATALOG) as url:
# DATA = json.load(url)
#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
'CUSTOM-VM-'
not
in
product
:
if
PRODUCT_FAMILY
in
product
:
# Discard non-product entries
...
...
@@ -103,4 +97,5 @@ with urllib.request.urlopen(CATALOG) as url:
realcpu
=
cpu
print
(
'google,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s'
%
(
name
,
realcpu
,
memory
,
cost
,
region
,
os
,
sharedcores
))
else
:
realname
=
realname
.
replace
(
'pg-'
,
''
)
print
(
'google,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s'
%
(
realname
,
cpu
,
memory
,
cost
,
region
,
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