292 lines
9.7 KiB
HTML
292 lines
9.7 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Use Moto as EC2 backend — Moto 0.4.10 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="index" title="Index"
|
|
href="genindex.html"/>
|
|
<link rel="search" title="Search" href="search.html"/>
|
|
<link rel="top" title="Moto 0.4.10 documentation" href="index.html"/>
|
|
|
|
|
|
<script src="_static/js/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav" role="document">
|
|
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search">
|
|
|
|
|
|
|
|
<a href="index.html" class="icon icon-home"> Moto
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div class="version">
|
|
0.4.10
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started with Moto</a></li>
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
|
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="index.html">Moto</a>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="rst-content">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
|
|
<ul class="wy-breadcrumbs">
|
|
|
|
<li><a href="index.html">Docs</a> »</li>
|
|
|
|
<li>Use Moto as EC2 backend</li>
|
|
|
|
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
|
|
<a href="_sources/ec2_tut.rst.txt" rel="nofollow"> View page source</a>
|
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<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-default"><div class="highlight"><pre><span></span><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="s2">"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-default"><div class="highlight"><pre><span></span><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="s1">'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-default"><div class="highlight"><pre><span></span><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 class="articleComments">
|
|
|
|
</div>
|
|
</div>
|
|
<footer>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2015, Steve Pulec.
|
|
|
|
</p>
|
|
</div>
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'./',
|
|
VERSION:'0.4.10',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true,
|
|
SOURCELINK_SUFFIX: '.txt'
|
|
};
|
|
</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>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.StickyNav.enable();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |