Commits

Anonymous committed 54d2677

support for dyndns names

Comments (0)

Files changed (3)

ec2control.ini.SAMPLE

 aws_key=<Amazon API key>
 aws_secret=<Amazon API secret>
 
-# instance names.  These names are local to this config and
-# don't have to match those used on AWS.
-instances=my_instance_one, my_instance_two
+# dyndns or similar url - will be hit via 
+# http, adding in public_hostname, ip_address,
+# if public_hostname exists for the instance
+dyndns_url=http://members.dyndns.org/nic/update?hostname=%(public_hostname)s&myip=%(ip_address)s&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
+dyndns_username=username
+dyndns_password=password
 
 # default instance name, optional,
 # used if no name is given with "startup" command
 # online
 public_ip_address=xxx.xxx.xxx.xxx
 
-# public hostname - if you have a public_ip_address,
+# public hostname - if you have a public_ip_address
+# or dyn dns account
 # this value can be used in the "success!" email
 public_hostname=myhostname.com
 

ec2control/config.py

 
 class Config(object):
     def __init__(self, config_file_name):
-        self.config = ConfigParser.ConfigParser()
+        self.config = ConfigParser.RawConfigParser()
         self.config.read([config_file_name])
 
     def _split_name(self, name):

ec2control/ec2.py

 from boto.ec2.connection import EC2Connection
 import time
 import logging
+import urllib2
+import base64
 log = logging.getLogger(__name__)
 
 class CommandError(Exception):
             public_ip_address = self.config.get('public_ip_address', None)
             if public_ip_address is not None:
                 if self._conn.associate_address(instance_id, public_ip_address):
+                    log.info("Associated public ip address %s with instance", public_ip_address)
                     self.public_ip_address = public_ip_address
+
+            dyndns_url = self.config_file.get('dyndns_url', None)
+            public_hostname = self.config.get('public_hostname', None)
+            if dyndns_url and public_hostname:
+                username = self.config_file.get('dyndns_username')
+                password = self.config_file.get('dyndns_password')
+                url = dyndns_url % {'public_hostname':public_hostname, 'ip_address':self.instance.ip_address}
+                log.info("Establishing dynamic dns: %s, userame %s, pw %s", url, username, password)               
+                req = urllib2.Request(url)
+                base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
+                req.add_header("Authorization", "Basic %s" % base64string)
+                result = urllib2.urlopen(req)
+                result.read()
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.