|
|
@@ -5,65 +5,82 @@ |
|
|
*/ |
|
|
|
|
|
var SERVICE_HOST = 'http://aws.amazon.com' |
|
|
var linux_light = { |
|
|
"linux-ri-light": '/ec2/pricing/json/linux-ri-light.json', |
|
|
"rhel-ri-light": '/ec2/pricing/json/rhel-ri-light.json', |
|
|
"sles-ri-light": '/ec2/pricing/json/sles-ri-light.json' |
|
|
} |
|
|
var linux_med = { |
|
|
"linux-ri-medium": '/ec2/pricing/json/linux-ri-medium.json', |
|
|
"rhel-ri-medium": '/ec2/pricing/json/rhel-ri-medium.json', |
|
|
"sles-ri-medium": '/ec2/pricing/json/sles-ri-medium.json' |
|
|
} |
|
|
var linux_heavy = { |
|
|
"rhel-ri-heavy": '/ec2/pricing/json/rhel-ri-heavy.json', |
|
|
"sles-ri-heavy": '/ec2/pricing/json/sles-ri-heavy.json', |
|
|
"linux-ri-heavy": '/ec2/pricing/json/linux-ri-heavy.json' |
|
|
} |
|
|
var linux_od = { |
|
|
"linux-od": '/ec2/pricing/json/linux-od.json', |
|
|
"rhel-od": '/ec2/pricing/json/rhel-od.json', |
|
|
"sles-od": '/ec2/pricing/json/sles-od.json' |
|
|
} |
|
|
var windows = { |
|
|
"mswinSQL-ri-medium": '/ec2/pricing/json/mswinSQL-ri-medium', |
|
|
"mswinSQL-ri-light": '/ec2/pricing/json/mswinSQL-ri-light.json', |
|
|
"mswinSQLWeb-ri-light": '/ec2/pricing/json/mswinSQLWeb-ri-light.json', |
|
|
"mswinSQLWeb-ri-medium": '/ec2/pricing/json/mswinSQLWeb-ri-medium.json', |
|
|
"mswin-ri-heavy": '/ec2/pricing/json/mswin-ri-heavy.json', |
|
|
"mswinSQL-ri-heavy": '/ec2/pricing/json/mswinSQL-ri-heavy.json', |
|
|
"mswinSQLWeb-ri-heavy": '/ec2/pricing/json/mswinSQLWeb-ri-heavy.json', |
|
|
"mswin-od": '/ec2/pricing/json/mswin-od.json', |
|
|
"mswinSQL-od": '/ec2/pricing/json/mswinSQL-od.json', |
|
|
"mswinSQLWeb-od": '/ec2/pricing/json/mswinSQLWeb-od.json', |
|
|
"mswin-ri-light": '/ec2/pricing/json/mswin-ri-light.json', |
|
|
"mswin-ri-medium": '/ec2/pricing/json/mswin-ri-medium.json' |
|
|
|
|
|
var data_sources = { |
|
|
"linux-od": { |
|
|
"uri": '/ec2/pricing/json/linux-od.json', |
|
|
"name": "OD Linux" |
|
|
}, |
|
|
"linux-ri-light": { |
|
|
"uri": '/ec2/pricing/json/linux-ri-light.json', |
|
|
"name": "RI Light [Linux]" |
|
|
}, |
|
|
"linux-ri-medium": { |
|
|
"uri": '/ec2/pricing/json/linux-ri-medium.json', |
|
|
"name": "RI Medium [Linux]" |
|
|
}, |
|
|
"linux-ri-heavy": { |
|
|
"uri": '/ec2/pricing/json/linux-ri-heavy.json', |
|
|
"name": "RI Heavy [Linux]" |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* A special function that runs when the spreadsheet is open, used to add a |
|
|
* custom menu to the spreadsheet. |
|
|
*/ |
|
|
function onOpen() { |
|
|
parseTypes = [ |
|
|
linux_od['linux-od'], |
|
|
// linux_light['linux-ri-light'], |
|
|
// linux_med['linux-ri-medium'], |
|
|
// linux_heavy['linux-ri-heavy'] |
|
|
] |
|
|
ss = SpreadsheetApp.getActiveSpreadsheet(); |
|
|
sheet = ss.getSheets()[0]; |
|
|
sheet.clearContents() |
|
|
/* Set the header and freeze it */ |
|
|
sheet.appendRow(["Region", "Instance Type", "Size", "Cost", "Rate Type", "Rate Term"]) |
|
|
sheet.setFrozenRows(1) |
|
|
for (i in parseTypes) { |
|
|
rows = parsePrices(parseTypes[i]) |
|
|
for (row in rows) { |
|
|
sheet.appendRow(rows[row]) |
|
|
} |
|
|
buildMenu() |
|
|
} |
|
|
|
|
|
function buildMenu() { |
|
|
|
|
|
menuItems = [] |
|
|
on_demand = { |
|
|
name: "On Demand", |
|
|
subMenus: [ |
|
|
{ |
|
|
name: "Linux", |
|
|
functionName: "linux_od" |
|
|
} |
|
|
] |
|
|
} |
|
|
menuItems.push(on_demand) |
|
|
ri_light = { |
|
|
name: "RI Light", |
|
|
subMenus: [ |
|
|
{ |
|
|
name: "Linux", |
|
|
functionName: "linux_ri_light" |
|
|
} |
|
|
]} |
|
|
menuItems.push(ri_light) |
|
|
ri_medium = { |
|
|
name: "RI Medium", |
|
|
subMenus: [ |
|
|
{ |
|
|
name: "Linux", |
|
|
functionName: "linux_ri_medium" |
|
|
} |
|
|
]} |
|
|
menuItems.push(ri_medium) |
|
|
ri_heavy = { |
|
|
name: "RI Heavy", |
|
|
subMenus: [ |
|
|
{ |
|
|
name: "Linux", |
|
|
functionName: "linux_ri_heavy" |
|
|
} |
|
|
]} |
|
|
menuItems.push(ri_heavy) |
|
|
var spreadsheet = SpreadsheetApp.getActive(); |
|
|
for (e in menuItems) { |
|
|
SpreadsheetApp.getActive().addMenu(menuItems[e].name, menuItems[e].subMenus); |
|
|
} |
|
|
} |
|
|
|
|
|
function parsePrices(indexKey) { |
|
|
Logger.log("fetching from" + SERVICE_HOST + indexKey) |
|
|
var jsondata = UrlFetchApp.fetch(SERVICE_HOST + indexKey) |
|
|
var jsondata = UrlFetchApp.fetch(SERVICE_HOST + data_sources[indexKey].uri) |
|
|
items = [] |
|
|
data = JSON.parse(jsondata.getContentText()); |
|
|
for (region in data['config']['regions']) { |
|
|
@@ -83,3 +100,36 @@ function parsePrices(indexKey) { |
|
|
} |
|
|
return items |
|
|
} |
|
|
|
|
|
function loadSource(source) { |
|
|
|
|
|
var spreadsheet = SpreadsheetApp.getActive(); |
|
|
data = parsePrices(source) |
|
|
sheet = spreadsheet.getSheetByName(source) |
|
|
if (sheet == null) { |
|
|
sheet = spreadsheet.insertSheet(source) |
|
|
} else { |
|
|
sheet.clearContents() |
|
|
} |
|
|
sheet.setFrozenRows(1) |
|
|
sheet.appendRow(["Region", "Instance Type", "Size", "Cost USD", "Rate Type", "Rate Term"]) |
|
|
for (i in data) { |
|
|
sheet.appendRow(data[i]) |
|
|
} |
|
|
} |
|
|
|
|
|
function linux_od() { |
|
|
loadSource('linux-od') |
|
|
} |
|
|
|
|
|
function linux_ri_light() { |
|
|
loadSource('linux-ri-light') |
|
|
} |
|
|
|
|
|
function linux_ri_medium() { |
|
|
loadSource('linux-ri-medium') |
|
|
} |
|
|
|
|
|
function linux_ri_heavy() { |
|
|
loadSource('linux-ri-heavy') |
|
|
} |