SshCommand, ScpCommand], verbose=True) # this is a good way to preflight check VMwareHypervisor.localRequired() # BEGIN essential example code ipaddress = "192.168.0.166" # a possible modification pointed out # makes sense e.g. if used together with whateverVm.vmxFile.setEthernetAdapter(adapter, "hostonly") #ipaddress = IPAddress.numberWithinSubnet(VMwareHypervisor.localHostOnlyIPAddress, 166) rootpw = "redwood" # Ubuntu kickstart supports only one regular user regularUser = ("jack","rainbow") # one possible way of making new VM names and directories name = IPAddress.nameWithNumber("example", ipaddress, separator=None) exampleVm = VMwareMachine(ScriptUser.loggedIn.userHomeRelative("vmware/examples/%s/%s.vmx" % (name, name))) # make the virtual machine exists = exampleVm.vmxFile.exists() if exists == False: exampleVm.mkdir() downloadedDistroIsoImage = UbIsoImage(Download.fromUrl ("http://releases.ubuntu.com/precise/ubuntu-12.04.3-alternate-i386.iso")) # some possible choices pointed out # server w command line only kickstartFileContent = UbKickstartFileContent(UbKickstartTemplates.usableUbKickstartTemplate001) kickstartFileContent.replaceRootpw(rootpw) kickstartFileContent.ubReplaceHostname(exampleVm.basenameStem) kickstartFileContent.ubCreateNetworkConfigurationSection() kickstartFileContent.ubAddNetworkConfigurationStatic(device="eth0", ipaddress=ipaddress, nameservers=Nameserver.list) # put in DHCP at eth0, to be used with NAT, works well if before hostonly #kickstartFileContent.ubAddNetworkConfigurationDhcp("eth0")
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