def container_upgrade(): usage = 'Usage: ' + request.url_root + 'container/upgrade?name=<container name>&template=<template name>&rpm=yes|no&image=yes|no' overc = Overc.Overc() container_name = request.args.get('name') template = request.args.get('template') rpm = request.args.get('rpm') image = request.args.get('image') if container_name is None or template is None: return json_msg(usage) if rpm is None or rpm == 'no': rpm_upgrade = False elif rpm == 'yes': rpm_upgrade = True elif rpm != 'no': return json_msg(usage) if image is None or image == 'no': image_upgrade = False elif image == 'yes': image_upgrade = True elif image != 'no': return json_msg(usage) overc._container_upgrade(container_name, template, rpm_upgrade, image_upgrade) return json_msg(overc.message)
def container_list(): usage = 'Usage: ' + request.url_root + 'container/list?template=<template name>' overc = Overc.Overc() template = request.args.get('template') if template is None: return json_msg(usage) overc._container_list(template) return json_msg(overc.message)
def container_delete_snapshots(): usage = 'Usage: ' + request.url_root + 'container/delete_snapshots?name=<container name>&template=<template name>' overc = Overc.Overc() container_name = request.args.get('name') template = request.args.get('template') if container_name is None or template is None: return json_msg(usage) overc._container_delete_snapshots(container_name, template) return json_msg(overc.message)
def container_send_image(): usage = 'Usage: ' + request.url_root + 'container/send_image?url=<image url>&template=<template name>' overc = Overc.Overc() url = request.args.get('url') template = request.args.get('template') if url is None or template is None: return json_msg(usage) overc._container_send_image(template, url) return json_msg(overc.message)
def system_rollback(): usage = 'Usage: ' + request.url_root + 'system/rollback?template=[dom0]' overc = Overc.Overc() template = request.args.get('template') if template != 'dom0': usage += "\n The only supported template is 'dom0'" return json_msg(usage) print "System will rollback and reboot!" overc._system_rollback(template)
def container_activate(): usage = 'Usage: ' + request.url_root + 'container/activate?name=<container name>&template=<template name>' overc = Overc.Overc() container_name = request.args.get('name') template = request.args.get('template') if container_name is None or template is None: return json_msg(usage) force = True overc._container_activate(container_name, template, force) return json_msg(overc.message)
def container_rollback(): usage = 'Usage: ' + request.url_root + 'container/rollback?name=<container name>&snapshot=<snapshot name>&template=<template name> [snapshot optional]' overc = Overc.Overc() container_name = request.args.get('name') snapshot = request.args.get('snapshot') template = request.args.get('template') if container_name is None or template is None: return json_msg(usage) overc._container_rollback(container_name, snapshot, template) return json_msg(overc.message)
def host_upgrade(): usage = 'Usage: ' + request.url_root + 'host/upgrade?reboot=[True|False]&force=[True|False]' overc = Overc.Overc() reboot_s = request.args.get('reboot') force_s = request.args.get('force') reboot = False force = False if reboot_s == "True": print "do reboot" reboot = True if force_s == "True": print "do force to upgrade" force = True overc._host_upgrade(reboot, force) return json_msg(overc.message)
def container_send_image(): usage = 'Usage: ' + request.url_root + 'container/send_image?url=<image url>&template=<template name>' overc = Overc.Overc() url = request.args.get('url') template = request.args.get('template') if url is None or template is None: return json_msg(usage) template_list = os.listdir("/etc/overc/container") if template not in template_list: usage += "\n The template name is not valid" return json_msg(usage) req = urllib2.Request(url) req.get_method = lambda: 'HEAD' try: status = urllib2.urlopen(req) except Exception, e: usage += "\n The image url is not valid" return json_msg(usage)
def system_upgrade(): usage = 'Usage: ' + request.url_root + 'system/upgrade?template=[dom0]&reboot=[True|False]&force=[True|False]' overc = Overc.Overc() reboot_s = request.args.get('reboot') force_s = request.args.get('force') template = request.args.get('template') reboot = False force = False if template != 'dom0': usage += "\n The only supported template is 'dom0'" return json_msg(usage) if reboot_s == "True": print "do reboot" if force_s == "True": print "force upgrade" force = True overc._system_upgrade(template, reboot, force) return json_msg(overc.message)
def host_rollback(): overc = Overc.Overc() overc.host_rollback() return json_msg(overc.message)
def host_newer(): overc = Overc.Overc() overc.host_newer() return json_msg(overc.message)
def host_update(): overc = Overc.Overc() overc.host_update() return json_msg(overc.message)
#!/usr/bin/python -Es import sys, os import subprocess import Overc if __name__ == '__main__': overc = Overc.Overc() overc.agency.clean_essential() overc.agency.clean_container()
def system_rollback(): overc = Overc.Overc() print "System will rollback and reboot!" overc.system_rollback()