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 b8eca7a1
authored
Oct 31, 2017
by
diegolima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support RDS parsing
1 parent
424eeb45
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
22 deletions
aws_parser.py
ec2.py
aws_parser.py
0 → 100644
View file @
b8eca7a
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
)
TERM_ONDEMAND
=
'JRTCKXETXF'
#Ondemand. TODO: Find out where to get this from
HOURLY_DIMENSION
=
'6YS6EN2CT7'
#Tier1. TODO: Find out where to get this from
if
PRODUCT_TYPE
==
'compute'
:
FCATALOG
=
'ec2.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json'
PRODUCT_FAMILY
=
'Compute Instance'
elif
PRODUCT_TYPE
==
'database'
:
FCATALOG
=
'rds.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json'
PRODUCT_FAMILY
=
'Database Instance'
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
][
'productFamily'
]
==
PRODUCT_FAMILY
:
sku
=
DATA
[
'products'
][
product
][
'sku'
]
key
=
DATA
[
'terms'
][
'OnDemand'
]
.
get
(
sku
)
if
key
:
cost
=
key
[
sku
+
'.'
+
TERM_ONDEMAND
][
'priceDimensions'
][
sku
+
'.'
+
TERM_ONDEMAND
+
'.'
+
HOURLY_DIMENSION
][
'pricePerUnit'
][
'USD'
]
if
cost
!=
'0.0000000000'
:
print
(
'aws'
,
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'instanceType'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'vcpu'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'memory'
],
end
=
','
)
print
(
cost
,
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'location'
],
end
=
','
)
if
PRODUCT_TYPE
==
'compute'
:
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'operatingSystem'
])
elif
PRODUCT_TYPE
==
'database'
:
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'databaseEngine'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
]
.
get
(
'databaseEdition'
),
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'licenseModel'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'deploymentOption'
])
ec2.py
deleted
100644 → 0
View file @
424eeb4
import
urllib.request
import
json
TERM_ONDEMAND
=
'JRTCKXETXF'
#TODO: Find out where to get this from
HOURLY_DIMENSION
=
'6YS6EN2CT7'
#TODO: Find out where to get this from
with
urllib
.
request
.
urlopen
(
"https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json"
)
as
url
:
DATA
=
json
.
loads
(
url
.
read
()
.
decode
())
for
product
in
DATA
[
"products"
]:
if
DATA
[
'products'
][
product
][
'productFamily'
]
==
'Compute Instance'
:
sku
=
DATA
[
'products'
][
product
][
'sku'
]
key
=
DATA
[
'terms'
][
'OnDemand'
]
.
get
(
sku
)
if
key
:
cost
=
key
[
sku
+
'.'
+
TERM_ONDEMAND
][
'priceDimensions'
][
sku
+
'.'
+
TERM_ONDEMAND
+
'.'
+
HOURLY_DIMENSION
][
'pricePerUnit'
][
'USD'
]
if
cost
!=
'0.0000000000'
:
print
(
'aws'
,
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'instanceType'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'vcpu'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'memory'
],
end
=
','
)
print
(
cost
,
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'location'
],
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'operatingSystem'
])
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