Пример #1
0
def iceage(options, args):
    if len(args) < 2:
        print "The iceage command requires a run name.  See --help"
        return 1
    dbname = args[1]

    cb = CloudInitD(options.database, db_name=dbname, log_level=options.loglevel, logdir=options.logdir, terminate=False, boot=False, ready=True)
    ha = cb.get_iaas_history()

    print_chars(0, "ID      \t:\tstate:\tassociated service\n")
    for h in ha:
        print_chars(1, "%s\t:\t%s\t:\t" % (h.get_id(), h.get_service_name()))
        state = h.get_state()
        clean = False
        color = None
        if state == "running":
            color = "green"
            clean = True
        elif state == "terminated" or state == "shutting-down":
            color="red"
        elif state == "pending":
            color="yellow"
            clean = True

        print_chars(1, ": %s\n" % (state), color=color)
        if options.kill and clean:
            print_chars(1, "Terminating %s\n" % (h.get_id()), bold=True)
            h.terminate()

    return 0
Пример #2
0
def clean_ice(options, args):
    """
    Clean all orphaned VMs
    """
    if len(args) < 2:
        print "The iceage command requires a run name.  See --help"
        return 1
    dbname = args[1]

    cb = CloudInitD(options.database, db_name=dbname, log_level=options.loglevel, logdir=options.logdir, terminate=False, boot=False, ready=True)
    ha = cb.get_iaas_history()

    for h in ha:
        state = h.get_state()
        handle = h.get_service_iaas_handle()
        if state == "running":
            if handle != h.get_id():
                print_chars(2, "Terminating an orphaned VM %s\n" % (h.get_id()), bold=True)
                h.terminate()
            elif h.get_context_state() == cloudinitd.service_state_initial:
                print_chars(2, "Terminating pre-staged VM %s\n" % (h.get_id()), bold=True)
                h.terminate()

    return 0