Exemplo n.º 1
0
def cmd_define(vm_name, vm_definition):
    manager = Manager()
    vm = manager.define_vm(vm_name, vm_definition)
    vm_hash = {
        "definition": vm.get_definition(),
        "state": vm.get_state()
    }
Exemplo n.º 2
0
def cmd_info(vm_name):
    manager = Manager()
    vm = manager.get_vm(vm_name)
    vm_hash = {
        "definition" : vm.get_definition(),
        "state" : vm.get_state()
    }
    return vm_hash
Exemplo n.º 3
0
def cmd_status():
    manager = Manager()
    vms = {}
    for vm_name in manager.list_vms():
        vm = manager.get_vm(vm_name)
        vm_hash = {
            "definition" : vm.get_definition(),
            "state" : vm.get_state()
        }
        vms[vm_name] = vm_hash
    return {
        "vms" : vms,
        "status" : get_system_stats(),
    }
Exemplo n.º 4
0
def process_request(request):
    action = request['action']
    data = request['data']
    if action == 'status':
        return cmd_status()
    vm_name = request['data'].get('vm_name', None)
    if vm_name is None:
        die("Missing vm_name parameter", STATUS_MISSING_DATA)

    if action == 'define':
        vm_definition = request['data'].get('definition', None)
        if vm_definition is None:
            die("Missing definition parameter", STATUS_MISSING_DATA)
        return cmd_define(vm_name, vm_definition)

    if action == 'migrate':
        vm_destination = request['data'].get('vm_destination', None)
        if vm_destination is None:
            die("Missing vm_destination parameter", STATUS_MISSING_DATA)
        return cmd_migrate(vm_name, vm_destination)

    if action == 'info':
        return cmd_info(vm_name)

    # all the rest are no-argument actions on existing VMs
    manager = Manager()
    try:
        vm = manager.get_vm(vm_name)
    except KeyError:
        if action in ('undefine', 'deprovision',):
            return
        raise

    if action == 'start':
        vm.start()
    elif action == 'stop':
        vm.stop()
    elif action == 'shutdown':
        vm.shutdown()
    elif action == 'undefine':
        vm.undefine()
    elif action == 'deprovision':
        vm.deprovision()