Changeset 102872 in vbox for trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
- Timestamp:
- Jan 15, 2024 8:52:48 AM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r98103 r102872 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 # pylint: disable=too-many-lines 3 4 # $Id$ 4 5 … … 52 53 import traceback 53 54 import shlex 55 import tempfile 54 56 import time 55 57 import re 56 58 import platform 57 59 from optparse import OptionParser 58 from pprint import pprint59 60 60 61 … … 251 252 return colored(str(mbyte)+'M', 'red') 252 253 253 def createVm(ctx, name, kind): 254 def platformArchFromString(ctx, arch): 255 if arch == 'x86' \ 256 or arch == 'x86_64' \ 257 or arch == 'x64': 258 return ctx['global'].constants.PlatformArchitecture_x86 259 elif arch == 'arm' \ 260 or arch == 'aarch32' \ 261 or arch == 'aarch64': 262 return ctx['global'].constants.PlatformArchitecture_ARM 263 return ctx['global'].constants.PlatformArchitecture_None 264 265 def createVm(ctx, name, arch, kind): 254 266 vbox = ctx['vb'] 255 mach = vbox.createMachine("", name, [], kind, "") 267 enmArch = platformArchFromString(ctx, arch) 268 if enmArch == ctx['global'].constants.PlatformArchitecture_None: 269 print("wrong / invalid platform architecture specified!") 270 return 271 sFlags = '' 272 sCipher = '' ## @todo No encryption support here yet! 273 sPasswordID = '' 274 sPassword = '' 275 mach = vbox.createMachine("", name, enmArch, [], kind, sFlags, sCipher, sPasswordID, sPassword) 256 276 mach.saveSettings() 257 277 print("created machine with UUID", mach.id) … … 275 295 276 296 def startVm(ctx, mach, vmtype): 277 vbox = ctx['vb']278 297 perf = ctx['perf'] 279 298 session = ctx['global'].getSessionObject() … … 341 360 print(metric['name'], metric['values_as_string']) 342 361 343 def guestExec( ctx, machine,console, cmds):344 exec(cmds) 362 def guestExec(_ctx, _machine, _console, cmds): 363 exec(cmds) # pylint: disable=exec-used 345 364 346 365 def printMouseEvent(_ctx, mev): … … 412 431 except: 413 432 traceback.print_exc() 414 pass415 433 416 434 if active: … … 438 456 except: 439 457 traceback.print_exc() 440 pass 458 441 459 if listener and registered: 442 460 eventSource.unregisterListener(listener) … … 477 495 # we create an aggregated event source to listen for multiple event sources (keyboard and mouse in our case) 478 496 agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource]) 479 demo = open(filename, 'w' )497 demo = open(filename, 'w', encoding='utf-8') 480 498 header = "VM=" + console.machine.name + "\n" 481 499 demo.write(header) … … 495 513 except: 496 514 traceback.print_exc() 497 pass 515 498 516 demo.close() 499 517 if listener and registered: … … 502 520 503 521 def playbackDemo(ctx, console, filename, dur): 504 demo = open(filename, 'r' )522 demo = open(filename, 'r', encoding='utf-8') 505 523 506 524 if dur == -1: … … 554 572 except: 555 573 traceback.print_exc() 556 pass 574 557 575 demo.close() 558 576 559 560 def takeScreenshotOld(_ctx, console, args): 561 from PIL import Image 577 def takeScreenshot(ctx, console, args): 562 578 display = console.display 563 579 if len(args) > 0: 564 580 f = args[0] 565 581 else: 566 f = "/tmp/screenshot.png"582 f = os.path.join(tempfile.gettempdir(), "screenshot.png") 567 583 if len(args) > 3: 568 584 screen = int(args[3]) 569 585 else: 570 586 screen = 0 571 (fbw, fbh, _fbbpp, fbx, fby, _) = display.getScreenResolution(screen) 572 if len(args) > 1: 573 w = int(args[1]) 574 else: 575 w = fbw 576 if len(args) > 2: 577 h = int(args[2]) 578 else: 579 h = fbh 580 581 print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)) 582 data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_RGBA) 583 size = (w, h) 584 mode = "RGBA" 585 im = Image.frombuffer(mode, size, str(data), "raw", mode, 0, 1) 586 im.save(f, "PNG") 587 588 def takeScreenshot(_ctx, console, args): 589 display = console.display 590 if len(args) > 0: 591 f = args[0] 592 else: 593 f = "/tmp/screenshot.png" 594 if len(args) > 3: 595 screen = int(args[3]) 596 else: 597 screen = 0 598 (fbw, fbh, _fbbpp, fbx, fby, _) = display.getScreenResolution(screen) 587 (fbw, fbh, _fbbpp, _fbx, _fby, _) = display.getScreenResolution(screen) 599 588 if len(args) > 1: 600 589 w = int(args[1]) … … 638 627 def guestStats(ctx, console, args): 639 628 guest = console.guest 629 if not guest: 630 print("Guest is not in a running state") 631 return 640 632 # we need to set up guest statistics 641 633 if len(args) > 0 : … … 691 683 def ginfo(ctx, console, _args): 692 684 guest = console.guest 685 if not guest: 686 print("Guest is not in a running state") 687 return 693 688 if guest.additionsRunLevel != ctx['const'].AdditionsRunLevelType_None: 694 689 print("Additions active, version %s" % (guest.additionsVersion)) … … 715 710 session = None 716 711 try: 717 vbox = ctx['vb']718 712 session = ctx['global'].openMachineSession(mach, fPermitSharing=True) 719 713 except Exception as e: … … 830 824 return matches 831 825 def apply(self, cmd): 832 exec(cmd, {'obj':self.obj, 'node':self, 'ctx':self.getCtx()}, {}) 826 exec(cmd, {'obj':self.obj, 'node':self, 'ctx':self.getCtx()}, {}) # pylint: disable=exec-used 833 827 def getCtx(self): 834 828 if hasattr(self, 'ctx'): … … 874 868 def __init__(self, parent, mach): 875 869 XPathNodeHolder.__init__(self, parent, mach, 'nics', XPathNodeVM, 'nics') 876 self.maxNic = self.getCtx()['vb'].systemProperties.getMaxNetworkAdapters(self.obj.chipsetType)870 self.maxNic = mach.platform.properties.getMaxNetworkAdapters(mach.platform.chipsetType) 877 871 def enum(self): 878 872 children = [] … … 915 909 def argsToMach(ctx, args): 916 910 if len(args) < 2: 917 print("usage: %s [vmname|uuid]" % (args[0]))911 print("usage: %s <vmname|uuid>" % (args[0])) 918 912 return None 919 913 uuid = args[1] 920 914 mach = machById(ctx, uuid) 921 if mach == None:915 if not mach: 922 916 print("Machine '%s' is unknown, use list command to find available machines" % (uuid)) 923 917 return mach … … 973 967 def infoCmd(ctx, args): 974 968 if len(args) < 2: 975 print("usage: info [vmname|uuid]")976 return 0 977 mach = argsToMach(ctx, args) 978 if mach == None:969 print("usage: info <vmname|uuid>") 970 return 0 971 mach = argsToMach(ctx, args) 972 if not mach: 979 973 return 0 980 974 try: … … 987 981 print(" ID [n/a]: %s" % (mach.id)) 988 982 print(" OS Type [via OSTypeId]: %s" % (vmos.description if vmos is not None else mach.OSTypeId)) 989 print(" Firmware [firmwareType]: %s (%s)" % (asEnumElem(ctx, "FirmwareType", mach.firmware Type), mach.firmwareType))983 print(" Firmware [firmwareType]: %s (%s)" % (asEnumElem(ctx, "FirmwareType", mach.firmwareSettings.firmwareType), mach.firmwareSettings.firmwareType)) 990 984 print() 991 985 print(" CPUs [CPUCount]: %d" % (mach.CPUCount)) … … 993 987 print(" VRAM [VRAMSize]: %dM" % (mach.graphicsAdapter.VRAMSize)) 994 988 print(" Monitors [monitorCount]: %d" % (mach.graphicsAdapter.monitorCount)) 995 print(" Chipset [chipsetType]: %s (%s)" % (asEnumElem(ctx, "ChipsetType", mach. chipsetType), mach.chipsetType))989 print(" Chipset [chipsetType]: %s (%s)" % (asEnumElem(ctx, "ChipsetType", mach.platform.chipsetType), mach.platform.chipsetType)) 996 990 print() 997 991 print(" Clipboard mode [clipboardMode]: %s (%s)" % (asEnumElem(ctx, "ClipboardMode", mach.clipboardMode), mach.clipboardMode)) … … 1001 995 print(" Teleport target on port %d (%s)" % (mach.teleporterPort, mach.teleporterPassword)) 1002 996 print() 1003 bios = mach.BIOSSettings 1004 print(" ACPI [BIOSSettings.ACPIEnabled]: %s" % (asState(bios.ACPIEnabled))) 1005 print(" APIC [BIOSSettings.IOAPICEnabled]: %s" % (asState(bios.IOAPICEnabled))) 1006 hwVirtEnabled = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled) 1007 print(" Hardware virtualization [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_Enabled, value)]: " + asState(hwVirtEnabled)) 1008 hwVirtVPID = mach.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_VPID) 1009 print(" VPID support [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_VPID, value)]: " + asState(hwVirtVPID)) 1010 hwVirtNestedPaging = mach.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_NestedPaging) 1011 print(" Nested paging [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_NestedPaging, value)]: " + asState(hwVirtNestedPaging)) 997 print(" ACPI [BIOSSettings.ACPIEnabled]: %s" % (asState(mach.firmwareSettings.ACPIEnabled))) 998 print(" APIC [BIOSSettings.IOAPICEnabled]: %s" % (asState(mach.firmwareSettings.IOAPICEnabled))) 999 if mach.platform.architecture == ctx['global'].constants.PlatformArchitecture_x86: 1000 hwVirtEnabled = mach.platform.x86.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled) 1001 print(" Hardware virtualization [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_Enabled, value)]: " + asState(hwVirtEnabled)) 1002 hwVirtVPID = mach.platform.x86.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_VPID) 1003 print(" VPID support [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_VPID, value)]: " + asState(hwVirtVPID)) 1004 hwVirtNestedPaging = mach.platform.x86.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_NestedPaging) 1005 print(" Nested paging [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_NestedPaging, value)]: " + asState(hwVirtNestedPaging)) 1006 print(" HPET [HPETEnabled]: %s" % (asState(mach.platform.x86.HPETEnabled))) 1012 1007 1013 1008 print(" Hardware 3d acceleration [accelerate3DEnabled]: " + asState(mach.graphicsAdapter.accelerate3DEnabled)) 1014 1009 print(" Hardware 2d video acceleration [accelerate2DVideoEnabled]: " + asState(mach.graphicsAdapter.accelerate2DVideoEnabled)) 1015 1016 print(" Use universal time [RTCUseUTC]: %s" % (asState(mach.RTCUseUTC))) 1017 print(" HPET [HPETEnabled]: %s" % (asState(mach.HPETEnabled))) 1018 if mach.audioAdapter.enabled: 1019 print(" Audio [via audioAdapter]: chip %s; host driver %s" % (asEnumElem(ctx, "AudioControllerType", mach.audioAdapter.audioController), asEnumElem(ctx, "AudioDriverType", mach.audioAdapter.audioDriver))) 1010 print(" Use universal time [RTCUseUTC]: %s" % (asState(mach.platform.RTCUseUTC))) 1011 audioAdp = mach.audioSettings.adapter 1012 if audioAdp.enabled: 1013 print(" Audio [via audioAdapter]: chip %s; host driver %s" % (asEnumElem(ctx, "AudioControllerType", audioAdp.audioController), asEnumElem(ctx, "AudioDriverType", audioAdp.audioDriver))) 1020 1014 print(" CPU hotplugging [CPUHotPlugEnabled]: %s" % (asState(mach.CPUHotPlugEnabled))) 1021 1015 … … 1094 1088 def startCmd(ctx, args): 1095 1089 if len(args) < 2: 1096 print("usage: start name<frontend>")1097 return 0 1098 mach = argsToMach(ctx, args) 1099 if mach == None:1090 print("usage: start <vmname|uuid> <frontend>") 1091 return 0 1092 mach = argsToMach(ctx, args) 1093 if not mach: 1100 1094 return 0 1101 1095 if len(args) > 2: … … 1107 1101 1108 1102 def createVmCmd(ctx, args): 1109 if len(args) != 3:1110 print("usage: createvm name ostype")1103 if len(args) != 4: 1104 print("usage: createvm <name> <arch> <ostype>") 1111 1105 return 0 1112 1106 name = args[1] 1113 oskind = args[2] 1107 arch = args[2] 1108 oskind = args[3] 1114 1109 try: 1115 1110 ctx['vb'].getGuestOSType(oskind) … … 1117 1112 print('Unknown OS type:', oskind) 1118 1113 return 0 1119 createVm(ctx, name, oskind)1114 createVm(ctx, name, arch, oskind) 1120 1115 return 0 1121 1116 1122 1117 def ginfoCmd(ctx, args): 1123 1118 if len(args) < 2: 1124 print("usage: ginfo [vmname|uuid]")1125 return 0 1126 mach = argsToMach(ctx, args) 1127 if mach == None:1119 print("usage: ginfo <vmname|uuid>") 1120 return 0 1121 mach = argsToMach(ctx, args) 1122 if not mach: 1128 1123 return 0 1129 1124 cmdExistingVm(ctx, mach, 'ginfo', '') 1130 1125 return 0 1131 1126 1132 def execInGuest(ctx, console, args, env, user, passwd, tmo, inputPipe=None, outputPipe=None): 1127 def gstctlPrintOk(_ctx, string): 1128 return print(colored(string, 'green')) 1129 1130 def gstctlPrintErr(_ctx, string): 1131 return print(colored(string, 'red')) 1132 1133 def execInGuest(ctx, console, args, env, user, passwd, tmo, inputPipe=None, _outputPipe=None): 1133 1134 if len(args) < 1: 1134 1135 print("exec in guest needs at least program name") 1135 1136 return 1136 1137 guest = console.guest 1137 guestSession = guest.createSession(user, passwd, "", "vboxshell guest exec")1138 1138 # shall contain program name as argv[0] 1139 1139 gargs = args 1140 print("executing %s with args %s as %s" % (args[0], gargs, user)) 1141 flags = 0 1140 if g_fVerbose: 1141 gstctlPrintOk(ctx, "starting guest session for user '%s' (password '%s')" % (user, passwd)) 1142 else: 1143 gstctlPrintOk(ctx, ("starting guest session for user '%s' ..." % (user))) 1144 try: 1145 guestSession = guest.createSession(user, passwd, "", "vboxshell guest exec") 1146 guestSession.waitForArray([ ctx['global'].constants.GuestSessionWaitForFlag_Start ], 30 * 1000) 1147 except Exception as e: 1148 gstctlPrintErr(ctx, "starting guest session failed:") 1149 printErr(ctx, e) 1150 return 1 1151 if g_fVerbose: 1152 gstctlPrintOk(ctx, "guest session %d started" % guestSession.id) 1153 aProcCreateFlags = [ ctx['global'].constants.ProcessCreateFlag_WaitForStdOut, \ 1154 ctx['global'].constants.ProcessCreateFlag_WaitForStdErr ] 1142 1155 if inputPipe is not None: 1143 flags = 1 # set WaitForProcessStartOnly 1144 print(args[0]) 1145 process = guestSession.processCreate(args[0], gargs, env, [], tmo) 1146 print("executed with pid %d" % (process.PID)) 1147 if pid != 0: 1156 aProcCreateFlags.extend([ ctx['global'].constants.ProcessCreateFlag_WaitForStdIn ]) 1157 if g_fVerbose: 1158 gstctlPrintOk(ctx, "starting process '%s' with args '%s' as user '%s' (password '%s')" % (args[0], gargs, user, passwd)) 1159 process = guestSession.processCreate(args[0], gargs, '', env, aProcCreateFlags, tmo) 1160 try: 1161 waitResult = process.waitForArray([ ctx['global'].constants.ProcessWaitForFlag_Start ], 30 * 1000) 1162 except Exception as e: 1163 gstctlPrintErr(ctx, "waiting for guest process start failed:") 1164 printErr(ctx, e) 1165 return 1 1166 if waitResult != ctx['global'].constants.ProcessWaitResult_Start: 1167 gstctlPrintErr(ctx, "process start failed: got wait result %d, expected %d" \ 1168 % (waitResult, ctx['global'].constants.ProcessWaitResult_Start) ) 1169 return 1 1170 procStatus = process.status 1171 if procStatus != ctx['global'].constants.ProcessStatus_Started: 1172 gstctlPrintErr(ctx, "process start failed: got process status %d, expected %d" \ 1173 % (procStatus, ctx['global'].constants.ProcessStatus_Started) ) 1174 return 1 1175 if g_fVerbose: 1176 gstctlPrintOk(ctx, "process %d started" % (process.PID)) 1177 if process.PID != 0: 1148 1178 try: 1149 while True: 1150 if inputPipe is not None: 1179 fCompleted = False 1180 fReadStdOut = False 1181 fReadStdErr = False 1182 while not fCompleted: 1183 waitResult = process.waitForArray([ ctx['global'].constants.ProcessWaitForFlag_Terminate, \ 1184 ctx['global'].constants.ProcessWaitForFlag_StdOut, \ 1185 ctx['global'].constants.ProcessWaitForFlag_StdErr ], 1000) 1186 if waitResult == ctx['global'].constants.ProcessWaitResult_WaitFlagNotSupported: 1187 fReadStdOut = True 1188 fReadStdErr = True 1189 elif waitResult == ctx['global'].constants.ProcessWaitResult_Terminate: 1190 fCompleted = True 1191 break 1192 elif waitResult == ctx['global'].constants.ProcessWaitResult_Timeout: 1193 gstctlPrintErr(ctx, "timeout while waiting for process") 1194 break 1195 else: 1196 gstctlPrintErr(ctx, "got unhandled wait result %d" % (waitResult)) 1197 if inputPipe: 1151 1198 indata = inputPipe(ctx) 1152 1199 if indata is not None: … … 1154 1201 off = 0 1155 1202 while write > 0: 1156 w = guest.setProcessInput(pid,0, 10*1000, indata[off:])1203 w = process.write(0, 10*1000, indata[off:]) 1157 1204 off = off + w 1158 1205 write = write - w … … 1160 1207 # EOF 1161 1208 try: 1162 guest.setProcessInput(pid, 1, 10*1000, " ")1209 process.write(0, 10*1000, " ") 1163 1210 except: 1164 1211 pass 1165 data = guest.getProcessOutput(pid, 0, 10000, 4096) 1166 if data and len(data) > 0: 1167 sys.stdout.write(data) 1168 continue 1169 progress.waitForCompletion(100) 1212 if fReadStdOut: 1213 data = process.read(1, 64 * 1024, 10*1000) 1214 if data and len(data): 1215 sys.stdout.write(bytes(data).decode('utf-8')) 1216 fReadStdOut = False 1217 if fReadStdErr: 1218 data = process.read(2, 64 * 1024, 10*1000) 1219 if data and len(data): 1220 sys.stderr.write(bytes(data).decode('utf-8')) 1221 fReadStdErr = False 1170 1222 ctx['global'].waitForEvents(0) 1171 data = guest.getProcessOutput(pid, 0, 0, 4096) 1172 if data and len(data) > 0: 1173 if outputPipe is not None: 1174 outputPipe(ctx, data) 1175 else: 1176 sys.stdout.write(data) 1177 continue 1178 if progress.completed: 1179 break 1223 1224 if fCompleted: 1225 exitCode = process.exitCode 1226 if exitCode == 0: 1227 gstctlPrintOk(ctx, "process exit code: %d" % (exitCode)) 1228 else: 1229 gstctlPrintErr(ctx, "process exit code: %d" % (exitCode)) 1180 1230 1181 1231 except KeyboardInterrupt: 1182 1232 print("Interrupted.") 1183 1233 ctx['interrupt'] = True 1184 if progress.cancelable: 1185 progress.cancel() 1186 (_reason, code, _flags) = guest.getProcessStatus(pid) 1187 print("Exit code: %d" % (code)) 1188 return 0 1189 else: 1190 reportError(ctx, progress) 1234 1235 except Exception as e: 1236 printErr(ctx, e) 1237 1238 if guestSession: 1239 try: 1240 if g_fVerbose: 1241 gstctlPrintOk(ctx, "closing guest session ...") 1242 guestSession.close() 1243 except: 1244 printErr(ctx, e) 1245 1246 return 0 1247 1191 1248 1192 1249 def copyToGuest(ctx, console, args, user, passwd): … … 1199 1256 1200 1257 def nh_raw_input(prompt=""): 1201 stream = sys.stdout1202 prompt = str(prompt)1203 1258 if prompt: 1204 stream.write(prompt) 1259 sys.stdout.write(prompt) 1260 sys.stdout.flush() 1205 1261 line = sys.stdin.readline() 1206 1262 if not line: … … 1210 1266 return line 1211 1267 1212 1213 1268 def getCred(_ctx): 1214 1269 import getpass 1215 1270 user = getpass.getuser() 1216 user_inp = nh_raw_input("User (%s): " % (user)) 1271 if user: 1272 user_inp = nh_raw_input("User (%s): " % (user)) 1273 else: 1274 user_inp = nh_raw_input("User: ") 1217 1275 if len(user_inp) > 0: 1218 1276 user = user_inp … … 1223 1281 def gexecCmd(ctx, args): 1224 1282 if len(args) < 2: 1225 print("usage: gexec [vmname|uuid]command args")1226 return 0 1227 mach = argsToMach(ctx, args) 1228 if mach == None:1283 print("usage: gexec <vmname|uuid> command args") 1284 return 0 1285 mach = argsToMach(ctx, args) 1286 if not mach: 1229 1287 return 0 1230 1288 gargs = args[2:] … … 1237 1295 def gcopyCmd(ctx, args): 1238 1296 if len(args) < 2: 1239 print("usage: gcopy [vmname|uuid]host_path guest_path")1240 return 0 1241 mach = argsToMach(ctx, args) 1242 if mach == None:1297 print("usage: gcopy <vmname|uuid> host_path guest_path") 1298 return 0 1299 mach = argsToMach(ctx, args) 1300 if not mach: 1243 1301 return 0 1244 1302 gargs = args[2:] … … 1256 1314 def gpipeCmd(ctx, args): 1257 1315 if len(args) < 4: 1258 print("usage: gpipe [vmname|uuid]hostProgram guestProgram, such as gpipe linux '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'")1259 return 0 1260 mach = argsToMach(ctx, args) 1261 if mach == None:1316 print("usage: gpipe <vmname|uuid> hostProgram guestProgram, such as gpipe linux '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'") 1317 return 0 1318 mach = argsToMach(ctx, args) 1319 if not mach: 1262 1320 return 0 1263 1321 hcmd = args[2] … … 1280 1338 def removeVmCmd(ctx, args): 1281 1339 mach = argsToMach(ctx, args) 1282 if mach == None:1340 if not mach: 1283 1341 return 0 1284 1342 removeVm(ctx, mach) … … 1287 1345 def pauseCmd(ctx, args): 1288 1346 mach = argsToMach(ctx, args) 1289 if mach == None:1347 if not mach: 1290 1348 return 0 1291 1349 cmdExistingVm(ctx, mach, 'pause', '') … … 1294 1352 def powerdownCmd(ctx, args): 1295 1353 mach = argsToMach(ctx, args) 1296 if mach == None:1354 if not mach: 1297 1355 return 0 1298 1356 cmdExistingVm(ctx, mach, 'powerdown', '') … … 1301 1359 def powerbuttonCmd(ctx, args): 1302 1360 mach = argsToMach(ctx, args) 1303 if mach == None:1361 if not mach: 1304 1362 return 0 1305 1363 cmdExistingVm(ctx, mach, 'powerbutton', '') … … 1308 1366 def resumeCmd(ctx, args): 1309 1367 mach = argsToMach(ctx, args) 1310 if mach == None:1368 if not mach: 1311 1369 return 0 1312 1370 cmdExistingVm(ctx, mach, 'resume', '') … … 1315 1373 def saveCmd(ctx, args): 1316 1374 mach = argsToMach(ctx, args) 1317 if mach == None:1375 if not mach: 1318 1376 return 0 1319 1377 cmdExistingVm(ctx, mach, 'save', '') … … 1322 1380 def statsCmd(ctx, args): 1323 1381 mach = argsToMach(ctx, args) 1324 if mach == None:1382 if not mach: 1325 1383 return 0 1326 1384 cmdExistingVm(ctx, mach, 'stats', '') … … 1329 1387 def guestCmd(ctx, args): 1330 1388 if len(args) < 3: 1331 print("usage: guest namecommands")1332 return 0 1333 mach = argsToMach(ctx, args) 1334 if mach == None:1389 print("usage: guest <vmname|uuid> commands") 1390 return 0 1391 mach = argsToMach(ctx, args) 1392 if not mach: 1335 1393 return 0 1336 1394 if mach.state != ctx['const'].MachineState_Running: … … 1342 1400 def screenshotCmd(ctx, args): 1343 1401 if len(args) < 2: 1344 print("usage: screenshot vm<file> <width> <height> <monitor>")1345 return 0 1346 mach = argsToMach(ctx, args) 1347 if mach == None:1402 print("usage: screenshot <vmname|uuid> <file> <width> <height> <monitor>") 1403 return 0 1404 mach = argsToMach(ctx, args) 1405 if not mach: 1348 1406 return 0 1349 1407 cmdExistingVm(ctx, mach, 'screenshot', args[2:]) … … 1352 1410 def teleportCmd(ctx, args): 1353 1411 if len(args) < 3: 1354 print("usage: teleport namehost:port <password>")1355 return 0 1356 mach = argsToMach(ctx, args) 1357 if mach == None:1412 print("usage: teleport <vmname|uuid> host:port <password>") 1413 return 0 1414 mach = argsToMach(ctx, args) 1415 if not mach: 1358 1416 return 0 1359 1417 cmdExistingVm(ctx, mach, 'teleport', args[2:]) … … 1371 1429 def openportalCmd(ctx, args): 1372 1430 if len(args) < 3: 1373 print("usage: openportal nameport <password>")1374 return 0 1375 mach = argsToMach(ctx, args) 1376 if mach == None:1431 print("usage: openportal <vmname|uuid> port <password>") 1432 return 0 1433 mach = argsToMach(ctx, args) 1434 if not mach: 1377 1435 return 0 1378 1436 port = int(args[2]) … … 1388 1446 def closeportalCmd(ctx, args): 1389 1447 if len(args) < 2: 1390 print("usage: closeportal name")1391 return 0 1392 mach = argsToMach(ctx, args) 1393 if mach == None:1448 print("usage: closeportal <vmname|uuid>") 1449 return 0 1450 mach = argsToMach(ctx, args) 1451 if not mach: 1394 1452 return 0 1395 1453 if mach.teleporterEnabled: … … 1399 1457 def gueststatsCmd(ctx, args): 1400 1458 if len(args) < 2: 1401 print("usage: gueststats name<check interval>")1402 return 0 1403 mach = argsToMach(ctx, args) 1404 if mach == None:1459 print("usage: gueststats <vmname|uuid> <check interval>") 1460 return 0 1461 mach = argsToMach(ctx, args) 1462 if not mach: 1405 1463 return 0 1406 1464 cmdExistingVm(ctx, mach, 'gueststats', args[2:]) … … 1419 1477 def plugcpuCmd(ctx, args): 1420 1478 if len(args) < 2: 1421 print("usage: plugcpu name cpuid")1422 return 0 1423 mach = argsToMach(ctx, args) 1424 if mach == None:1479 print("usage: plugcpu <vmname|uuid> <cpuid>") 1480 return 0 1481 mach = argsToMach(ctx, args) 1482 if not mach: 1425 1483 return 0 1426 1484 if str(mach.sessionState) != str(ctx['const'].SessionState_Locked): … … 1433 1491 def unplugcpuCmd(ctx, args): 1434 1492 if len(args) < 2: 1435 print("usage: unplugcpu name cpuid")1436 return 0 1437 mach = argsToMach(ctx, args) 1438 if mach == None:1493 print("usage: unplugcpu <vmname|uuid> <cpuid>") 1494 return 0 1495 mach = argsToMach(ctx, args) 1496 if not mach: 1439 1497 return 0 1440 1498 if str(mach.sessionState) != str(ctx['const'].SessionState_Locked): … … 1448 1506 expr = 'mach.'+args[0]+' = '+args[1] 1449 1507 print("Executing", expr) 1450 exec(expr) 1508 exec(expr) # pylint: disable=exec-used 1451 1509 1452 1510 def setvarCmd(ctx, args): 1453 1511 if len(args) < 4: 1454 print("usage: setvar [vmname|uuid] expr value")1455 return 0 1456 mach = argsToMach(ctx, args) 1457 if mach == None:1512 print("usage: setvar <vmname|uuid> <expr> <value>") 1513 return 0 1514 mach = argsToMach(ctx, args) 1515 if not mach: 1458 1516 return 0 1459 1517 cmdClosedVm(ctx, mach, setvar, args[2:]) … … 1480 1538 1481 1539 mach = argsToMach(ctx, args) 1482 if mach == None:1540 if not mach: 1483 1541 return 0 1484 1542 cmdClosedVm(ctx, mach, setvmextra, [key, value]) … … 1516 1574 return 1 1517 1575 1518 def aliasCmd( ctx, args):1576 def aliasCmd(_ctx, args): 1519 1577 if len(args) == 3: 1520 1578 aliases[args[1]] = args[2] … … 1525 1583 return 0 1526 1584 1527 def verboseCmd( ctx, args):1585 def verboseCmd(_ctx, args): 1528 1586 global g_fVerbose 1529 1587 if len(args) > 1: … … 1533 1591 return 0 1534 1592 1535 def colorsCmd( ctx, args):1593 def colorsCmd(_ctx, args): 1536 1594 global g_fHasColors 1537 1595 if len(args) > 1: … … 1541 1599 return 0 1542 1600 1543 def hostCmd(ctx, args):1601 def hostCmd(ctx, _args): 1544 1602 vbox = ctx['vb'] 1545 1603 try: … … 1595 1653 def monitorGuestCmd(ctx, args): 1596 1654 if len(args) < 2: 1597 print("usage: monitorGuest name(duration)")1598 return 0 1599 mach = argsToMach(ctx, args) 1600 if mach == None:1655 print("usage: monitorGuest <vmname|uuid> (duration)") 1656 return 0 1657 mach = argsToMach(ctx, args) 1658 if not mach: 1601 1659 return 0 1602 1660 dur = 5 … … 1612 1670 return 0 1613 1671 mach = argsToMach(ctx, args) 1614 if mach == None:1672 if not mach: 1615 1673 return 0 1616 1674 dur = 5 … … 1626 1684 return 0 1627 1685 mach = argsToMach(ctx, args) 1628 if mach == None:1686 if not mach: 1629 1687 return 0 1630 1688 dur = 5 … … 1640 1698 return 0 1641 1699 mach = argsToMach(ctx, args) 1642 if mach == None:1700 if not mach: 1643 1701 return 0 1644 1702 dur = 5 … … 1680 1738 def portForwardCmd(ctx, args): 1681 1739 if len(args) != 5: 1682 print("usage: portForward <vm > <adapter> <hostPort> <guestPort>")1683 return 0 1684 mach = argsToMach(ctx, args) 1685 if mach == None:1740 print("usage: portForward <vmname|uuid> <adapter> <hostPort> <guestPort>") 1741 return 0 1742 mach = argsToMach(ctx, args) 1743 if not mach: 1686 1744 return 0 1687 1745 adapterNum = int(args[2]) … … 1711 1769 def showLogCmd(ctx, args): 1712 1770 if len(args) < 2: 1713 print("usage: showLog vm<num>")1714 return 0 1715 mach = argsToMach(ctx, args) 1716 if mach == None:1771 print("usage: showLog <vmname|uuid> <num>") 1772 return 0 1773 mach = argsToMach(ctx, args) 1774 if not mach: 1717 1775 return 0 1718 1776 … … 1734 1792 def findLogCmd(ctx, args): 1735 1793 if len(args) < 3: 1736 print("usage: findLog vm pattern<num>")1737 return 0 1738 mach = argsToMach(ctx, args) 1739 if mach == None:1794 print("usage: findLog <vmname|uuid> <pattern> <num>") 1795 return 0 1796 mach = argsToMach(ctx, args) 1797 if not mach: 1740 1798 return 0 1741 1799 … … 1765 1823 def findAssertCmd(ctx, args): 1766 1824 if len(args) < 2: 1767 print("usage: findAssert vm<num>")1768 return 0 1769 mach = argsToMach(ctx, args) 1770 if mach == None:1825 print("usage: findAssert <vmname|uuid> <num>") 1826 return 0 1827 mach = argsToMach(ctx, args) 1828 if not mach: 1771 1829 return 0 1772 1830 … … 1805 1863 expr = ' '.join(args[1:]) 1806 1864 try: 1807 exec(expr) 1865 exec(expr) # pylint: disable=exec-used 1808 1866 except Exception as e: 1809 1867 printErr(ctx, e) … … 1812 1870 return 0 1813 1871 1814 def reloadExtCmd(ctx, args):1872 def reloadExtCmd(ctx, _args): 1815 1873 # maybe will want more args smartness 1816 1874 checkUserExtensions(ctx, commands, getHomeFolder(ctx)) … … 1823 1881 return 0 1824 1882 try: 1825 lf = open(args[1], 'r' )1883 lf = open(args[1], 'r', encoding='utf-8') 1826 1884 except IOError as e: 1827 1885 print("cannot open:", args[1], ":", e) … … 1846 1904 return 0 1847 1905 1848 def sleepCmd( ctx, args):1906 def sleepCmd(_ctx, args): 1849 1907 if len(args) != 2: 1850 1908 print("usage: sleep <secs>") … … 1859 1917 1860 1918 1861 def shellCmd( ctx, args):1919 def shellCmd(_ctx, args): 1862 1920 if len(args) < 2: 1863 1921 print("usage: shell <commands>") … … 1926 1984 return 0 1927 1985 1928 def reconnectCmd(ctx, args):1986 def reconnectCmd(ctx, _args): 1929 1987 if ctx['wsinfo'] is None: 1930 1988 print("Never connected...") … … 2238 2296 print("created HDD at %s as %s" % (colPath(ctx,hdd.location), hdd.id)) 2239 2297 else: 2240 print("cannot create disk (file %s exist?)" % (loc))2241 reportError(ctx,progress)2242 return 02298 print("cannot create disk (file %s exist?)" % (loc)) 2299 reportError(ctx,progress) 2300 return 0 2243 2301 2244 2302 return 0 … … 2251 2309 vbox = ctx['vb'] 2252 2310 loc = args[1] 2253 setImageId = False2254 imageId = ""2255 setParentId = False2256 parentId = ""2257 2311 hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False) 2258 2312 print("registered HDD as %s" % (hdd.id)) 2259 2313 return 0 2260 2314 2261 def controldevice( ctx, mach, args):2315 def controldevice(_ctx, mach, args): 2262 2316 [ctr, port, slot, devtype, uuid] = args 2263 2317 mach.attachDevice(ctr, port, slot, devtype, uuid) … … 2265 2319 def attachHddCmd(ctx, args): 2266 2320 if len(args) < 3: 2267 print("usage: attachHdd vm hdd controller port:slot")2321 print("usage: attachHdd <vmname|uuid> <hdd> <controller> <port:slot>") 2268 2322 return 0 2269 2323 … … 2300 2354 def detachHddCmd(ctx, args): 2301 2355 if len(args) < 3: 2302 print("usage: detachHdd vm hdd")2356 print("usage: detachHdd <vmname|uuid> <hdd>") 2303 2357 return 0 2304 2358 … … 2383 2437 loc = args[1] 2384 2438 try: 2439 vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2440 except: 2441 print("no DVD with path %s registered" % (loc)) 2442 return 0 2443 2444 print("Unregistered ISO at %s" % (colPath(ctx, loc))) 2445 return 0 2446 2447 def removeIsoCmd(ctx, args): 2448 if len(args) != 2: 2449 print("usage: removeIso path") 2450 return 0 2451 2452 vbox = ctx['vb'] 2453 loc = args[1] 2454 try: 2385 2455 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2386 2456 except: … … 2388 2458 return 0 2389 2459 2390 progress = dvd.close() 2391 print("Unregistered ISO at %s" % (colPath(ctx, loc))) 2392 2393 return 0 2394 2395 def removeIsoCmd(ctx, args): 2396 if len(args) != 2: 2397 print("usage: removeIso path") 2398 return 0 2399 2460 progress = dvd.deleteStorage() 2461 if progressBar(ctx, progress): 2462 print("Removed ISO at %s" % (colPath(ctx, dvd.location))) 2463 else: 2464 reportError(ctx, progress) 2465 return 0 2466 2467 def attachIsoCmd(ctx, args): 2468 if len(args) < 3: 2469 print("usage: attachIso <vmname|uuid> <iso> <controller> <port:slot>") 2470 return 0 2471 2472 mach = argsToMach(ctx, args) 2473 if mach is None: 2474 return 0 2400 2475 vbox = ctx['vb'] 2401 loc = args[ 1]2476 loc = args[2] 2402 2477 try: 2403 2478 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) … … 2405 2480 print("no DVD with path %s registered" % (loc)) 2406 2481 return 0 2407 2408 progress = dvd.deleteStorage()2409 if progressBar(ctx, progress):2410 print("Removed ISO at %s" % (colPath(ctx, dvd.location)))2411 else:2412 reportError(ctx, progress)2413 return 0 2414 2415 def attachIsoCmd(ctx, args):2482 if len(args) > 3: 2483 ctr = args[3] 2484 (port, slot) = args[4].split(":") 2485 else: 2486 [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_DVD) 2487 cmdClosedVm(ctx, mach, lambda ctx, mach, args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_DVD, dvd)) 2488 return 0 2489 2490 def detachIsoCmd(ctx, args): 2416 2491 if len(args) < 3: 2417 print("usage: attachIso vm iso controller port:slot")2492 print("usage: detachIso <vmname|uuid> <iso>") 2418 2493 return 0 2419 2494 … … 2428 2503 print("no DVD with path %s registered" % (loc)) 2429 2504 return 0 2505 2506 detachMedium(ctx, mach.id, dvd) 2507 return 0 2508 2509 def mountIsoCmd(ctx, args): 2510 if len(args) < 3: 2511 print("usage: mountIso <vmname|uuid> <iso> <controller> <port:slot>") 2512 return 0 2513 2514 mach = argsToMach(ctx, args) 2515 if mach is None: 2516 return 0 2517 vbox = ctx['vb'] 2518 loc = args[2] 2519 try: 2520 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2521 except: 2522 print("no DVD with path %s registered" % (loc)) 2523 return 0 2524 2430 2525 if len(args) > 3: 2431 2526 ctr = args[3] 2432 2527 (port, slot) = args[4].split(":") 2433 2528 else: 2434 [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_DVD)2435 cmdClosedVm(ctx, mach, lambda ctx, mach, args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_DVD, dvd))2436 return 02437 2438 def detachIsoCmd(ctx, args):2439 if len(args) < 3:2440 print("usage: detachIso vm iso")2441 return 02442 2443 mach = argsToMach(ctx, args)2444 if mach is None:2445 return 02446 vbox = ctx['vb']2447 loc = args[2]2448 try:2449 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)2450 except:2451 print("no DVD with path %s registered" % (loc))2452 return 02453 2454 detachMedium(ctx, mach.id, dvd)2455 return 02456 2457 def mountIsoCmd(ctx, args):2458 if len(args) < 3:2459 print("usage: mountIso vm iso controller port:slot")2460 return 02461 2462 mach = argsToMach(ctx, args)2463 if mach is None:2464 return 02465 vbox = ctx['vb']2466 loc = args[2]2467 try:2468 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)2469 except:2470 print("no DVD with path %s registered" % (loc))2471 return 02472 2473 if len(args) > 3:2474 ctr = args[3]2475 (port, slot) = args[4].split(":")2476 else:2477 2529 # autodetect controller and location, just find first controller with media == DVD 2478 2530 [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_DVD) … … 2484 2536 def unmountIsoCmd(ctx, args): 2485 2537 if len(args) < 2: 2486 print("usage: unmountIso vm controller port:slot")2538 print("usage: unmountIso <vmname|uuid> <controller> <port:slot>") 2487 2539 return 0 2488 2540 … … 2490 2542 if mach is None: 2491 2543 return 0 2492 vbox = ctx['vb']2493 2544 2494 2545 if len(args) > 3: … … 2503 2554 return 0 2504 2555 2505 def attachCtr( ctx, mach, args):2556 def attachCtr(_ctx, mach, args): 2506 2557 [name, bus, ctrltype] = args 2507 2558 ctr = mach.addStorageController(name, bus) … … 2511 2562 def attachCtrCmd(ctx, args): 2512 2563 if len(args) < 4: 2513 print("usage: attachCtr vm cname bus<type>")2564 print("usage: attachCtr <vmname|uuid> <controller name> <bus> <type>") 2514 2565 return 0 2515 2566 … … 2535 2586 def detachCtrCmd(ctx, args): 2536 2587 if len(args) < 3: 2537 print("usage: detachCtr vm name")2588 print("usage: detachCtr <vmname|uuid> <controller name>") 2538 2589 return 0 2539 2590 … … 2545 2596 return 0 2546 2597 2547 def usbctr( ctx,mach, console, args):2598 def usbctr(_ctx, _mach, console, args): 2548 2599 if args[0]: 2549 2600 console.attachUSBDevice(args[1], "") … … 2553 2604 def attachUsbCmd(ctx, args): 2554 2605 if len(args) < 3: 2555 print("usage: attachUsb vm deviceuid")2606 print("usage: attachUsb <vmname|uuid> <device uid>") 2556 2607 return 0 2557 2608 … … 2565 2616 def detachUsbCmd(ctx, args): 2566 2617 if len(args) < 3: 2567 print("usage: detachUsb vm deviceuid")2618 print("usage: detachUsb <vmname|uuid> <device uid>") 2568 2619 return 0 2569 2620 … … 2593 2644 def shareFolderCmd(ctx, args): 2594 2645 if len(args) < 4: 2595 print("usage: shareFolder vm path name <writable> <persistent>")2646 print("usage: shareFolder <vmname|uuid> <path> <name> <writable|persistent>") 2596 2647 return 0 2597 2648 … … 2617 2668 def unshareFolderCmd(ctx, args): 2618 2669 if len(args) < 3: 2619 print("usage: unshareFolder vm name")2670 print("usage: unshareFolder <vmname|uuid> <name>") 2620 2671 return 0 2621 2672 … … 2637 2688 def snapshotCmd(ctx, args): 2638 2689 if (len(args) < 2 or args[1] == 'help'): 2639 print("Take snapshot: snapshot vm take name<description>")2640 print("Restore snapshot: snapshot vm restore name")2641 print("Merge snapshot: snapshot vm merge name")2690 print("Take snapshot: snapshot <vmname|uuid> take <name> <description>") 2691 print("Restore snapshot: snapshot <vmname|uuid> restore <name>") 2692 print("Merge snapshot: snapshot <vmname|uuid> merge <name>") 2642 2693 return 0 2643 2694 … … 2648 2699 if cmd == 'take': 2649 2700 if len(args) < 4: 2650 print("usage: snapshot vm take name<description>")2701 print("usage: snapshot <vmname|uuid> take <name> <description>") 2651 2702 return 0 2652 2703 name = args[3] … … 2660 2711 if cmd == 'restore': 2661 2712 if len(args) < 4: 2662 print("usage: snapshot vm restore name")2713 print("usage: snapshot <vmname|uuid> restore <name>") 2663 2714 return 0 2664 2715 name = args[3] … … 2669 2720 if cmd == 'restorecurrent': 2670 2721 if len(args) < 4: 2671 print("usage: snapshot vmrestorecurrent")2722 print("usage: snapshot <vmname|uuid> restorecurrent") 2672 2723 return 0 2673 2724 snap = mach.currentSnapshot() … … 2677 2728 if cmd == 'delete': 2678 2729 if len(args) < 4: 2679 print("usage: snapshot vm delete name")2730 print("usage: snapshot <vmname|uuid> delete <name>") 2680 2731 return 0 2681 2732 name = args[3] … … 2687 2738 return 0 2688 2739 2689 def natAlias( ctx, mach,nicnum, nat, args=[]):2740 def natAlias(_ctx, _mach, _nicnum, nat, args=[]): 2690 2741 """This command shows/alters NAT's alias settings. 2691 usage: nat <vm > <nicnum> alias [default|[log] [proxyonly] [sameports]]2742 usage: nat <vmname|uuid> <nicnum> alias [default|[log] [proxyonly] [sameports]] 2692 2743 default - set settings to default values 2693 2744 log - switch on alias logging … … 2724 2775 return (0, None) 2725 2776 2726 def natSettings( ctx, mach,nicnum, nat, args):2777 def natSettings(_ctx, _mach, _nicnum, nat, args): 2727 2778 """This command shows/alters NAT settings. 2728 usage: nat <vm > <nicnum> settings [<mtu> [[<socsndbuf> <sockrcvbuf> [<tcpsndwnd> <tcprcvwnd>]]]]2779 usage: nat <vmname|uuid> <nicnum> settings [<mtu> [[<socsndbuf> <sockrcvbuf> [<tcpsndwnd> <tcprcvwnd>]]]] 2729 2780 mtu - set mtu <= 16000 2730 2781 socksndbuf/sockrcvbuf - sets amount of kb for socket sending/receiving buffer … … 2758 2809 return (0, None) 2759 2810 2760 def natDns( ctx, mach,nicnum, nat, args):2811 def natDns(_ctx, _mach, _nicnum, nat, args): 2761 2812 """This command shows/alters DNS's NAT settings 2762 usage: nat <vm > <nicnum> dns [passdomain] [proxy] [usehostresolver]2813 usage: nat <vmname|uuid> <nicnum> dns [passdomain] [proxy] [usehostresolver] 2763 2814 passdomain - enforces builtin DHCP server to pass domain 2764 2815 proxy - switch on builtin NAT DNS proxying mechanism … … 2777 2828 def natTftp(ctx, mach, nicnum, nat, args): 2778 2829 """This command shows/alters TFTP settings 2779 usage nat <vm > <nicnum> tftp [prefix <prefix>| bootfile <bootfile>| server <server>]2830 usage nat <vmname|uuid> <nicnum> tftp [prefix <prefix>| bootfile <bootfile>| server <server>] 2780 2831 prefix - alters prefix TFTP settings 2781 2832 bootfile - alters bootfile TFTP settings … … 2788 2839 if server is None: 2789 2840 server = '10.0.%d/24' % (int(nicnum) + 2) 2790 (server, mask) = server.split('/')2841 (server, _mask) = server.split('/') 2791 2842 while server.count('.') != 3: 2792 2843 server += '.0' 2793 (a, b, c, d) = server.split('.')2844 (a, b, c, _d) = server.split('.') 2794 2845 server = '%d.%d.%d.4' % (a, b, c) 2795 2846 prefix = nat.TFTPPrefix … … 2816 2867 return (0, None) 2817 2868 2818 def natPortForwarding(ctx, mach,nicnum, nat, args):2869 def natPortForwarding(ctx, _mach, _nicnum, nat, args): 2819 2870 """This command shows/manages port-forwarding settings 2820 2871 usage: 2821 nat <vm > <nicnum> <pf> [ simple tcp|udp <hostport> <guestport>]2872 nat <vmname|uuid> <nicnum> <pf> [ simple tcp|udp <hostport> <guestport>] 2822 2873 |[no_name tcp|udp <hostip> <hostport> <guestip> <guestport>] 2823 2874 |[ex tcp|udp <pf-name> <hostip> <hostport> <guestip> <guestport>] … … 2859 2910 return (1, None) 2860 2911 2861 a = pfcmd[args[1]]['func']()2912 _a = pfcmd[args[1]]['func']() 2862 2913 return (0, None) 2863 2914 2864 def natNetwork( ctx,mach, nicnum, nat, args):2915 def natNetwork(_ctx, _mach, nicnum, nat, args): 2865 2916 """This command shows/alters NAT network settings 2866 usage: nat <vm > <nicnum> network [<network>]2917 usage: nat <vmname|uuid> <nicnum> network [<network>] 2867 2918 """ 2868 2919 if len(args) == 1: … … 2882 2933 def natCmd(ctx, args): 2883 2934 """This command is entry point to NAT settins management 2884 usage: nat <vm > <nicnum> <cmd> <cmd-args>2935 usage: nat <vmname|uuid> <nicnum> <cmd> <cmd-args> 2885 2936 cmd - [alias|settings|tftp|dns|pf|network] 2886 2937 for more information about commands: … … 2906 2957 print(natCmd.__doc__) 2907 2958 return 0 2908 mach = ctx['argsToMach'](args)2909 if mach == None:2959 mach = argsToMach(ctx, args) 2960 if not mach: 2910 2961 print("please specify vm") 2911 2962 return 0 2912 if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in list(range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType))): 2913 print('please specify adapter num %d isn\'t in range [0-%d]' % (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType))) 2963 platformProps = mach.platform.properties 2964 if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in list(range(0, platformProps.getMaxNetworkAdapters(mach.platform.chipsetType))): 2965 print('please specify adapter num %d isn\'t in range [0-%d]' % (args[2], platformProps.getMaxNetworkAdapters(mach.platform.chipsetType))) 2914 2966 return 0 2915 2967 nicnum = int(args[2]) … … 2954 3006 return (0, None) 2955 3007 2956 def nicTraceSubCmd( ctx, vm,nicnum, adapter, args):3008 def nicTraceSubCmd(_ctx, _vm, _nicnum, adapter, args): 2957 3009 ''' 2958 usage: nic <vm > <nicnum> trace [on|off [file]]3010 usage: nic <vmname|uuid> <nicnum> trace [on|off [file]] 2959 3011 ''' 2960 3012 (rc, r) = nicSwitchOnOff(adapter, 'traceEnabled', args) … … 2966 3018 return (0, None) 2967 3019 2968 def nicLineSpeedSubCmd( ctx, vm,nicnum, adapter, args):3020 def nicLineSpeedSubCmd(_ctx, _vm, _nicnum, adapter, args): 2969 3021 if len(args) == 1: 2970 3022 r = '%d kbps'% (adapter.lineSpeed) … … 2977 3029 return (0, None) 2978 3030 2979 def nicCableSubCmd( ctx, vm,nicnum, adapter, args):3031 def nicCableSubCmd(_ctx, _vm, _nicnum, adapter, args): 2980 3032 ''' 2981 usage: nic <vm > <nicnum> cable [on|off]3033 usage: nic <vmname|uuid> <nicnum> cable [on|off] 2982 3034 ''' 2983 3035 return nicSwitchOnOff(adapter, 'cableConnected', args) 2984 3036 2985 def nicEnableSubCmd( ctx, vm,nicnum, adapter, args):3037 def nicEnableSubCmd(_ctx, _vm, _nicnum, adapter, args): 2986 3038 ''' 2987 usage: nic <vm > <nicnum> enable [on|off]3039 usage: nic <vmname|uuid> <nicnum> enable [on|off] 2988 3040 ''' 2989 3041 return nicSwitchOnOff(adapter, 'enabled', args) 2990 3042 2991 def nicTypeSubCmd(ctx, vm,nicnum, adapter, args):3043 def nicTypeSubCmd(ctx, _vm, _nicnum, adapter, args): 2992 3044 ''' 2993 usage: nic <vm > <nicnum> type [Am79c970A|Am79c970A|I82540EM|I82545EM|I82543GC|Virtio]3045 usage: nic <vmname|uuid> <nicnum> type [Am79c970A|Am79c970A|I82540EM|I82545EM|I82543GC|Virtio] 2994 3046 ''' 2995 3047 if len(args) == 1: … … 3007 3059 return (0, None) 3008 3060 3009 def nicAttachmentSubCmd(ctx, vm,nicnum, adapter, args):3061 def nicAttachmentSubCmd(ctx, _vm, _nicnum, adapter, args): 3010 3062 ''' 3011 usage: nic <vm > <nicnum> attachment [Null|NAT|Bridged <interface>|Internal <name>|HostOnly <interface>3063 usage: nic <vmname|uuid> <nicnum> attachment [Null|NAT|Bridged <interface>|Internal <name>|HostOnly <interface> 3012 3064 ''' 3013 3065 if len(args) == 1: … … 3068 3120 ''' 3069 3121 This command to manage network adapters 3070 usage: nic <vm > <nicnum> <cmd> <cmd-args>3122 usage: nic <vmname|uuid> <nicnum> <cmd> <cmd-args> 3071 3123 where cmd : attachment, trace, linespeed, cable, enable, type 3072 3124 ''' … … 3095 3147 return 0 3096 3148 3149 platformProps = vm.platform.properties 3097 3150 if len(args) < 3 \ 3098 or int(args[2]) not in list(range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType))):3099 print('please specify adapter num %d isn\'t in range [0-%d]'% (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType)))3151 or int(args[2]) not in list(range(0, platformProps.getMaxNetworkAdapters(vm.platform.chipsetType))): 3152 print('please specify adapter num %d isn\'t in range [0-%d]'% (args[2], platformProps.getMaxNetworkAdapters(vm.platform.chipsetType))) 3100 3153 return 0 3101 3154 nicnum = int(args[2]) … … 3152 3205 def recordDemoCmd(ctx, args): 3153 3206 if len(args) < 3: 3154 print("usage: recordDemo vm filename (duration)")3155 return 0 3156 mach = argsToMach(ctx, args) 3157 if mach == None:3207 print("usage: recordDemo <vmname|uuid> <filename> [duration in s]") 3208 return 0 3209 mach = argsToMach(ctx, args) 3210 if not mach: 3158 3211 return 0 3159 3212 filename = args[2] … … 3166 3219 def playbackDemoCmd(ctx, args): 3167 3220 if len(args) < 3: 3168 print("usage: playbackDemo vm filename (duration)")3169 return 0 3170 mach = argsToMach(ctx, args) 3171 if mach == None:3221 print("usage: playbackDemo <vmname|uuid> <filename> [duration in s]") 3222 return 0 3223 mach = argsToMach(ctx, args) 3224 if not mach: 3172 3225 return 0 3173 3226 filename = args[2] … … 3210 3263 return 0 3211 3264 mach = argsToMach(ctx, args) 3212 if mach == None:3265 if not mach: 3213 3266 return 0 3214 3267 cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx, mach, console, args: lspci(ctx, console)]) … … 3217 3270 def attachpciCmd(ctx, args): 3218 3271 if len(args) < 3: 3219 print("usage: attachpci vm hostpci <guestpci>")3220 return 0 3221 mach = argsToMach(ctx, args) 3222 if mach == None:3272 print("usage: attachpci <vmname|uuid> <host pci address> <guest pci address>") 3273 return 0 3274 mach = argsToMach(ctx, args) 3275 if not mach: 3223 3276 return 0 3224 3277 hostaddr = parsePci(args[2]) … … 3239 3292 def detachpciCmd(ctx, args): 3240 3293 if len(args) < 3: 3241 print("usage: detachpci vm hostpci")3242 return 0 3243 mach = argsToMach(ctx, args) 3244 if mach == None:3294 print("usage: detachpci <vmname|uuid> <host pci address>") 3295 return 0 3296 mach = argsToMach(ctx, args) 3297 if not mach: 3245 3298 return 0 3246 3299 hostaddr = parsePci(args[2]) … … 3273 3326 3274 3327 commands = {'help':['Prints help information', helpCmd, 0], 3275 'start':['Start virtual machine by name or uuid: start Linuxheadless', startCmd, 0],3276 'createVm':['Create virtual machine: createVm m acvmMacOS', createVmCmd, 0],3328 'start':['Start virtual machine by name or uuid: start mytestvm headless', startCmd, 0], 3329 'createVm':['Create virtual machine: createVm myvmname x86 MacOS', createVmCmd, 0], 3277 3330 'removeVm':['Remove virtual machine', removeVmCmd, 0], 3278 3331 'pause':['Pause virtual machine', pauseCmd, 0], … … 3290 3343 'alias':['Control aliases', aliasCmd, 0], 3291 3344 'verbose':['Toggle verbosity', verboseCmd, 0], 3292 'setvar':['Set VM s variable: setvar Fedora BIOSSettings.ACPIEnabled True', setvarCmd, 0],3345 'setvar':['Set VM variable: setvar mytestvm firmwareSettings.ACPIEnabled True', setvarCmd, 0], 3293 3346 'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print(m.name, "has", m.memorySize, "M")\'', evalCmd, 0], 3294 3347 'quit':['Exits', quitCmd, 0], 3295 3348 'host':['Show host information', hostCmd, 0], 3296 'guest':['Execute command for guest: guest Win32\'console.mouse.putMouseEvent(20, 20, 0, 0, 0)\'', guestCmd, 0],3297 'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win3210', monitorGuestCmd, 0],3298 'monitorGuestKbd':['Monitor guest keyboard for some time: monitorGuestKbd Win3210', monitorGuestKbdCmd, 0],3299 'monitorGuestMouse':['Monitor guest mouse for some time: monitorGuestMouse Win3210', monitorGuestMouseCmd, 0],3300 'monitorGuestMultiTouch':['Monitor guest touch screen for some time: monitorGuestMultiTouch Win3210', monitorGuestMultiTouchCmd, 0],3349 'guest':['Execute command for guest: guest mytestvm \'console.mouse.putMouseEvent(20, 20, 0, 0, 0)\'', guestCmd, 0], 3350 'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest mytestvm 10', monitorGuestCmd, 0], 3351 'monitorGuestKbd':['Monitor guest keyboard for some time: monitorGuestKbd mytestvm 10', monitorGuestKbdCmd, 0], 3352 'monitorGuestMouse':['Monitor guest mouse for some time: monitorGuestMouse mytestvm 10', monitorGuestMouseCmd, 0], 3353 'monitorGuestMultiTouch':['Monitor guest touch screen for some time: monitorGuestMultiTouch mytestvm 10', monitorGuestMultiTouchCmd, 0], 3301 3354 'monitorVBox':['Monitor what happens with VirtualBox for some time: monitorVBox 10', monitorVBoxCmd, 0], 3302 'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward Win320 8080 80', portForwardCmd, 0],3303 'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0],3304 'findLog':['Show entries matching pattern in log file of the VM, : findLog Win32PDM|CPUM', findLogCmd, 0],3305 'findAssert':['Find assert in log file of the VM, : findAssert Win32', findAssertCmd, 0],3355 'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward mytestvm 0 8080 80', portForwardCmd, 0], 3356 'showLog':['Show log file of the VM, : showLog mytestvm', showLogCmd, 0], 3357 'findLog':['Show entries matching pattern in log file of the VM, : findLog mytestvm PDM|CPUM', findLogCmd, 0], 3358 'findAssert':['Find assert in log file of the VM, : findAssert mytestvm', findAssertCmd, 0], 3306 3359 'reloadExt':['Reload custom extensions: reloadExt', reloadExtCmd, 0], 3307 3360 'runScript':['Run VBox script: runScript script.vbox', runScriptCmd, 0], 3308 3361 'sleep':['Sleep for specified number of seconds: sleep 3.14159', sleepCmd, 0], 3309 3362 'shell':['Execute external shell command: shell "ls /etc/rc*"', shellCmd, 0], 3310 'exportVm':['Export VM in OVF format: exportVm Win/tmp/win.ovf', exportVMCmd, 0],3311 'screenshot':['Take VM screenshot to a file: screenshot Win/tmp/win.png 1024 768 0', screenshotCmd, 0],3312 'teleport':['Teleport VM to another box (see openportal): teleport Winanotherhost:8000 <passwd> <maxDowntime>', teleportCmd, 0],3363 'exportVm':['Export VM in OVF format: exportVm mytestvm /tmp/win.ovf', exportVMCmd, 0], 3364 'screenshot':['Take VM screenshot to a file: screenshot mytestvm /tmp/win.png 1024 768 0', screenshotCmd, 0], 3365 'teleport':['Teleport VM to another box (see openportal): teleport mytestvm anotherhost:8000 <passwd> <maxDowntime>', teleportCmd, 0], 3313 3366 'typeGuest':['Type arbitrary text in guest: typeGuest Linux "^lls\\n&UP;&BKSP;ess /etc/hosts\\nq^c" 0.7', typeGuestCmd, 0], 3314 'openportal':['Open portal for teleportation of VM from another box (see teleport): openportal Win8000 <passwd>', openportalCmd, 0],3367 'openportal':['Open portal for teleportation of VM from another box (see teleport): openportal mytestvm 8000 <passwd>', openportalCmd, 0], 3315 3368 'closeportal':['Close teleportation portal (see openportal, teleport): closeportal Win', closeportalCmd, 0], 3316 3369 'getextra':['Get extra data, empty key lists all: getextra <vm|global> <key>', getExtraDataCmd, 0], 3317 3370 'setextra':['Set extra data, empty value removes key: setextra <vm|global> <key> <value>', setExtraDataCmd, 0], 3318 'gueststats':['Print available guest stats (only Windows guests with additions so far): gueststats Win32', gueststatsCmd, 0],3319 'plugcpu':['Add a CPU to a running VM: plugcpu Win1', plugcpuCmd, 0],3371 'gueststats':['Print available guest stats (only Windows guests with additions so far): gueststats mytestvm', gueststatsCmd, 0], 3372 'plugcpu':['Add a CPU to a running VM: plugcpu mytestvm 1', plugcpuCmd, 0], 3320 3373 'unplugcpu':['Remove a CPU from a running VM (additions required, Windows cannot unplug): unplugcpu Linux 1', unplugcpuCmd, 0], 3321 3374 'createHdd': ['Create virtual HDD: createHdd 1000 /disk.vdi ', createHddCmd, 0], … … 3323 3376 'registerHdd': ['Register HDD image with VirtualBox instance: registerHdd /disk.vdi', registerHddCmd, 0], 3324 3377 'unregisterHdd': ['Unregister HDD image with VirtualBox instance: unregisterHdd /disk.vdi', unregisterHddCmd, 0], 3325 'attachHdd': ['Attach HDD to the VM: attachHdd win/disk.vdi "IDE Controller" 0:1', attachHddCmd, 0],3326 'detachHdd': ['Detach HDD from the VM: detachHdd win/disk.vdi', detachHddCmd, 0],3378 'attachHdd': ['Attach HDD to the VM: attachHdd mytestvm /disk.vdi "IDE Controller" 0:1', attachHddCmd, 0], 3379 'detachHdd': ['Detach HDD from the VM: detachHdd mytestvm /disk.vdi', detachHddCmd, 0], 3327 3380 'registerIso': ['Register CD/DVD image with VirtualBox instance: registerIso /os.iso', registerIsoCmd, 0], 3328 3381 'unregisterIso': ['Unregister CD/DVD image with VirtualBox instance: unregisterIso /os.iso', unregisterIsoCmd, 0], 3329 3382 'removeIso': ['Permanently remove CD/DVD image: removeIso /os.iso', removeIsoCmd, 0], 3330 'attachIso': ['Attach CD/DVD to the VM: attachIso win/os.iso "IDE Controller" 0:1', attachIsoCmd, 0],3331 'detachIso': ['Detach CD/DVD from the VM: detachIso win/os.iso', detachIsoCmd, 0],3332 'mountIso': ['Mount CD/DVD to the running VM: mountIso win/os.iso "IDE Controller" 0:1', mountIsoCmd, 0],3333 'unmountIso': ['Unmount CD/DVD from running VM: unmountIso win"IDE Controller" 0:1', unmountIsoCmd, 0],3334 'attachCtr': ['Attach storage controller to the VM: attachCtr winCtr0 IDE ICH6', attachCtrCmd, 0],3335 'detachCtr': ['Detach HDD from the VM: detachCtr winCtr0', detachCtrCmd, 0],3336 'attachUsb': ['Attach USB device to the VM (use listUsb to show available devices): attachUsb winuuid', attachUsbCmd, 0],3337 'detachUsb': ['Detach USB device from the VM: detachUsb winuuid', detachUsbCmd, 0],3383 'attachIso': ['Attach CD/DVD to the VM: attachIso mytestvm /os.iso "IDE Controller" 0:1', attachIsoCmd, 0], 3384 'detachIso': ['Detach CD/DVD from the VM: detachIso mytestvm /os.iso', detachIsoCmd, 0], 3385 'mountIso': ['Mount CD/DVD to the running VM: mountIso mytestvm /os.iso "IDE Controller" 0:1', mountIsoCmd, 0], 3386 'unmountIso': ['Unmount CD/DVD from running VM: unmountIso mytestvm "IDE Controller" 0:1', unmountIsoCmd, 0], 3387 'attachCtr': ['Attach storage controller to the VM: attachCtr mytestvm Ctr0 IDE ICH6', attachCtrCmd, 0], 3388 'detachCtr': ['Detach HDD from the VM: detachCtr mytestvm Ctr0', detachCtrCmd, 0], 3389 'attachUsb': ['Attach USB device to the VM (use listUsb to show available devices): attachUsb mytestvm uuid', attachUsbCmd, 0], 3390 'detachUsb': ['Detach USB device from the VM: detachUsb mytestvm uuid', detachUsbCmd, 0], 3338 3391 'listMedia': ['List media known to this VBox instance', listMediaCmd, 0], 3339 3392 'listUsb': ['List known USB devices', listUsbCmd, 0], 3340 'shareFolder': ['Make host\'s folder visible to guest: shareFolder win/share share writable', shareFolderCmd, 0],3393 'shareFolder': ['Make host\'s folder visible to guest: shareFolder mytestvm /share share writable', shareFolderCmd, 0], 3341 3394 'unshareFolder': ['Remove folder sharing', unshareFolderCmd, 0], 3342 3395 'gui': ['Start GUI frontend', guiCmd, 0], … … 3348 3401 'foreachvm' : ['Perform command for each VM', foreachvmCmd, 0], 3349 3402 'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print(obj.name)"', foreachCmd, 0], 3350 'recordDemo':['Record demo: recordDemo Win32file.dmo 10', recordDemoCmd, 0],3351 'playbackDemo':['Playback demo: playbackDemo Win32file.dmo 10', playbackDemoCmd, 0],3352 'lspci': ['List PCI devices attached to the VM: lspci Win32', lspciCmd, 0],3353 'attachpci': ['Attach host PCI device to the VM: attachpci Win3201:00.0', attachpciCmd, 0],3354 'detachpci': ['Detach host PCI device from the VM: detachpci Win3201:00.0', detachpciCmd, 0],3403 'recordDemo':['Record demo: recordDemo mytestvm file.dmo 10', recordDemoCmd, 0], 3404 'playbackDemo':['Playback demo: playbackDemo mytestvm file.dmo 10', playbackDemoCmd, 0], 3405 'lspci': ['List PCI devices attached to the VM: lspci mytestvm', lspciCmd, 0], 3406 'attachpci': ['Attach host PCI device to the VM: attachpci mytestvm 01:00.0', attachpciCmd, 0], 3407 'detachpci': ['Detach host PCI device from the VM: detachpci mytestvm 01:00.0', detachpciCmd, 0], 3355 3408 'goto': ['Go to line in script (script-only)', gotoCmd, 0] 3356 3409 } … … 3394 3447 # they will also be picked up, so this way one can exchange 3395 3448 # shell extensions easily. 3396 def addExtsFromFile( ctx, cmds, filename):3449 def addExtsFromFile(_ctx, cmds, filename): 3397 3450 if not os.path.isfile(filename): 3398 3451 return 3399 3452 d = {} 3400 3453 try: 3401 exec(compile(open(filename ).read(), filename, 'exec'), d, d)3454 exec(compile(open(filename, encoding='utf-8').read(), filename, 'exec'), d, d) # pylint: disable=exec-used 3402 3455 for (k, v) in list(d['commands'].items()): 3403 3456 if g_fVerbose: … … 3482 3535 else: 3483 3536 if sys.version_info[0] <= 2: 3484 cmd = raw_input(ctx['prompt']) 3537 cmd = raw_input(ctx['prompt']) # pylint: disable=undefined-variable 3485 3538 else: 3486 3539 cmd = input(ctx['prompt']) … … 3502 3555 try: 3503 3556 # There is no need to disable metric collection. This is just an example. 3504 if ct ['perf']:3557 if ctx['perf']: 3505 3558 ctx['perf'].disable(['*'], [vbox.host]) 3506 3559 except: … … 3515 3568 def runGuestCommandCb(ctx, uuid, guestLambda, args): 3516 3569 mach = machById(ctx, uuid) 3517 if mach == None:3570 if not mach: 3518 3571 return 0 3519 3572 args.insert(0, guestLambda) … … 3521 3574 return 0 3522 3575 3523 def main( argv):3576 def main(_argv): 3524 3577 3525 3578 # … … 3534 3587 parse.add_option("-o", dest="opt_line", help = "option line") 3535 3588 global g_fVerbose, g_sScriptFile, g_fBatchMode, g_fHasColors, g_fHasReadline, g_sCmd 3536 (options, args) = parse.parse_args()3589 (options, _args) = parse.parse_args() 3537 3590 g_fVerbose = options.verbose 3538 3591 style = options.style … … 3633 3686 if __name__ == '__main__': 3634 3687 main(sys.argv) 3635
Note:
See TracChangeset
for help on using the changeset viewer.