├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.rst ├── docs ├── Makefile ├── _static │ └── shaker-sidebar.jpg ├── _templates │ ├── sidebarintro.html │ └── sidebarlogo.html ├── _themes │ ├── LICENSE │ ├── README │ ├── flask_theme_support.py │ └── shaker │ │ ├── layout.html │ │ ├── relations.html │ │ ├── static │ │ └── flasky.css_t │ │ └── theme.conf ├── conf.py ├── index.rst └── ref │ └── profile.rst ├── requirements.txt ├── scripts ├── shaker └── shaker-terminate ├── setup.py ├── shaker ├── __init__.py ├── ami.py ├── config.py ├── log.py ├── template.py └── version.py └── util └── ubuntu_cloud_images.py /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | docs/_build/ 3 | dist/ 4 | shaker.egg-info/ 5 | MANIFEST 6 | 7 | # Compiled source # 8 | ################### 9 | *.com 10 | *.class 11 | *.dll 12 | *.exe 13 | *.o 14 | *.so 15 | *.pyc 16 | 17 | # Packages # 18 | ############ 19 | # it's better to unpack these files and commit the raw source 20 | # git has its own built in compression methods 21 | *.7z 22 | *.dmg 23 | *.gz 24 | *.iso 25 | *.jar 26 | *.rar 27 | *.tar 28 | *.zip 29 | 30 | # Logs and databases # 31 | ###################### 32 | pip-log.txt 33 | *.log 34 | *.sql 35 | *.sqlite 36 | *.rdb 37 | 38 | # OS generated files # 39 | ###################### 40 | .DS_Store* 41 | ehthumbs.db 42 | Icon? 43 | Thumbs.db 44 | 45 | # IDE generated files # 46 | ####################### 47 | *.sublime-project 48 | *.sublime-workspace 49 | .codeintel/* 50 | .rvmrc 51 | *_flymake.py 52 | 53 | # Django static folder 54 | static/* 55 | 56 | # Reports 57 | reports/* 58 | 59 | # Dev Utils 60 | _rebuild.sh 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Jeff Bauer 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 17 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 26 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include docs *.rst 2 | recursive-exclude docs/_build * 3 | include requirements.txt 4 | include README.rst 5 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Shaker: A Salt Minion Factory for EC2 Instances 2 | =============================================== 3 | 4 | Shaker is BSD-New Licensed command-line application to launch Salt 5 | minions as Amazon EC2 instances. 6 | 7 | `Salt `_ is a powerful remote execution 8 | manager that can be used to administer servers in a fast and 9 | efficient way. 10 | 11 | Running an Amazon EC2 instance as a Salt minion is fairly simple. 12 | Also tedious, if you need to launch minions often. Shaker bridges 13 | the gap between launching an EC2 instance and bootstrapping it as 14 | a Salt minion. 15 | 16 | 17 | Example 18 | ------- 19 | 20 | Shaker is usually run from the command line. To start a Salt minion, 21 | have it connect upon boot to Salt master *salt.example.com*: 22 | 23 | :: 24 | 25 | $ shaker --ami ami-057bcf6c --master salt.example.com 26 | 27 | Started Instance: i-9175d8f4 28 | 29 | To access: ssh ubuntu@ec2-107-20-93-179.compute-1.amazonaws.com 30 | To terminate: shaker-terminate i-9175d8f4 31 | 32 | 33 | Documentation and Links 34 | ----------------------- 35 | 36 | * `ReadTheDocs `_ 37 | * `GitHub Repository `_ 38 | * `Salt `_ 39 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python $(shell which sphinx-build) 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/shaker.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/shaker.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/shaker" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/shaker" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /docs/_static/shaker-sidebar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubic/shaker/54ac4a614be44ca54ba04d8bae981391ffb39c32/docs/_static/shaker-sidebar.jpg -------------------------------------------------------------------------------- /docs/_templates/sidebarintro.html: -------------------------------------------------------------------------------- 1 | 6 | 7 |

8 | 10 |

11 | 12 |

13 | Shaker is a program for launching Salt 14 | minions to run as Amazon EC2 instances. A minion will connect 15 | to a master servers, which provides configuration management. 16 |

17 | 18 |

Feedback

19 |

20 | Feedback is greatly appreciated. If you have any questions, comments, 21 | or suggestions, please 22 | send me an email. 23 |

24 | 25 | 26 |

Useful Links

27 | 33 | -------------------------------------------------------------------------------- /docs/_templates/sidebarlogo.html: -------------------------------------------------------------------------------- 1 | 6 |

7 | 9 |

10 | 11 |

12 | Shaker is a factory for launching salt minions as Amazon EC2 instances. 13 | You are currently looking at the documentation of the 14 | development release. 15 |

16 | 17 | -------------------------------------------------------------------------------- /docs/_themes/LICENSE: -------------------------------------------------------------------------------- 1 | Further Modifications: 2 | 3 | Copyright (c) 2012 Jeff Bauer. 4 | 5 | 6 | Modifications: 7 | 8 | Copyright (c) 2011 Kenneth Reitz. 9 | 10 | 11 | Original Project: 12 | 13 | Copyright (c) 2010 by Armin Ronacher. 14 | 15 | 16 | Some rights reserved. 17 | 18 | Redistribution and use in source and binary forms of the theme, with or 19 | without modification, are permitted provided that the following conditions 20 | are met: 21 | 22 | * Redistributions of source code must retain the above copyright 23 | notice, this list of conditions and the following disclaimer. 24 | 25 | * Redistributions in binary form must reproduce the above 26 | copyright notice, this list of conditions and the following 27 | disclaimer in the documentation and/or other materials provided 28 | with the distribution. 29 | 30 | * The names of the contributors may not be used to endorse or 31 | promote products derived from this software without specific 32 | prior written permission. 33 | 34 | We kindly ask you to only use these themes in an unmodified manner just 35 | for Flask and Flask-related products, not for unrelated projects. If you 36 | like the visual style and want to use it for your own projects, please 37 | consider making some larger changes to the themes (such as changing 38 | font faces, sizes, colors or margins). 39 | 40 | THIS THEME IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 41 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 44 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 46 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 47 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 48 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | ARISING IN ANY WAY OUT OF THE USE OF THIS THEME, EVEN IF ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | -------------------------------------------------------------------------------- /docs/_themes/README: -------------------------------------------------------------------------------- 1 | shaker Theme Sphinx Style 2 | ========================= 3 | 4 | Theme based on Kenneth Reitz theme, which in turns was based 5 | on Mitsuhiko's themes for Flask and Flask related projects. 6 | 7 | To use this style in your Sphinx documentation, follow 8 | this guide: 9 | 10 | 1. put this folder as _themes into your docs folder. Alternatively 11 | you can also use git submodules to check out the contents there. 12 | 13 | 2. add this to your conf.py: :: 14 | 15 | sys.path.append(os.path.abspath('_themes')) 16 | html_theme_path = ['_themes'] 17 | html_theme = 'shaker' 18 | 19 | -------------------------------------------------------------------------------- /docs/_themes/flask_theme_support.py: -------------------------------------------------------------------------------- 1 | # flasky extensions. flasky pygments style based on tango style 2 | from pygments.style import Style 3 | from pygments.token import Keyword, Name, Comment, String, Error, \ 4 | Number, Operator, Generic, Whitespace, Punctuation, Other, Literal 5 | 6 | 7 | class FlaskyStyle(Style): 8 | background_color = "#f8f8f8" 9 | default_style = "" 10 | 11 | styles = { 12 | # No corresponding class for the following: 13 | #Text: "", # class: '' 14 | Whitespace: "underline #f8f8f8", # class: 'w' 15 | Error: "#a40000 border:#ef2929", # class: 'err' 16 | Other: "#000000", # class 'x' 17 | 18 | Comment: "italic #8f5902", # class: 'c' 19 | Comment.Preproc: "noitalic", # class: 'cp' 20 | 21 | Keyword: "bold #004461", # class: 'k' 22 | Keyword.Constant: "bold #004461", # class: 'kc' 23 | Keyword.Declaration: "bold #004461", # class: 'kd' 24 | Keyword.Namespace: "bold #004461", # class: 'kn' 25 | Keyword.Pseudo: "bold #004461", # class: 'kp' 26 | Keyword.Reserved: "bold #004461", # class: 'kr' 27 | Keyword.Type: "bold #004461", # class: 'kt' 28 | 29 | Operator: "#582800", # class: 'o' 30 | Operator.Word: "bold #004461", # class: 'ow' - like keywords 31 | 32 | Punctuation: "bold #000000", # class: 'p' 33 | 34 | # because special names such as Name.Class, Name.Function, etc. 35 | # are not recognized as such later in the parsing, we choose them 36 | # to look the same as ordinary variables. 37 | Name: "#000000", # class: 'n' 38 | Name.Attribute: "#c4a000", # class: 'na' - to be revised 39 | Name.Builtin: "#004461", # class: 'nb' 40 | Name.Builtin.Pseudo: "#3465a4", # class: 'bp' 41 | Name.Class: "#000000", # class: 'nc' - to be revised 42 | Name.Constant: "#000000", # class: 'no' - to be revised 43 | Name.Decorator: "#888", # class: 'nd' - to be revised 44 | Name.Entity: "#ce5c00", # class: 'ni' 45 | Name.Exception: "bold #cc0000", # class: 'ne' 46 | Name.Function: "#000000", # class: 'nf' 47 | Name.Property: "#000000", # class: 'py' 48 | Name.Label: "#f57900", # class: 'nl' 49 | Name.Namespace: "#000000", # class: 'nn' - to be revised 50 | Name.Other: "#000000", # class: 'nx' 51 | Name.Tag: "bold #004461", # class: 'nt' - like a keyword 52 | Name.Variable: "#000000", # class: 'nv' - to be revised 53 | Name.Variable.Class: "#000000", # class: 'vc' - to be revised 54 | Name.Variable.Global: "#000000", # class: 'vg' - to be revised 55 | Name.Variable.Instance: "#000000", # class: 'vi' - to be revised 56 | 57 | Number: "#990000", # class: 'm' 58 | 59 | Literal: "#000000", # class: 'l' 60 | Literal.Date: "#000000", # class: 'ld' 61 | 62 | String: "#4e9a06", # class: 's' 63 | String.Backtick: "#4e9a06", # class: 'sb' 64 | String.Char: "#4e9a06", # class: 'sc' 65 | String.Doc: "italic #8f5902", # class: 'sd' - like a comment 66 | String.Double: "#4e9a06", # class: 's2' 67 | String.Escape: "#4e9a06", # class: 'se' 68 | String.Heredoc: "#4e9a06", # class: 'sh' 69 | String.Interpol: "#4e9a06", # class: 'si' 70 | String.Other: "#4e9a06", # class: 'sx' 71 | String.Regex: "#4e9a06", # class: 'sr' 72 | String.Single: "#4e9a06", # class: 's1' 73 | String.Symbol: "#4e9a06", # class: 'ss' 74 | 75 | Generic: "#000000", # class: 'g' 76 | Generic.Deleted: "#a40000", # class: 'gd' 77 | Generic.Emph: "italic #000000", # class: 'ge' 78 | Generic.Error: "#ef2929", # class: 'gr' 79 | Generic.Heading: "bold #000080", # class: 'gh' 80 | Generic.Inserted: "#00A000", # class: 'gi' 81 | Generic.Output: "#888", # class: 'go' 82 | Generic.Prompt: "#745334", # class: 'gp' 83 | Generic.Strong: "bold #000000", # class: 'gs' 84 | Generic.Subheading: "bold #800080", # class: 'gu' 85 | Generic.Traceback: "bold #a40000", # class: 'gt' 86 | } 87 | -------------------------------------------------------------------------------- /docs/_themes/shaker/layout.html: -------------------------------------------------------------------------------- 1 | {%- extends "basic/layout.html" %} 2 | {%- block extrahead %} 3 | {{ super() }} 4 | {% if theme_touch_icon %} 5 | 6 | {% endif %} 7 | 8 | {% endblock %} 9 | {%- block relbar2 %}{% endblock %} 10 | {%- block footer %} 11 | 14 | 15 | Fork me on GitHub 16 | 17 | 28 | 29 | {%- endblock %} 30 | -------------------------------------------------------------------------------- /docs/_themes/shaker/relations.html: -------------------------------------------------------------------------------- 1 |

Related Topics

2 | 20 | -------------------------------------------------------------------------------- /docs/_themes/shaker/static/flasky.css_t: -------------------------------------------------------------------------------- 1 | /* 2 | * flasky.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * :copyright: Copyright 2010 by Armin Ronacher. Modifications by Kenneth Reitz. 6 | * :license: Flask Design License, see LICENSE for details. 7 | */ 8 | 9 | {% set page_width = '940px' %} 10 | {% set sidebar_width = '220px' %} 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: 'goudy old style', 'minion pro', 'bell mt', Georgia, 'Hiragino Mincho Pro'; 18 | font-size: 17px; 19 | background-color: white; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | width: {{ page_width }}; 27 | margin: 30px auto 0 auto; 28 | } 29 | 30 | div.documentwrapper { 31 | float: left; 32 | width: 100%; 33 | } 34 | 35 | div.bodywrapper { 36 | margin: 0 0 0 {{ sidebar_width }}; 37 | } 38 | 39 | div.sphinxsidebar { 40 | width: {{ sidebar_width }}; 41 | } 42 | 43 | hr { 44 | border: 1px solid #B1B4B6; 45 | } 46 | 47 | div.body { 48 | background-color: #ffffff; 49 | color: #3E4349; 50 | padding: 0 30px 0 30px; 51 | } 52 | 53 | img.floatingflask { 54 | padding: 0 0 10px 10px; 55 | float: right; 56 | } 57 | 58 | div.footer { 59 | width: {{ page_width }}; 60 | margin: 20px auto 30px auto; 61 | font-size: 14px; 62 | color: #888; 63 | text-align: right; 64 | } 65 | 66 | div.footer a { 67 | color: #888; 68 | } 69 | 70 | div.related { 71 | display: none; 72 | } 73 | 74 | div.sphinxsidebar a { 75 | color: #444; 76 | text-decoration: none; 77 | border-bottom: 1px dotted #999; 78 | } 79 | 80 | div.sphinxsidebar a:hover { 81 | border-bottom: 1px solid #999; 82 | } 83 | 84 | div.sphinxsidebar { 85 | font-size: 14px; 86 | line-height: 1.5; 87 | } 88 | 89 | div.sphinxsidebarwrapper { 90 | padding: 18px 10px; 91 | } 92 | 93 | div.sphinxsidebarwrapper p.logo { 94 | padding: 0; 95 | margin: -10px 0 0 -20px; 96 | text-align: center; 97 | } 98 | 99 | div.sphinxsidebar h3, 100 | div.sphinxsidebar h4 { 101 | font-family: 'Garamond', 'Georgia', serif; 102 | color: #444; 103 | font-size: 24px; 104 | font-weight: normal; 105 | margin: 0 0 5px 0; 106 | padding: 0; 107 | } 108 | 109 | div.sphinxsidebar h4 { 110 | font-size: 20px; 111 | } 112 | 113 | div.sphinxsidebar h3 a { 114 | color: #444; 115 | } 116 | 117 | div.sphinxsidebar p.logo a, 118 | div.sphinxsidebar h3 a, 119 | div.sphinxsidebar p.logo a:hover, 120 | div.sphinxsidebar h3 a:hover { 121 | border: none; 122 | } 123 | 124 | div.sphinxsidebar p { 125 | color: #555; 126 | margin: 10px 0; 127 | } 128 | 129 | div.sphinxsidebar ul { 130 | margin: 10px 0; 131 | padding: 0; 132 | color: #000; 133 | } 134 | 135 | div.sphinxsidebar input { 136 | border: 1px solid #ccc; 137 | font-family: 'Georgia', serif; 138 | font-size: 1em; 139 | } 140 | 141 | /* -- body styles ----------------------------------------------------------- */ 142 | 143 | a { 144 | color: #004B6B; 145 | text-decoration: underline; 146 | } 147 | 148 | a:hover { 149 | color: #6D4100; 150 | text-decoration: underline; 151 | } 152 | 153 | div.body h1, 154 | div.body h2, 155 | div.body h3, 156 | div.body h4, 157 | div.body h5, 158 | div.body h6 { 159 | font-family: 'Garamond', 'Georgia', serif; 160 | font-weight: normal; 161 | margin: 30px 0px 10px 0px; 162 | padding: 0; 163 | } 164 | 165 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 166 | div.body h2 { font-size: 180%; } 167 | div.body h3 { font-size: 150%; } 168 | div.body h4 { font-size: 130%; } 169 | div.body h5 { font-size: 100%; } 170 | div.body h6 { font-size: 100%; } 171 | 172 | a.headerlink { 173 | color: #ddd; 174 | padding: 0 4px; 175 | text-decoration: none; 176 | } 177 | 178 | a.headerlink:hover { 179 | color: #444; 180 | background: #eaeaea; 181 | } 182 | 183 | div.body p, div.body dd, div.body li { 184 | line-height: 1.4em; 185 | } 186 | 187 | div.admonition { 188 | background: #fafafa; 189 | margin: 20px -30px; 190 | padding: 10px 30px; 191 | border-top: 1px solid #ccc; 192 | border-bottom: 1px solid #ccc; 193 | } 194 | 195 | div.admonition tt.xref, div.admonition a tt { 196 | border-bottom: 1px solid #fafafa; 197 | } 198 | 199 | dd div.admonition { 200 | margin-left: -60px; 201 | padding-left: 60px; 202 | } 203 | 204 | div.admonition p.admonition-title { 205 | font-family: 'Garamond', 'Georgia', serif; 206 | font-weight: normal; 207 | font-size: 24px; 208 | margin: 0 0 10px 0; 209 | padding: 0; 210 | line-height: 1; 211 | } 212 | 213 | div.admonition p.last { 214 | margin-bottom: 0; 215 | } 216 | 217 | div.highlight { 218 | background-color: white; 219 | } 220 | 221 | dt:target, .highlight { 222 | background: #FAF3E8; 223 | } 224 | 225 | div.note { 226 | background-color: #eee; 227 | border: 1px solid #ccc; 228 | } 229 | 230 | div.seealso { 231 | background-color: #ffc; 232 | border: 1px solid #ff6; 233 | } 234 | 235 | div.topic { 236 | background-color: #eee; 237 | } 238 | 239 | p.admonition-title { 240 | display: inline; 241 | } 242 | 243 | p.admonition-title:after { 244 | content: ":"; 245 | } 246 | 247 | pre, tt { 248 | font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 249 | font-size: 0.9em; 250 | } 251 | 252 | img.screenshot { 253 | } 254 | 255 | tt.descname, tt.descclassname { 256 | font-size: 0.95em; 257 | } 258 | 259 | tt.descname { 260 | padding-right: 0.08em; 261 | } 262 | 263 | img.screenshot { 264 | -moz-box-shadow: 2px 2px 4px #eee; 265 | -webkit-box-shadow: 2px 2px 4px #eee; 266 | box-shadow: 2px 2px 4px #eee; 267 | } 268 | 269 | table.docutils { 270 | border: 1px solid #888; 271 | -moz-box-shadow: 2px 2px 4px #eee; 272 | -webkit-box-shadow: 2px 2px 4px #eee; 273 | box-shadow: 2px 2px 4px #eee; 274 | } 275 | 276 | table.docutils td, table.docutils th { 277 | border: 1px solid #888; 278 | padding: 0.25em 0.7em; 279 | } 280 | 281 | table.field-list, table.footnote { 282 | border: none; 283 | -moz-box-shadow: none; 284 | -webkit-box-shadow: none; 285 | box-shadow: none; 286 | } 287 | 288 | table.footnote { 289 | margin: 15px 0; 290 | width: 100%; 291 | border: 1px solid #eee; 292 | background: #fdfdfd; 293 | font-size: 0.9em; 294 | } 295 | 296 | table.footnote + table.footnote { 297 | margin-top: -15px; 298 | border-top: none; 299 | } 300 | 301 | table.field-list th { 302 | padding: 0 0.8em 0 0; 303 | } 304 | 305 | table.field-list td { 306 | padding: 0; 307 | } 308 | 309 | table.footnote td.label { 310 | width: 0px; 311 | padding: 0.3em 0 0.3em 0.5em; 312 | } 313 | 314 | table.footnote td { 315 | padding: 0.3em 0.5em; 316 | } 317 | 318 | dl { 319 | margin: 0; 320 | padding: 0; 321 | } 322 | 323 | dl dd { 324 | margin-left: 30px; 325 | } 326 | 327 | blockquote { 328 | margin: 0 0 0 30px; 329 | padding: 0; 330 | } 331 | 332 | ul, ol { 333 | margin: 10px 0 10px 30px; 334 | padding: 0; 335 | } 336 | 337 | pre { 338 | background: #eee; 339 | padding: 7px 30px; 340 | margin: 15px -30px; 341 | line-height: 1.3em; 342 | } 343 | 344 | dl pre, blockquote pre, li pre { 345 | margin-left: -60px; 346 | padding-left: 60px; 347 | } 348 | 349 | dl dl pre { 350 | margin-left: -90px; 351 | padding-left: 90px; 352 | } 353 | 354 | tt { 355 | background-color: #ecf0f3; 356 | color: #222; 357 | /* padding: 1px 2px; */ 358 | } 359 | 360 | tt.xref, a tt { 361 | background-color: #FBFBFB; 362 | border-bottom: 1px solid white; 363 | } 364 | 365 | a.reference { 366 | text-decoration: none; 367 | border-bottom: 1px dotted #004B6B; 368 | } 369 | 370 | a.reference:hover { 371 | border-bottom: 1px solid #6D4100; 372 | } 373 | 374 | a.footnote-reference { 375 | text-decoration: none; 376 | font-size: 0.7em; 377 | vertical-align: top; 378 | border-bottom: 1px dotted #004B6B; 379 | } 380 | 381 | a.footnote-reference:hover { 382 | border-bottom: 1px solid #6D4100; 383 | } 384 | 385 | a:hover tt { 386 | background: #EEE; 387 | } 388 | 389 | 390 | @media screen and (max-width: 870px) { 391 | 392 | div.sphinxsidebar { 393 | display: none; 394 | } 395 | 396 | div.document { 397 | width: 100%; 398 | 399 | } 400 | 401 | div.documentwrapper { 402 | margin-left: 0; 403 | margin-top: 0; 404 | margin-right: 0; 405 | margin-bottom: 0; 406 | } 407 | 408 | div.bodywrapper { 409 | margin-top: 0; 410 | margin-right: 0; 411 | margin-bottom: 0; 412 | margin-left: 0; 413 | } 414 | 415 | ul { 416 | margin-left: 0; 417 | } 418 | 419 | .document { 420 | width: auto; 421 | } 422 | 423 | .footer { 424 | width: auto; 425 | } 426 | 427 | .bodywrapper { 428 | margin: 0; 429 | } 430 | 431 | .footer { 432 | width: auto; 433 | } 434 | 435 | .github { 436 | display: none; 437 | } 438 | 439 | 440 | 441 | } 442 | 443 | 444 | 445 | @media screen and (max-width: 875px) { 446 | 447 | body { 448 | margin: 0; 449 | padding: 20px 30px; 450 | } 451 | 452 | div.documentwrapper { 453 | float: none; 454 | background: white; 455 | } 456 | 457 | div.sphinxsidebar { 458 | display: block; 459 | float: none; 460 | width: 102.5%; 461 | margin: 50px -30px -20px -30px; 462 | padding: 10px 20px; 463 | background: #333; 464 | color: white; 465 | } 466 | 467 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 468 | div.sphinxsidebar h3 a { 469 | color: white; 470 | } 471 | 472 | div.sphinxsidebar a { 473 | color: #aaa; 474 | } 475 | 476 | div.sphinxsidebar p.logo { 477 | display: none; 478 | } 479 | 480 | div.document { 481 | width: 100%; 482 | margin: 0; 483 | } 484 | 485 | div.related { 486 | display: block; 487 | margin: 0; 488 | padding: 10px 0 20px 0; 489 | } 490 | 491 | div.related ul, 492 | div.related ul li { 493 | margin: 0; 494 | padding: 0; 495 | } 496 | 497 | div.footer { 498 | display: none; 499 | } 500 | 501 | div.bodywrapper { 502 | margin: 0; 503 | } 504 | 505 | div.body { 506 | min-height: 0; 507 | padding: 0; 508 | } 509 | 510 | .rtd_doc_footer { 511 | display: none; 512 | } 513 | 514 | .document { 515 | width: auto; 516 | } 517 | 518 | .footer { 519 | width: auto; 520 | } 521 | 522 | .footer { 523 | width: auto; 524 | } 525 | 526 | .github { 527 | display: none; 528 | } 529 | } 530 | 531 | 532 | /* scrollbars */ 533 | 534 | ::-webkit-scrollbar { 535 | width: 6px; 536 | height: 6px; 537 | } 538 | 539 | ::-webkit-scrollbar-button:start:decrement, 540 | ::-webkit-scrollbar-button:end:increment { 541 | display: block; 542 | height: 10px; 543 | } 544 | 545 | ::-webkit-scrollbar-button:vertical:increment { 546 | background-color: #fff; 547 | } 548 | 549 | ::-webkit-scrollbar-track-piece { 550 | background-color: #eee; 551 | -webkit-border-radius: 3px; 552 | } 553 | 554 | ::-webkit-scrollbar-thumb:vertical { 555 | height: 50px; 556 | background-color: #ccc; 557 | -webkit-border-radius: 3px; 558 | } 559 | 560 | ::-webkit-scrollbar-thumb:horizontal { 561 | width: 50px; 562 | background-color: #ccc; 563 | -webkit-border-radius: 3px; 564 | } 565 | 566 | /* misc. */ 567 | 568 | .revsys-inline { 569 | display: none!important; 570 | } -------------------------------------------------------------------------------- /docs/_themes/shaker/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = flasky.css 4 | pygments_style = flask_theme_support.FlaskyStyle 5 | 6 | [options] 7 | touch_icon = 8 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # shaker documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Jan 31 20:33:49 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | class Mock(object): 17 | ''' 18 | Mock out specified imports 19 | 20 | This allows autodoc to do it's thing without having oodles of req'd 21 | installed libs. This doesn't work with ``import *`` imports. 22 | 23 | http://read-the-docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules 24 | ''' 25 | def __init__(self, *args, **kwargs): 26 | pass 27 | 28 | def __call__(self, *args, **kwargs): 29 | return Mock() 30 | 31 | @classmethod 32 | def __getattr__(self, name): 33 | if name in ('__file__', '__path__'): 34 | return '/dev/null' 35 | elif name[0] == name[0].upper(): 36 | return type(name, (), {}) 37 | else: 38 | return Mock() 39 | 40 | MOCK_MODULES = [ 41 | 'yaml', 42 | 'M2Crypto', 43 | ] 44 | 45 | for mod_name in MOCK_MODULES: 46 | sys.modules[mod_name] = Mock() 47 | 48 | import shaker 49 | from shaker import __version__ 50 | 51 | # If extensions (or modules to document with autodoc) are in another directory, 52 | # add these directories to sys.path here. If the directory is relative to the 53 | # documentation root, use os.path.abspath to make it absolute, like shown here. 54 | #sys.path.insert(0, os.path.abspath('.')) 55 | 56 | # -- General configuration ----------------------------------------------------- 57 | 58 | # If your documentation needs a minimal Sphinx version, state it here. 59 | #needs_sphinx = '1.0' 60 | 61 | # Add any Sphinx extension module names here, as strings. They can be extensions 62 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 63 | extensions = ['sphinx.ext.autodoc'] 64 | 65 | # Add any paths that contain templates here, relative to this directory. 66 | templates_path = ['_templates'] 67 | 68 | # The suffix of source filenames. 69 | source_suffix = '.rst' 70 | 71 | # The encoding of source files. 72 | #source_encoding = 'utf-8-sig' 73 | 74 | # The master toctree document. 75 | master_doc = 'index' 76 | 77 | # General information about the project. 78 | project = u'Shaker' 79 | copyright = u'2012, Jeff Bauer' 80 | 81 | # The version info for the project you're documenting, acts as replacement for 82 | # |version| and |release|, also used in various other places throughout the 83 | # built documents. 84 | # 85 | # The short X.Y version. 86 | version = __version__ 87 | # The full version, including alpha/beta/rc tags. 88 | release = version 89 | 90 | # The language for content autogenerated by Sphinx. Refer to documentation 91 | # for a list of supported languages. 92 | #language = None 93 | 94 | # There are two options for replacing |today|: either, you set today to some 95 | # non-false value, then it is used: 96 | #today = '' 97 | # Else, today_fmt is used as the format for a strftime call. 98 | #today_fmt = '%B %d, %Y' 99 | 100 | # List of patterns, relative to source directory, that match files and 101 | # directories to ignore when looking for source files. 102 | exclude_patterns = ['_build'] 103 | 104 | # The reST default role (used for this markup: `text`) to use for all documents. 105 | #default_role = None 106 | 107 | # If true, '()' will be appended to :func: etc. cross-reference text. 108 | #add_function_parentheses = True 109 | 110 | # If true, the current module name will be prepended to all description 111 | # unit titles (such as .. function::). 112 | #add_module_names = True 113 | 114 | # If true, sectionauthor and moduleauthor directives will be shown in the 115 | # output. They are ignored by default. 116 | #show_authors = False 117 | 118 | # The name of the Pygments (syntax highlighting) style to use. 119 | #pygments_style = 'sphinx' 120 | pygments_style = 'flask_theme_support.FlaskyStyle' 121 | 122 | # A list of ignored prefixes for module index sorting. 123 | #modindex_common_prefix = [] 124 | 125 | 126 | # -- Options for HTML output --------------------------------------------------- 127 | 128 | # The theme to use for HTML and HTML Help pages. See the documentation for 129 | # a list of builtin themes. 130 | sys.path.append(os.path.abspath('_themes')) 131 | html_theme_path = ['_themes'] # custom themes 132 | html_theme = 'shaker' 133 | 134 | # Theme options are theme-specific and customize the look and feel of a theme 135 | # further. For a list of options available for each theme, see the 136 | # documentation. 137 | #html_theme_options = {} 138 | 139 | # The name for this set of Sphinx documents. If None, it defaults to 140 | # " v documentation". 141 | #html_title = None 142 | 143 | # A shorter title for the navigation bar. Default is the same as html_title. 144 | #html_short_title = None 145 | 146 | # The name of an image file (relative to this directory) to place at the top 147 | # of the sidebar. 148 | #html_logo = None 149 | 150 | # The name of an image file (within the static path) to use as favicon of the 151 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 152 | # pixels large. 153 | #html_favicon = None 154 | 155 | # Add any paths that contain custom static files (such as style sheets) here, 156 | # relative to this directory. They are copied after the builtin static files, 157 | # so a file named "default.css" will overwrite the builtin "default.css". 158 | html_static_path = ['_static'] 159 | 160 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 161 | # using the given strftime format. 162 | #html_last_updated_fmt = '%b %d, %Y' 163 | 164 | # If true, SmartyPants will be used to convert quotes and dashes to 165 | # typographically correct entities. 166 | #html_use_smartypants = True 167 | 168 | # Custom sidebar templates, maps document names to template names. 169 | html_sidebars = { 170 | 'index': ['sidebarintro.html', 'sourcelink.html', 'searchbox.html'], 171 | '**': ['sidebarlogo.html', 'localtoc.html', 'relations.html', 172 | 'sourcelink.html', 'searchbox.html'] 173 | } 174 | 175 | # Additional templates that should be rendered to pages, maps page names to 176 | # template names. 177 | #html_additional_pages = {} 178 | 179 | # If false, no module index is generated. 180 | #html_domain_indices = True 181 | 182 | # If false, no index is generated. 183 | #html_use_index = True 184 | 185 | # If true, the index is split into individual pages for each letter. 186 | #html_split_index = False 187 | 188 | # If true, links to the reST sources are added to the pages. 189 | #html_show_sourcelink = True 190 | 191 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 192 | #html_show_sphinx = True 193 | 194 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 195 | #html_show_copyright = True 196 | 197 | # If true, an OpenSearch description file will be output, and all pages will 198 | # contain a tag referring to it. The value of this option must be the 199 | # base URL from which the finished HTML is served. 200 | #html_use_opensearch = '' 201 | 202 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 203 | #html_file_suffix = None 204 | 205 | # Output file base name for HTML help builder. 206 | htmlhelp_basename = 'shakerdoc' 207 | 208 | 209 | # -- Options for LaTeX output -------------------------------------------------- 210 | 211 | latex_elements = { 212 | # The paper size ('letterpaper' or 'a4paper'). 213 | #'papersize': 'letterpaper', 214 | 215 | # The font size ('10pt', '11pt' or '12pt'). 216 | #'pointsize': '10pt', 217 | 218 | # Additional stuff for the LaTeX preamble. 219 | #'preamble': '', 220 | } 221 | 222 | # Grouping the document tree into LaTeX files. List of tuples 223 | # (source start file, target name, title, author, documentclass [howto/manual]). 224 | latex_documents = [ 225 | ('index', 'Shaker.tex', u'Shaker Documentation', 226 | u'Jeff Bauer', 'manual'), 227 | ] 228 | 229 | # The name of an image file (relative to this directory) to place at the top of 230 | # the title page. 231 | #latex_logo = None 232 | 233 | # For "manual" documents, if this is true, then toplevel headings are parts, 234 | # not chapters. 235 | #latex_use_parts = False 236 | 237 | # If true, show page references after internal links. 238 | #latex_show_pagerefs = False 239 | 240 | # If true, show URL addresses after external links. 241 | #latex_show_urls = False 242 | 243 | # Documents to append as an appendix to all manuals. 244 | #latex_appendices = [] 245 | 246 | # If false, no module index is generated. 247 | #latex_domain_indices = True 248 | 249 | 250 | # -- Options for manual page output -------------------------------------------- 251 | 252 | # One entry per manual page. List of tuples 253 | # (source start file, name, description, authors, manual section). 254 | man_pages = [ 255 | ('index', 'shaker', u'Shaker Documentation', 256 | [u'Jeff Bauer'], 1) 257 | ] 258 | 259 | # If true, show URL addresses after external links. 260 | #man_show_urls = False 261 | 262 | 263 | # -- Options for Texinfo output ------------------------------------------------ 264 | 265 | # Grouping the document tree into Texinfo files. List of tuples 266 | # (source start file, target name, title, author, 267 | # dir menu entry, description, category) 268 | texinfo_documents = [ 269 | ('index', 'shaker', u'Shaker Documentation', 270 | u'Jeff Bauer', 'shaker', 'One line description of project.', 271 | 'Miscellaneous'), 272 | ] 273 | 274 | # Documents to append as an appendix to all manuals. 275 | #texinfo_appendices = [] 276 | 277 | # If false, no module index is generated. 278 | #texinfo_domain_indices = True 279 | 280 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 281 | #texinfo_show_urls = 'footnote' 282 | 283 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. shaker documentation master file, created by 2 | sphinx-quickstart on Tue Jan 31 20:33:49 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Shaker: A Salt Minion Factory for EC2 Ubuntu Server Instances 7 | ============================================================= 8 | 9 | Release v\ |version|. 10 | 11 | Shaker is BSD-New Licensed command-line application to launch Salt 12 | minions as Amazon EC2 instances. 13 | 14 | `Salt `_ is a powerful remote execution 15 | manager that can be used to administer servers in a fast and 16 | efficient way. 17 | 18 | Running an Amazon EC2 instance as a Salt minion is fairly simple. 19 | Also tedious, if you need to launch minions often. Shaker bridges 20 | the gap between launching an EC2 instance and bootstrapping it as 21 | a Salt minion. 22 | 23 | 24 | Example 25 | ------- 26 | 27 | Shaker is usually run from the command line. To start a Salt minion, 28 | have it connect upon boot to Salt master *salt.example.com*: 29 | 30 | :: 31 | 32 | $ shaker --ami ami-057bcf6c --master salt.example.com 33 | 34 | Started Instance: i-9175d8f4 35 | 36 | To access: ssh ubuntu@ec2-107-20-93-179.compute-1.amazonaws.com 37 | To terminate: shaker-terminate i-9175d8f4 38 | 39 | 40 | Reference 41 | --------- 42 | 43 | Reference information on configuration of Shaker profiles, 44 | command-line options. 45 | 46 | .. toctree:: 47 | :maxdepth: 1 48 | 49 | ref/profile 50 | 51 | Indices and tables 52 | ================== 53 | 54 | * :ref:`genindex` 55 | * :ref:`modindex` 56 | * :ref:`search` 57 | 58 | -------------------------------------------------------------------------------- /docs/ref/profile.rst: -------------------------------------------------------------------------------- 1 | ============================ 2 | Shaker Profile Configuration 3 | ============================ 4 | 5 | Salt minions are usually launched with Shaker specifying a 6 | user-defined profile, which overrides ``default`` values. A 7 | user-defined profile effectively extends the default, so you may 8 | modify ``default`` with global values, declaring only per-minion 9 | values in the minion profile. 10 | 11 | Unless otherwise specified, profiles are located in the 12 | ``~/.shaker/profile`` directory. 13 | 14 | Salt-Specific Configuration Options 15 | ----------------------------------- 16 | 17 | ``salt_master`` 18 | --------------- 19 | 20 | Default: None 21 | 22 | Specify the location of a running Salt master. 23 | 24 | .. code-block:: yaml 25 | 26 | salt_master: salt.example.com 27 | 28 | ``salt_id`` 29 | ----------- 30 | 31 | Default: ``hostname`` (fully-qualified) 32 | 33 | ``salt_id`` identifies this salt minion to the master. If not 34 | specified, defaults to the fully qualified hostname. 35 | 36 | .. code-block:: yaml 37 | 38 | salt_id: moonunit 39 | 40 | ``salt_grains`` 41 | --------------- 42 | 43 | Default: None 44 | 45 | Specify the `salt grains `_ for the minion. 46 | 47 | .. code-block:: yaml 48 | 49 | salt_grains: 50 | roles: 51 | - webserver 52 | - memcache 53 | deployment: datacenter4 54 | 55 | ``pre_seed`` 56 | ------------- 57 | 58 | Default: False 59 | 60 | ``pre_seed`` seeds the master with a generated salt key, which is 61 | copied to the minion upon instance creation. 62 | 63 | .. code-block:: yaml 64 | 65 | pre_seed: true 66 | 67 | Host Configuration Options 68 | -------------------------- 69 | 70 | ``ip_address`` 71 | -------------- 72 | 73 | Default: None 74 | 75 | ``ip_address`` assigns an elastic ip address to minion after the 76 | instance is launched. If the ip address is already in use, the 77 | assignment will fail. 78 | 79 | .. code-block:: yaml 80 | 81 | ip_address: 111.22.33.44 82 | 83 | ``hostname`` 84 | ------------- 85 | 86 | Default: (determined by EC2 startup) 87 | 88 | The hostname is passed to EC2 initialization, prior to boot-up. 89 | The usual case is to specify hostname and domain because these 90 | values determine the Salt minion ID in the absence of an explicit 91 | ``salt_id``. 92 | 93 | .. code-block:: yaml 94 | 95 | hostname: igor 96 | 97 | ``domain`` 98 | ---------- 99 | 100 | Default: (assigned by Amazon: amazonaws.com) 101 | 102 | The domain name assigned to the instance. 103 | 104 | .. code-block:: yaml 105 | 106 | domain: example.com 107 | 108 | 109 | ``timezone`` 110 | ------------ 111 | 112 | Default: (UTC, if not specified) 113 | 114 | `Timezone `_ 115 | for your instance. 116 | 117 | .. code-block:: yaml 118 | 119 | timezone: America/Chicago 120 | 121 | 122 | ``ssh_import`` 123 | -------------- 124 | 125 | Default: None 126 | 127 | Import public keys from `launchpad.net `_. 128 | Only applicable for Ubuntu cloud-init. User names are 129 | comma-separated, no spaces. 130 | 131 | Launchpad provides a free service for 132 | `registering public keys `_ 133 | that are assigned to Ubuntu instances, if specified in ``ssh_import``. 134 | 135 | .. code-block:: yaml 136 | 137 | ssh_import: jbauer,akoumjian 138 | 139 | ``sudouser`` 140 | ------------ 141 | 142 | Default: None 143 | 144 | Install the user with sudo privileges. If ``sudouser`` is listed 145 | in ``ssh_import``, the public key will be installed from 146 | `launchpad.net `_. 147 | 148 | .. code-block:: yaml 149 | 150 | sudouser: jbauer 151 | 152 | ``ssh_port`` 153 | ------------ 154 | 155 | Default: ``22`` 156 | 157 | Port enabled to allow ssh connections. You may specify a 158 | non-standard ssh port, but verify it's open in your 159 | ``ec2_security_group``. 160 | 161 | .. code-block:: yaml 162 | 163 | ssh_port: 6222 164 | 165 | ``ubuntu_release`` 166 | -------------- 167 | 168 | Default: ``precise`` 169 | 170 | Specify the distribution to launch: *precise*, *oneiric*, *natty*, *maverick*, or *lucid*. 171 | 172 | *Note: Only* ``lucid`` *and* ``precise`` *(or later) are likely to work, until the Salt 173 | packaging is backported to other non-LTS distributions.* 174 | 175 | .. code-block:: yaml 176 | 177 | ubuntu_release: lucid 178 | 179 | ``check_name_before_create`` 180 | ---------------------------- 181 | 182 | If a box with the same Name tag exists, do not attempt to create another one. 183 | 184 | .. code-block:: yaml 185 | 186 | check_name_before_create: False 187 | 188 | ``check_name_after_create`` 189 | --------------------------- 190 | 191 | If a box with the same Name tag exists, leave your with none. 192 | 193 | .. code-block:: yaml 194 | 195 | check_name_after_create: True 196 | 197 | ``additional_tags`` 198 | --------------------------- 199 | 200 | You can add any custom AWS tags you want. 201 | 202 | .. code-block:: yaml 203 | 204 | additional_tags: 205 | project: homepage 206 | environment: production 207 | 208 | EC2-Specific Configuration Options 209 | ---------------------------------- 210 | 211 | ``ec2_access_key_id`` 212 | --------------------- 213 | 214 | Default: None 215 | 216 | AWS access key that is used for creating a connection to the service. 217 | If not given, `boto's defaults ` 218 | like ``~/.boto`` or environment variables are used. 219 | 220 | .. code-block:: yaml 221 | 222 | ec2_access_key_id: 223 | 224 | 225 | ``ec2_secret_access_key`` 226 | ------------------------- 227 | 228 | Default: None 229 | 230 | Use this if you are setting also ec2_access_key_id_ in you profile. 231 | 232 | .. code-block:: yaml 233 | 234 | ec2_secret_access_key: 235 | 236 | 237 | ``ec2_region`` 238 | -------------- 239 | 240 | Default: us-east-1 241 | 242 | Specify the 243 | `region `_ 244 | to use for the instance. The default may be changed in ``~/.shaker/profile/default``. 245 | 246 | .. code-block:: yaml 247 | 248 | ec2_zone: eu-west-1 249 | 250 | 251 | ``ec2_zone`` 252 | ------------ 253 | 254 | Default: None 255 | 256 | Specify the 257 | `zone `_ 258 | to start the instance in or leave empty for EC2 to choose a zone for you. 259 | The default may be changed in ``~/.shaker/profile/default``. 260 | 261 | .. code-block:: yaml 262 | 263 | ec2_zone: us-west-1a 264 | 265 | 266 | ``ec2_instance_type`` 267 | --------------------- 268 | 269 | Default: ``m1.small`` 270 | 271 | `Amazon EC2 Instance Type `_: 272 | 273 | * t1.micro 274 | * m1.small (default) 275 | * m2.xlarge, m2.2xlarge, m2.4xlarge 276 | * c1.medium, c1.xlarge, cc1.4xlarge, cc2.8xlarge 277 | 278 | .. code-block:: yaml 279 | 280 | ec2_instance_type: t1.micro 281 | 282 | ``ec2_ami_id`` 283 | -------------- 284 | 285 | Default: None 286 | 287 | The `AMI `_ id of the image to launch. 288 | Note that AMI's are region-specific, so you must specify the the 289 | appropriate AMI for the specific ``ec2_zone``. Specifying 290 | ``ec2_ami_id`` overrides ``ubuntu_release`` below. 291 | 292 | .. code-block:: yaml 293 | 294 | ec2_ami_id: ami-6ba27502 295 | 296 | ``ec2_size`` 297 | ------------ 298 | 299 | Default: (determined by EC2 startup) 300 | 301 | Size of the root partition in gigabytes. If zero or not specified, 302 | defaults to the instance type. 303 | 304 | .. code-block:: yaml 305 | 306 | ec2_size: 20 307 | 308 | ``ec2_key_name`` 309 | ---------------- 310 | 311 | Default: ``default`` 312 | 313 | Name of the 314 | `key pair `_ 315 | used to create the instance. If not specified and only one key-pair is available, it will be 316 | used. Otherwise you must disambiguate by specifying the key-pair. 317 | 318 | .. code-block:: yaml 319 | 320 | ec2_key_name: rubickey 321 | 322 | ``ec2_security_group`` 323 | ---------------------- 324 | 325 | Default: ``default`` 326 | 327 | The security group to control port access to the instance (ssh, 328 | http, etc.) If not specified, use ``default``, which generally 329 | permits port 22 for ssh access. 330 | 331 | .. code-block:: yaml 332 | 333 | ec2_security_group: webserver 334 | 335 | ``ec2_security_groups`` 336 | ----------------------- 337 | 338 | Default: ``[]`` 339 | 340 | Overrides ``ec2_security_group`` if multiple security groups are needed. 341 | 342 | .. code-block:: yaml 343 | 344 | ec2_security_groups: 345 | - default 346 | - webserver 347 | 348 | ``ec2_placement_group`` 349 | ----------------------- 350 | 351 | Default: ``None`` 352 | 353 | The placement group of the instance. Typically used for high 354 | performance computing. 355 | 356 | .. code-block:: yaml 357 | 358 | ec2_placement_group: hpc_cluster 359 | 360 | ``ec2_monitoring_enabled`` 361 | -------------------------- 362 | 363 | Default: ``false`` 364 | 365 | Enable EC2 instance monitoring with 366 | `CloudWatch `_ 367 | 368 | .. code-block:: yaml 369 | 370 | ec2_monitoring_enabled: true 371 | 372 | ``ec2_root_device`` 373 | ------------------- 374 | 375 | Default: ``/dev/sda1`` 376 | 377 | Specify the root device name for the instance. 378 | 379 | .. code-block:: yaml 380 | 381 | ec2_root_device: /dev/sdh 382 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | boto>=2.0 2 | Jinja2 3 | PyYAML 4 | M2Crypto 5 | -------------------------------------------------------------------------------- /scripts/shaker: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | This script is used to launch ec2 salt minions 4 | """ 5 | 6 | import os 7 | import shaker 8 | 9 | def main(): 10 | """ 11 | The main function 12 | """ 13 | s = shaker.EBSFactory() 14 | s.process() 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /scripts/shaker-terminate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Convenience script to terminate ec2 instances 4 | """ 5 | import os 6 | import sys 7 | import boto.ec2 8 | 9 | def terminate_instance(id): 10 | """Terminate an instance by searching through all the regions. 11 | """ 12 | for region in boto.ec2.regions(): 13 | conn = region.connect() 14 | for reservation in conn.get_all_instances(): 15 | for instance in reservation.instances: 16 | if instance.id == id: 17 | print "Terminating instance: {0}".format(id) 18 | instance.terminate() 19 | return 20 | print "Unable to terminate instance: {0}".format(id) 21 | 22 | 23 | if __name__ == '__main__': 24 | if len(sys.argv) < 2: 25 | print "usage: {0} instance-id".format( 26 | os.path.basename(sys.argv[0])) 27 | else: 28 | terminate_instance(sys.argv[1]) 29 | 30 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import with_statement 2 | 3 | import os 4 | 5 | from distutils.core import setup 6 | if os.environ.get('VIRTUAL_ENV'): 7 | from setuptools import setup 8 | 9 | exec(compile(open("shaker/version.py").read(), "shaker/version.py", 'exec')) 10 | VER = __version__ 11 | 12 | 13 | # Utility function to read the README file. 14 | def read(fname): 15 | return open(os.path.join(os.path.dirname(__file__), fname)).read() 16 | 17 | 18 | requirements = '' 19 | with open('requirements.txt') as f: 20 | requirements = f.read() 21 | 22 | setup( 23 | name="shaker", 24 | packages=["shaker"], 25 | version=VER, 26 | description="EC2 Salt Minion Launcher", 27 | author="Jeff Bauer", 28 | author_email="jbauer@rubic.com", 29 | url="https://github.com/rubic/shaker", 30 | keywords=["salt", "ec2", "aws"], 31 | classifiers=[ 32 | "Programming Language :: Python", 33 | "Programming Language :: Python :: 2.6", 34 | "Programming Language :: Python :: 2.7", 35 | "Development Status :: 3 - Alpha", 36 | "Environment :: Console", 37 | "Intended Audience :: Developers", 38 | "License :: OSI Approved :: BSD License", 39 | "Operating System :: POSIX", 40 | "Topic :: System :: Distributed Computing", 41 | "Topic :: System :: Systems Administration", 42 | ], 43 | long_description=read('README.rst'), 44 | scripts=['scripts/shaker', 45 | 'scripts/shaker-terminate', 46 | ], 47 | install_requires=requirements, 48 | ) 49 | -------------------------------------------------------------------------------- /shaker/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Build and launch EBS instances as salt minions. 3 | """ 4 | from shaker.version import __version__ 5 | 6 | import os 7 | import sys 8 | import time 9 | import optparse 10 | import email.mime 11 | from tempfile import TemporaryFile 12 | from M2Crypto import BIO, RSA, m2 13 | import boto 14 | import boto.ec2 15 | from boto.ec2.blockdevicemapping import EBSBlockDeviceType, BlockDeviceMapping 16 | import shaker.log 17 | import shaker.config 18 | import shaker.template 19 | LOG = shaker.log.getLogger(__name__) 20 | RUN_INSTANCE_TIMEOUT = 180 # seconds 21 | DEFAULT_MINION_PKI_DIR = '/etc/salt/pki/master/minions' 22 | 23 | # table takne from http://aws.amazon.com/ec2/instance-types/ 24 | InstanceTypes = [ 25 | 'm3.medium', 26 | 'm3.large', 27 | 'm3.xlarge', 28 | 'm3.2xlarge', 29 | 'm1.small', 30 | 'm1.medium', 31 | 'm1.large', 32 | 'm1.xlarge', 33 | 'c3.large', 34 | 'c3.xlarge', 35 | 'c3.2xlarge', 36 | 'c3.4xlarge', 37 | 'c3.8xlarge', 38 | 'c1.medium', 39 | 'c1.xlarge', 40 | 'cc2.8xlarge', 41 | 'g2.2xlarge', 42 | 'cg1.4xlarge', 43 | 'm2.xlarge', 44 | 'm2.2xlarge', 45 | 'm2.4xlarge', 46 | 'cr1.8xlarge', 47 | 'i2.xlarge', 48 | 'i2.2xlarge', 49 | 'i2.4xlarge', 50 | 'i2.8xlarge', 51 | 'hs1.8xlarge', 52 | 'hi1.4xlarge', 53 | 't1.micro', 54 | 't2.medium', 55 | ] 56 | 57 | 58 | class EBSFactory(object): 59 | """EBSFactory - build and launch EBS salt minions. 60 | """ 61 | def __init__(self): 62 | cli, config_dir, profile = self.parse_cli() 63 | self.profile = shaker.config.user_profile( 64 | cli, 65 | config_dir, 66 | profile) 67 | self.pki_dir = shaker.config.get_pki_dir(config_dir) 68 | self.userdata_dir = shaker.config.get_userdata_dir(config_dir) 69 | self.dry_run = cli.dry_run 70 | self.write_user_data = cli.write_user_data 71 | self.minion_pki_dir = cli.minion_pki_dir or DEFAULT_MINION_PKI_DIR 72 | self.config = dict(self.profile) 73 | self.config['config_dir'] = config_dir 74 | self.pre_seed = cli.pre_seed or self.config['pre_seed'] 75 | self.ip_address = cli.ip_address or self.config['ip_address'] 76 | self.additional_tags = self.config['additional_tags'] 77 | self.check_name_before_create = self.config['check_name_before_create'] 78 | self.check_name_after_create = self.config['check_name_after_create'] 79 | 80 | def process(self): 81 | if self.pre_seed: 82 | if not self.generate_minion_keys(): 83 | return False 84 | self.user_data = self.build_mime_multipart() 85 | if self.write_user_data or ( 86 | self.get_keyname() and not self.pre_seed and not self.dry_run): 87 | self.write_user_data_to_file() 88 | self.conn = self.get_connection() 89 | if not self.conn: 90 | errmsg = "Unable to establish a connection for: {0}".format( 91 | self.config['ec2_region']) 92 | LOG.error(errmsg) 93 | return False 94 | if not self.verify_settings(): 95 | return False 96 | if self.dry_run: 97 | return True 98 | if self.pre_seed: 99 | self.pre_seed_minion() 100 | self.launch_instance() 101 | assigned_ip_address = None 102 | if self.ip_address: 103 | ip_in_use = self.ip_address_in_use() 104 | if ip_in_use: 105 | errmsg = "Unable to assign ip address {0}, " \ 106 | "already in use with instance {1}".format( 107 | self.ip_address, ip_in_use.id) 108 | LOG.error(errmsg) 109 | else: 110 | self.conn.associate_address(self.instance.id, self.ip_address) 111 | assigned_ip_address = self.ip_address 112 | if self.config['assign_dns']: 113 | LOG.info("assign_dns not yet implemented") #XXX Not yet implemented 114 | self.assign_dns(self.config['assign_dns']) 115 | self.output_response_to_user(assigned_ip_address) 116 | return True 117 | 118 | def get_connection(self): 119 | conn_params = { 120 | 'aws_access_key_id': self.config['ec2_access_key_id'], 121 | 'aws_secret_access_key': self.config['ec2_secret_access_key'], 122 | } 123 | try: 124 | conn = boto.ec2.connect_to_region(self.config['ec2_region'], **conn_params) 125 | except boto.exception.BotoClientError as e: 126 | errmsg = "Unable to connect to the region {0}: {1}".format( 127 | self.config['ec2_region'], e.reason) 128 | LOG.error(errmsg) 129 | conn = None 130 | return conn 131 | 132 | def verify(self): 133 | if not self.verify_settings(): 134 | return False 135 | if self.check_name_before_create and self.running_host_with_same_tag(): 136 | return False 137 | return True 138 | 139 | def launch_instance(self): 140 | if not self.verify(): 141 | return 142 | is_instance_store = self.conn.get_all_images(self.config['ec2_ami_id'], filters={'root-device-type': 'instance-store'}) 143 | if is_instance_store: 144 | block_map = None 145 | else: 146 | block_map = BlockDeviceMapping() 147 | root_device = self.config['ec2_root_device'] 148 | block_map[root_device] = EBSBlockDeviceType() 149 | if self.config['ec2_size']: 150 | block_map[root_device].size = self.config['ec2_size'] 151 | block_map[root_device].delete_on_termination = True 152 | reservation = self.conn.run_instances( 153 | self.config['ec2_ami_id'], 154 | key_name=self.config['ec2_key_name'], 155 | security_groups=self.config['ec2_security_groups'] or [self.config['ec2_security_group']], 156 | instance_type=self.config['ec2_instance_type'], 157 | placement=self.config['ec2_zone'], 158 | placement_group=self.config['ec2_placement_group'], 159 | monitoring_enabled=self.config['ec2_monitoring_enabled'], 160 | block_device_map=block_map, 161 | user_data=self.user_data) 162 | self.instance = reservation.instances[0] 163 | self.add_tags(self.instance) 164 | secs = RUN_INSTANCE_TIMEOUT 165 | rest_interval = 5 166 | while secs and not self.instance.state == 'running': 167 | time.sleep(rest_interval) 168 | secs = secs - rest_interval 169 | try: 170 | self.instance.update() 171 | except boto.exception.EC2ResponseError: 172 | pass 173 | if secs <= 0: 174 | errmsg = "run instance {0} failed after {1} seconds".format( 175 | self.instance.id, RUN_INSTANCE_TIMEOUT) 176 | LOG.error(errmsg) 177 | 178 | def add_tags(self, instance): 179 | if self.config['hostname']: 180 | self.assign_name_tag() 181 | for name, tag in self.additional_tags.items(): 182 | instance.add_tag(name, tag) 183 | 184 | def output_response_to_user(self, assigned_ip_address): 185 | msg1 = "Started Instance: {0}\n".format(self.instance.id) 186 | LOG.info(msg1) 187 | print msg1 188 | p = int(self.config['ssh_port']) 189 | port = str(p) if p and not p == 22 else '' 190 | ## change user to 'root' for all non-Ubuntu systems 191 | user = self.config['sudouser'] if self.config['sudouser'] and self.config['ssh_import'] else 'ubuntu' 192 | address = assigned_ip_address if assigned_ip_address else self.instance.public_dns_name 193 | # TODO: replace public dns with fqdn, where appropriate 194 | msg2 = "To access: ssh {0}{1}@{2}\n".format( 195 | '-p {0} '.format(port) if port else '', 196 | user, 197 | address) 198 | msg3 = "To terminate: shaker-terminate {0}".format( 199 | self.instance.id) 200 | LOG.info(msg2) 201 | LOG.info(msg3) 202 | print msg2 203 | print msg3 204 | 205 | def write_user_data_to_file(self): 206 | keyname = self.get_keyname() 207 | if keyname: 208 | pathname = os.path.join(self.userdata_dir, keyname) 209 | with open(pathname, 'w') as f: 210 | f.write('{0}\n'.format(self.user_data)) 211 | LOG.info("user data written to {0}".format(pathname)) 212 | else: 213 | LOG.error("unable to determine salt_id: specify hostname") 214 | 215 | def pre_seed_minion(self): 216 | """Pre-seed minion keys, updating /etc/salt/pki/minion 217 | """ 218 | if not os.access(self.minion_pki_dir, os.W_OK | os.X_OK): 219 | errmsg = "directory not writeable: {0}".format(self.minion_pki_dir) 220 | LOG.error(errmsg) 221 | return False 222 | keyname = self.get_keyname() 223 | minionpubkey_pathname = os.path.join( 224 | self.minion_pki_dir, 225 | keyname) 226 | with open(minionpubkey_pathname, 'w') as f: 227 | f.write(self.public_key) 228 | return True 229 | 230 | def get_keyname(self): 231 | if self.config.get('salt_id'): 232 | keyname = self.config['salt_id'] 233 | elif self.config.get('hostname'): 234 | if self.config.get('domain'): 235 | keyname = "{0}.{1}".format( 236 | self.config['hostname'], 237 | self.config['domain']) 238 | else: 239 | keyname = self.config['hostname'] 240 | else: 241 | keyname = None 242 | return keyname 243 | 244 | def ip_address_in_use(self): 245 | """If the ip_address is in use, return associated instance, 246 | otherwise return None. 247 | """ 248 | for instances in [r.instances for r in self.conn.get_all_instances()]: 249 | for i in instances: 250 | if i.ip_address == self.ip_address and i.state == 'running': 251 | return i 252 | return None 253 | 254 | def generate_minion_keys(self): 255 | #XXX TODO: Replace M2Crypto with PyCrypto 256 | # see: https://github.com/saltstack/salt/pull/1112/files 257 | # generate keys 258 | keyname = self.get_keyname() 259 | if not keyname: 260 | LOG.error("Must specify salt_id or hostname") 261 | return False 262 | gen = RSA.gen_key(2048, 1, callback=lambda x,y,z:None) 263 | pubpath = os.path.join(self.pki_dir, 264 | '{0}.pub'.format(keyname)) 265 | gen.save_pub_key(pubpath) 266 | LOG.info("public key {0}".format(pubpath)) 267 | if self.config.get('save_keys'): 268 | cumask = os.umask(191) 269 | gen.save_key( 270 | os.path.join( 271 | self.pki_dir, 272 | '{0}.pem'.format(keyname)), 273 | None) 274 | os.umask(cumask) 275 | # public key 276 | _pub = TemporaryFile() 277 | bio_pub = BIO.File(_pub) 278 | m2.rsa_write_pub_key(gen.rsa, bio_pub._ptr()) 279 | _pub.seek(0) 280 | self.config['public_key'] = self.public_key = _pub.read() 281 | self.config['formatted_public_key'] = '\n'.join( 282 | " {0}".format(k) for k in self.public_key.split('\n')) 283 | # private key 284 | _pem = TemporaryFile() 285 | bio_pem = BIO.File(_pem) 286 | gen.save_key_bio(bio_pem, None) 287 | _pem.seek(0) 288 | self.config['private_key'] = self.private_key = _pem.read() 289 | self.config['formatted_private_key'] = '\n'.join( 290 | " {0}".format(k) for k in self.private_key.split('\n')) 291 | return True 292 | 293 | def running_host_with_same_tag(self): 294 | tag = self.config['hostname'] 295 | for reservation in self.conn.get_all_instances(): 296 | for i in reservation.instances: 297 | if tag == i.tags.get('Name'): 298 | return True 299 | return False 300 | 301 | def assign_name_tag(self): 302 | """Assign the 'Name' tag to the instance, but only if it 303 | isn't already in use. 304 | """ 305 | if self.check_name_after_create and self.running_host_with_same_tag(): 306 | return 307 | tag = self.config['hostname'] 308 | self.instance.add_tag('Name', tag) 309 | 310 | def build_mime_multipart(self): 311 | userData = shaker.template.UserData(self.config) 312 | outer = email.mime.multipart.MIMEMultipart() 313 | for content, subtype, filename in [ 314 | (userData.user_script, 'x-shellscript', 'user-script.txt'), 315 | (userData.cloud_init, 'cloud-config', 'cloud-config.txt'), 316 | (userData.boothook_script, 'cloud-boothook', 'boothook-script.txt'),]: 317 | msg = email.mime.text.MIMEText(content, _subtype=subtype) 318 | msg.add_header('Content-Disposition', 319 | 'attachment', 320 | filename=filename) 321 | outer.attach(msg) 322 | return outer.as_string() 323 | 324 | def verify_settings(self): 325 | if not self.config['ec2_ami_id']: 326 | LOG.error("Missing ec2_ami_id") 327 | return False 328 | if not self.config['ec2_key_name']: 329 | # If no key pair has been specified, just use the first one, 330 | # if it's the only key pair. Otherwise the user must specify. 331 | key_pairs = self.conn.get_all_key_pairs() 332 | if len(key_pairs) < 1: 333 | LOG.error("No key pair available for region: {0}" % self.conn) 334 | elif len(key_pairs) > 1: 335 | errmsg = "Must specify ec2-key or ec2_key_name: {0}".format( 336 | ', '.join([kp.name for kp in key_pairs])) 337 | LOG.error(errmsg) 338 | return False 339 | self.config['ec2_key_name'] = [kp.name for kp in key_pairs][0] 340 | if self.config['ec2_size']: 341 | try: 342 | self.config['ec2_size'] = int(self.config['ec2_size']) 343 | except ValueError: 344 | LOG.error("Invalid ec2_size: {0}".format( 345 | self.config['ec2_size'])) 346 | return False 347 | if not self.config['ec2_instance_type'] in InstanceTypes: 348 | LOG.error("Invalid ec2_instance_type: {0}".format( 349 | self.config['ec2_instance_type'])) 350 | return False 351 | return True 352 | 353 | def parse_cli(self): 354 | parser = optparse.OptionParser( 355 | usage="%prog [options] profile", 356 | version="%%prog {0}".format(__version__)) 357 | parser.add_option( 358 | '-a', '--ami', dest='ec2_ami_id', metavar='AMI', 359 | help='Build instance from AMI') 360 | parser.add_option( 361 | '--release', dest='release', 362 | metavar='UBUNTU_RELEASE', default='', 363 | help="Ubuntu release (precise, lucid, etc.)") 364 | parser.add_option('--ec2-group', dest='ec2_security_group') 365 | parser.add_option('--ec2-key', dest='ec2_key_name') 366 | parser.add_option('--ec2-region', dest='ec2_region', 367 | help="Region to use: us-east-1, etc.") 368 | parser.add_option('--ec2-zone', dest='ec2_zone', 369 | help="Availability zone to use: us-east-1b, etc.") 370 | parser.add_option('--instance-type', dest='ec2_instance_type', 371 | help="One of t1.micro, m1.small, ...") 372 | parser.add_option('--placement-group', dest='ec2_placement_group') 373 | parser.add_option( 374 | '--config-dir', dest='config_dir', 375 | help="Configuration directory") 376 | parser.add_option( 377 | '--user-data', dest='user_data_template', 378 | help="User data template file") 379 | parser.add_option( 380 | '--cloud-init', dest='cloud_init_template', 381 | help="cloud-init template file") 382 | parser.add_option( 383 | '--minion-template', dest='minion_template', 384 | help="Minion template file") 385 | parser.add_option( 386 | '--boothook-template', dest='boothook_template', 387 | help="Boothook template file") 388 | parser.add_option( 389 | '--dry-run', dest='dry_run', 390 | action='store_true', default=False, 391 | help="Log the initialization setup, but don't launch the instance") 392 | parser.add_option( 393 | '-m', '--master', dest='salt_master', 394 | metavar='SALT_MASTER', default='', 395 | help="Connect salt minion to SALT_MASTER") 396 | parser.add_option( 397 | '--grains', dest='salt_grains', 398 | metavar='SALT_GRAINS', default='', 399 | help="Assign SALT_GRAINS to salt minion, semicolon separated list of key:value,value2") 400 | parser.add_option( 401 | '--pillar_roots', dest='salt_pillar_roots_dir', 402 | metavar='SALT_PILLAR_ROOTS', default='', 403 | help="Assign SALT_PILLAR_ROOTS to salt minion, path as string") 404 | 405 | parser.add_option( 406 | '--hostname', dest='hostname', 407 | metavar='HOSTNAME', default='', 408 | help="Assign HOSTNAME to salt minion") 409 | parser.add_option( 410 | '--domain', dest='domain', 411 | metavar='DOMAIN', default='', 412 | help="Assign DOMAIN name to salt minion") 413 | parser.add_option( 414 | '--ip_address', dest='ip_address', 415 | metavar='IP_ADDRESS', default='', 416 | help="Assign elastic IP address to salt minion") 417 | parser.add_option( 418 | '--preseed', dest='pre_seed', 419 | action='store_true', default=False, 420 | help="Pre-seed the minion keys") 421 | parser.add_option( 422 | '--save-keys', dest='save_keys', 423 | action='store_true', default=False, 424 | help="Save keys locally, including the pre-seeded private key") 425 | parser.add_option( 426 | '--minion-pki-dir', dest='minion_pki_dir', 427 | metavar='PKI_DIR', default=DEFAULT_MINION_PKI_DIR, 428 | help="Minion PKI_DIR, when pre-seeding minion keys") 429 | parser.add_option( 430 | '-w', '--write-user-data', dest='write_user_data', 431 | action='store_true', default=False, 432 | help="Write user-data to USERDATA directory (~/.shaker/userdata)") 433 | import shaker.log 434 | parser.add_option('-l', 435 | '--log-level', 436 | dest='log_level', 437 | default='info', 438 | choices=shaker.log.LOG_LEVELS.keys(), 439 | help='Log level: {0}. \nDefault: %%default'.format( 440 | ', '.join(shaker.log.LOG_LEVELS.keys())) 441 | ) 442 | (opts, args) = parser.parse_args() 443 | if len(args) < 1: 444 | if opts.ec2_ami_id or opts.release: 445 | profile = None 446 | else: 447 | print parser.format_help().strip() 448 | errmsg = "\nError: Specify shaker profile or EC2 ami or Ubuntu release" 449 | raise SystemExit(errmsg) 450 | else: 451 | profile = args[0] 452 | import shaker.config 453 | config_dir = shaker.config.get_config_dir(opts.config_dir) 454 | shaker.log.start_logger( 455 | __name__, 456 | os.path.join(config_dir, 'shaker.log'), 457 | opts.log_level) 458 | if opts.ec2_ami_id: 459 | opts.distro = '' # mutually exclusive 460 | else: 461 | opts.distro = opts.release 462 | LOG.info("shaker invoked with args: {0}".format(', '.join(sys.argv[1:]))) 463 | return opts, config_dir, profile 464 | -------------------------------------------------------------------------------- /shaker/ami.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | Select the AMI from specified distro 6 | 7 | >>> profile = {'ec2_zone': 'us-west-1a'} 8 | >>> get_ami(profile) 9 | 'ami-d50c2890' 10 | 11 | >>> release = 'lucid' 12 | >>> get_ami(profile, release) 13 | 'ami-b988acfc' 14 | 15 | >>> profile['ec2_architecture'] = 'x86_64' 16 | >>> get_ami(profile, release) 17 | 'ami-bb88acfe' 18 | """ 19 | 20 | import yaml 21 | 22 | import shaker.log 23 | LOG = shaker.log.getLogger(__name__) 24 | 25 | DEFAULT_RELEASE = 'precise' 26 | 27 | def get_ami(profile, release=None): 28 | """Return an AMI ID matching the distro. 29 | """ 30 | y = yaml.load(EBSImages) 31 | if not release: 32 | release = profile.get('ubuntu_release') or DEFAULT_RELEASE 33 | try: 34 | region = profile['ec2_zone'][:-1] 35 | architecture = profile.get('ec2_architecture', 'i386') 36 | for distro in y['release']: 37 | if release in y[distro]: 38 | return y[distro][release][region][architecture] 39 | except KeyError: 40 | pass 41 | except IndexError: 42 | pass 43 | return None 44 | 45 | # EBSImages to be treated as (and eventually packaged) a yaml file. 46 | 47 | EBSImages = """# Amazon EC2 AMIs - EBS Images 48 | release: 49 | ubuntu: precise 50 | 51 | ubuntu: 52 | precise: 53 | ap-northeast-1: 54 | x86_64: ami-c047fac1 55 | i386: ami-bc47fabd 56 | ap-southeast-1: 57 | x86_64: ami-eadb9ab8 58 | i386: ami-e4db9ab6 59 | eu-west-1: 60 | x86_64: ami-db595faf 61 | i386: ami-d1595fa5 62 | sa-east-1: 63 | x86_64: ami-2e845d33 64 | i386: ami-32845d2f 65 | us-east-1: 66 | x86_64: ami-137bcf7a 67 | i386: ami-057bcf6c 68 | us-west-1: 69 | x86_64: ami-d70c2892 70 | i386: ami-d50c2890 71 | us-west-2: 72 | x86_64: ami-1cdd532c 73 | i386: ami-1add532a 74 | oneiric: 75 | ap-northeast-1: 76 | x86_64: ami-9405b995 77 | i386: ami-9205b993 78 | ap-southeast-1: 79 | x86_64: ami-a86424fa 80 | i386: ami-aa6424f8 81 | eu-west-1: 82 | x86_64: ami-3dcacb49 83 | i386: ami-33cacb47 84 | sa-east-1: 85 | x86_64: ami-00f22b1d 86 | i386: ami-06f22b1b 87 | us-east-1: 88 | x86_64: ami-cdc072a4 89 | i386: ami-cbc072a2 90 | us-west-1: 91 | x86_64: ami-fb5176be 92 | i386: ami-ff5176ba 93 | us-west-2: 94 | x86_64: ami-b47af484 95 | i386: ami-b27af482 96 | natty: 97 | ap-northeast-1: 98 | x86_64: ami-6c47f56d 99 | i386: ami-6a47f56b 100 | ap-southeast-1: 101 | x86_64: ami-5a5e1f08 102 | i386: ami-545e1f06 103 | eu-west-1: 104 | x86_64: ami-e9bfbb9d 105 | i386: ami-efbfbb9b 106 | sa-east-1: 107 | x86_64: ami-404b955d 108 | i386: ami-464b955b 109 | us-east-1: 110 | x86_64: ami-699f3600 111 | i386: ami-9f9c35f6 112 | us-west-1: 113 | x86_64: ami-1dd0f558 114 | i386: ami-13d0f556 115 | us-west-2: 116 | x86_64: ami-6449c654 117 | i386: ami-6249c652 118 | maverick: 119 | ap-northeast-1: 120 | x86_64: ami-741dac75 121 | i386: ami-721dac73 122 | ap-southeast-1: 123 | x86_64: ami-0e8acd5c 124 | i386: ami-0a8acd58 125 | eu-west-1: 126 | x86_64: ami-c57942b1 127 | i386: ami-db7942af 128 | sa-east-1: 129 | x86_64: ami-10a9770d 130 | i386: ami-16a9770b 131 | us-east-1: 132 | x86_64: ami-d78f57be 133 | i386: ami-d38f57ba 134 | us-west-1: 135 | x86_64: ami-3b154e7e 136 | i386: ami-39154e7c 137 | us-west-2: 138 | x86_64: ami-64fd7154 139 | i386: ami-62fd7152 140 | lucid: 141 | ap-northeast-1: 142 | x86_64: ami-8876ca89 143 | i386: ami-8676ca87 144 | ap-southeast-1: 145 | x86_64: ami-903575c2 146 | i386: ami-923575c0 147 | eu-west-1: 148 | x86_64: ami-5d4a4b29 149 | i386: ami-534a4b27 150 | sa-east-1: 151 | x86_64: ami-6ac91077 152 | i386: ami-68c91075 153 | us-east-1: 154 | x86_64: ami-c7b202ae 155 | i386: ami-c5b202ac 156 | us-west-1: 157 | x86_64: ami-bb88acfe 158 | i386: ami-b988acfc 159 | us-west-2: 160 | x86_64: ami-1a4fc12a 161 | i386: ami-184fc128 162 | """ 163 | 164 | if __name__ == "__main__": 165 | import doctest 166 | doctest.testmod() 167 | -------------------------------------------------------------------------------- /shaker/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | """ 4 | Shaker configuration 5 | """ 6 | 7 | from jinja2 import Template 8 | import yaml 9 | import shaker.ami 10 | import shaker.log 11 | LOG = shaker.log.getLogger(__name__) 12 | 13 | DEFAULTS = { 14 | # These values will be overridden in profile/default or 15 | # a user profile, or command-line options. 16 | 'hostname': None, 17 | 'domain': None, 18 | 'sudouser': None, 19 | 'ssh_port': '22', 20 | 'ssh_import': None, 21 | 'timezone': None, 22 | 'assign_dns': False, # Hmmm ...? 23 | 'ec2_access_key_id': None, 24 | 'ec2_secret_access_key': None, 25 | 'ec2_region': 'us-east-1', 26 | 'ec2_zone': None, 27 | 'ec2_instance_type': 'm1.small', 28 | 'ec2_ami_id': None, 29 | 'ubuntu_release': None, 30 | 'ec2_size': None, 31 | 'ec2_key_name': None, 32 | 'ec2_security_group': 'default', 33 | 'ec2_security_groups': [], 34 | 'ec2_monitoring_enabled': False, 35 | 'ec2_root_device': '/dev/sda1', 36 | 'ec2_architecture': 'i386', 37 | 'ec2_placement_group': None, 38 | 'salt_master': None, 39 | 'salt_id': None, 40 | 'salt_grains': [], 41 | 'salt_pillar_roots_dir': None, 42 | 'cloud_init_template': None, 43 | 'user_data_template': None, 44 | 'boothook_template': None, 45 | 'minion_template': None, 46 | 'pre_seed': False, 47 | 'ip_address': None, 48 | 'check_name_before_create': False, 49 | 'check_name_after_create': True, 50 | 'additional_tags': {}, 51 | } 52 | 53 | 54 | def get_config_dir(path=None): 55 | """ 56 | Return the shaker configuration directory. Create and populate 57 | it if missing. 58 | """ 59 | if path: 60 | config_dir = path 61 | elif os.environ.get('SHAKER_CONFIG_DIR'): 62 | config_dir = os.environ['SHAKER_CONFIG_DIR'] 63 | else: 64 | config_dir = os.path.expanduser("~/.shaker") 65 | if not os.path.isdir(config_dir): 66 | os.makedirs(config_dir) 67 | return config_dir 68 | 69 | 70 | def get_pki_dir(config_dir): 71 | pki_dir = os.path.join(config_dir, 'pki') 72 | if not os.path.isdir(pki_dir): 73 | os.makedirs(pki_dir) 74 | return pki_dir 75 | 76 | 77 | def get_userdata_dir(config_dir): 78 | userdata_dir = os.path.join(config_dir, 'userdata') 79 | if not os.path.isdir(userdata_dir): 80 | os.makedirs(userdata_dir) 81 | return userdata_dir 82 | 83 | 84 | def default_profile(config_dir): 85 | profile_dir = os.path.join(config_dir, 'profile') 86 | default_profile = os.path.join(profile_dir, 'default') 87 | if not os.path.isdir(profile_dir): 88 | os.makedirs(profile_dir) 89 | if not os.path.isfile(default_profile): 90 | LOG.info("Default profile not found, creating: {0}".format(default_profile)) 91 | template = Template(DEFAULT_PROFILE) 92 | with open(default_profile, 'w') as f: 93 | f.write(template.render(DEFAULTS)) 94 | profile = dict(DEFAULTS) 95 | profile.update(yaml.load(file(default_profile, 'r')) or {}) 96 | return profile 97 | 98 | 99 | def create_profile(profile, config_dir, profile_name): 100 | """ 101 | Generate a profile with config parameters and save to disk 102 | 103 | Parameters not specified in the config will inherit from 104 | the default profile. 105 | """ 106 | profile_dir = os.path.join(config_dir, 'profile') 107 | profile_path = os.path.join(profile_dir, profile_name) 108 | profile_copy = dict(profile) 109 | if not os.path.isfile(profile_path): 110 | msg = "Creating new profile: {0}".format(profile_path) 111 | else: 112 | msg = "Overwriting profile: {0}".format(profile_path) 113 | LOG.info(msg) 114 | print msg 115 | with open(profile_path, 'w') as f: 116 | f.write(yaml.dump(profile_copy, default_flow_style=False)) 117 | return profile_copy 118 | 119 | 120 | def user_profile(cli, config_dir, profile_name=None): 121 | """User profile, cli overrides defaults. 122 | """ 123 | profile = default_profile(config_dir) or {} 124 | if profile_name: 125 | profile_dir = os.path.join(config_dir, 'profile') 126 | profile_path = os.path.join(profile_dir, profile_name) 127 | default_path = os.path.join(profile_dir, 'default') 128 | if not os.path.isfile(profile_path): 129 | import shutil 130 | shutil.copy2(default_path, profile_path) 131 | LOG.info("Created profile: {0}".format(profile_path)) 132 | else: 133 | try: 134 | profile.update(yaml.load(file(profile_path, 'r')) or {}) 135 | except yaml.scanner.ScannerError, err: 136 | msg = "Error scanning profile {0}: {1}".format( 137 | profile_path, err) 138 | LOG.error(msg) 139 | else: 140 | LOG.info("No profile specified.") 141 | for k, v in cli.__dict__.items(): 142 | if k in profile and v: 143 | profile[k] = v 144 | # If the distro is specified in the command-line, we override 145 | # the profile ec2_ami_id value. 146 | if cli.distro: 147 | ec2_ami_id = shaker.ami.get_ami(profile, cli.distro) 148 | if ec2_ami_id: 149 | profile['ec2_ami_id'] = ec2_ami_id 150 | else: 151 | msg = "Unable to find AMI for distro: {0}".format(cli.distro) 152 | LOG.info(msg) 153 | if not profile['ec2_ami_id'] and profile['ubuntu_release']: 154 | profile['ec2_ami_id'] = shaker.ami.get_ami(profile['ubuntu_release'], profile) 155 | msg = "Selected AMI {0} in zone {1}".format( 156 | profile['ec2_ami_id'], 157 | profile['ec2_zone']) 158 | LOG.info(msg) 159 | 160 | # if grains are specified in command-line, we override the 161 | # profile grains value 162 | if cli.salt_grains: 163 | grains = {} 164 | for pair in cli.salt_grains.split(';'): 165 | for key, value in pair.split(':'): 166 | grains[key] = value.split(',') 167 | profile['salt_grains'] = grains 168 | 169 | ## override profile pillar_roots_dir by cli 170 | if cli.salt_pillar_roots_dir: 171 | profile['salt_pillar_roots_dir'] = cli.salt_pillar_roots_dir 172 | return profile 173 | 174 | 175 | DEFAULT_PROFILE = """#################################################################### 176 | # hostname, domain to assign the instance. 177 | #################################################################### 178 | 179 | #hostname: 180 | #domain: 181 | 182 | #################################################################### 183 | # salt_master is the location (dns or ip) of the salt master 184 | # to connect to, e.g.: master.example.com 185 | #################################################################### 186 | 187 | #salt_master: 188 | 189 | #################################################################### 190 | # salt_id identifies this salt minion. If not specified, 191 | # defaults to the fully qualified hostname. 192 | #################################################################### 193 | 194 | #salt_id: 195 | 196 | #################################################################### 197 | # salt_grains identifies grains on this salt minion. 198 | # If not specified, defaults to empty list. 199 | #################################################################### 200 | 201 | #salt_grains: 202 | 203 | #################################################################### 204 | # salt_pillar_roots_dir identifies pillar_roots config on this 205 | # salt minion. 206 | # If not specified, defaults to none and pillar_roots aren't set. 207 | #################################################################### 208 | 209 | #salt_pillar_roots_dir: /srv/pillar 210 | 211 | # Pre-seed the master with a generated salt key, which is copied 212 | # to the minion upon instance creation. Default is false. 213 | #################################################################### 214 | 215 | #pre_seed: False 216 | 217 | #################################################################### 218 | # Assign elastic ip address to minion after the instance is 219 | # launched. If the ip address is already in use, the 220 | # assignment will fail. Default is None. 221 | #################################################################### 222 | 223 | #ip_address: 224 | 225 | #################################################################### 226 | # Check whether there is box with the same Name. Either let it ends 227 | # before the instance is created or leave the instance without Name 228 | #################################################################### 229 | 230 | #check_name_before_create: False 231 | #check_name_after_create: True 232 | 233 | #################################################################### 234 | # You can add any custom AWS tags you want 235 | #################################################################### 236 | 237 | #additional_tags: 238 | # project: homepage 239 | # environment: production 240 | 241 | #################################################################### 242 | # Install the user with sudo privileges. If sudouser is listed 243 | # in ssh_import, the public key will be installed from 244 | # lauchpad.net. From the command-line, sudouser will default 245 | # to $LOGNAME, if not otherwise specified. 246 | #################################################################### 247 | 248 | #sudouser: 249 | 250 | #################################################################### 251 | # Import public keys from lauchpad.net. Only applicable for 252 | # Ubuntu cloud-init. User names are comma-separated, no spaces. 253 | #################################################################### 254 | 255 | #ssh_import: 256 | 257 | #################################################################### 258 | # ssh_port: You may define a non-standard ssh port, but verify 259 | # it's open in your ec2_security_group. 260 | #################################################################### 261 | 262 | #ssh_port: {{ ssh_port }} 263 | 264 | #################################################################### 265 | # timezone: 266 | # e.g. timezone: America/Chicago 267 | # http://en.wikipedia.org/wiki/List_of_tz_database_time_zones 268 | #################################################################### 269 | 270 | #timezone: 271 | 272 | #################################################################### 273 | # aws credentials: 274 | # you can set up your aws credentials for this profile 275 | # or you can leave it out and fallback to boto's defaults 276 | # http://docs.pythonboto.org/en/latest/boto_config_tut.html 277 | #################################################################### 278 | 279 | #ec2_access_key_id: 280 | #ec2_secret_access_key: 281 | 282 | #################################################################### 283 | # ec2_region: EC2 region - us-east-1 (default), eu-west-1, etc. 284 | # ec2_zone: if not specified, EC2 chooses a zone for you 285 | # ec2_placement_group: placement group of an instance with HPC 286 | #################################################################### 287 | 288 | #ec2_region: {{ ec2_region }} 289 | #ec2_zone: {{ ec2_zone }} 290 | #ec2_placement_group': {{ ec2_placement_group }} 291 | 292 | #################################################################### 293 | # ec2_instance_type defaults to m1.small 294 | # http://aws.amazon.com/ec2/instance-types/ 295 | # 296 | # t1.micro 297 | # m1.small (default) 298 | # m2.xlarge, m2.2xlarge, m2.4xlarge 299 | # c1.medium, c1.xlarge, cc1.4xlarge, cc2.8xlarge 300 | # 301 | #################################################################### 302 | 303 | #ec2_instance_type: {{ ec2_instance_type }} 304 | 305 | #################################################################### 306 | # ec2_ami_id: AMI image to launch. Note AMI's are 307 | # region-specific, so you must specify the the appropriate AMI 308 | # for the ec2_zone above. ec2_ami_id overrides ubuntu_release 309 | # below. 310 | #################################################################### 311 | 312 | #ec2_ami_id: 313 | 314 | #################################################################### 315 | # ubuntu_release: precise, oneiric, natty, maverick, lucid, hardy 316 | # TODO: add support for Debian: sid, etc. 317 | #################################################################### 318 | 319 | #ubuntu_release: {{ ubuntu_release }} 320 | 321 | #################################################################### 322 | # ec2_size: size of the root file partition in GB. If not 323 | # specified (or zero), defaults to the instance type. 324 | #################################################################### 325 | 326 | #ec2_size: {{ ec2_size }} 327 | 328 | #################################################################### 329 | # ec2_key_name: Name of the key pair used to create the instance. 330 | # If not specified and only one key-pair is available, it will be 331 | # used. Otherwise you must specify the key-pair. Further info: 332 | # http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/generating-a-keypair.html 333 | #################################################################### 334 | 335 | #ec2_key_name: 336 | 337 | #################################################################### 338 | # ec2_security_group: The security group to control port access 339 | # to the instance (ssh, http, etc.) If not specified, use 340 | # 'default', which generally permits port 22 for ssh access. 341 | #################################################################### 342 | 343 | #ec2_security_group: default 344 | 345 | #################################################################### 346 | # ec2_security_groups: Overrides ec2_security_group setting if 347 | # multiple groups are needed. 348 | #################################################################### 349 | 350 | #ec2_security_groups: [] 351 | 352 | #################################################################### 353 | # ec2_monitoring_enabled: 354 | # http://aws.amazon.com/cloudwatch/ 355 | #################################################################### 356 | 357 | #ec2_monitoring_enabled: false 358 | 359 | #################################################################### 360 | # ec2_root_device: root device will be deleted upon termination 361 | # of the instance by default. 362 | #################################################################### 363 | 364 | #ec2_root_device: /dev/sda1 365 | """ 366 | -------------------------------------------------------------------------------- /shaker/log.py: -------------------------------------------------------------------------------- 1 | import os 2 | import logging 3 | 4 | LOG_LEVELS = { 5 | 'debug': logging.DEBUG, 6 | 'error': logging.ERROR, 7 | 'info': logging.INFO, 8 | 'none': logging.NOTSET, 9 | 'warning': logging.WARNING, 10 | } 11 | 12 | def start_logger(logname, filename, log_level): 13 | consoleLogger = logging.StreamHandler() 14 | consoleLogger.setLevel(logging.WARNING) 15 | logging.getLogger(logname).addHandler(consoleLogger) 16 | formatter = logging.Formatter( 17 | '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s') 18 | 19 | directory, _ = os.path.split(filename) 20 | if not os.path.isdir(directory): 21 | os.makedirs(directory) 22 | 23 | fileLogger = logging.FileHandler(filename=filename) 24 | fileLogger.setLevel(LOG_LEVELS[log_level]) 25 | fileLogger.setFormatter(formatter) 26 | logging.getLogger(logname).addHandler(fileLogger) 27 | logger = logging.getLogger(logname) 28 | logger.setLevel(LOG_LEVELS[log_level]) 29 | 30 | 31 | def getLogger(logname): 32 | return logging.getLogger(logname) 33 | -------------------------------------------------------------------------------- /shaker/template.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Handle the templates to configure user-data. 5 | """ 6 | import os 7 | import re 8 | from jinja2 import Environment 9 | from jinja2 import FileSystemLoader 10 | 11 | from shaker import __version__ 12 | 13 | import shaker.log 14 | LOG = shaker.log.getLogger(__name__) 15 | 16 | CLOUD_INIT_PREFIX = 'cloud-init' 17 | USER_SCRIPT_PREFIX = 'user-script' 18 | BOOTHOOK_SCRIPT_PREFIX = 'boothook-script' 19 | 20 | 21 | class UserData(object): 22 | def __init__(self, config): 23 | self.config = config 24 | self.config.update({'version': __version__}) 25 | self.template_dir = self.get_template_dir(self.config['config_dir']) 26 | self.env = self.get_jinja_env() 27 | minion_template = re.sub('\n\n+', '\n\n', self.render_template('minion_template', default_contents=MINION_TEMPLATE)) 28 | self.config['rendered_minion_template'] = minion_template 29 | self.user_script = re.sub('\n\n+', '\n\n', self.render_template('user_data_template', default_contents=USER_SCRIPT)) 30 | self.boothook_script = re.sub('\n\n+', '\n\n', self.render_template('boothook_template', default_contents=BOOTHOOK_SCRIPT)) 31 | self.cloud_init = re.sub('\n\n+', '\n\n', self.render_template('cloud_init_template', default_contents=CLOUD_INIT)) 32 | 33 | def get_jinja_env(self): 34 | ## Using '/' in loader allows to check for absolute paths. 35 | loader = FileSystemLoader([os.getcwd(), self.template_dir, '/']) 36 | env = Environment(loader=loader) 37 | return env 38 | 39 | def render_template(self, template_arg, default_contents=None): 40 | """ 41 | Retrieve rendered template text from file. 42 | """ 43 | prefixes = { 44 | 'cloud_init_template': CLOUD_INIT_PREFIX, 45 | 'user_data_template': USER_SCRIPT_PREFIX, 46 | 'boothook_template': BOOTHOOK_SCRIPT_PREFIX, 47 | 'minion_template': 'minion-template' 48 | } 49 | prefix = prefixes[template_arg] 50 | 51 | if self.config[template_arg] == None: 52 | template_name = "%s.%s" % (prefix, __version__) 53 | template_path = os.path.join(self.template_dir, template_name) 54 | ## Create from default if it doesn't exist. 55 | if not os.path.isfile(template_path): 56 | template_file = open(template_path, 'w') 57 | template_file.write(default_contents) 58 | template_file.close() 59 | else: 60 | template_name = self.config[template_arg] 61 | 62 | return self.env.get_template(template_name).render(self.config) 63 | 64 | def get_template_dir(self, config_dir): 65 | """Return the template directory name, creating the 66 | directory if absent (and populating with boilerplate). 67 | """ 68 | template_dir = os.path.join(config_dir, 'templates') 69 | if not os.path.isdir(template_dir): 70 | os.makedirs(template_dir) 71 | return template_dir 72 | 73 | 74 | CLOUD_INIT = """#cloud-config 75 | # Shaker version: {{ version }} 76 | {% if salt_master %} 77 | {% if not ubuntu_release in ['lucid', 'maverick', 'natty'] %} 78 | apt_sources: 79 | - source: "ppa:saltstack/salt" 80 | 81 | apt_upgrade: true 82 | {% endif %} 83 | {% endif %} 84 | 85 | {% if ssh_import %} 86 | ssh_import_id: [{{ ssh_import }}] 87 | {% endif %} 88 | 89 | {% if hostname %} 90 | hostname: {{ hostname }} 91 | {% if domain %} 92 | fqdn: {{ hostname }}.{{ domain }} 93 | {% endif %} 94 | {% endif %} 95 | 96 | {{ rendered_minion_template }} 97 | """ 98 | 99 | BOOTHOOK_SCRIPT = """#!/bin/sh 100 | # Change ssh port number in boothook, if needed. 101 | {% if ssh_port and ssh_port != '22' %} 102 | # change ssh port 22 to non-standard port and restart sshd 103 | sed -i "s/^Port 22$/Port {{ ssh_port }}/" /etc/ssh/sshd_config 104 | /etc/init.d/ssh restart 105 | {% endif %} 106 | """ 107 | 108 | USER_SCRIPT = """#!/bin/sh 109 | # Shaker version: {{ version }} 110 | {% if timezone %} 111 | # set timezone 112 | echo "{{ timezone }}" | tee /etc/timezone 113 | dpkg-reconfigure --frontend noninteractive tzdata 114 | restart cron 115 | {% endif %} 116 | 117 | {% if domain and hostname %} 118 | sed -i "s/127.0.0.1 ubuntu/127.0.0.1 localhost {{ hostname }}.{{ domain }} {{ hostname }}/" /etc/hosts 119 | # temp work-around for cloudinit bug: https://bugs.launchpad.net/cloud-init/ 120 | echo "127.0.0.1 localhost {{ hostname }}.{{ domain }} {{ hostname }}" >> /etc/hosts 121 | {% elif hostname %} 122 | hostname: {{ hostname }} 123 | {% endif %} 124 | 125 | {% if sudouser %} 126 | # create new user with sudo privileges 127 | useradd -m -s /bin/bash {{ sudouser }} 128 | {% if ssh_import %}cp -rp /home/ubuntu/.ssh /home/{{ sudouser }}/.ssh 129 | chown -R {{ sudouser }}:{{ sudouser }} /home/{{ sudouser }}/.ssh 130 | {% endif %} 131 | echo "{{ sudouser }} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers 132 | {% endif %} 133 | 134 | {% if size and root_device %} 135 | # resize the filesystem to use specified space 136 | resize2fs {{ root_device }} 137 | {% endif %} 138 | 139 | {% if salt_master %} 140 | # Install salt-minion and run as daemon 141 | 142 | {% if ubuntu_release in ['lucid', 'maverick'] %} 143 | aptitude -y install python-software-properties && add-apt-repository ppa:chris-lea/libpgm && add-apt-repository ppa:chris-lea/zeromq && add-apt-repository ppa:saltstack/salt && aptitude update 144 | {% endif %} 145 | 146 | apt-get -y install salt-minion 147 | 148 | service salt-minion stop 149 | 150 | cat > /etc/salt/minion < /etc/salt/pki/minion.pub < /etc/salt/pki/minion.pem <