Exemplo n.º 1
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
Exemplo n.º 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
Exemplo n.º 3
0
def create_new_domain(args):
    hostname = args["hostname"]
    vgname = args["vgname"]
    tarball = args["tarball"]
    memory = args["memory"]
    disk = args["disk"]
    vcpus = 1

    lvname = hostname
    device_name = system.create_logical_volume_in_GB(vgname, lvname, disk,
                                                     True, "@wbvm")
    if device_name == None:
        wbui.play_sound("fail")
        dialogbox.messagebox.execute(gui.res.string_domain_failed, None,
                                     gui.res.caution_sign)
        return

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

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

    try:
        s = system.getSystem()
        with s.temporaryMount(device_name, None, "inode32") as tmpdir:
            with dialogbox.progressbar.open(
                    gui.res.string_download_description) as pb:
                with s.openWbForInput("extract_archive",
                                      (tarball, tmpdir)) as extract_archive:
                    nbr = s.getNonblockingReader(extract_archive.stdout)
                    line = nbr.readline()
                    while line != "":
                        if line != None:
                            (n, m) = map(lambda a: float(a), line.split('/'))
                            pb.setProgress(n / m)
                        if gui.yieldFrame():
                            extract_archive.send_signal(signal.SIGINT)
                        line = nbr.readline()

            cli_import.set_hostname(tmpdir, hostname)

            # https://github.com/wbrxcorp/walbrix/issues/39
            xen_conf_dir = os.path.join(tmpdir, "etc/xen")
            if not os.path.isdir(xen_conf_dir):
                if os.path.exists(xen_conf_dir): os.unlink(xen_conf_dir)
                os.makedirs(xen_conf_dir)
            with open(os.path.join(xen_conf_dir, "config"), "w") as f:
                f.write("memory=%d\n" % memory)
                f.write("vcpus=%d\n" % vcpus)

            # rootのパスワードをつける
            serialnum = status.get_serial_number()
            set_root_password(tmpdir, serialnum)

            # VAのメタデータを得る
            metadata = system.get_va_metadata(device_name, tmpdir)

            # メタデータを元に、コンフィギュレーションを行う
            if metadata != None:
                configuration_messages = configure_va(metadata, tmpdir)

    except Exception, e:
        s = system.getSystem()
        s.removeLogicalVolume(device_name)
        wbui.play_sound("fail")
        traceback.print_exc(file=sys.stderr)
        dialogbox.messagebox.execute(gui.res.string_create_failed % (e), None,
                                     gui.res.caution_sign)
        return False
Exemplo n.º 4
0
def create_new_domain(args):
    hostname = args["hostname"]
    vgname = args["vgname"]
    tarball = args["tarball"]
    memory = args["memory"]
    disk = args["disk"]
    vcpus = 1

    lvname = hostname
    device_name = system.create_logical_volume_in_GB(vgname, lvname, disk, True, "@wbvm")
    if device_name == None:
        wbui.play_sound("fail")
        dialogbox.messagebox.execute(gui.res.string_domain_failed, None, gui.res.caution_sign)
        return

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

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

    try:
        s = system.getSystem()
        with s.temporaryMount(device_name, None, "inode32") as tmpdir:
            with dialogbox.progressbar.open(gui.res.string_download_description) as pb:
                with s.openWbForInput("extract_archive", (tarball, tmpdir)) as extract_archive:
                    nbr = s.getNonblockingReader(extract_archive.stdout)
                    line = nbr.readline()
                    while line != "":
                        if line != None:
                            (n, m) = map(lambda a: float(a), line.split('/'))
                            pb.setProgress(n / m)
                        if gui.yieldFrame():
                            extract_archive.send_signal(signal.SIGINT)
                        line = nbr.readline()

            cli_import.set_hostname(tmpdir, hostname)

            # https://github.com/wbrxcorp/walbrix/issues/39
            xen_conf_dir = os.path.join(tmpdir, "etc/xen")
            if not os.path.isdir(xen_conf_dir):
                if os.path.exists(xen_conf_dir): os.unlink(xen_conf_dir)
                os.makedirs(xen_conf_dir)
            with open(os.path.join(xen_conf_dir, "config"), "w") as f:
                f.write("memory=%d\n" % memory)
                f.write("vcpus=%d\n" % vcpus)

            # rootのパスワードをつける
            serialnum = status.get_serial_number()
            set_root_password(tmpdir, serialnum)

            # VAのメタデータを得る
            metadata = system.get_va_metadata(device_name, tmpdir)

            # メタデータを元に、コンフィギュレーションを行う
            if metadata != None:
                configuration_messages = configure_va(metadata, tmpdir)

    except Exception, e:
        s = system.getSystem()
        s.removeLogicalVolume(device_name)
        wbui.play_sound("fail")
        traceback.print_exc(file=sys.stderr)
        dialogbox.messagebox.execute(gui.res.string_create_failed % (e), None, gui.res.caution_sign)
        return False