def select_disk(): disks = list_available_disks() if len(disks) == 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_disk_description, dialogbox.DialogBox.OK(), gui.res.caution_sign) return None # ディスク選択 options = [] disks_by_name = {} for disk in disks: logicalname = disk["logicalname"] product = disk["product"] size = disk["size"] options.append({ "id": logicalname, "label": gui.res.string_lps % (logicalname, product, size) }) disks_by_name[logicalname] = [product, size] logicalname = gui.selectbox.execute(gui.res.string_volume_choice, options) if logicalname == None: return None product = disks_by_name[logicalname][0] size = disks_by_name[logicalname][1] return ("/dev/" + logicalname, product, size)
def down(): global selected if is_able_to_go_down(): wbui.play_sound("move") selected += 1 update() return True return False
def reboot(domain): if dialogbox.messagebox.execute(gui.res.string_restart_ins % (domain["name"]), dialogbox.DialogBox.OKCANCEL()) != "ok": return False ret = os.system("xl reboot %s" % (domain["name"])) if ret != 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_unable_restart_ins,None, gui.res.caution_sign) return False return True
def main(): wbui.play_sound("click") if gui.messagebox.execute(gui.res.string_console_migration, ["ok", "cancel"]) != "ok": return pygame.quit() os.execv("/usr/bin/openvt", ["openvt", "-wsl", "--", "/bin/login", "-f", "root"])
def destroy(domain): if dialogbox.messagebox.execute(gui.res.string_kill_vm % (domain["name"]), dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) != "ok": return False ret = os.system("xl destroy %s" % (domain["name"])) if ret != 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_not_killed,None, gui.res.caution_sign) return False #else footer.window.setText(gui.res.string_terminated) return True
def shutdown(domain): if dialogbox.messagebox.execute(gui.res.string_exit_desc % (domain["name"]), dialogbox.DialogBox.OKCANCEL()) != "ok": return False ret = os.system("xl shutdown %s" % (domain["name"])) if ret != 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_unable,None, gui.res.caution_sign) return False footer.window.setText(gui.res.string_domain_issued) return True
def enter(): if selected == 0: wbui.play_sound("click") create_vg() return else: # vgに対するオペレーションメニューを表示 wbui.play_sound("click") vg = vglist[selected - 1]["name"] lvs = subprocess.Popen("lvs --noheadings --separator='|' %s" % (vg), shell=True, stdout=subprocess.PIPE, close_fds=True) line = lvs.stdout.readline() lv_list = [] while line: lv = line.split("|")[0].strip() lv_list.append(lv) line = lvs.stdout.readline() lvs.wait() operations = [{ "label": gui.res.string_volume_remove }, { "label": gui.res.string_logic_volume, "id": "lvs" }] if len(lv_list) == 0: operations[0]["id"] = "remove" operation = gui.selectbox.execute(vg, operations) if operation == "remove": if dialogbox.messagebox.execute( gui.res.string_volume_del_area % (vg), dialogbox.DialogBox.OKCANCEL()) != "ok": return None if system.exec_shell("vgremove -f %s" % (vg)) == 0: dialogbox.messagebox.execute(gui.res.string_volume_deleted % (vg)) else: dialogbox.messagebox.execute(gui.res.string_not_remove % (vg), None, gui.res.caution_sign) refresh() elif operation == "lvs": max_show = 20 msg = gui.res.string_logical_volume_included % (vg) if len(lv_list) == 0: msg += gui.res.string_do_not else: for i in range(0, min(len(lv_list), max_show)): if i > 0: msg += "," msg += lv_list[i] if i < len(lv_list) - 1: msg += (gui.res.string_other % (len(lv_list) - max_show)) dialogbox.messagebox.execute(msg)
def operate_app(app): operations = [{"id":"run", "label":gui.res.string_app_start},{"id":"delete", "label":gui.res.string_app_remove}] app_name = app["name"] operation = gui.selectbox.execute(app_name, operations) if operation == "run": if dialogbox.messagebox.execute(gui.res.string_launch_apps % (app["name"]), dialogbox.DialogBox.OKCANCEL()) == "ok": try: run_app(app) except Exception, e: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_apps_not_started % e, None, gui.res.caution_sign)
def reboot(domain): if dialogbox.messagebox.execute( gui.res.string_restart_ins % (domain["name"]), dialogbox.DialogBox.OKCANCEL()) != "ok": return False ret = os.system("xl reboot %s" % (domain["name"])) if ret != 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_unable_restart_ins, None, gui.res.caution_sign) return False return True
def destroy(domain): if dialogbox.messagebox.execute(gui.res.string_kill_vm % (domain["name"]), dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) != "ok": return False ret = os.system("xl destroy %s" % (domain["name"])) if ret != 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_not_killed, None, gui.res.caution_sign) return False #else footer.window.setText(gui.res.string_terminated) return True
def shutdown(domain): if dialogbox.messagebox.execute( gui.res.string_exit_desc % (domain["name"]), dialogbox.DialogBox.OKCANCEL()) != "ok": return False ret = os.system("xl shutdown %s" % (domain["name"])) if ret != 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_unable, None, gui.res.caution_sign) return False footer.window.setText(gui.res.string_domain_issued) return True
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
def create_vg(): # ディスク選択 selected_disk = select_disk() if selected_disk == None: return logicalname = selected_disk[0] product = selected_disk[1] size = selected_disk[2] # VGの名前をユーザーに決めてもらう vgname = input_vg_name(logicalname) if vgname == None: return if dialogbox.messagebox.execute( gui.res.string_erase_msg % (size, product, logicalname, vgname), dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) != "ok": return try: with gui.progressbar.SyncedProgressBar( gui.res.string_disk_partition) as progressBar: s = system.getSystem() with s.openWbForInput("initialize_disk", [logicalname, vgname]) as initialize_disk: nbr = s.getNonblockingReader(initialize_disk.stdout) line = nbr.readline() while line != "": if line != None: (x, y) = (float(x) for x in line.rstrip().split('/')) progressBar.setProgress(x / y) progressBar.yieldFrame() line = nbr.readline() except Exception as e: traceback.print_exc(file=sys.stderr) wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_volume_fail % e.message, None, gui.res.caution_sign) return None refresh() wbui.play_sound("success") gui.messagebox.execute(gui.res.string_volume_success % (vgname)) return vgname
def enter(): if selected == 0: wbui.play_sound("click") create_vg() return else: # vgに対するオペレーションメニューを表示 wbui.play_sound("click") vg = vglist[selected - 1]["name"] lvs = subprocess.Popen("lvs --noheadings --separator='|' %s" % (vg), shell=True, stdout=subprocess.PIPE, close_fds=True) line = lvs.stdout.readline() lv_list = [] while line: lv = line.split("|")[0].strip() lv_list.append(lv) line = lvs.stdout.readline() lvs.wait() operations = [{"label":gui.res.string_volume_remove},{"label":gui.res.string_logic_volume,"id":"lvs"}] if len(lv_list) == 0: operations[0]["id"] = "remove" operation = gui.selectbox.execute(vg, operations) if operation == "remove": if dialogbox.messagebox.execute(gui.res.string_volume_del_area % (vg), dialogbox.DialogBox.OKCANCEL()) != "ok": return None if system.exec_shell("vgremove -f %s" % (vg)) == 0: dialogbox.messagebox.execute(gui.res.string_volume_deleted % (vg)) else: dialogbox.messagebox.execute(gui.res.string_not_remove % (vg), None, gui.res.caution_sign) refresh() elif operation == "lvs": max_show = 20 msg = gui.res.string_logical_volume_included % (vg) if len(lv_list) == 0: msg += gui.res.string_do_not else: for i in range(0, min(len(lv_list),max_show)): if i > 0: msg += "," msg += lv_list[i] if i < len(lv_list) - 1: msg += (gui.res.string_other % (len(lv_list) - max_show)) dialogbox.messagebox.execute(msg)
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
def create_vg(): # ディスク選択 selected_disk = select_disk() if selected_disk == None: return logicalname = selected_disk[0] product = selected_disk[1] size = selected_disk[2] # VGの名前をユーザーに決めてもらう vgname = input_vg_name(logicalname) if vgname == None: return if dialogbox.messagebox.execute(gui.res.string_erase_msg % (size, product, logicalname,vgname), dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) != "ok": return try: with gui.progressbar.SyncedProgressBar(gui.res.string_disk_partition) as progressBar: s = system.getSystem() with s.openWbForInput("initialize_disk", [logicalname, vgname]) as initialize_disk: nbr = s.getNonblockingReader(initialize_disk.stdout) line = nbr.readline() while line != "": if line != None: (x, y) = (float(x) for x in line.rstrip().split('/')) progressBar.setProgress(x / y) progressBar.yieldFrame() line = nbr.readline() except Exception as e: traceback.print_exc(file=sys.stderr) wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_volume_fail % e.message, None, gui.res.caution_sign) return None refresh() wbui.play_sound("success") gui.messagebox.execute(gui.res.string_volume_success % (vgname)) return vgname
def select_disk(): disks = list_available_disks() if len(disks) == 0: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_disk_description, dialogbox.DialogBox.OK(), gui.res.caution_sign) return None # ディスク選択 options = [] disks_by_name = {} for disk in disks: logicalname = disk["logicalname"] product = disk["product"] size = disk["size"] options.append({"id":logicalname,"label":gui.res.string_lps % (logicalname, product, size)}) disks_by_name[logicalname] = [product, size] logicalname = gui.selectbox.execute(gui.res.string_volume_choice,options) if logicalname == None: return None product = disks_by_name[logicalname][0] size = disks_by_name[logicalname][1] return ("/dev/" + logicalname, product, size)
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
# メタデータを元に、コンフィギュレーションを行う 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 if not operate.start_domain(hostname): return False wbui.play_sound("success") dialogbox.messagebox.execute(gui.res.string_creation_completed) if configuration_messages != None: for msg in configuration_messages: dialogbox.messagebox.execute(msg) if metadata != None: instructions = metadata.findall("./instruction") if len(instructions) > 0: dialogbox.messagebox.execute(instructions[0].text) return True def determine_new_domain_name(dom_base_name):
def main(): clock = gui.getClock() screen = gui.getScreen() title = resource_loader.loadImage("title.png") title_background = resource_loader.loadImage(("title_background.jpg", "title_background.png"), screen) copyright = resource_loader.loadImage("copyright.png") for y in range(1,100,10): clock.tick(60) screen.blit(title_background, title_background.get_rect()) rotitle = pygame.transform.rotozoom(title, 0, y / 100.0) screen.blit(rotitle, (320 - rotitle.get_width() / 2,200 - rotitle.get_height() / 2)) pygame.display.flip() for y in range(0, 120, 10): clock.tick(60) screen.blit(title_background, title_background.get_rect()) screen.blit(title, (320 - title.get_width() / 2, 200 - title.get_height() / 2)) screen.blit(copyright, (400, 510 - y)) pygame.display.flip() # シリアルナンバー表示 s = system.getSystem() hostname_txt = pygamehelper.render_font_with_shadow(gui.res.font_splash_serialno, u"SERIAL#: %s" % (s.getHostname()), (255, 255, 255)) screen.blit(hostname_txt, (16, 430)) pygame.display.flip() oldbg = screen.copy() count = 0 start_msg = pygamehelper.render_font_with_shadow(gui.res.font_splash_message, gui.res.string_enter_key_start, (255, 255, 255)) while True: clock.tick(8) event = pygame.event.poll() if gui.isSelectEvent(event): break if count == 0: screen.blit(start_msg, (screen.get_width() / 2 - start_msg.get_width() / 2, screen.get_height() * 2 / 3 - start_msg.get_height() / 2)) pygame.display.update() elif count == 6: screen.blit(oldbg, (0,0)) pygame.display.update() count += 1 if count > 11: count = 0 wbui.play_sound("click") background = resource_loader.loadImage(("background.jpg", "background.png"), screen) for alpha in reversed(range(0,255,32)): clock.tick(60) screen.blit(background, background.get_rect()) oldbg.set_alpha(alpha) screen.blit(oldbg, oldbg.get_rect()) pygame.display.flip() try: desktop = gui.DesktopWindow(screen.get_size()) gui.setDesktop(desktop) for i in (1,2,3): if try_auth(): return True else: gui.messagebox.execute(gui.res.string_incorrect_pass, ["ok"], gui.res.color_dialog_negative) finally: gui.setDesktop(None) return False
# メタデータを元に、コンフィギュレーションを行う 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 if not operate.start_domain(hostname): return False wbui.play_sound("success") dialogbox.messagebox.execute(gui.res.string_creation_completed) if configuration_messages != None: for msg in configuration_messages: dialogbox.messagebox.execute(msg) if metadata != None: instructions = metadata.findall("./instruction") if len(instructions) > 0: dialogbox.messagebox.execute(instructions[0].text) return True def determine_new_domain_name(dom_base_name): domain.refresh()
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