コード例 #1
0
# 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")
    #kickstartFileContent.ubAddNetworkConfigurationStatic(device="eth1", ipaddress=ipaddress, nameservers=Nameserver.list)
    # some possible modifications pointed out
    #kickstartFileContent.ubSetUpgradeNone()
    #kickstartFileContent.ubSetUpgradeSafe()