Commits

Peter Leschev  committed 6d99578 Draft Merge
  • Participants
  • Parent commits 4272d86, 61308b1

Comments (0)

Files changed (3)

File bellatrix/lib/ec2_lib.py

 import os
 import sys
 import time
+import pwd
 
 import boto
 from boto.s3.key import Key
             logging.error("Error getting information for image:%s " % ami)
         return ret
 
-    def getEc2Instance(self, ami, key_name, security_group, instance_type, instance_initiated_shutdown_behavior=bellatrix.TERMINATE, new_size=None):
+    def getEc2Instance(self, ami, key_name, security_group, instance_type, instance_initiated_shutdown_behavior=bellatrix.TERMINATE, new_size=None, scm_subject=None, scm_author=None, scm_email=None, build_info=None, triggered_by=None):
         image = self.getImage(ami)
-        inst = self._startInstance(image, key_name, security_group, instance_type, self.NAME, instance_initiated_shutdown_behavior=instance_initiated_shutdown_behavior, new_size=new_size)
+        inst = self._startInstance(image, key_name, security_group, instance_type, self.NAME, instance_initiated_shutdown_behavior=instance_initiated_shutdown_behavior, new_size=new_size, scm_subject=scm_subject, scm_author=scm_author, scm_email=scm_email, build_info=build_info, triggered_by=triggered_by)
         return inst
 
-    def startInstance(self, ami, instance_type, key_name, security_groups, new_size=None):
-        inst = self.getEc2Instance(ami, key_name, security_groups.split(), instance_type, bellatrix.TERMINATE, new_size)
+    def startInstance(self, ami, instance_type, key_name, security_groups, new_size=None, scm_subject=None, scm_author=None, scm_email=None, build_info=None, triggered_by=None):
+        inst = self.getEc2Instance(ami, key_name, security_groups.split(), instance_type, bellatrix.TERMINATE, new_size=new_size, scm_subject=scm_subject, scm_author=scm_author, scm_email=scm_email, build_info=build_info, triggered_by=triggered_by)
         dns_name = self.getDNSName(inst)
         self.waitUntilInstanceIsReady(inst)
         return inst, dns_name
 
-    def _startInstance(self, image, key_name, security_group, instance_type, owner_name=os.path.basename(__file__), instance_initiated_shutdown_behavior=bellatrix.TERMINATE, new_size=None):
+    def _startInstance(self, image, key_name, security_group, instance_type, owner_name=os.path.basename(__file__), instance_initiated_shutdown_behavior=bellatrix.TERMINATE, new_size=None, scm_subject=None, scm_author=None, scm_email=None, build_info=None, triggered_by=None):
         """
         starts an instance given an 'image' object
         
                       block_device_map=mapping)
         logging.info("we got %d instance (should be only one)." % len(reservation.instances))
         i = reservation.instances[0]
-        self.tagInstance(i.id, "Name",  owner_name + " started me")
+        self.tagInstance(i.id, "Name",  pwd.getpwuid(os.getuid()).pw_name + " started me")
+        if scm_subject != None:
+            self.tagInstance(i.id, "SCM Commit Subject", scm_subject)
+        if scm_author != None:
+            self.tagInstance(i.id, "SCM Author", scm_author)
+        if scm_email != None:
+            self.tagInstance(i.id, "SCM Email", scm_email)
+        if build_info != None:
+            self.tagInstance(i.id, "Build Info", build_info)
+        if triggered_by != None:
+            self.tagInstance(i.id, "Build trigger by", triggered_by)
         return i
-
+        
     def stopInstance(self, i):
         i.stop()
     

File bellatrix/start_instance.py

         self.out_file = bellatrix_util.getOutFile(__file__)
         
 
-    def startInstance(self, ami, instance_type, key_name, security_groups, new_size):
+    def startInstance(self, ami, instance_type, key_name, security_groups, new_size, scm_subject, scm_author, scm_email, build_info, triggered_by):
         #todo: use the whole set of attributes and default options
-        inst, dns_name = self._ec2.startInstance(ami, instance_type, key_name, security_groups, new_size)
+        inst, dns_name = self._ec2.startInstance(ami, instance_type, key_name, security_groups, new_size, scm_subject, scm_author, scm_email, build_info, triggered_by)
         util.writeFile(self.out_file, inst.id + "," + dns_name)
         
 
-def run(ami, instance_type, key_name, security_groups, new_size):
+def run(ami, instance_type, key_name, security_groups, new_size, scm_subject, scm_author, scm_email, build_info, triggered_by):
     r = Run(bellatrix_util.getKey(), bellatrix_util.getSecret())
-    r.startInstance(ami, instance_type, key_name, security_groups, new_size)
+    r.startInstance(ami, instance_type, key_name, security_groups, new_size, scm_subject, scm_author, scm_email, build_info, triggered_by)
     return 0
 
 

File bin/bellatrix

 def startinstance(args):
     logging.info("starting EC2 instance...")
     logging.info("ami:%s type:%s key_name:%s security_groups:%s new size:%s" % (args.ami, args.type, args.key_name, args.security_groups, args.new_size))
-    sys.exit(bellatrix.start_instance.run(args.ami, args.type, args.key_name, args.security_groups, args.new_size))
+    sys.exit(bellatrix.start_instance.run(args.ami, args.type, args.key_name, args.security_groups, args.new_size, args.scm_subject, args.scm_author, args.scm_email, args.build_info, args.triggered_by))
 
 def provision(args):
     logging.info("provisioning...")
     parser_startinstance.add_argument('--type', help='instance type. t1.micro by default. Please take a look at: http://aws.amazon.com/ec2/instance-types for more info.', 
     choices=['m1.small', 'm1.large', 'm1.xlarge', 't1.micro', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge', 'c1.medium', 'c1.xlarge', 'cc1.4xlarge', 'cc2.8xlarge'], 
     default='t1.micro', nargs='?')
-    parser_startinstance.add_argument('--new_size',
-    help="""Overrides default size (in giga bytes) of the EBS volume.""",
-    default=None, nargs='?', type=int)
+    parser_startinstance.add_argument('--new_size', help="""Overrides default size (in giga bytes) of the EBS volume.""", default=None, nargs='?', type=int)
+    parser_startinstance.add_argument('--scm_subject', help="""Creates a scm_subject tag for the newly created instance.""", default=None, nargs='?')
+    parser_startinstance.add_argument('--scm_author', help="""Creates a scm_author tag for the newly created instance.""", default=None, nargs='?')
+    parser_startinstance.add_argument('--scm_email', help="""Creates a scm_email tag for the newly created instance.""", default=None, nargs='?')
+    parser_startinstance.add_argument('--build_info', help="""Creates a build_info tag for the newly created instance, used to help identify the cause of launch.""", default=None, nargs='?')
+    parser_startinstance.add_argument('--triggered_by', help="""Creates a triggered_by tag on the instance, used to help trace the cause of the instance's launch.""", default=None, nargs='?')
     parser_startinstance.set_defaults(func=startinstance)
 
     parser_provision = subparsers.add_parser('provision', help='Apply a configuration to a running machine (EC2 or not).')