Example #1
0
                                                      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")
Example #2
0
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
Example #3
0
#!/usr/bin/python

# demoing some control of virtual machines

from nrvr.util.ipaddress import IPAddress
from nrvr.util.user import ScriptUser
from nrvr.vm.vmware import VMwareMachine, VMwareHypervisor

ipaddress = "192.168.4.171"
name = IPAddress.nameWithNumber("example", ipaddress)
exampleVm = VMwareMachine(ScriptUser.loggedIn.userHomeRelative("vmware/examples/%s/%s.vmx" % (name, name)))
VMwareHypervisor.local.start(exampleVm.vmxFilePath, gui=True)
print exampleVm.sshCommand(["ls nonexistent ; echo `hostname`"]).output

import os
import os.path
import shutil
import tempfile
from nrvr.util.times import Timestamp

_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
Example #4
0
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