Exemplo n.º 1
0
def cli_reset():
    check_cli_ip("/api/cli/reset")
    return None

    for instanceid, instance in Instance.objects().items():
        instance.cheapskate["grp"] = "1"

    Instance.save_all()

    return "Instances reset"
Exemplo n.º 2
0
def cli_reset():
    check_cli_ip("/api/cli/reset")
    return None

    for instanceid, instance in Instance.objects().items():
        instance.cheapskate["grp"] = "1"

    Instance.save_all()

    return "Instances reset"
Exemplo n.º 3
0
def cli_start_business_hours():
    check_cli_ip("/api/cli/shutdown")

    result = Instance.start_business_hours()
    if result:
        return result
    else:
        return "No instances meet criteria"
Exemplo n.º 4
0
def cli_start_business_hours():
    check_cli_ip("/api/cli/shutdown")

    result = Instance.start_business_hours()
    if result:
        return result
    else:
        return "No instances meet criteria"
Exemplo n.º 5
0
def cli_shutdown_check():
    check_cli_ip("/api/cli/shutdown_check")

    with open("shutdown_due.json","w") as shut:
        output = []
        for instanceid, instance in Instance.shutdown_due(hours=3).items():
            inst = instance.as_dict()
            inst.pop("product", None)
            output.append(inst)
        shut.write(json.dumps(output, sort_keys=True, indent=4, separators=(',',': ')))
    return "Shutdown file contains {} servers".format(len(output)) 
Exemplo n.º 6
0
def cli_shutdown():
    check_cli_ip("/api/cli/shutdown")
    result = {}

    instances = json.load(open("shutdown_due.json"))
    if len(instances) == 0:
        return "No shutdowns required"

    for instance in instances:
        result[instance["id"]] = Instance.objects()[instance["id"]].shutdown()

    return result
Exemplo n.º 7
0
def cli_shutdown():
    check_cli_ip("/api/cli/shutdown")
    result = {}

    instances = json.load(open("shutdown_due.json"))
    if len(instances) == 0:
        return "No shutdowns required"

    for instance in instances:
        result[instance["id"]] = Instance.objects()[instance["id"]].shutdown()

    return result
Exemplo n.º 8
0
def cli_shutdown_check():
    check_cli_ip("/api/cli/shutdown_check")

    with open("shutdown_due.json", "w") as shut:
        output = []
        for instanceid, instance in Instance.shutdown_due(hours=3).items():
            inst = instance.__dict__()
            inst.pop("product", None)
            output.append(inst)
        shut.write(
            json.dumps(output,
                       sort_keys=True,
                       indent=4,
                       separators=(',', ': ')))
    return "Shutdown file contains {} servers".format(len(output))
Exemplo n.º 9
0
def ec2_instance_update(instance_id):
    instance = Instance.objects()[instance_id]
    hours = request.forms.get("hours")
    user = request.headers.get("Remote-User")
    instance.update(user=user, hours=int(hours))
    return json.dumps(instance.as_dict())
Exemplo n.º 10
0
def ec2_instance(instance_id):
    return Instance.objects()[instance_id].as_dict()
Exemplo n.º 11
0
def ec2_instances():
    return {"objects": Instance.objects_list()}
Exemplo n.º 12
0
def ec2_tag_volumes(instance_id, tagname):
    check_cli_ip("/api/tag")
    Instance.objects()[instance_id].update_volume_tags(tagname)

    return "All instance voluems updated"
Exemplo n.º 13
0
def ec2_tag_instance(instance_id, tag, name):
    check_cli_ip("/api/tag")
    return Instance.objects()[instance_id].tag_instance(tag, name)
Exemplo n.º 14
0
def ec2_instance_update(instance_id):
    instance = Instance.objects()[instance_id]
    hours = request.forms.get("hours")
    user = request.headers.get("Remote-User")
    instance.update(user=user, hours=int(hours))
    return json.dumps(instance.__dict__())
Exemplo n.º 15
0
def ec2_instance(instance_id):
    return Instance.objects()[instance_id].__dict__()
Exemplo n.º 16
0
def ec2_instances():
    return {"objects": Instance.objects_list()}