172 lines
8.5 KiB
HTML
172 lines
8.5 KiB
HTML
<!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 — 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>‘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">>>> </span><span class="kn">import</span> <span class="nn">boto.ec2</span><span class="o">,</span> <span class="nn">moto</span>
|
|
<span class="gp">>>> </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">>>> </span><span class="n">mock_ec2</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
|
<span class="gp">>>> </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">"eu-west-1"</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">>>> </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">'ami-f00ba4'</span><span class="p">)</span>
|
|
<span class="gp">>>> </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’s attributes:</p>
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </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">{'_in_monitoring_element': False,</span>
|
|
<span class="go"> '_placement': None,</span>
|
|
<span class="go"> '_previous_state': None,</span>
|
|
<span class="go"> '_state': pending(0),</span>
|
|
<span class="go"> 'ami_launch_index': u'0',</span>
|
|
<span class="go"> 'architecture': u'x86_64',</span>
|
|
<span class="go"> 'block_device_mapping': None,</span>
|
|
<span class="go"> 'client_token': '',</span>
|
|
<span class="go"> 'connection': EC2Connection:ec2.eu-west-1.amazonaws.com,</span>
|
|
<span class="go"> 'dns_name': u'ec2-54.214.135.84.compute-1.amazonaws.com',</span>
|
|
<span class="go"> 'ebs_optimized': False,</span>
|
|
<span class="go"> 'eventsSet': None,</span>
|
|
<span class="go"> 'group_name': None,</span>
|
|
<span class="go"> 'groups': [],</span>
|
|
<span class="go"> 'hypervisor': u'xen',</span>
|
|
<span class="go"> 'id': u'i-91dd2f32',</span>
|
|
<span class="go"> 'image_id': u'f00ba4',</span>
|
|
<span class="go"> 'instance_profile': None,</span>
|
|
<span class="go"> 'instance_type': u'm1.small',</span>
|
|
<span class="go"> 'interfaces': [NetworkInterface:eni-ed65f870],</span>
|
|
<span class="go"> 'ip_address': u'54.214.135.84',</span>
|
|
<span class="go"> 'item': u'\n ',</span>
|
|
<span class="go"> 'kernel': u'None',</span>
|
|
<span class="go"> 'key_name': u'None',</span>
|
|
<span class="go"> 'launch_time': u'2015-07-27T05:59:57Z',</span>
|
|
<span class="go"> 'monitored': True,</span>
|
|
<span class="go"> 'monitoring': u'\n ',</span>
|
|
<span class="go"> 'monitoring_state': u'enabled',</span>
|
|
<span class="go"> 'persistent': False,</span>
|
|
<span class="go"> 'platform': None,</span>
|
|
<span class="go"> 'private_dns_name': u'ip-10.136.187.180.ec2.internal',</span>
|
|
<span class="go"> 'private_ip_address': u'10.136.187.180',</span>
|
|
<span class="go"> 'product_codes': [],</span>
|
|
<span class="go"> 'public_dns_name': u'ec2-54.214.135.84.compute-1.amazonaws.com',</span>
|
|
<span class="go"> 'ramdisk': None,</span>
|
|
<span class="go"> 'reason': '',</span>
|
|
<span class="go"> 'region': RegionInfo:eu-west-1,</span>
|
|
<span class="go"> 'requester_id': None,</span>
|
|
<span class="go"> 'root_device_name': None,</span>
|
|
<span class="go"> 'root_device_type': None,</span>
|
|
<span class="go"> 'sourceDestCheck': u'true',</span>
|
|
<span class="go"> 'spot_instance_request_id': None,</span>
|
|
<span class="go"> 'state_reason': None,</span>
|
|
<span class="go"> 'subnet_id': None,</span>
|
|
<span class="go"> 'tags': {},</span>
|
|
<span class="go"> 'virtualization_type': u'paravirtual',</span>
|
|
<span class="go"> 'vpc_id': 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">
|
|
©2015, Steve Pulec.
|
|
|
|
|
|
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.3.1</a>
|
|
& <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> |