Example #1
0
def expand(domain):
    s = system.getSystem()
    device = domain["device"]
    orig_disk = domain.get("size") or s.determineLogicalVolumeSizeInGB(device)
    min_disk = int(orig_disk) + 1
    disk = gui.inputbox.TextInputBox(gui.res.string_new_size, min_disk, None, 1, 5, "0123456789").execute(gui.getDesktop())
    if disk == None: return False
    disk = int(disk)
    if disk < min_disk:
        gui.messagebox.execute(gui.res.string_size_desc, ["ok"], gui.res.color_dialog_negative)
        return False
    if min_disk < 2048 and disk >= 2048:
        gui.messagebox.execute(string_cant_across_2tb, ["ok"], gui.res.color_dialog_negative)
        return False

    if subprocess.Popen("lvextend -L %dG %s" % (disk, device), shell=True, close_fds=True).wait() != 0:
        gui.messagebox.execute(gui.res.string_free_space_desc, ["ok"], gui.res.color_dialog_negative)
        return False

    with s.temporaryMount(device, None, "inode32") as tmpdir:
        if subprocess.Popen("xfs_growfs %s" % tmpdir, shell=True, close_fds=True).wait() != 0:
            gui.messagebox.execute(gui.res.string_assign_desc, ["ok"], gui.res.color_dialog_negative)
            return False
    
    gui.messagebox.execute(gui.res.string_enhanced, ["ok"])
    return True
Example #2
0
def duplicate(domain):
    name = domain["name"]
    src_device = domain["device"]
    use_snapshot = domain.get("open") != False
    if use_snapshot:
        if dialogbox.messagebox.execute(
                gui.res.string_operation_desc,
                dialogbox.DialogBox.OKCANCEL()) != "ok":
            return

    s = system.getSystem()
    lvsize = domain.get("size") or s.determineLogicalVolumeSizeInGB(src_device)
    new_domain = edit_duplicate_domain(name)
    if new_domain == None: return

    hostname = new_domain["hostname"]
    vgname = new_domain["vgname"]

    lvname = hostname
    device_name = system.create_logical_volume_in_GB(vgname, lvname, lvsize,
                                                     True, "@wbvm")
    if device_name == None:
        wbui.play_sound("fail")
        gui.messagebox.execute(gui.res.string_duplicate_fail, ["ok"],
                               gui.res.color_dialog_negative)
        return

    metadata = None  # /etc/wb-va.xml

    # マーキーに作成中の仮想マシンに関する情報を表示
    footer.window.setText(gui.res.string_duplication_description %
                          (name, vgname, hostname))

    try:
        if use_snapshot:
            with s.openSnapshot(src_device, 1) as snapshot:
                exec_duplicate(snapshot, device_name, hostname)
        else:
            exec_duplicate(src_device, device_name, hostname)
    except Exception, e:
        s.removeLogicalVolume(device_name)
        wbui.play_sound("fail")
        traceback.print_exc(file=sys.stderr)
        gui.messagebox.execute(gui.res.string_replicate_fails % (e), ["ok"],
                               gui.res.color_dialog_negative)
        return False
Example #3
0
def duplicate(domain):
    name = domain["name"]
    src_device = domain["device"]
    use_snapshot = domain.get("open") != False
    if use_snapshot:
        if dialogbox.messagebox.execute(gui.res.string_operation_desc, dialogbox.DialogBox.OKCANCEL()) != "ok": return

    s = system.getSystem()
    lvsize = domain.get("size") or s.determineLogicalVolumeSizeInGB(src_device)
    new_domain = edit_duplicate_domain(name)
    if new_domain == None: return

    hostname = new_domain["hostname"]
    vgname = new_domain["vgname"]

    lvname = hostname
    device_name = system.create_logical_volume_in_GB(vgname, lvname, lvsize, True, "@wbvm")
    if device_name == None:
        wbui.play_sound("fail")
        gui.messagebox.execute(gui.res.string_duplicate_fail, ["ok"], gui.res.color_dialog_negative)
        return

    metadata = None # /etc/wb-va.xml

    # マーキーに作成中の仮想マシンに関する情報を表示
    footer.window.setText(gui.res.string_duplication_description % (name,vgname,hostname) )

    try:
        if use_snapshot:
            with s.openSnapshot(src_device, 1) as snapshot:
                exec_duplicate(snapshot, device_name, hostname)
        else:
            exec_duplicate(src_device, device_name, hostname)
    except Exception, e:
        s.removeLogicalVolume(device_name)
        wbui.play_sound("fail")
        traceback.print_exc(file=sys.stderr)
        gui.messagebox.execute(gui.res.string_replicate_fails % (e), ["ok"], gui.res.color_dialog_negative)
        return False
Example #4
0
def expand(domain):
    s = system.getSystem()
    device = domain["device"]
    orig_disk = domain.get("size") or s.determineLogicalVolumeSizeInGB(device)
    min_disk = int(orig_disk) + 1
    disk = gui.inputbox.TextInputBox(gui.res.string_new_size, min_disk, None,
                                     1, 5,
                                     "0123456789").execute(gui.getDesktop())
    if disk == None: return False
    disk = int(disk)
    if disk < min_disk:
        gui.messagebox.execute(gui.res.string_size_desc, ["ok"],
                               gui.res.color_dialog_negative)
        return False
    if min_disk < 2048 and disk >= 2048:
        gui.messagebox.execute(string_cant_across_2tb, ["ok"],
                               gui.res.color_dialog_negative)
        return False

    if subprocess.Popen(
            "lvextend -L %dG %s" %
        (disk, device), shell=True, close_fds=True).wait() != 0:
        gui.messagebox.execute(gui.res.string_free_space_desc, ["ok"],
                               gui.res.color_dialog_negative)
        return False

    with s.temporaryMount(device, None, "inode32") as tmpdir:
        if subprocess.Popen("xfs_growfs %s" % tmpdir,
                            shell=True,
                            close_fds=True).wait() != 0:
            gui.messagebox.execute(gui.res.string_assign_desc, ["ok"],
                                   gui.res.color_dialog_negative)
            return False

    gui.messagebox.execute(gui.res.string_enhanced, ["ok"])
    return True
Example #5
0
def run(domain):
    operations = []
    memory = domain.get("memory")
    domain_name = domain["name"]
    s = system.getSystem()
    if memory is None:
        operations.append({
            "id": "start",
            "label": gui.res.string_domain_operate_start
        })
    else:
        if s.isRunningAsGetty():
            operations.append({
                "id": "console",
                "label": gui.res.string_console
            })
        operations.append({"id": "shutdown", "label": gui.res.string_ins_ends})
        operations.append({"id": "reboot", "label": gui.res.string_restart})
        operations.append({"id": "destroy", "label": gui.res.string_stop})
    if domain["autostart"]:
        operations.append({
            "id": "noautostart",
            "label": gui.res.string_can_automatic
        })
    else:
        operations.append({
            "id": "autostart",
            "label": gui.res.string_auto_start
        })

    modifiable = domain.get("writable") and not domain.get(
        "open") and domain.get("fstype") == "xfs"

    if memory == None:
        if modifiable:
            operations.append({
                "id": "rename",
                "label": gui.res.string_name_ram
            })
            operations.append({
                "id": "expand",
                "label": gui.res.string_extend_space
            })
            operations.append({
                "id": "vpn",
                "label": gui.res.string_vpn_config
            })
        operations.append({"id": "delete", "label": gui.res.string_remove})
    operations.append({"id": "duplicate", "label": gui.res.string_replicate})

    metadata = get_va_metadata_from_cache(domain_name)
    instruction = None
    if metadata != None:
        instructions = metadata.findall("./instruction")
        if len(instructions) > 0:
            instruction = instructions[0].text

    if instruction != None:
        operations.append({"id": "instruction", "label": gui.res.string_learn})

    operation = gui.selectbox.execute(domain_name, operations)

    if operation == "start":
        return start(domain)
    elif operation == "console":
        return console(domain)
    elif operation == "shutdown":
        return shutdown(domain)
    elif operation == "reboot":
        return reboot(domain)
    elif operation == "destroy":
        return destroy(domain)
    elif operation == "delete":
        return delete(domain)
    elif operation == "rename":
        return rename(domain["name"], domain["device"])
    elif operation == "expand":
        return expand(domain)
    elif operation == "duplicate":
        return duplicate(domain)
    elif operation == "vpn":
        return vpn(domain)
    elif operation == "autostart":
        cli_autostart.set_autostart(domain_name, True)
        footer.window.setText(string_vm_autostart % (domain_name))
        return True

    elif operation == "noautostart":
        cli_autostart.set_autostart(domain_name, False)
        footer.window.setText(string_vm_no_autostart % (domain_name))
        return True

    elif operation == "instruction":
        dialogbox.messagebox.execute(instruction)
    return False
Example #6
0
def run(domain):
    operations = []
    memory = domain.get("memory")
    domain_name = domain["name"]
    s = system.getSystem()
    if memory is None:
        operations.append({"id":"start","label":gui.res.string_domain_operate_start})
    else:
        if s.isRunningAsGetty(): 
            operations.append({"id":"console","label":gui.res.string_console})
        operations.append({"id":"shutdown","label":gui.res.string_ins_ends})
        operations.append({"id":"reboot","label":gui.res.string_restart})
        operations.append({"id":"destroy","label":gui.res.string_stop})
    if domain["autostart"]:
        operations.append({"id":"noautostart","label":gui.res.string_can_automatic})
    else:
        operations.append({"id":"autostart","label":gui.res.string_auto_start})

    modifiable = domain.get("writable") and not domain.get("open") and domain.get("fstype") == "xfs"
    
    if memory == None:
        if modifiable: 
            operations.append({"id":"rename", "label":gui.res.string_name_ram})
            operations.append({"id":"expand", "label":gui.res.string_extend_space})
            operations.append({"id":"vpn", "label":gui.res.string_vpn_config})
        operations.append({"id":"delete","label":gui.res.string_remove})
    operations.append({"id":"duplicate", "label":gui.res.string_replicate})

    metadata = get_va_metadata_from_cache(domain_name)
    instruction = None
    if metadata != None:
        instructions = metadata.findall("./instruction")
        if len(instructions) > 0:
            instruction = instructions[0].text

    if instruction != None:
        operations.append({"id":"instruction","label":gui.res.string_learn})

    operation = gui.selectbox.execute(domain_name, operations)

    if operation == "start":
        return start(domain)
    elif operation == "console":
        return console(domain)
    elif operation == "shutdown":
        return shutdown(domain)
    elif operation == "reboot":
        return reboot(domain)
    elif operation == "destroy":
        return destroy(domain)
    elif operation == "delete":
        return delete(domain)
    elif operation == "rename":
        return rename(domain["name"],domain["device"])
    elif operation == "expand":
        return expand(domain)
    elif operation == "duplicate":
        return duplicate(domain)
    elif operation == "vpn":
        return vpn(domain)
    elif operation == "autostart":
        cli_autostart.set_autostart(domain_name, True)
        footer.window.setText(string_vm_autostart % (domain_name))
        return True

    elif operation == "noautostart":
        cli_autostart.set_autostart(domain_name, False)
        footer.window.setText(string_vm_no_autostart % (domain_name))
        return True

    elif operation == "instruction":
        dialogbox.messagebox.execute(instruction)
    return False