Anonymous avatar Anonymous committed f21529c

add support for elastic ip binding, public hostname

Comments (0)

Files changed (3)

ec2control.ini.SAMPLE

 # instance sections for each of the above names.
 
 [instance_my_instance_one]
+# instance id - this is the amazon id
 instance_id=i-12345678
+
+# public ip - if present, associate_address()
+# will be called when the instance is brought
+# online
+public_ip_address=xxx.xxx.xxx.xxx
+
+# public hostname - if you have a public_ip_address,
+# this value can be used in the "success!" email
+public_hostname=myhostname.com
+
+# descriptive name used in emails
 descriptive_name=My Instance
+
+# any custom key/value pairs can be
+# added here
 custom_key_one=Some Custom Value
 
 [instance_my_instance_two]

ec2control/ec2.py

 
     @property
     def ip_address(self):
+        """Return the dynamic IP address of the instance"""
         if self.instance:
             return self.instance.ip_address
         else:
             return None
 
+    @property
+    def public_hostname(self):
+        """Return the best internet name for the instance.
+
+        If public_hostname is set, returns that.
+        Else if public_ip_address is present, returns that.
+        Otherwise returns ip_address.
+        If the instance is not running, returns None
+        in all cases.
+        """
+
+        if self.instance:
+            if "public_hostname" in self.config:
+                return self.config['public_hostname']
+            elif "public_ip_address" in self.config:
+                return self.config['public_ip_address']
+            else:
+                return self.instance.ip_address
+        else:
+            return None
+
     def start(self):
         instance_id = self.config['instance_id']
         log.info("Starting instance id: %s", instance_id)
         self.status = inst.state
         log.info("Status: %s", self.status)
 
+        if self.status == "running":
+            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):
+                    self.public_ip_address = public_ip_address

sample_templates/minecraft.mako

 <%def name="subject()">
     % if status == 'started':
         % if instance.status == 'running':
-            ${instance.descriptive_name} is online!  ${instance.ip_address}:${instance.config['minecraft_port']}
+            ${instance.descriptive_name} is online!  ${instance.public_hostname}:${instance.config['minecraft_port']}
         % else:
             ${instance.descriptive_name} failed to start!
         % endif
 <%def name="body()">
 % if status == 'started':
     % if instance.status == 'running':
-Your presence is welcome at ${instance.descriptive_name}!  ${instance.ip_address}:${instance.config['minecraft_port']}
+Your presence is welcome at ${instance.descriptive_name}!  ${instance.public_hostname}:${instance.config['minecraft_port']}
     % else:
 ${instance.descriptive_name} wasn't able to start !   Status is ${instance.status}
     % endif
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.