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"
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"
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))
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
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))
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())
def ec2_instance(instance_id): return Instance.objects()[instance_id].as_dict()
def ec2_instances(): return {"objects": Instance.objects_list()}
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"
def ec2_tag_instance(instance_id, tag, name): check_cli_ip("/api/tag") return Instance.objects()[instance_id].tag_instance(tag, name)
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__())
def ec2_instance(instance_id): return Instance.objects()[instance_id].__dict__()