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 9a0d9c7d
authored
Nov 03, 2017
by
diegolima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Traduzir nomes de regiao
1 parent
d2520957
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
17 deletions
aws_parser.py
aws_parser.py
View file @
9a0d9c7
...
@@ -17,19 +17,39 @@ if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'):
...
@@ -17,19 +17,39 @@ if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'):
TERM_ONDEMAND
=
'JRTCKXETXF'
#Ondemand. TODO: Find out where to get this from
TERM_ONDEMAND
=
'JRTCKXETXF'
#Ondemand. TODO: Find out where to get this from
HOURLY_DIMENSION
=
'6YS6EN2CT7'
#Tier1. TODO: Find out where to get this from
HOURLY_DIMENSION
=
'6YS6EN2CT7'
#Tier1. TODO: Find out where to get this from
def
locationmap
(
argument
):
switcher
=
{
"Asia Pacific (Tokyo)"
:
"ap-northeast-1"
,
"Asia Pacific (Seoul)"
:
"ap-northeast-2"
,
"Asia Pacific (Mumbai)"
:
"ap-south-1"
,
"Asia Pacific (Singapore)"
:
"ap-southeast-1"
,
"Asia Pacific (Sydney)"
:
"ap-southeast-2"
,
"Canada (Central)"
:
"ca-central-1"
,
"EU (Frankfurt)"
:
"eu-central-1"
,
"EU (Ireland)"
:
"eu-west-1"
,
"EU (London)"
:
"eu-west-2"
,
"South America (Sao Paulo)"
:
"sa-east-1"
,
"US East (N. Virginia)"
:
"us-east-1"
,
"US East (Ohio)"
:
"us-east-2"
,
"US West (N. California)"
:
"us-west-1"
,
"US West (Oregon)"
:
"us-west-2"
,
"AWS GovCloud (US)"
:
"us-gov-west-1"
,
}
return
switcher
.
get
(
argument
,
"UNKNOWNREGIONERROR"
)
if
PRODUCT_TYPE
==
'compute'
:
if
PRODUCT_TYPE
==
'compute'
:
FCATALOG
=
'ec2.json'
FCATALOG
=
'e
xamples/aws_e
c2.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json'
PRODUCT_FAMILY
=
'Compute Instance'
PRODUCT_FAMILY
=
'Compute Instance'
elif
PRODUCT_TYPE
==
'database'
:
elif
PRODUCT_TYPE
==
'database'
:
FCATALOG
=
'rds.json'
FCATALOG
=
'
examples/aws_
rds.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json'
CATALOG
=
'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json'
PRODUCT_FAMILY
=
'Database Instance'
PRODUCT_FAMILY
=
'Database Instance'
with
urllib
.
request
.
urlopen
(
CATALOG
)
as
url
:
#
with urllib.request.urlopen(CATALOG) as url:
DATA
=
json
.
loads
(
url
.
read
()
.
decode
())
#
DATA = json.loads(url.read().decode())
#
with open(FCATALOG) as url:
with
open
(
FCATALOG
)
as
url
:
#
DATA = json.load(url)
DATA
=
json
.
load
(
url
)
for
product
in
DATA
[
"products"
]:
for
product
in
DATA
[
"products"
]:
if
DATA
[
'products'
][
product
][
'productFamily'
]
==
PRODUCT_FAMILY
:
if
DATA
[
'products'
][
product
][
'productFamily'
]
==
PRODUCT_FAMILY
:
sku
=
DATA
[
'products'
][
product
][
'sku'
]
sku
=
DATA
[
'products'
][
product
][
'sku'
]
...
@@ -37,16 +57,16 @@ with urllib.request.urlopen(CATALOG) as url:
...
@@ -37,16 +57,16 @@ with urllib.request.urlopen(CATALOG) as url:
if
key
:
if
key
:
cost
=
key
[
sku
+
'.'
+
TERM_ONDEMAND
][
'priceDimensions'
][
sku
+
'.'
+
TERM_ONDEMAND
+
'.'
+
HOURLY_DIMENSION
][
'pricePerUnit'
][
'USD'
]
cost
=
key
[
sku
+
'.'
+
TERM_ONDEMAND
][
'priceDimensions'
][
sku
+
'.'
+
TERM_ONDEMAND
+
'.'
+
HOURLY_DIMENSION
][
'pricePerUnit'
][
'USD'
]
if
cost
!=
'0.0000000000'
:
if
cost
!=
'0.0000000000'
:
print
(
'aws'
,
end
=
','
)
name
=
DATA
[
'products'
][
product
][
'attributes'
][
'instanceType'
]
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'instanceType'
],
end
=
','
)
region
=
locationmap
(
DATA
[
'products'
][
product
][
'attributes'
][
'location'
])
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'vcpu'
],
end
=
','
)
cpu
=
DATA
[
'products'
][
product
][
'attributes'
][
'vcpu'
]
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'memory'
],
end
=
','
)
memory
=
DATA
[
'products'
][
product
][
'attributes'
][
'memory'
]
print
(
cost
,
end
=
','
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'location'
],
end
=
','
)
if
PRODUCT_TYPE
==
'compute'
:
if
PRODUCT_TYPE
==
'compute'
:
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'operatingSystem'
])
os
=
DATA
[
'products'
][
product
][
'attributes'
][
'operatingSystem'
]
print
(
'aws,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s'
%
(
name
,
cpu
,
memory
,
cost
,
region
,
os
))
elif
PRODUCT_TYPE
==
'database'
:
elif
PRODUCT_TYPE
==
'database'
:
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'databaseEngine'
],
end
=
','
)
os
=
DATA
[
'products'
][
product
][
'attributes'
][
'databaseEngine'
]
print
(
DATA
[
'products'
][
product
][
'attributes'
]
.
get
(
'databaseEdition'
),
end
=
','
)
edition
=
DATA
[
'products'
][
product
][
'attributes'
]
.
get
(
'databaseEdition'
)
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'licenseModel'
],
end
=
','
)
licensemodel
=
DATA
[
'products'
][
product
][
'attributes'
][
'licenseModel'
]
print
(
DATA
[
'products'
][
product
][
'attributes'
][
'deploymentOption'
])
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
))
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