optionsParser = OptionParser( usage="%prog [options] vmxfile command [arguments]", description="""Send a command to a VM. Assumes .ports file to exist and to have an entry for ssh for the user.""", version="%prog 1.0") optionsParser.add_option("-u", "--user", type="string", dest="user", help="user, default %default", default="root") (options, args) = optionsParser.parse_args() # preflight checks SystemRequirements.commandsRequiredByImplementations([SshCommand], verbose=False) if len(args) < 1: optionsParser.error("did not find vmxfile argument") vmx = args.pop(0) vm = VMwareMachine(vmx) if len(args) < 1: optionsParser.error("did not find command argument") commandAndArguments = args[0:] sshCommand = vm.sshCommand(commandAndArguments, user=options.user) print sshCommand.output
exampleVm.vmxFile.removeAllIdeCdromImages() modifiedDistroIsoImage.remove() # start up for accepting known host key VMwareHypervisor.local.start(exampleVm.vmxFilePath, gui=True) exampleVm.sleepUntilHasAcceptedKnownHostKey(ticker=True) # a possible choice pointed out #exampleVm.sshCommand([LinuxUtil.commandToEnableSudo(exampleVm.regularUser)]) # a possible choice pointed out #exampleVm.sshCommand([UbGnome.ubCommandToEnableAutoLogin(exampleVm.regularUser)]) # these ssh commands here are just a demo print "------" print exampleVm.sshCommand(["ls", "-al"]).output print "------" print exampleVm.sshCommand(["ls nonexistent ; echo `hostname`"]).output print "------" # these scp commands here are just a demo exampleDir = os.path.join(tempfile.gettempdir(), Timestamp.microsecondTimestamp()) os.mkdir(exampleDir, 0755) try: sendDir = os.path.join(exampleDir, "send") os.mkdir(sendDir, 0755) exampleFile1 = os.path.join(sendDir, "example1.txt") with open(exampleFile1, "w") as outputFile: outputFile.write("this is an example\n" * 1000000) scpExample1 = exampleVm.scpPutCommand(fromHostPath=exampleFile1, toGuestPath="~/example1.txt") print "returncode=" + str(scpExample1.returncode) print "output=" + scpExample1.output
from nrvr.remote.ssh import SshCommand from nrvr.util.requirements import SystemRequirements from nrvr.vm.vmware import VMwareMachine optionsParser = OptionParser(usage="%prog [options] vmxfile command [arguments]", description= """Send a command to a VM. Assumes .ports file to exist and to have an entry for ssh for the user.""", version="%prog 1.0") optionsParser.add_option("-u", "--user", type="string", dest="user", help="user, default %default", default="root") (options, args) = optionsParser.parse_args() # preflight checks SystemRequirements.commandsRequiredByImplementations([SshCommand], verbose=False) if len(args) < 1: optionsParser.error("did not find vmxfile argument") vmx = args.pop(0) vm = VMwareMachine(vmx) if len(args) < 1: optionsParser.error("did not find command argument") commandAndArguments = args[0:] sshCommand = vm.sshCommand(commandAndArguments, user=options.user) print sshCommand.output