<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Python on iMil.net</title>
    <link>http://imil.net/blog/tags/python/</link>
    <description>Recent content in Python on iMil.net</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 12 Jun 2017 06:35:01 +0000</lastBuildDate>
    <atom:link href="http://imil.net/blog/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Cash monitoring</title>
      <link>http://imil.net/blog/posts/2017/cash-monitoring/</link>
      <pubDate>Mon, 12 Jun 2017 06:35:01 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2017/cash-monitoring/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m kind of back in the &lt;a href=&#34;https://en.wikipedia.org/wiki/Mining_pool&#34;&gt;mining&lt;/a&gt; arena. Like everyone else nowadays, I&amp;rsquo;m mining &lt;a href=&#34;https://www.ethereum.org/&#34;&gt;Ethereum&lt;/a&gt; with a couple of &lt;a href=&#34;https://cryptojunction.com/ethereum-mining-hardware-comparison/&#34;&gt;R9 290 &amp;amp; 290X&lt;/a&gt; graphic cards I bought second-hand.&lt;br&gt;&#xA;So far everything works as intended, but as a proper control freak, I &lt;strong&gt;need&lt;/strong&gt; to know what&amp;rsquo;s happening in real-time, what&amp;rsquo;s my firepower, how&amp;rsquo;s the mining doing etc&amp;hellip;&lt;br&gt;&#xA;Like many, I use a &lt;a href=&#34;https://en.wikipedia.org/wiki/Mining_pool&#34;&gt;mining pool&lt;/a&gt;, &lt;a href=&#34;https://ethermine.org&#34;&gt;ethermine&lt;/a&gt; to be precise, and those guys had the good taste of exposing a &lt;code&gt;JSON API&lt;/code&gt;.&lt;br&gt;&#xA;Using &lt;a href=&#34;https://collectd.org/documentation/manpages/collectd-python.5.shtml&#34;&gt;collectd-python&lt;/a&gt; capabilities, I was able to write a short &lt;code&gt;python&lt;/code&gt; script that feeds:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Launch the AWS Console from the CLI or a mobile phone</title>
      <link>http://imil.net/blog/posts/2017/launching-the-aws-management-console-from-the-cli/</link>
      <pubDate>Sat, 20 May 2017 15:48:47 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2017/launching-the-aws-management-console-from-the-cli/</guid>
      <description>&lt;p&gt;At &lt;em&gt;${DAYJOB}&lt;/em&gt; I happen to manipulate quite a few &lt;a href=&#34;https://aws.amazon.com/&#34;&gt;AWS&lt;/a&gt; accounts for different customers, and I find it really annoying to log out from one web console, to log into a new one, with the right credentials, account ids and &lt;a href=&#34;https://aws.amazon.com/iam/details/mfa/&#34;&gt;MFA&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://aws.amazon.com/blogs/security/how-to-enable-cross-account-access-to-the-aws-management-console/&#34;&gt;Here&lt;/a&gt; you can read a good blog post on how to enable cross account access for third parties and use a basic script to open a web browser to switch from one account to the other.&lt;br&gt;&#xA;I liked this idea so I pushed it a bit further and wrote &lt;a href=&#34;https://github.com/iMilnb/awstools/tree/master/kriskross&#34;&gt;this small piece of code&lt;/a&gt; which allows you not only to switch accounts, but also to simply open any &lt;a href=&#34;https://aws.amazon.com/&#34;&gt;AWS&lt;/a&gt; account from the command line.&lt;/p&gt;</description>
    </item>
    <item>
      <title>30 python lines Dynamic DNS</title>
      <link>http://imil.net/blog/posts/2017/20-lines-dynamic-dns-system/</link>
      <pubDate>Mon, 20 Feb 2017 09:00:11 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2017/20-lines-dynamic-dns-system/</guid>
      <description>&lt;p&gt;Here in Spain, I chose Movistar as my Internet provider, I must say I&amp;rsquo;m pretty happy with it, symmetric 300Mbps fiber optics and good service. The only annoying aspect is that they do not provide static IP for free, something I was used to and was very convenient.&lt;/p&gt;&#xA;&lt;p&gt;In order to reach my network from places where I can&amp;rsquo;t connect to my VPN, I wrote a very simple &lt;em&gt;Dynamic DNS&lt;/em&gt; system using &lt;a href=&#34;https://github.com/rthalley/dnspython&#34;&gt;dnspython&lt;/a&gt;, and it turned out to be fairly easy.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fetch monit status in JSON</title>
      <link>http://imil.net/blog/posts/2016/fetch-monit-status-in-json/</link>
      <pubDate>Wed, 16 Mar 2016 07:04:29 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2016/fetch-monit-status-in-json/</guid>
      <description>&lt;p&gt;I wanted to use &lt;a href=&#34;https://mmonit.com/monit/&#34;&gt;monit&lt;/a&gt; as my desktop-alerting system, meaning that when a service or a machine is unreachable on my personnal network, I&amp;rsquo;d see a red dot somewhere on my desktop. Why not &lt;a href=&#34;https://www.nagios.org/&#34;&gt;nagios&lt;/a&gt; you&amp;rsquo;d ask? because my needs are not worth the hassle.&lt;/p&gt;&#xA;&lt;p&gt;Unfortunately, &lt;a href=&#34;https://mmonit.com/monit/&#34;&gt;monit&lt;/a&gt; does not have simple and nice little desktop apps like &lt;a href=&#34;https://nagstamon.ifw-dresden.de/&#34;&gt;nagstamon&lt;/a&gt;, so I decided to write my own.&lt;/p&gt;&#xA;&lt;p&gt;It does not seem to be well known, but &lt;a href=&#34;https://mmonit.com/monit/&#34;&gt;monit&lt;/a&gt; publishes a special &lt;em&gt;URI&lt;/em&gt; that shows a status report in &lt;em&gt;XML&lt;/em&gt; when the mini-&lt;em&gt;HTTP&lt;/em&gt; status server is enabled. The &lt;em&gt;JSON&lt;/em&gt; one is only available for the commercial product they sell, &lt;em&gt;M/Monit&lt;/em&gt;, so I wrote this small utility to manipulate status values in a &lt;em&gt;JSON&lt;/em&gt; format and show a status report within your &lt;code&gt;shell&lt;/code&gt; console.&lt;/p&gt;</description>
    </item>
    <item>
      <title>EC2 VPN connection informations (updated)</title>
      <link>http://imil.net/blog/posts/2015/ec2-vpn-connection-informations/</link>
      <pubDate>Sat, 06 Jun 2015 11:19:42 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2015/ec2-vpn-connection-informations/</guid>
      <description>&lt;p&gt;For a mysterious reason, &lt;em&gt;EC2 VPN&lt;/em&gt; connection informations are stored in &lt;em&gt;XML&lt;/em&gt; within the &lt;em&gt;JSON&lt;/em&gt; data retrieved by either &lt;a href=&#34;https://github.com/boto/boto3&#34;&gt;boto&lt;/a&gt; or the &lt;a href=&#34;https://github.com/aws/aws-cli&#34;&gt;awscli&lt;/a&gt; command line tool.&lt;/p&gt;&#xA;&lt;p&gt;Here&amp;rsquo;s a quick &lt;em&gt;python&lt;/em&gt; snippet to convert those datas in a convenient, easily parsable &lt;code&gt;dict&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;!-- raw HTML omitted --&gt;&#xA;&lt;!-- raw HTML omitted --&gt;&#xA;&lt;p&gt;Combining this piece of code with &lt;a href=&#34;http://jinja.pocoo.org/docs/dev/&#34;&gt;jinja2&lt;/a&gt; could help you generate &lt;a href=&#34;http://ipsec-tools.sourceforge.net/&#34;&gt;racoon&lt;/a&gt; (or whatever &lt;em&gt;IPSec&lt;/em&gt; software you use) on the fly.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://gist.github.com/iMilnb/ba7b46dfc854544bf3c8&#34;&gt;here&lt;/a&gt;&amp;rsquo;s a complete example of an automatic generation for &lt;a href=&#34;http://ipsec-tools.sourceforge.net/&#34;&gt;racoon / ipsec&lt;/a&gt; configuration files using the previous snippet, along with &lt;a href=&#34;http://jinja.pocoo.org/docs/dev/&#34;&gt;jinja2&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Latency based Alias DNS record in Route53</title>
      <link>http://imil.net/blog/posts/2015/latency-based-alias-dns-record-in-route53/</link>
      <pubDate>Thu, 04 Jun 2015 23:05:56 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2015/latency-based-alias-dns-record-in-route53/</guid>
      <description>&lt;p&gt;Yes, I know I write a lot about &lt;em&gt;AWS&lt;/em&gt; these days, but you know, obsession is my thing.&lt;/p&gt;&#xA;&lt;p&gt;So as I wrote earlier, I generate my &lt;em&gt;CloudFormation&lt;/em&gt; templates using &lt;a href=&#34;https://github.com/cloudtools/troposphere&#34;&gt;troposphere&lt;/a&gt;, and the one thing I had to finish today was to register a latency based Alias record on &lt;a href=&#34;http://aws.amazon.com/documentation/route53/&#34;&gt;Route53&lt;/a&gt; for an &lt;a href=&#34;http://aws.amazon.com/documentation/elastic-load-balancing/&#34;&gt;ELB&lt;/a&gt;. While &lt;a href=&#34;http://aws.amazon.com/documentation/route53/&#34;&gt;Route53&lt;/a&gt; &lt;em&gt;GUI&lt;/em&gt; is fairly easy to use, I&amp;rsquo;ve been stuck on its programmatic emanation for quite a while, so here&amp;rsquo;s a &lt;a href=&#34;https://github.com/cloudtools/troposphere&#34;&gt;troposphere&lt;/a&gt; definition of such a &lt;em&gt;CloudFormation&lt;/em&gt; object:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rock your CloudFormation with troposphere and boto</title>
      <link>http://imil.net/blog/posts/2015/rock-your-cloudformation-with-troposphere-and-boto/</link>
      <pubDate>Thu, 04 Jun 2015 10:55:48 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2015/rock-your-cloudformation-with-troposphere-and-boto/</guid>
      <description>&lt;p&gt;So you&amp;rsquo;re using &lt;a href=&#34;http://aws.amazon.com/fr/cloudformation/&#34;&gt;AWS CloudFormation&lt;/a&gt; in order to bring up complex infrastructures; haven&amp;rsquo;t you already told yourself that instead of writing down all those &lt;code&gt;JSON&lt;/code&gt; lines by hand, you could bring more fun to your architect life?&#xA;I did, and I found a way to programmatically design a whole architecture using &lt;a href=&#34;https://github.com/cloudtools/troposphere/&#34;&gt;troposphere&lt;/a&gt; and &lt;a href=&#34;http://boto3.readthedocs.org/en/latest/&#34;&gt;boto3&lt;/a&gt;.&#xA;Simply put, &lt;a href=&#34;https://github.com/cloudtools/troposphere/&#34;&gt;troposphere&lt;/a&gt; gives you bindings in order to generate &lt;em&gt;CloudFormation&lt;/em&gt;&amp;rsquo;s &lt;code&gt;JSON&lt;/code&gt; template, but hey, it&amp;rsquo;s python, meaning that you can create loops, use conditions and even dynamically build objects.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Github flavored markdown with python</title>
      <link>http://imil.net/blog/posts/2013/github-flavored-markdown-with-python/</link>
      <pubDate>Sun, 28 Jul 2013 23:05:45 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2013/github-flavored-markdown-with-python/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m slowly migrating some parts of my personal Wiki to &lt;a href=&#34;http://github.com&#34;&gt;Github&lt;/a&gt; using their own &lt;em&gt;markdown&lt;/em&gt; syntax. Before committing, I wanted to make sure the docs look like they should. Here&amp;rsquo;s a small &lt;a href=&#34;http://flask.pocoo.org/&#34;&gt;Flask&lt;/a&gt; snippet I wrote in order to achieve this:&lt;/p&gt;&#xA;&lt;!-- raw HTML omitted --&gt;&#xA;&lt;!-- raw HTML omitted --&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://pypi.python.org/pypi/Markdown&#34;&gt;Python Markdown&lt;/a&gt; has an extension called &lt;a href=&#34;http://pythonhosted.org/Markdown/extensions/fenced_code_blocks.html&#34;&gt;fenced code blocks&lt;/a&gt; which supports &lt;em&gt;Github&lt;/em&gt;&amp;rsquo;s tidle (```) syntax, thus making this small program&amp;rsquo;s output similar to what the doc will finally look like.&lt;/p&gt;</description>
    </item>
    <item>
      <title>LDAP Flask-Login snippet</title>
      <link>http://imil.net/blog/posts/2013/ldap-flask-login-snippet/</link>
      <pubDate>Sat, 06 Jul 2013 10:38:55 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2013/ldap-flask-login-snippet/</guid>
      <description>&lt;p&gt;At ${DAYWORK}, I am writing a simple &lt;a href=&#34;http://flask.pocoo.org/&#34;&gt;Flask&lt;/a&gt; web frontend for our new information system. I wanted to have a simple authentication method and so I found the &lt;a href=&#34;https://pypi.python.org/pypi/Flask-Login&#34;&gt;Flask-Login&lt;/a&gt; extention for &lt;em&gt;Flask&lt;/em&gt; which takes care of user validation, session remembrance , and has a callback method in order to plug the authentication on whatever backend you&amp;rsquo;d like.&lt;/p&gt;&#xA;&lt;p&gt;I came up with that little piece of code which makes &lt;em&gt;Flask-Login&lt;/em&gt; check a &lt;em&gt;user / password&lt;/em&gt; couple against a LDAP server, and validates a user regarding its &lt;code&gt;user ID&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>SaltStack: dynamic sls (updated for 0.15.3)</title>
      <link>http://imil.net/blog/posts/2013/saltstack-dynamic-sls/</link>
      <pubDate>Thu, 06 Jun 2013 21:26:39 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2013/saltstack-dynamic-sls/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been learning and diving into &lt;a href=&#34;http://saltstack.com/community.html&#34;&gt;SaltStack&lt;/a&gt; for about a month now, for both work and personal interest, that thing simply rocks. In the meantime, I&amp;rsquo;ve contributed a couple of modules, like &lt;a href=&#34;https://github.com/saltstack/salt/blob/develop/salt/modules/bridge.py&#34;&gt;bridging&lt;/a&gt; and &lt;a href=&#34;https://github.com/saltstack/salt/blob/develop/salt/modules/xapi.py&#34;&gt;Xen&lt;/a&gt; support, plus a couple of &lt;a href=&#34;http://docs.saltstack.com/topics/targeting/grains.html&#34;&gt;grains&lt;/a&gt; improvements for NetBSD.&lt;/p&gt;&#xA;&lt;p&gt;But most of all, I&amp;rsquo;ve been preparing my &lt;em&gt;${DAYJOB}&lt;/em&gt; infrastructure for &lt;em&gt;Salt&lt;/em&gt;, and I must say this has been much easier than I thought, thanks to this beautifully designed piece of code.&#xA;One aspect I&amp;rsquo;d like to share is the simple way I found to make a &lt;a href=&#34;http://docs.saltstack.com/ref/configuration/minion.html&#34;&gt;minion&lt;/a&gt; dynamically configured, through custom-made grains.&lt;/p&gt;</description>
    </item>
    <item>
      <title>GateOne, more than a web-based SSH</title>
      <link>http://imil.net/blog/posts/2013/gateone-more-than-a-web-based-ssh/</link>
      <pubDate>Sat, 26 Jan 2013 12:52:37 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2013/gateone-more-than-a-web-based-ssh/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been searching for a Web-based SSH for quite a while, and I recently read about &lt;a href=&#34;http://liftoffsoftware.com/Products/GateOne&#34;&gt;GateOne&lt;/a&gt; on the dedicated &lt;a href=&#34;http://en.wikipedia.org/wiki/Web-based_SSH&#34;&gt;Wikipedia&lt;/a&gt; page. Not only &lt;em&gt;GateOne&lt;/em&gt; does what I was searching for, but it also comes up with nice features like interpreting images on-the-fly.&lt;/p&gt;&#xA;&lt;p&gt;The remote server on which I intended to run this software is, of course, a &lt;em&gt;NetBSD 6.0 domU&lt;/em&gt;, and as I anticipated, some work was needed in order to make &lt;em&gt;GateOne&lt;/em&gt; work on this platform.&lt;/p&gt;</description>
    </item>
    <item>
      <title>au-to-ma-gic</title>
      <link>http://imil.net/blog/posts/2010/au-to-ma-gic/</link>
      <pubDate>Sat, 13 Feb 2010 01:08:59 +0000</pubDate>
      <guid>http://imil.net/blog/posts/2010/au-to-ma-gic/</guid>
      <description>&lt;p&gt;Au boulot, j&amp;rsquo;ai élu une solution de déploiement à haute teneur en convivialité qui m&amp;rsquo;a été suggérée par &lt;a href=&#34;http://www.rottenbytes.info/&#34;&gt;nico&lt;/a&gt;, j&amp;rsquo;ai nommé &lt;a href=&#34;http://docs.fabfile.org/0.9.0/&#34;&gt;fabric&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Ce soft à l&amp;rsquo;utilisation simplissime permet en un tournemain de réaliser des opérations complexes en masse sur une architecture distante en utilisant le protocole &lt;a href=&#34;http://fr.wikipedia.org/wiki/Secure_Shell&#34;&gt;SSH&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Si la documentation de la plupart des fonctions est clarissime, l&amp;rsquo;une d&amp;rsquo;entre elles, qui pourtant me semblait avoir un fort potentiel loutresque, n&amp;rsquo;était pas très clairement exposée: &lt;code&gt;upload_template&lt;/code&gt;.&#xA;Cette fonction, comme son nom semble l&amp;rsquo;indiquer, permet d&amp;rsquo;envoyer sur un serveur distant un fichier &amp;ldquo;template&amp;rdquo; en ayant préalablement remplacé des variables par le contenu souhaité. Après un peu de lecture du code source de &lt;em&gt;fabric&lt;/em&gt;, la subtilité de son utilisation m&amp;rsquo;est apparue.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
