Example #1
0
    def create_launch_config(self,
                             launch_config_name=None,
                             env=None,
                             xively_service=None,
                             stack=None):
        e = Ec2()
        v = Vpc()
        vpc = v.get_vpc_from_env(env=env)
        keyname = Misc.get_value_from_array_hash(dictlist=vpc['Tags'],
                                                 key='Keypair')
        baseami = e.query_base_image(stack=stack)
        ostype = Misc.get_value_from_array_hash(dictlist=baseami['Tags'],
                                                key='Os')
        instance_type = Misc.get_value_from_array_hash(
            dictlist=baseami['Tags'], key='Instancetype')
        image = baseami.get('ImageId')
        sgs = e.get_security_group_ids_for_launch(
            vpcid=vpc.get('VpcId'),
            stack=stack,
            ostype=ostype,
            xively_service=xively_service)
        iam = "ec2"
        y = Misc.get_app_ports_yaml('app_ports')
        port = y[xively_service]
        userdata = Misc.get_autoscale_userdata_for_os(ostype=ostype).format(
            env=env, stack=stack, xively_service=xively_service, port=port)
        monitoring = {}
        monitoring['Enabled'] = True

        self.autoscale.create_launch_configuration(
            LaunchConfigurationName=launch_config_name,
            ImageId=image,
            KeyName=keyname,
            SecurityGroups=sgs,
            UserData=userdata,
            InstanceType=instance_type,
            InstanceMonitoring=monitoring,
            IamInstanceProfile=iam)