mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-19 13:09:52 -07:00
* configure.ac, Makefile.am, === removed directory
usr/share/byobu/ec2, usr/lib/byobu/ec2_cost, usr/lib/byobu/include/ec2instancespricing.py, usr/lib/byobu/include/Makefile.am, usr/share/byobu/ec2/Makefile.am, usr/share/byobu/ec2/rates.ap-northeast-1, usr/share/byobu/ec2/rates.ap-southeast-1, usr/share/byobu/ec2/rates.eu-west-1, usr/share/byobu/ec2/rates.us- east-1, usr/share/byobu/ec2/rates.us-west-1, usr/share/byobu/ec2/rates.us-west-2: - use a smarter algorithm for estimating ec2 cost - include ec2instancespricing.py from https://github.com/erans/ec2instancespricing
This commit is contained in:
parent
4c4db71836
commit
06b4b8c451
16 changed files with 459 additions and 142 deletions
|
@ -1,7 +1,6 @@
|
||||||
SUBDIRS = etc/byobu \
|
SUBDIRS = etc/byobu \
|
||||||
etc/profile.d \
|
etc/profile.d \
|
||||||
usr/share/applications \
|
usr/share/applications \
|
||||||
usr/share/byobu/ec2 \
|
|
||||||
usr/share/byobu/keybindings \
|
usr/share/byobu/keybindings \
|
||||||
usr/share/byobu/pixmaps \
|
usr/share/byobu/pixmaps \
|
||||||
usr/share/byobu/profiles \
|
usr/share/byobu/profiles \
|
||||||
|
|
|
@ -20,7 +20,6 @@ AC_OUTPUT(Makefile \
|
||||||
etc/byobu/Makefile \
|
etc/byobu/Makefile \
|
||||||
etc/profile.d/Makefile \
|
etc/profile.d/Makefile \
|
||||||
usr/share/applications/Makefile \
|
usr/share/applications/Makefile \
|
||||||
usr/share/byobu/ec2/Makefile \
|
|
||||||
usr/share/byobu/keybindings/Makefile \
|
usr/share/byobu/keybindings/Makefile \
|
||||||
usr/share/byobu/pixmaps/Makefile \
|
usr/share/byobu/pixmaps/Makefile \
|
||||||
usr/share/byobu/profiles/Makefile \
|
usr/share/byobu/profiles/Makefile \
|
||||||
|
|
13
debian/changelog
vendored
13
debian/changelog
vendored
|
@ -1,6 +1,17 @@
|
||||||
byobu (5.31) unreleased; urgency=low
|
byobu (5.31) unreleased; urgency=low
|
||||||
|
|
||||||
* UNRELEASED
|
* configure.ac, Makefile.am, === removed directory
|
||||||
|
usr/share/byobu/ec2, usr/lib/byobu/ec2_cost,
|
||||||
|
usr/lib/byobu/include/ec2instancespricing.py,
|
||||||
|
usr/lib/byobu/include/Makefile.am, usr/share/byobu/ec2/Makefile.am,
|
||||||
|
usr/share/byobu/ec2/rates.ap-northeast-1,
|
||||||
|
usr/share/byobu/ec2/rates.ap-southeast-1,
|
||||||
|
usr/share/byobu/ec2/rates.eu-west-1, usr/share/byobu/ec2/rates.us-
|
||||||
|
east-1, usr/share/byobu/ec2/rates.us-west-1,
|
||||||
|
usr/share/byobu/ec2/rates.us-west-2:
|
||||||
|
- use a smarter algorithm for estimating ec2 cost
|
||||||
|
- include ec2instancespricing.py from
|
||||||
|
https://github.com/erans/ec2instancespricing
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Mon, 28 Jan 2013 02:21:15 -0600
|
-- Dustin Kirkland <kirkland@ubuntu.com> Mon, 28 Jan 2013 02:21:15 -0600
|
||||||
|
|
||||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -12,7 +12,7 @@ Vcs-Bzr: http://bazaar.launchpad.net/~kirkland/byobu/trunk
|
||||||
Package: byobu
|
Package: byobu
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends:
|
Depends:
|
||||||
${misc:Depends}, ${perl:Depends},
|
${misc:Depends}, ${perl:Depends}, ${python:Depends},
|
||||||
debconf (>= 0.5) | debconf-2.0,
|
debconf (>= 0.5) | debconf-2.0,
|
||||||
gettext-base,
|
gettext-base,
|
||||||
python,
|
python,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# ec2_cost: approximate EC2 cost (USD) of the current instance
|
# ec2_cost: approximate EC2 cost (USD) of the current instance
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Canonical Ltd.
|
# Copyright (C) 2008 Canonical Ltd.
|
||||||
# Copyright (C) 2011 Dustin Kirkland
|
# Copyright (C) 2011-2013 Dustin Kirkland
|
||||||
#
|
#
|
||||||
# Authors: Dustin Kirkland <kirkland@byobu.co>
|
# Authors: Dustin Kirkland <kirkland@byobu.co>
|
||||||
#
|
#
|
||||||
|
@ -20,11 +20,11 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# Data Transfer Cost Basis
|
# Data Transfer Cost Basis
|
||||||
# Incoming $0.10/GB
|
# Incoming $0.01/GB
|
||||||
# Outgoing $0.17/GB
|
# Outgoing $0.12/GB
|
||||||
# (This gets more complex if you use >1TB/mo)
|
# (This gets more complex if you use >10TB/mo)
|
||||||
RX_RATE="0.10"
|
RX_RATE="0.01"
|
||||||
TX_RATE="0.15"
|
TX_RATE="0.12"
|
||||||
|
|
||||||
__ec2_cost_detail() {
|
__ec2_cost_detail() {
|
||||||
DETAIL=1
|
DETAIL=1
|
||||||
|
@ -33,46 +33,27 @@ __ec2_cost_detail() {
|
||||||
|
|
||||||
__ec2_cost() {
|
__ec2_cost() {
|
||||||
local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ec2_cost"
|
local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ec2_cost"
|
||||||
|
if [ -s "$cache.rate" ]; then
|
||||||
|
read rate < "$cache.rate"
|
||||||
|
elif metadata_available; then
|
||||||
# Try to use metadata service
|
# Try to use metadata service
|
||||||
if metadata_available; then
|
|
||||||
[ -s "$cache.zone" ] || wget -q -O "$cache.zone" http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null &
|
[ -s "$cache.zone" ] || wget -q -O "$cache.zone" http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null &
|
||||||
sleep 0.02
|
sleep 0.02
|
||||||
[ -s "$cache.zone" ] && read zone < "$cache.zone"
|
[ -s "$cache.zone" ] && read zone < "$cache.zone"
|
||||||
[ -r "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}" ] || zone="us-east-1d"
|
zone=${zone%%[a-z]}
|
||||||
. "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}"
|
|
||||||
[ -s "$cache.type" ] || wget -q -O "$cache.type" http://169.254.169.254/latest/meta-data/instance-type 2>/dev/null &
|
[ -s "$cache.type" ] || wget -q -O "$cache.type" http://169.254.169.254/latest/meta-data/instance-type 2>/dev/null &
|
||||||
sleep 0.02
|
sleep 0.02
|
||||||
[ -s "$cache.type" ] && type=$($BYOBU_SED -e "s/\./_/g" "$cache.type")
|
[ -s "$cache.type" ] && read type < "$cache.type"
|
||||||
eval rate="\$$type"
|
$BYOBU_PREFIX/lib/byobu/include/ec2instancespricing.py --type ondemand --filter-region $zone --filter-type $type --filter-os-type linux --format csv | tail -n1 > "$cache.rate"
|
||||||
file_to_stat="$cache.type"
|
read rate < "$cache.rate"
|
||||||
fi
|
fi
|
||||||
if [ -z "$rate" ]; then
|
if [ -z "$rate" ]; then
|
||||||
# No instance type/rate, exit immediately unless we explicitly want an estimate
|
# Unknown rate, exit immediately
|
||||||
[ "$EC2_ESTIMATE" = "1" ] || return
|
# Rate estimation is now deprecated
|
||||||
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
|
return
|
||||||
# Count CPUs, Memory, Architecture, hours
|
fi
|
||||||
cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1
|
rate=${rate##*,}
|
||||||
mem=$(grep ^MemTotal /proc/meminfo | awk '{print $2}')
|
|
||||||
# /etc/hostname gets created at installation (but might get updated...other ideas?)
|
|
||||||
file_to_stat="/etc/hostname"
|
file_to_stat="/etc/hostname"
|
||||||
# Guess this system's going rate, based on mem available (m* types)
|
|
||||||
if [ $mem -lt 700000 ]; then
|
|
||||||
rate=$t1_micro
|
|
||||||
elif [ $mem -gt 64000000 ]; then
|
|
||||||
rate=$m2_4xlarge
|
|
||||||
elif [ $mem -gt 32000000 ]; then
|
|
||||||
rate=$m2_2xlarge
|
|
||||||
elif [ $mem -gt 16000000 ]; then
|
|
||||||
rate=$m2_xlarge
|
|
||||||
elif [ $mem -gt 14000000 ]; then
|
|
||||||
rate=$m1_xlarge
|
|
||||||
elif [ $mem -gt 7000000 ]; then
|
|
||||||
rate=$m1_large
|
|
||||||
else
|
|
||||||
# Otherwise, scale based on number of cpu's (c* types)
|
|
||||||
rate=$(printf "%s %s" "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}')
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
|
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
|
||||||
# Auto detect network interface
|
# Auto detect network interface
|
||||||
[ -r "/proc/net/route" ] || return
|
[ -r "/proc/net/route" ] || return
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
inclibdirdir = $(prefix)/lib/@PACKAGE@/include
|
inclibdirdir = $(prefix)/lib/@PACKAGE@/include
|
||||||
inclibdir_SCRIPTS = common constants cycle-status dirs mondrian notify_osd shutil
|
inclibdir_SCRIPTS = common constants cycle-status dirs mondrian notify_osd shutil ec2instancespricing.py
|
||||||
|
|
425
usr/lib/byobu/include/ec2instancespricing.py
Executable file
425
usr/lib/byobu/include/ec2instancespricing.py
Executable file
|
@ -0,0 +1,425 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# Copyright (c) 2012 Eran Sandler (eran@sandler.co.il), http://eran.sandler.co.il, http://forecastcloudy.net
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
#
|
||||||
|
import urllib2
|
||||||
|
import argparse
|
||||||
|
try:
|
||||||
|
import simplejson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
|
EC2_REGIONS = [
|
||||||
|
"us-east-1",
|
||||||
|
"us-west-1",
|
||||||
|
"us-west-2",
|
||||||
|
"eu-west-1",
|
||||||
|
"ap-southeast-1",
|
||||||
|
"ap-southeast-2",
|
||||||
|
"ap-northeast-1",
|
||||||
|
"sa-east-1"
|
||||||
|
]
|
||||||
|
|
||||||
|
EC2_INSTANCE_TYPES = [
|
||||||
|
"t1.micro",
|
||||||
|
"m1.small",
|
||||||
|
"m1.medium",
|
||||||
|
"m1.large",
|
||||||
|
"m1.xlarge",
|
||||||
|
"m2.xlarge",
|
||||||
|
"m2.2xlarge",
|
||||||
|
"m2.4xlarge",
|
||||||
|
"c1.medium",
|
||||||
|
"c1.xlarge",
|
||||||
|
"cc1.4xlarge",
|
||||||
|
"cc2.8xlarge",
|
||||||
|
"cg1.4xlarge",
|
||||||
|
"cr1.8xlarge",
|
||||||
|
"m3.xlarge",
|
||||||
|
"m3.2xlarge",
|
||||||
|
"hi1.4xlarge",
|
||||||
|
"hs1.8xlarge"
|
||||||
|
]
|
||||||
|
|
||||||
|
EC2_OS_TYPES = [
|
||||||
|
"linux",
|
||||||
|
"mswin"
|
||||||
|
]
|
||||||
|
|
||||||
|
JSON_NAME_TO_EC2_REGIONS_API = {
|
||||||
|
"us-east" : "us-east-1",
|
||||||
|
"us-east-1" : "us-east-1",
|
||||||
|
"us-west" : "us-west-1",
|
||||||
|
"us-west-1" : "us-west-1",
|
||||||
|
"us-west-2" : "us-west-2",
|
||||||
|
"eu-ireland" : "eu-west-1",
|
||||||
|
"eu-west-1" : "eu-west-1",
|
||||||
|
"apac-sin" : "ap-southeast-1",
|
||||||
|
"ap-southeast-1" : "ap-southeast-1",
|
||||||
|
"ap-southeast-2" : "ap-southeast-2",
|
||||||
|
"apac-syd" : "ap-southeast-2",
|
||||||
|
"apac-tokyo" : "ap-northeast-1",
|
||||||
|
"ap-northeast-1" : "ap-northeast-1",
|
||||||
|
"sa-east-1" : "sa-east-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
EC2_REGIONS_API_TO_JSON_NAME = {
|
||||||
|
"us-east-1" : "us-east",
|
||||||
|
"us-west-1" : "us-west",
|
||||||
|
"us-west-2" : "us-west-2",
|
||||||
|
"eu-west-1" : "eu-ireland",
|
||||||
|
"ap-southeast-1" : "apac-sin",
|
||||||
|
"ap-southeast-2" : "apac-syd",
|
||||||
|
"ap-northeast-1" : "apac-tokyo",
|
||||||
|
"sa-east-1" : "sa-east-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANCES_ON_DEMAND_URL = "http://aws.amazon.com/ec2/pricing/pricing-on-demand-instances.json"
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_LINUX_URL = "http://aws.amazon.com/ec2/pricing/ri-light-linux.json"
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_WINDOWS_URL = "http://aws.amazon.com/ec2/pricing/ri-light-mswin.json"
|
||||||
|
INSTNACES_RESERVED_MEDIUM_UTILIZATION_LINUX_URL = "http://aws.amazon.com/ec2/pricing/ri-medium-linux.json"
|
||||||
|
INSTANCES_RESERVED_MEDIUM_UTILIZATION_WINDOWS_URL = "http://aws.amazon.com/ec2/pricing/ri-medium-mswin.json"
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_LINUX_URL = "http://aws.amazon.com/ec2/pricing/ri-heavy-linux.json"
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_WINDOWS_URL = "http://aws.amazon.com/ec2/pricing/ri-heavy-mswin.json"
|
||||||
|
|
||||||
|
INSTANCES_RESERVED_OS_TYPE_BY_URL = {
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_LINUX_URL : "linux",
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_WINDOWS_URL : "mswin",
|
||||||
|
INSTNACES_RESERVED_MEDIUM_UTILIZATION_LINUX_URL : "linux",
|
||||||
|
INSTANCES_RESERVED_MEDIUM_UTILIZATION_WINDOWS_URL : "mswin",
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_LINUX_URL : "linux",
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_WINDOWS_URL : "mswin"
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANCES_RESERVED_UTILIZATION_TYPE_BY_URL = {
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_LINUX_URL : "light",
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_WINDOWS_URL : "light",
|
||||||
|
INSTNACES_RESERVED_MEDIUM_UTILIZATION_LINUX_URL : "medium",
|
||||||
|
INSTANCES_RESERVED_MEDIUM_UTILIZATION_WINDOWS_URL : "medium",
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_LINUX_URL : "heavy",
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_WINDOWS_URL : "heavy"
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_CURRENCY = "USD"
|
||||||
|
|
||||||
|
INSTANCE_TYPE_MAPPING = {
|
||||||
|
"stdODI" : "m1",
|
||||||
|
"uODI" : "t1",
|
||||||
|
"hiMemODI" : "m2",
|
||||||
|
"hiCPUODI" : "c1",
|
||||||
|
"clusterComputeI" : "cc1",
|
||||||
|
"clusterGPUI" : "cg1",
|
||||||
|
"hiIoODI" : "hi1",
|
||||||
|
"secgenstdODI" : "m3",
|
||||||
|
"hiStoreODI": "hs1",
|
||||||
|
"clusterHiMemODI": "cr1",
|
||||||
|
|
||||||
|
# Reserved Instance Types
|
||||||
|
"stdResI" : "m1",
|
||||||
|
"uResI" : "t1",
|
||||||
|
"hiMemResI" : "m2",
|
||||||
|
"hiCPUResI" : "c1",
|
||||||
|
"clusterCompResI" : "cc1",
|
||||||
|
"clusterGPUResI" : "cg1",
|
||||||
|
"hiIoResI" : "hi1",
|
||||||
|
"secgenstdResI" : "m3",
|
||||||
|
"hiStoreResI": "hs1",
|
||||||
|
"clusterHiMemResI": "cr1"
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANCE_SIZE_MAPPING = {
|
||||||
|
"u" : "micro",
|
||||||
|
"sm" : "small",
|
||||||
|
"med" : "medium",
|
||||||
|
"lg" : "large",
|
||||||
|
"xl" : "xlarge",
|
||||||
|
"xxl" : "2xlarge",
|
||||||
|
"xxxxl" : "4xlarge",
|
||||||
|
"xxxxxxxxl" : "8xlarge"
|
||||||
|
}
|
||||||
|
|
||||||
|
def _load_data(url):
|
||||||
|
f = urllib2.urlopen(url)
|
||||||
|
return json.loads(f.read())
|
||||||
|
|
||||||
|
def get_ec2_reserved_instances_prices(filter_region=None, filter_instance_type=None, filter_os_type=None):
|
||||||
|
""" Get EC2 reserved instances prices. Results can be filtered by region """
|
||||||
|
|
||||||
|
get_specific_region = (filter_region is not None)
|
||||||
|
if get_specific_region:
|
||||||
|
filter_region = EC2_REGIONS_API_TO_JSON_NAME[filter_region]
|
||||||
|
get_specific_instance_type = (filter_instance_type is not None)
|
||||||
|
get_specific_os_type = (filter_os_type is not None)
|
||||||
|
|
||||||
|
currency = DEFAULT_CURRENCY
|
||||||
|
|
||||||
|
urls = [
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_LINUX_URL,
|
||||||
|
INSTANCES_RESERVED_LIGHT_UTILIZATION_WINDOWS_URL,
|
||||||
|
INSTNACES_RESERVED_MEDIUM_UTILIZATION_LINUX_URL,
|
||||||
|
INSTANCES_RESERVED_MEDIUM_UTILIZATION_WINDOWS_URL,
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_LINUX_URL,
|
||||||
|
INSTANCES_RESERVED_HEAVY_UTILIZATION_WINDOWS_URL
|
||||||
|
]
|
||||||
|
|
||||||
|
result_regions = []
|
||||||
|
result_regions_index = {}
|
||||||
|
result = {
|
||||||
|
"config" : {
|
||||||
|
"currency" : currency,
|
||||||
|
},
|
||||||
|
"regions" : result_regions
|
||||||
|
}
|
||||||
|
|
||||||
|
for u in urls:
|
||||||
|
os_type = INSTANCES_RESERVED_OS_TYPE_BY_URL[u]
|
||||||
|
utilization_type = INSTANCES_RESERVED_UTILIZATION_TYPE_BY_URL[u]
|
||||||
|
data = _load_data(u)
|
||||||
|
if "config" in data and data["config"] and "regions" in data["config"] and data["config"]["regions"]:
|
||||||
|
for r in data["config"]["regions"]:
|
||||||
|
if "region" in r and r["region"]:
|
||||||
|
if get_specific_region and filter_region != r["region"]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
region_name = JSON_NAME_TO_EC2_REGIONS_API[r["region"]]
|
||||||
|
if region_name in result_regions_index:
|
||||||
|
instance_types = result_regions_index[region_name]["instanceTypes"]
|
||||||
|
else:
|
||||||
|
instance_types = []
|
||||||
|
result_regions.append({
|
||||||
|
"region" : region_name,
|
||||||
|
"instanceTypes" : instance_types
|
||||||
|
})
|
||||||
|
result_regions_index[region_name] = result_regions[-1]
|
||||||
|
|
||||||
|
if "instanceTypes" in r:
|
||||||
|
for it in r["instanceTypes"]:
|
||||||
|
instance_type = INSTANCE_TYPE_MAPPING[it["type"]]
|
||||||
|
if "sizes" in it:
|
||||||
|
for s in it["sizes"]:
|
||||||
|
instance_size = INSTANCE_SIZE_MAPPING[s["size"]]
|
||||||
|
|
||||||
|
prices = {
|
||||||
|
"1year" : {
|
||||||
|
"hourly" : None,
|
||||||
|
"upfront" : None
|
||||||
|
},
|
||||||
|
"3year" : {
|
||||||
|
"hourly" : None,
|
||||||
|
"upfront" : None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_type = "%s.%s" % (instance_type, instance_size)
|
||||||
|
if _type == "cc1.8xlarge":
|
||||||
|
# Fix conflict where cc1 and cc2 share the same type
|
||||||
|
_type = "cc2.8xlarge"
|
||||||
|
|
||||||
|
if get_specific_instance_type and _type != filter_instance_type:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if get_specific_os_type and os_type != filter_os_type:
|
||||||
|
continue
|
||||||
|
|
||||||
|
instance_types.append({
|
||||||
|
"type" : _type,
|
||||||
|
"os" : os_type,
|
||||||
|
"utilization" : utilization_type,
|
||||||
|
"prices" : prices
|
||||||
|
})
|
||||||
|
|
||||||
|
for price_data in s["valueColumns"]:
|
||||||
|
price = None
|
||||||
|
try:
|
||||||
|
price = float(price_data["prices"][currency])
|
||||||
|
except ValueError:
|
||||||
|
price = None
|
||||||
|
|
||||||
|
if price_data["name"] == "yrTerm1":
|
||||||
|
prices["1year"]["upfront"] = price
|
||||||
|
elif price_data["name"] == "yrTerm1Hourly":
|
||||||
|
prices["1year"]["hourly"] = price
|
||||||
|
elif price_data["name"] == "yrTerm3":
|
||||||
|
prices["3year"]["upfront"] = price
|
||||||
|
elif price_data["name"] == "yrTerm3Hourly":
|
||||||
|
prices["3year"]["hourly"] = price
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_ec2_ondemand_instances_prices(filter_region=None, filter_instance_type=None, filter_os_type=None):
|
||||||
|
""" Get EC2 on-demand instances prices. Results can be filtered by region """
|
||||||
|
|
||||||
|
get_specific_region = (filter_region is not None)
|
||||||
|
if get_specific_region:
|
||||||
|
filter_region = EC2_REGIONS_API_TO_JSON_NAME[filter_region]
|
||||||
|
|
||||||
|
get_specific_instance_type = (filter_instance_type is not None)
|
||||||
|
get_specific_os_type = (filter_os_type is not None)
|
||||||
|
|
||||||
|
currency = DEFAULT_CURRENCY
|
||||||
|
|
||||||
|
result_regions = []
|
||||||
|
result = {
|
||||||
|
"config" : {
|
||||||
|
"currency" : currency,
|
||||||
|
"unit" : "perhr"
|
||||||
|
},
|
||||||
|
"regions" : result_regions
|
||||||
|
}
|
||||||
|
|
||||||
|
data = _load_data(INSTANCES_ON_DEMAND_URL)
|
||||||
|
if "config" in data and data["config"] and "regions" in data["config"] and data["config"]["regions"]:
|
||||||
|
for r in data["config"]["regions"]:
|
||||||
|
if "region" in r and r["region"]:
|
||||||
|
if get_specific_region and filter_region != r["region"]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
region_name = JSON_NAME_TO_EC2_REGIONS_API[r["region"]]
|
||||||
|
instance_types = []
|
||||||
|
if "instanceTypes" in r:
|
||||||
|
for it in r["instanceTypes"]:
|
||||||
|
instance_type = INSTANCE_TYPE_MAPPING[it["type"]]
|
||||||
|
if "sizes" in it:
|
||||||
|
for s in it["sizes"]:
|
||||||
|
instance_size = INSTANCE_SIZE_MAPPING[s["size"]]
|
||||||
|
|
||||||
|
for price_data in s["valueColumns"]:
|
||||||
|
price = None
|
||||||
|
try:
|
||||||
|
price = float(price_data["prices"][currency])
|
||||||
|
except ValueError:
|
||||||
|
price = None
|
||||||
|
|
||||||
|
_type = "%s.%s" % (instance_type, instance_size)
|
||||||
|
if _type == "cc1.8xlarge":
|
||||||
|
# Fix conflict where cc1 and cc2 share the same type
|
||||||
|
_type = "cc2.8xlarge"
|
||||||
|
|
||||||
|
if get_specific_instance_type and _type != filter_instance_type:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if get_specific_os_type and price_data["name"] != filter_os_type:
|
||||||
|
continue
|
||||||
|
|
||||||
|
instance_types.append({
|
||||||
|
"type" : _type,
|
||||||
|
"os" : price_data["name"],
|
||||||
|
"price" : price
|
||||||
|
})
|
||||||
|
|
||||||
|
result_regions.append({
|
||||||
|
"region" : region_name,
|
||||||
|
"instanceTypes" : instance_types
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
def none_as_string(v):
|
||||||
|
if not v:
|
||||||
|
return ""
|
||||||
|
else:
|
||||||
|
return v
|
||||||
|
|
||||||
|
try:
|
||||||
|
import argparse
|
||||||
|
except ImportError:
|
||||||
|
print "ERROR: You are running Python < 2.7. Please use pip to install argparse: pip install argparse"
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(add_help=True, description="Print out the current prices of EC2 instances")
|
||||||
|
parser.add_argument("--type", "-t", help="Show ondemand or reserved instances", choices=["ondemand", "reserved"], required=True)
|
||||||
|
parser.add_argument("--filter-region", "-fr", help="Filter results to a specific region", choices=EC2_REGIONS, default=None)
|
||||||
|
parser.add_argument("--filter-type", "-ft", help="Filter results to a specific instance type", choices=EC2_INSTANCE_TYPES, default=None)
|
||||||
|
parser.add_argument("--filter-os-type", "-fo", help="Filter results to a specific os type", choices=EC2_OS_TYPES, default=None)
|
||||||
|
parser.add_argument("--format", "-f", choices=["json", "table", "csv"], help="Output format", default="table")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.format == "table":
|
||||||
|
try:
|
||||||
|
from prettytable import PrettyTable
|
||||||
|
except ImportError:
|
||||||
|
print "ERROR: Please install 'prettytable' using pip: pip install prettytable"
|
||||||
|
|
||||||
|
data = None
|
||||||
|
if args.type == "ondemand":
|
||||||
|
data = get_ec2_ondemand_instances_prices(args.filter_region, args.filter_type, args.filter_os_type)
|
||||||
|
elif args.type == "reserved":
|
||||||
|
data = get_ec2_reserved_instances_prices(args.filter_region, args.filter_type, args.filter_os_type)
|
||||||
|
|
||||||
|
if args.format == "json":
|
||||||
|
print json.dumps(data)
|
||||||
|
elif args.format == "table":
|
||||||
|
x = PrettyTable()
|
||||||
|
|
||||||
|
if args.type == "ondemand":
|
||||||
|
try:
|
||||||
|
x.set_field_names(["region", "type", "os", "price"])
|
||||||
|
except AttributeError:
|
||||||
|
x.field_names = ["region", "type", "os", "price"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
x.aligns[-1] = "l"
|
||||||
|
except AttributeError:
|
||||||
|
x.align["price"] = "l"
|
||||||
|
|
||||||
|
for r in data["regions"]:
|
||||||
|
region_name = r["region"]
|
||||||
|
for it in r["instanceTypes"]:
|
||||||
|
x.add_row([region_name, it["type"], it["os"], none_as_string(it["price"])])
|
||||||
|
elif args.type == "reserved":
|
||||||
|
try:
|
||||||
|
x.set_field_names(["region", "type", "os", "utilization", "term", "price", "upfront"])
|
||||||
|
except AttributeError:
|
||||||
|
x.field_names = ["region", "type", "os", "utilization", "term", "price", "upfront"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
x.aligns[-1] = "l"
|
||||||
|
x.aligns[-2] = "l"
|
||||||
|
except AttributeError:
|
||||||
|
x.align["price"] = "l"
|
||||||
|
x.align["upfront"] = "l"
|
||||||
|
|
||||||
|
for r in data["regions"]:
|
||||||
|
region_name = r["region"]
|
||||||
|
for it in r["instanceTypes"]:
|
||||||
|
for term in it["prices"]:
|
||||||
|
x.add_row([region_name, it["type"], it["os"], it["utilization"], term, none_as_string(it["prices"][term]["hourly"]), none_as_string(it["prices"][term]["upfront"])])
|
||||||
|
|
||||||
|
print x
|
||||||
|
elif args.format == "csv":
|
||||||
|
if args.type == "ondemand":
|
||||||
|
print "region,type,os,price"
|
||||||
|
for r in data["regions"]:
|
||||||
|
region_name = r["region"]
|
||||||
|
for it in r["instanceTypes"]:
|
||||||
|
print "%s,%s,%s,%s" % (region_name, it["type"], it["os"], none_as_string(it["price"]))
|
||||||
|
elif args.type == "reserved":
|
||||||
|
print "region,type,os,utilization,term,price,upfront"
|
||||||
|
for r in data["regions"]:
|
||||||
|
region_name = r["region"]
|
||||||
|
for it in r["instanceTypes"]:
|
||||||
|
for term in it["prices"]:
|
||||||
|
print "%s,%s,%s,%s,%s,%s,%s" % (region_name, it["type"], it["os"], it["utilization"], term, none_as_string(it["prices"][term]["hourly"]), none_as_string(it["prices"][term]["upfront"]))
|
|
@ -1,2 +0,0 @@
|
||||||
ec2dir = $(datadir)/@PACKAGE@/ec2
|
|
||||||
ec2_DATA = rates.ap-northeast-1 rates.ap-southeast-1 rates.eu-west-1 rates.us-east-1 rates.us-west-1 rates.us-west-2
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 2011-11-09: Approximate Instance Cost Basis per hour from
|
|
||||||
# http://aws.amazon.com/ec2/instance-types/
|
|
||||||
# http://aws.amazon.com/ec2/pricing/
|
|
||||||
# for AP - Tokyo
|
|
||||||
m1_small="0.10"
|
|
||||||
m1_large="0.40"
|
|
||||||
m1_xlarge="0.80"
|
|
||||||
t1_micro="0.027"
|
|
||||||
m2_xlarge="0.60"
|
|
||||||
m2_2xlarge="1.20"
|
|
||||||
m2_4xlarge="2.39"
|
|
||||||
c1_medium="0.20"
|
|
||||||
c1_xlarge="0.80"
|
|
||||||
cc1_4xlarge="1.60"
|
|
||||||
cg1_4xlarge="2.10"
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 2011-11-09: Approximate Instance Cost Basis per hour from
|
|
||||||
# http://aws.amazon.com/ec2/instance-types/
|
|
||||||
# http://aws.amazon.com/ec2/pricing/
|
|
||||||
# for AP - Singapore
|
|
||||||
m1_small="0.095"
|
|
||||||
m1_large="0.38"
|
|
||||||
m1_xlarge="0.76"
|
|
||||||
t1_micro="0.025"
|
|
||||||
m2_xlarge="0.57"
|
|
||||||
m2_2xlarge="1.14"
|
|
||||||
m2_4xlarge="2.28"
|
|
||||||
c1_medium="0.19"
|
|
||||||
c1_xlarge="0.76"
|
|
||||||
cc1_4xlarge="1.60"
|
|
||||||
cg1_4xlarge="2.10"
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 2011-11-09: Approximate Instance Cost Basis per hour from
|
|
||||||
# http://aws.amazon.com/ec2/instance-types/
|
|
||||||
# http://aws.amazon.com/ec2/pricing/
|
|
||||||
# for EU - Ireland
|
|
||||||
m1_small="0.095"
|
|
||||||
m1_large="0.38"
|
|
||||||
m1_xlarge="0.76"
|
|
||||||
t1_micro="0.025"
|
|
||||||
m2_xlarge="0.57"
|
|
||||||
m2_2xlarge="1.14"
|
|
||||||
m2_4xlarge="2.28"
|
|
||||||
c1_medium="0.19"
|
|
||||||
c1_xlarge="0.76"
|
|
||||||
cc1_4xlarge="1.60"
|
|
||||||
cg1_4xlarge="2.10"
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 2011-11-09: Approximate Instance Cost Basis per hour from
|
|
||||||
# http://aws.amazon.com/ec2/instance-types/
|
|
||||||
# http://aws.amazon.com/ec2/pricing/
|
|
||||||
# for US - N. Virginia
|
|
||||||
m1_small="0.085"
|
|
||||||
m1_large="0.34"
|
|
||||||
m1_xlarge="0.68"
|
|
||||||
t1_micro="0.02"
|
|
||||||
m2_xlarge="0.50"
|
|
||||||
m2_2xlarge="1.00"
|
|
||||||
m2_4xlarge="2.00"
|
|
||||||
c1_medium="0.17"
|
|
||||||
c1_xlarge="0.68"
|
|
||||||
cc1_4xlarge="1.60"
|
|
||||||
cg1_4xlarge="2.10"
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 2011-11-09: Approximate Instance Cost Basis per hour from
|
|
||||||
# http://aws.amazon.com/ec2/instance-types/
|
|
||||||
# http://aws.amazon.com/ec2/pricing/
|
|
||||||
# for US - N. California
|
|
||||||
M1_SMALL="0.095"
|
|
||||||
M1_LARGE="0.38"
|
|
||||||
M1_XLARGE="0.76"
|
|
||||||
T1_MICRO="0.025"
|
|
||||||
M2_XLARGE="0.57"
|
|
||||||
M2_2XLARGE="1.14"
|
|
||||||
M2_4XLARGE="2.28"
|
|
||||||
C1_MEDIUM="0.19"
|
|
||||||
C1_XLARGE="0.76"
|
|
||||||
CC1_4XLARGE="1.60"
|
|
||||||
CG1_4XLARGE="2.10"
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 2011-11-09: Approximate Instance Cost Basis per hour from
|
|
||||||
# http://aws.amazon.com/ec2/instance-types/
|
|
||||||
# http://aws.amazon.com/ec2/pricing/
|
|
||||||
# for US - Oregon
|
|
||||||
m1_small="0.085"
|
|
||||||
m1_large="0.34"
|
|
||||||
m1_xlarge="0.68"
|
|
||||||
t1_micro="0.02"
|
|
||||||
m2_xlarge="0.50"
|
|
||||||
m2_2xlarge="1.00"
|
|
||||||
m2_4xlarge="2.00"
|
|
||||||
c1_medium="0.17"
|
|
||||||
c1_xlarge="0.68"
|
|
||||||
cc1_4xlarge="1.60"
|
|
||||||
cg1_4xlarge="2.10"
|
|
|
@ -72,9 +72,3 @@
|
||||||
# to instead count number of distinct users logged onto the system
|
# to instead count number of distinct users logged onto the system
|
||||||
# Default: 0
|
# Default: 0
|
||||||
#USERS_DISTINCT=0
|
#USERS_DISTINCT=0
|
||||||
|
|
||||||
# If we're not in EC2 (ie, no metadata service, and no known instance type), the
|
|
||||||
# ec2_cost status is disabled by default. To override, and get an esitmate, set
|
|
||||||
# this to '1'.
|
|
||||||
# Default: 0
|
|
||||||
#EC2_ESTIMATE=0
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ The background colors of the \fBbyobu\fP status lines can be adjusted by editing
|
||||||
|
|
||||||
\fBdistro\fP \- OS/distribution name of the release running on the current system as reported by \fBlsb_release(1)\fP or \fI/etc/issue\fP; displayed in the lower bar in bold black text toward the left on a grey background; you may override the detected release with DISTRO=Whatever in \fI$BYOBU_CONFIG_DIR/statusrc\fP
|
\fBdistro\fP \- OS/distribution name of the release running on the current system as reported by \fBlsb_release(1)\fP or \fI/etc/issue\fP; displayed in the lower bar in bold black text toward the left on a grey background; you may override the detected release with DISTRO=Whatever in \fI$BYOBU_CONFIG_DIR/statusrc\fP
|
||||||
|
|
||||||
\fBec2_cost\fP \- an estimation of the cost of the current boot of the system in terms of the Amazon EC2 billing model; displayed in the lower bar toward the right in green text on a black background; there is a leading '~' to indicate that this is an estimation, and the monetary units are US Dollars '$'; if not running in EC2, this plugin is disabled unless EC2_ESTIMATE=1 in \fI~/.byobu/statusrc\fP
|
\fBec2_cost\fP \- an estimation of the cost of the current boot of the system in terms of the Amazon EC2 billing model; displayed in the lower bar toward the right in green text on a black background; the monetary units are US Dollars '$'; this plugin only works when an AWS-compatible metadata server is available at \fIhttp://169.254.169.254\fP
|
||||||
|
|
||||||
\fBentropy\fP \- a count of the system's current entropy in bytes; displayed in the lower bar toward the right in yellow text on a dark grey background; there is a leading 'e' to indicate 'entropy'
|
\fBentropy\fP \- a count of the system's current entropy in bytes; displayed in the lower bar toward the right in yellow text on a dark grey background; there is a leading 'e' to indicate 'entropy'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue