moto/docs/_build/html/ec2_tut.html

172 lines
8.5 KiB
HTML
Raw Normal View History

2015-07-27 15:44:41 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Use Moto as EC2 backend &mdash; Moto 0.4.10 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.4.10',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Moto 0.4.10 documentation" href="index.html" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="use-moto-as-ec2-backend">
<span id="ec2-tut"></span><h1>Use Moto as EC2 backend<a class="headerlink" href="#use-moto-as-ec2-backend" title="Permalink to this headline"></a></h1>
<p>This tutorial explains <code class="docutils literal"><span class="pre">moto.ec2</span></code>&#8216;s features and how to use it. This
tutorial assumes that you have already downloaded and installed boto and moto.
Before all code examples the following snippet is launched:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">boto.ec2</span><span class="o">,</span> <span class="nn">moto</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mock_ec2</span> <span class="o">=</span> <span class="n">moto</span><span class="o">.</span><span class="n">mock_ec2</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mock_ec2</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">conn</span> <span class="o">=</span> <span class="n">boto</span><span class="o">.</span><span class="n">ec2</span><span class="o">.</span><span class="n">connect_to_region</span><span class="p">(</span><span class="s">&quot;eu-west-1&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="launching-instances">
<h2>Launching instances<a class="headerlink" href="#launching-instances" title="Permalink to this headline"></a></h2>
<p>After mock is started, the behavior is the same than previously:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">reservation</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">run_instances</span><span class="p">(</span><span class="s">&#39;ami-f00ba4&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">reservation</span><span class="o">.</span><span class="n">instances</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">Instance:i-91dd2f32</span>
</pre></div>
</div>
<p>Moto set static or generate random object&#8217;s attributes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">vars</span><span class="p">(</span><span class="n">reservation</span><span class="o">.</span><span class="n">instances</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="go">{&#39;_in_monitoring_element&#39;: False,</span>
<span class="go"> &#39;_placement&#39;: None,</span>
<span class="go"> &#39;_previous_state&#39;: None,</span>
<span class="go"> &#39;_state&#39;: pending(0),</span>
<span class="go"> &#39;ami_launch_index&#39;: u&#39;0&#39;,</span>
<span class="go"> &#39;architecture&#39;: u&#39;x86_64&#39;,</span>
<span class="go"> &#39;block_device_mapping&#39;: None,</span>
<span class="go"> &#39;client_token&#39;: &#39;&#39;,</span>
<span class="go"> &#39;connection&#39;: EC2Connection:ec2.eu-west-1.amazonaws.com,</span>
<span class="go"> &#39;dns_name&#39;: u&#39;ec2-54.214.135.84.compute-1.amazonaws.com&#39;,</span>
<span class="go"> &#39;ebs_optimized&#39;: False,</span>
<span class="go"> &#39;eventsSet&#39;: None,</span>
<span class="go"> &#39;group_name&#39;: None,</span>
<span class="go"> &#39;groups&#39;: [],</span>
<span class="go"> &#39;hypervisor&#39;: u&#39;xen&#39;,</span>
<span class="go"> &#39;id&#39;: u&#39;i-91dd2f32&#39;,</span>
<span class="go"> &#39;image_id&#39;: u&#39;f00ba4&#39;,</span>
<span class="go"> &#39;instance_profile&#39;: None,</span>
<span class="go"> &#39;instance_type&#39;: u&#39;m1.small&#39;,</span>
<span class="go"> &#39;interfaces&#39;: [NetworkInterface:eni-ed65f870],</span>
<span class="go"> &#39;ip_address&#39;: u&#39;54.214.135.84&#39;,</span>
<span class="go"> &#39;item&#39;: u&#39;\n &#39;,</span>
<span class="go"> &#39;kernel&#39;: u&#39;None&#39;,</span>
<span class="go"> &#39;key_name&#39;: u&#39;None&#39;,</span>
<span class="go"> &#39;launch_time&#39;: u&#39;2015-07-27T05:59:57Z&#39;,</span>
<span class="go"> &#39;monitored&#39;: True,</span>
<span class="go"> &#39;monitoring&#39;: u&#39;\n &#39;,</span>
<span class="go"> &#39;monitoring_state&#39;: u&#39;enabled&#39;,</span>
<span class="go"> &#39;persistent&#39;: False,</span>
<span class="go"> &#39;platform&#39;: None,</span>
<span class="go"> &#39;private_dns_name&#39;: u&#39;ip-10.136.187.180.ec2.internal&#39;,</span>
<span class="go"> &#39;private_ip_address&#39;: u&#39;10.136.187.180&#39;,</span>
<span class="go"> &#39;product_codes&#39;: [],</span>
<span class="go"> &#39;public_dns_name&#39;: u&#39;ec2-54.214.135.84.compute-1.amazonaws.com&#39;,</span>
<span class="go"> &#39;ramdisk&#39;: None,</span>
<span class="go"> &#39;reason&#39;: &#39;&#39;,</span>
<span class="go"> &#39;region&#39;: RegionInfo:eu-west-1,</span>
<span class="go"> &#39;requester_id&#39;: None,</span>
<span class="go"> &#39;root_device_name&#39;: None,</span>
<span class="go"> &#39;root_device_type&#39;: None,</span>
<span class="go"> &#39;sourceDestCheck&#39;: u&#39;true&#39;,</span>
<span class="go"> &#39;spot_instance_request_id&#39;: None,</span>
<span class="go"> &#39;state_reason&#39;: None,</span>
<span class="go"> &#39;subnet_id&#39;: None,</span>
<span class="go"> &#39;tags&#39;: {},</span>
<span class="go"> &#39;virtualization_type&#39;: u&#39;paravirtual&#39;,</span>
<span class="go"> &#39;vpc_id&#39;: None}</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Use Moto as EC2 backend</a><ul>
<li><a class="reference internal" href="#launching-instances">Launching instances</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/ec2_tut.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2015, Steve Pulec.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.3.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.6</a>
|
<a href="_sources/ec2_tut.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>