Example #1
0
                                                      VmdkFile, VMwareHypervisor,
                                                      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
Example #2
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