Changeset 28606 in vbox
- Timestamp:
- Apr 22, 2010 4:12:35 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 60453
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r28478 r28606 233 233 mgr = ctx['mgr'] 234 234 vb = ctx['vb'] 235 mach = vb.createMachine(name, kind, base, "" )235 mach = vb.createMachine(name, kind, base, "", False) 236 236 mach.saveSettings() 237 237 print "created machine with UUID",mach.id … … 245 245 id = mach.id 246 246 print "removing machine ",mach.name,"with UUID",id 247 session = ctx['global'].openMachineSession(id) 248 try: 249 mach = session.machine 250 for d in ctx['global'].getArray(mach, 'mediumAttachments'): 251 mach.detachDevice(d.controller, d.port, d.device) 252 except: 253 traceback.print_exc() 254 mach.saveSettings() 255 ctx['global'].closeMachineSession(session) 247 cmdClosedVm(ctx, mach, detachVmDevice, ["ALL"]) 256 248 mach = vb.unregisterMachine(id) 257 249 if mach: … … 502 494 session.close() 503 495 496 497 def cmdClosedVm(ctx,mach,cmd,args=[],save=True): 498 session = ctx['global'].openMachineSession(mach.id) 499 mach = session.machine 500 try: 501 cmd(ctx, mach, args) 502 except Exception, e: 503 print 'failed: ',e 504 if g_verbose: 505 traceback.print_exc() 506 if save: 507 mach.saveSettings() 508 session.close() 509 504 510 def machById(ctx,id): 505 511 mach = None … … 556 562 return "<unknown>" 557 563 564 def enumFromString(ctx,enum,str): 565 all = ctx['ifaces'].all_values(enum) 566 return all.get(str, None) 567 558 568 def listCmd(ctx, args): 559 569 for m in getMachines(ctx, True): … … 575 585 print " One can use setvar <mach> <var> <value> to change variable, using name in []." 576 586 print " Name [name]: %s" %(mach.name) 587 print " Description [description]: %s" %(mach.description) 577 588 print " ID [n/a]: %s" %(mach.id) 578 589 print " OS Type [via OSTypeId]: %s" %(os.description) … … 618 629 print " Controllers:" 619 630 for controller in controllers: 620 print " '%s' %s bus: %d" % (controller.name, asEnumElem(ctx,"StorageControllerType", controller.controllerType), controller.bus)631 print " '%s': bus %s type %s" % (controller.name, asEnumElem(ctx,"StorageBus", controller.bus), asEnumElem(ctx,"StorageControllerType", controller.controllerType)) 621 632 622 633 attaches = ctx['global'].getArray(mach, 'mediumAttachments') … … 671 682 return 0 672 683 673 def create Cmd(ctx, args):684 def createVmCmd(ctx, args): 674 685 if (len(args) < 3 or len(args) > 4): 675 print "usage: create name ostype <basefolder>"686 print "usage: createvm name ostype <basefolder>" 676 687 return 0 677 688 name = args[1] … … 722 733 return 0 723 734 724 def remove Cmd(ctx, args):735 def removeVmCmd(ctx, args): 725 736 mach = argsToMach(ctx,args) 726 737 if mach == None: … … 801 812 return 0 802 813 814 def portalsettings(ctx,mach,args): 815 enabled = args[0] 816 mach.teleporterEnabled = enabled 817 if enabled: 818 port = args[1] 819 passwd = args[2] 820 mach.teleporterPort = port 821 mach.teleporterPassword = passwd 822 803 823 def openportalCmd(ctx, args): 804 824 if (len(args) < 3): … … 814 834 passwd = "" 815 835 if not mach.teleporterEnabled or mach.teleporterPort != port or passwd: 816 session = ctx['global'].openMachineSession(mach.id) 817 mach1 = session.machine 818 mach1.teleporterEnabled = True 819 mach1.teleporterPort = port 820 mach1.teleporterPassword = passwd 821 mach1.saveSettings() 822 session.close() 836 cmdClosedVm(ctx, mach, portalsettings, [True, port, passwd]) 823 837 startVm(ctx, mach, "gui") 824 838 return 0 … … 832 846 return 0 833 847 if mach.teleporterEnabled: 834 session = ctx['global'].openMachineSession(mach.id) 835 mach1 = session.machine 836 mach1.teleporterEnabled = False 837 mach1.saveSettings() 838 session.close() 848 cmdClosedVm(ctx, mach, portalsettings, [False]) 839 849 return 0 840 850 … … 849 859 return 0 850 860 861 def plugcpu(ctx,mach,args): 862 plug = args[0] 863 cpu = args[1] 864 if plug: 865 print "Adding CPU %d..." %(cpu) 866 mach.hotPlugCPU(cpu) 867 else: 868 print "Removing CPU %d..." %(cpu) 869 mach.hotUnplugCPU(cpu) 870 851 871 def plugcpuCmd(ctx, args): 852 872 if (len(args) < 2): … … 858 878 if str(mach.sessionState) != str(ctx['ifaces'].SessionState_Open): 859 879 if mach.CPUHotPlugEnabled: 860 session = ctx['global'].openMachineSession(mach.id) 861 try: 862 mach1 = session.machine 863 cpu = int(args[2]) 864 print "Adding CPU %d..." %(cpu) 865 mach1.hotPlugCPU(cpu) 866 mach1.saveSettings() 867 except: 868 session.close() 869 raise 870 session.close() 880 cmdClosedVm(ctx, mach, plugcpu, [True, int(args[2])]) 871 881 else: 872 882 cmdExistingVm(ctx, mach, 'plugcpu', args[2]) … … 882 892 if str(mach.sessionState) != str(ctx['ifaces'].SessionState_Open): 883 893 if mach.CPUHotPlugEnabled: 884 session = ctx['global'].openMachineSession(mach.id) 885 try: 886 mach1 = session.machine 887 cpu = int(args[2]) 888 print "Removing CPU %d..." %(cpu) 889 mach1.hotUnplugCPU(cpu) 890 mach1.saveSettings() 891 except: 892 session.close() 893 raise 894 session.close() 894 cmdClosedVm(ctx, mach, plugcpu, [False, int(args[2])]) 895 895 else: 896 896 cmdExistingVm(ctx, mach, 'unplugcpu', args[2]) 897 897 return 0 898 899 def setvar(ctx,mach,args): 900 expr = 'mach.'+args[0]+' = '+args[1] 901 print "Executing",expr 902 exec expr 898 903 899 904 def setvarCmd(ctx, args): … … 904 909 if mach == None: 905 910 return 0 906 session = ctx['global'].openMachineSession(mach.id) 907 mach = session.machine 908 expr = 'mach.'+args[2]+' = '+args[3] 909 print "Executing",expr 910 try: 911 exec expr 912 except Exception, e: 913 print 'failed: ',e 914 if g_verbose: 915 traceback.print_exc() 916 mach.saveSettings() 917 session.close() 918 return 0 919 911 cmdClosedVm(ctx, mach, setvar, args[2:]) 912 return 0 913 914 def setvmextra(ctx,mach,args): 915 key = args[0] 916 value = args[1] 917 print "%s: setting %s to %s" %(mach.name, key, value) 918 mach.setExtraData(key, value) 920 919 921 920 def setExtraDataCmd(ctx, args): … … 935 934 if mach == None: 936 935 return 0 937 session = ctx['global'].openMachineSession(mach.id) 938 mach = session.machine 939 mach.setExtraData(key, value) 940 mach.saveSettings() 941 session.close() 936 cmdClosedVm(ctx, mach, setvmextra, [key, value]) 942 937 return 0 943 938 … … 966 961 keys = [ key ] 967 962 for k in keys: 968 printExtraKey(args[1], k, ctx['vb'].getExtraData(k))963 printExtraKey(args[1], k, obj.getExtraData(k)) 969 964 970 965 return 0 … … 1537 1532 return 0 1538 1533 1534 def controldevice(ctx,mach,args): 1535 [ctr,port,slot,type,id] = args 1536 mach.attachDevice(ctr, port, slot,type,id) 1537 1539 1538 def attachHddCmd(ctx,args): 1540 1539 if (len(args) < 4): … … 1554 1553 ctr = args[3] 1555 1554 (port,slot) = args[4].split(":") 1556 1557 session = ctx['global'].openMachineSession(mach.id) 1558 mach = session.machine 1559 try: 1560 mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_HardDisk, hdd.id) 1561 except Exception, e: 1562 print 'failed: ',e 1563 mach.saveSettings() 1564 session.close() 1555 cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_HardDisk,hdd.id)) 1565 1556 return 0 1566 1557 1558 def detachVmDevice(ctx,mach,args): 1559 atts = ctx['global'].getArray(mach, 'mediumAttachments') 1560 hid = args[0] 1561 for a in atts: 1562 if a.medium: 1563 if hid == "ALL" or a.medium.id == hid: 1564 mach.detachDevice(a.controller, a.port, a.device) 1565 1567 1566 def detachMedium(ctx,mid,medium): 1568 session = ctx['global'].openMachineSession(mid) 1569 mach = session.machine 1570 try: 1571 atts = ctx['global'].getArray(mach, 'mediumAttachments') 1572 hid = medium.id 1573 for a in atts: 1574 if a.medium and a.medium.id == hid: 1575 mach.detachDevice(a.controller, a.port, a.device) 1576 except Exception, e: 1577 session.close() 1578 raise e 1579 mach.saveSettings() 1580 session.close() 1567 cmdClosedVm(ctx, mach, detachVmDevice, [medium.id]) 1581 1568 1582 1569 def detachHddCmd(ctx,args): … … 1657 1644 return 0 1658 1645 1659 1660 1646 def unregisterIsoCmd(ctx,args): 1661 1647 if (len(args) != 2): … … 1712 1698 ctr = args[3] 1713 1699 (port,slot) = args[4].split(":") 1714 1715 session = ctx['global'].openMachineSession(mach.id) 1716 mach = session.machine 1717 try: 1718 mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_DVD, dvd.id) 1719 except Exception, e: 1720 print 'failed: ',e 1721 mach.saveSettings() 1722 session.close() 1700 cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_DVD,dvd.id)) 1723 1701 return 0 1724 1702 … … 1742 1720 return 0 1743 1721 1744 1745 1722 def mountIsoCmd(ctx,args): 1746 1723 if (len(args) < 5): … … 1782 1759 1783 1760 return 0 1761 1762 def attachCtr(ctx,mach,args): 1763 [name, bus, type] = args 1764 ctr = mach.addStorageController(name, bus) 1765 if type != None: 1766 ctr.controllerType = type 1767 1768 def attachCtrCmd(ctx,args): 1769 if (len(args) < 4): 1770 print "usage: attachCtr vm cname bus <type>" 1771 return 0 1772 1773 if len(args) > 4: 1774 type = enumFromString(ctx,'StorageControllerType', args[4]) 1775 if type == None: 1776 print "Controller type %s unknown" %(args[4]) 1777 return 0 1778 else: 1779 type = None 1780 1781 mach = ctx['machById'](args[1]) 1782 if mach is None: 1783 return 0 1784 bus = enumFromString(ctx,'StorageBus', args[3]) 1785 if bus is None: 1786 print "Bus type %s unknown" %(args[3]) 1787 return 0 1788 name = args[2] 1789 cmdClosedVm(ctx, mach, attachCtr, [name, bus, type]) 1790 return 0 1791 1792 def detachCtrCmd(ctx,args): 1793 if (len(args) < 3): 1794 print "usage: detachCtr vm name" 1795 return 0 1796 1797 mach = ctx['machById'](args[1]) 1798 if mach is None: 1799 return 0 1800 ctr = args[2] 1801 cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.removeStorageController(ctr)) 1802 return 0 1803 1784 1804 1785 1805 aliases = {'s':'start', … … 1794 1814 commands = {'help':['Prints help information', helpCmd, 0], 1795 1815 'start':['Start virtual machine by name or uuid: start Linux', startCmd, 0], 1796 'create ':['Create virtual machine', createCmd, 0],1797 'remove ':['Remove virtual machine', removeCmd, 0],1816 'createVm':['Create virtual machine: createVm macvm MacOS', createVmCmd, 0], 1817 'removeVm':['Remove virtual machine', removeVmCmd, 0], 1798 1818 'pause':['Pause virtual machine', pauseCmd, 0], 1799 1819 'resume':['Resume virtual machine', resumeCmd, 0], … … 1845 1865 'mountIso': ['Mount CD/DVD to the running VM: mountIso win /os.iso "IDE Controller" 0:1', mountIsoCmd, 0], 1846 1866 'unmountIso': ['Unmount CD/DVD from running VM: unmountIso win "IDE Controller" 0:1', unmountIsoCmd, 0], 1867 'attachCtr': ['Attach storage controller to the VM: attachCtr win Ctr0 IDE ICH6', attachCtrCmd, 0], 1868 'detachCtr': ['Detach HDD from the VM: detachCtr win Ctr0', detachCtrCmd, 0], 1847 1869 'listMediums': ['List mediums known to this VBox instance', listMediumsCmd, 0] 1848 1870 }
Note:
See TracChangeset
for help on using the changeset viewer.