Ejemplo n.º 1
0
def main():
    parser = optparse.OptionParser()
    parser.add_option( "-c", "--config", dest="config_file", help="AutoScale config INI", metavar="FILE" )
    parser.add_option( "-a", "--asg", dest="asg_name", help="AutoScaleGroup Name to be deleted", metavar="ASG" )
    (options, args) = parser.parse_args()
    logging.info( "Using config file [%s]" % options.config_file )

    config = parse_config( options.config_file ) 

    aws_access = config.get("AWS", 'access')
    aws_secret = config.get("AWS", 'secret')

    lc = autoscalelib.lc_object(
        config.get("LaunchConfig", 'name'),
        config.get("LaunchConfig", 'image'),
        config.get("LaunchConfig", 'key'),
        config.get("LaunchConfig", 'user_data'),
        config.get("LaunchConfig", 'security_groups'),
        config.get("LaunchConfig", 'instance_type')
    )
    logging.debug( "LC CONFIG = %s" % lc.__dict__ )

    asg = autoscalelib.asg_object(
        config.get("AutoScaleGroup", 'group_name'),
        config.get("AutoScaleGroup", 'zones'),
        config.get("AutoScaleGroup", 'min_instances'),
        config.get("AutoScaleGroup", 'max_instances'),
        lc
    )

    aws_connection = AutoScaleConnection( aws_access, aws_secret )
    lc.connection = aws_connection
    lc.delete()
Ejemplo n.º 2
0
def main():
    parser = optparse.OptionParser()
    parser.add_option( "-c", "--config", dest="config_file", help="AutoScale config INI", metavar="FILE" )
    (options, args) = parser.parse_args()
    logging.info( "Using config file [%s]" % options.config_file )

    config = parse_config( options.config_file ) 

    aws_access = config.get("AWS", 'access')
    aws_secret = config.get("AWS", 'secret')

    logging.debug( "Connecting to AWS with access [%s] and secret [%s]" % ( aws_access, aws_secret ) )
    aws_connection = AutoScaleConnection( aws_access, aws_secret )

    lc = autoscalelib.lc_object(
        config.get("LaunchConfig", 'name'),
        config.get("LaunchConfig", 'image'),
        config.get("LaunchConfig", 'key'),
        config.get("LaunchConfig", 'user_data'),
        config.get("LaunchConfig", 'security_groups'),
        config.get("LaunchConfig", 'instance_type')
    )
    logging.debug( "LC CONFIG = %s" % lc.__dict__ )

    asg = autoscalelib.asg_object(
        config.get("AutoScaleGroup", 'group_name'),
        config.get("AutoScaleGroup", 'zones'),
        config.get("AutoScaleGroup", 'min_instances'),
        config.get("AutoScaleGroup", 'max_instances'),
        lc
    )

    if ( autoscalelib.lc_exists( aws_connection, lc ) ):
        print "LaunchConfig [%s] Exists!" % lc.name
        autoscalelib.delete_lc( aws_connection, lc )
    else:
        print "LaunchConfig [%s] does NOT exists, creating now." % lc.name
        autoscalelib.create_lc( aws_connection, lc )

    if ( autoscalelib.asg_exists( aws_connection, asg ) ):
        print "AutoScale Group [%s] Exists!" % asg.name
        autoscalelib.update_asg( aws_connection, asg )
        autoscalelib.delete_asg( aws_connection, asg )
    else:
        print "AutoScale Group [%s] does NOT exists, creating now." % asg.name
        autoscalelib.create_asg( aws_connection, asg )