Ejemplo n.º 1
0
def exec_duplicate(src, dest, hostname):
    s = system.getSystem()
    with gui.progressbar.SyncedProgressBar(gui.res.string_cloning) as pb:
        try:
            with s.openCancellableProcessForInput(["xfs_copy", src,
                                                   dest]) as xfs_copy:
                nbr = s.getNonblockingReader(xfs_copy.stdout)
                output = ""
                percentage_pattern = re.compile('[0-9]{1,3}%')
                str = nbr.read()
                while str != "":
                    pb.yieldFrame()
                    if str != None:
                        output += str
                        progress = float(
                            percentage_pattern.findall(output)[-1]
                            [0:-1]) / 100.0
                        pb.setProgress(progress)
                    str = nbr.read()
        except system.ProcessKilled:
            pass  # killed is proper result

        with s.temporaryMount(dest, None, "inode32") as tmpdir:
            # growfsする
            subprocess.Popen("xfs_growfs %s" % tmpdir,
                             shell=True,
                             close_fds=True).wait()
            # ホスト名をつける
            cli_import.set_hostname(tmpdir, hostname)
            # VAのメタデータを得る
            metadata = system.get_va_metadata(dest, tmpdir)
Ejemplo n.º 2
0
def exec_duplicate(src, dest, hostname):
    s = system.getSystem()
    with gui.progressbar.SyncedProgressBar(gui.res.string_cloning) as pb:
        try:
            with s.openCancellableProcessForInput(["xfs_copy", src, dest]) as xfs_copy:
                nbr = s.getNonblockingReader(xfs_copy.stdout)
                output = ""
                percentage_pattern = re.compile('[0-9]{1,3}%')
                str = nbr.read()
                while str != "":
                    pb.yieldFrame()
                    if str != None: 
                        output += str
                        progress = float(percentage_pattern.findall(output)[-1][0:-1]) / 100.0
                        pb.setProgress(progress)
                    str = nbr.read()
        except system.ProcessKilled:
            pass # killed is proper result

        with s.temporaryMount(dest, None, "inode32") as tmpdir:
            # growfsする
            subprocess.Popen("xfs_growfs %s" % tmpdir, shell=True, close_fds=True).wait()
            # ホスト名をつける
            cli_import.set_hostname(tmpdir, hostname)
            # VAのメタデータを得る
            metadata = system.get_va_metadata(dest, tmpdir)
Ejemplo 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
Ejemplo 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