Created
April 15, 2022 19:15
-
-
Save zonca/3cc70af86d24a0bcc176f2b18d0cc9dd to your computer and use it in GitHub Desktop.
Jetstream2_SU_calculator.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/zonca/3cc70af86d24a0bcc176f2b18d0cc9dd/jetstream2_su_calculator.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "MWw9DUyeI3xF" | |
}, | |
"source": [ | |
"# Jetstream2 SU calculator\n", | |
"\n", | |
"Virtual Machine sizes and their vCPUs determine the SU cost and are available on [the Jetstream2 website](https://docs.jetstream-cloud.org/general/vmsizes/)." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"id": "T9AYpCcvI3xH" | |
}, | |
"outputs": [], | |
"source": [ | |
"from astropy.table import QTable\n", | |
"from astropy import units as u" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"id": "NeYY6zppI3xI" | |
}, | |
"outputs": [], | |
"source": [ | |
"#!openstack flavor list -f csv > openstack_flavor.csv" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "OplFFM8HI3xI", | |
"outputId": "a0fe0db6-df97-42fe-ed6c-01af40313c07" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Overwriting openstack_flavor.csv\n" | |
] | |
} | |
], | |
"source": [ | |
"%%file openstack_flavor.csv\n", | |
"\"ID\",\"Name\",\"RAM\",\"Disk\",\"Ephemeral\",\"VCPUs\",\"Is Public\"\n", | |
"\"1\",\"m3.tiny\",3072,20,0,1,True\n", | |
"\"2\",\"m3.small\",6144,20,0,2,True\n", | |
"\"3\",\"m3.quad\",15360,20,0,4,True\n", | |
"\"4\",\"m3.medium\",30720,60,0,8,True\n", | |
"\"5\",\"m3.large\",61440,60,0,16,True\n", | |
"\"7\",\"m3.xl\",128000,60,0,32,True\n", | |
"\"8\",\"m3.2xl\",256000,60,0,64,True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"SU = u.def_unit(\"SU\")\n", | |
"month = u.def_unit(\"month\", 30*u.day)" | |
], | |
"metadata": { | |
"id": "wBHROmafoFNB" | |
}, | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"flavor = QTable.read(\"openstack_flavor.csv\", units={\"RAM\":u.MB, \"Disk\":u.GB})\n", | |
"flavor.add_index(\"Name\")\n", | |
"flavor[\"SU/hour\"] = flavor[\"VCPUs\"] * SU / u.hour" | |
], | |
"metadata": { | |
"id": "W4JGmR89lzwH" | |
}, | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"id": "YOMTrPy-I3xJ" | |
}, | |
"outputs": [], | |
"source": [ | |
"flavor[\"RAM\"] = flavor[\"RAM\"].to(u.GB)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"flavor" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 244 | |
}, | |
"id": "uFGgma03nl8l", | |
"outputId": "9918d131-2456-4fa0-c3f9-d0d9e9e42c62" | |
}, | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<QTable length=7>\n", | |
" ID Name RAM Disk Ephemeral VCPUs Is Public SU/hour\n", | |
" Gbyte Gbyte SU / h\n", | |
"int64 str9 float64 float64 int64 int64 str4 float64\n", | |
"----- --------- ------- ------- --------- ----- --------- -------\n", | |
" 1 m3.tiny 3.072 20.0 0 1 True 1.0\n", | |
" 2 m3.small 6.144 20.0 0 2 True 2.0\n", | |
" 3 m3.quad 15.36 20.0 0 4 True 4.0\n", | |
" 4 m3.medium 30.72 60.0 0 8 True 8.0\n", | |
" 5 m3.large 61.44 60.0 0 16 True 16.0\n", | |
" 7 m3.xl 128.0 60.0 0 32 True 32.0\n", | |
" 8 m3.2xl 256.0 60.0 0 64 True 64.0" | |
], | |
"text/html": [ | |
"<div><i>QTable length=7</i>\n", | |
"<table id=\"table140218308969872\" class=\"table-striped table-bordered table-condensed\">\n", | |
"<thead><tr><th>ID</th><th>Name</th><th>RAM</th><th>Disk</th><th>Ephemeral</th><th>VCPUs</th><th>Is Public</th><th>SU/hour</th></tr></thead>\n", | |
"<thead><tr><th></th><th></th><th>Gbyte</th><th>Gbyte</th><th></th><th></th><th></th><th>SU / h</th></tr></thead>\n", | |
"<thead><tr><th>int64</th><th>str9</th><th>float64</th><th>float64</th><th>int64</th><th>int64</th><th>str4</th><th>float64</th></tr></thead>\n", | |
"<tr><td>1</td><td>m3.tiny</td><td>3.072</td><td>20.0</td><td>0</td><td>1</td><td>True</td><td>1.0</td></tr>\n", | |
"<tr><td>2</td><td>m3.small</td><td>6.144</td><td>20.0</td><td>0</td><td>2</td><td>True</td><td>2.0</td></tr>\n", | |
"<tr><td>3</td><td>m3.quad</td><td>15.36</td><td>20.0</td><td>0</td><td>4</td><td>True</td><td>4.0</td></tr>\n", | |
"<tr><td>4</td><td>m3.medium</td><td>30.72</td><td>60.0</td><td>0</td><td>8</td><td>True</td><td>8.0</td></tr>\n", | |
"<tr><td>5</td><td>m3.large</td><td>61.44</td><td>60.0</td><td>0</td><td>16</td><td>True</td><td>16.0</td></tr>\n", | |
"<tr><td>7</td><td>m3.xl</td><td>128.0</td><td>60.0</td><td>0</td><td>32</td><td>True</td><td>32.0</td></tr>\n", | |
"<tr><td>8</td><td>m3.2xl</td><td>256.0</td><td>60.0</td><td>0</td><td>64</td><td>True</td><td>64.0</td></tr>\n", | |
"</table></div>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"id": "0oqZlhA4I3xK" | |
}, | |
"outputs": [], | |
"source": [ | |
"num_instances = {\"m3.small\":2, \"m3.medium\":1, \"m3.xl\":3}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "ZK1eDhObI3xK", | |
"outputId": "e1b763e6-c0a6-4491-d1e8-6af8fffed27b" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"SU Usage: 2 m3.small 1 m3.medium 3 m3.xl \n", | |
"108.0 SU / h\n", | |
"2592.0 SU / d\n", | |
"77760.0 SU / month\n", | |
"946728.0 SU / yr\n" | |
] | |
} | |
], | |
"source": [ | |
"su_cost = 0\n", | |
"title = \"SU Usage: \"\n", | |
"for k,v in num_instances.items():\n", | |
" title += f\"{v} {k} \"\n", | |
" su_cost += v * flavor.loc[k][\"SU/hour\"]\n", | |
"print(title)\n", | |
"print(su_cost)\n", | |
"for timespan in [SU/u.day, SU/month, SU/u.year]:\n", | |
" print(su_cost.to(timespan))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"" | |
], | |
"metadata": { | |
"id": "7QZMjyT_MCYQ" | |
}, | |
"execution_count": 9, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.9" | |
}, | |
"colab": { | |
"name": "Jetstream2_SU_calculator.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run in the browser: https://colab.research.google.com/gist/zonca/3cc70af86d24a0bcc176f2b18d0cc9dd/jetstream2_su_calculator.ipynb