예제 #1
0
 def get_ami_stacks(self):
     """
     This function returns all ami stacks in an account
     :return: a dict containing the puppet_roles
     """
     from wrapper.ec2 import Ec2
     from wrapper.iam import Iam
     ec2 = Ec2(session=self.session)
     iam = Iam(session=self.session)
     account_id = iam.get_account_id()
     return ec2.get_ami_stacks(account_id=account_id)
예제 #2
0
 def get_ami_from_tag(self, puppet_role):
     from wrapper.ec2 import Ec2
     from wrapper.iam import Iam
     ec2 = Ec2(session=self.session)
     iam_modul = Iam(session=self.session)
     account_id = iam_modul.get_account_id()
     baseami_object = ec2.get_images(account_id=account_id,
                                     filters=[{
                                         'Name': 'tag:Puppet_role',
                                         'Values': [puppet_role]
                                     }])[0]
     return baseami_object
예제 #3
0
 def create_instance_lamdba(self, args=None):
     """
     This function is invoked by lambda to provision multiple at same time
     :param args: A dict with keypairs needed
     :return: instance objects created
     """
     from wrapper.ec2 import Ec2
     from wrapper.iam import Iam
     ec2 = Ec2(session=self.session)
     iam = Iam(session=self.session)
     account_id = iam.get_account_id()
     inst_name = args['instance_name'].pop()
     # linux or windows userdata formated for start
     if 'snappyindex' in args:
         logger.debug("Deploying a snappyindex")
         snappyindex = args['snappyindex'].pop()
         userdata = args['userdata']
         userdata = userdata.format(index=snappyindex,
                                    accountid=args['accountid'],
                                    channelname=args['channelname'],
                                    newrelic=args['newrelic'],
                                    broker=args['broker'],
                                    hostname=inst_name,
                                    env=args['env'],
                                    devicestring=args['devicestring'],
                                    branch=args['branch'])
     elif 'userdata' in args:
         userdata = args['userdata']
     else:
         userdata = Misc.get_userdata_for_os(ostype=args['ostype']).format(
             hostname=inst_name, env=args['env'], account=account_id)
     instance = ec2.run_instance(baseamiid=args['baseamiid'],
                                 key_name=args['keypair'],
                                 securitygroup=args['securitygroup'],
                                 instancetype=args['instance_type'],
                                 subnet=args['subnet'].pop(),
                                 user_data=userdata,
                                 shutdown=args['shutdown'],
                                 monitoring=args['monitoring'],
                                 ebsoptimized=args['ebsoptimized'],
                                 dry_run=args['dry_run'],
                                 iam_name=args['iam'])
     # add snappyindex to tag
     if 'snappyindex' in args:
         ec2.tag_resource(instanceid=instance.get('InstanceId'),
                          tags={
                              'Name': inst_name,
                              'Requester': args['requester'],
                              'Puppet_role': args['puppet_role'],
                              'Xively_service': args['xively_service'],
                              'Customer': args['customer'],
                              'Snappy_index': str(snappyindex),
                              'Environment': args['env']
                          })
     else:
         ec2.tag_resource(instanceid=instance.get('InstanceId'),
                          tags={
                              'Name': inst_name,
                              'Requester': args['requester'],
                              'Puppet_role': args['puppet_role'],
                              'Xively_service': args['xively_service'],
                              'Customer': args['customer'],
                              'Environment': args['env']
                          })
     return instance