Commits

Levi Lovelock  committed f41dae5

BUILDENG-1727: Added SCM info tags to instances made from Bellatrix.

  • Participants
  • Parent commits b4a4763

Comments (0)

Files changed (3)

File bellatrix/lib/ec2_lib.py

             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):
         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)
         return inst
 
-    def startInstance(self, ami, instance_type, key_name, security_groups, new_size=None):
+    def startInstance(self, ami, instance_type, key_name, security_groups, new_size=None, scm_subject=None, scm_author=None, scm_email=None):
         inst = self.getEc2Instance(ami, key_name, security_groups.split(), instance_type, bellatrix.TERMINATE, new_size)
         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):
         """
         starts an instance given an 'image' object
         
         logging.info("we got %d instance (should be only one)." % len(reservation.instances))
         i = reservation.instances[0]
         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)
         return i
 
     def stopInstance(self, i):

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):
         #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)
         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):
     r = Run(bellatrix_util.getKey(), bellatrix_util.getSecret())
     r.startInstance(ami, instance_type, key_name, security_groups, new_size)
     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))
 
 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, narges='?')
+    parser_startinstance.add_argument('--scm_author', help="""Creates a scm_author tag for the newly created instance.""", default=None, narges='?')
+    parser_startinstance.add_argument('--scm_email', help="""Creates a scm_email tag for the newly created instance.""", default=None, narges='?')
     parser_startinstance.set_defaults(func=startinstance)
 
     parser_provision = subparsers.add_parser('provision', help='Apply a configuration to a running machine (EC2 or not).')