[one-users] How config Windows vm template?

Robert Parrott parrott at seas.harvard.edu
Fri Aug 12 08:36:26 PDT 2011


We  would certainly be interested in hearing about your experiences with this!

Thanks,
Rob


2011/8/11 Carlos Martín Sánchez <cmartin at opennebula.org>:
> Hi André,
>
> Looks like we don't have many users virtualizing windows machines.
> Maybe this kind of questions can be better helped in a windows support
> list...
>
> Since you took the time to create and share the contextualization scripts,
> if you come up with a working procedure and want to contribute a guide or
> how-to, we'd be glad to have it in the community wiki [1].
>
> Regards.
>
> [1] http://opennebula.org/documentation:community:index
> --
> Carlos Martín, MSc
> Project Major Contributor
> OpenNebula - The Open Source Toolkit for Cloud Computing
> www.OpenNebula.org | cmartin at opennebula.org
>
>
> 2011/8/5 André Monteiro <andremonteiro at ua.pt>
>>
>>  Hello,
>>
>> I've been working in a windows script to contextualize VMs.
>> By your experience, what's the best way to run the script automatically
>> when creating a new instance? I can create it manually as a CD-ROM and run
>> the windows7.one with the drive attached, but is there an automatic way?
>>
>> ################### Windows context configuring script ###################
>> ########### Created by andremonteiro at ua.pt and tsbatista at ua.pt ###########
>>
>> [string]$computerName = "$env:computername"
>> [string]$ConnectionString = "WinNT://$computerName"
>> [string]$ipaddress = ""
>> function getContext($file) {
>>  $context = @{}
>>  switch -regex -file $file {
>>   '(.+)="(.+)"' {
>>    $name,$value = $matches[1..2]
>>    $context[$name] = $value
>>   }
>>  }
>>  return $context
>> }
>> function addLocalUser($context) {
>>     # Create new user
>>  $username =  $context["username"]
>>  $ADSI = [adsi]$ConnectionString
>>  $user = $ADSI.Create("user",$userName)
>>  $user.setPassword($context["user_password"])
>>  $user.SetInfo()
>>
>>     # Add user to local Administrators
>>     $groups = "Administrators", "Administradores"
>>
>>     foreach ($grp in $groups) {
>>     if([ADSI]::Exists("WinNT://$computerName/$grp,group")) {
>>   $group = [ADSI] "WinNT://$computerName/$grp,group"
>>    $group.Add("WinNT://$computerName/$username")
>>   }
>>  }
>> }
>> function getIp($mac) {
>>     $octet = $mac.Split(":")
>>     [String] $ip = ""
>>     $ip += [convert]::toint32($octet[2],16)
>>     $ip += "."+[convert]::toint32($octet[3],16)
>>     $ip += "."+[convert]::toint32($octet[4],16)
>>     $ip += "."+[convert]::toint32($octet[5],16)
>>     $ipaddress = $ip
>>     return $ip
>> }
>> function getGateway($mac) {
>>     $octet = $mac.Split(":")
>>     [String] $ip = ""
>>     $ip += [convert]::toint32($octet[2],16)
>>     $ip += "."+[convert]::toint32($octet[3],16)
>>     $ip += "."+[convert]::toint32($octet[4],16)
>>     $ip += ".1"
>>     return $ip
>> }
>> function configureNetwork($context) {
>>     $Nics = Get-WMIObject Win32_NetworkAdapterConfiguration | where
>> {$_.IPEnabled -eq "TRUE" -and ($_.MACAddress)}
>>     foreach ($nic in $Nics) {
>>         [String]$mac = $nic.MACAddress
>>         [String]$ip = getIp($mac)
>>         [String]$gw = getGateway($mac)
>>         $nic.ReleaseDHCPLease()
>>         $nic.EnableStatic($ip , "255.255.255.0")
>>         $nic.SetGateways($gw)
>>         $nic.SetDNSServerSearchOrder($gw)
>>         $nic.SetDynamicDNSRegistration("FALSE")
>>     }
>> }
>> function renameComputer($context) {
>>     $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
>>     $ComputerInfo.rename($context["HOSTNAME"]+$ipaddress.Split(".")[3])
>> }
>> function enableRemoteDesktop()
>> {
>>     #Get RDP parameters
>>     #(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace
>> root\cimv2\terminalservices).AllowTsConnections
>>     #Set RDP state
>>     #(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace
>> root\cimv2\terminalservices).SetAllowTsConnections(1)
>>     #Get RDP Required Authentication
>>     #(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace
>> root\cimv2\terminalservices -Filter
>> "TerminalName='RDP-tcp'").UserAuthenticationRequired
>>     #Set RDP Required Authentication
>>     #(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace
>> root\cimv2\terminalservices -Filter
>> "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(1)
>>     $Terminal = (Get-WmiObject -Class "Win32_TerminalServiceSetting"
>> -Namespace root\cimv2\terminalservices).SetAllowTsConnections(1)
>>     return $Terminal
>> }
>> # Create folder Context if unexistant
>> if( -not(Test-Path "c:\context\")) {
>>  New-Item "c:\context\" -type directory
>> }
>> # Execute the script
>> if( -not(Test-Path "c:\context\contextualized") -and(Test-Path
>> "D:\context.sh")) {
>>     $context = @{}
>>     $context = getContext('D:\context.sh')
>>     Set-ExecutionPolicy unrestricted -force # not needed if already done
>> once on the VM
>>     addLocalUser($context)
>>     configureNetwork($context)
>>     renameComputer($context)
>>     enableRemoteDesktop()
>>     echo "contextualized" |Out-File ("c:\context\contextualized")
>>     restart-computer
>> }
>> # remember to disable password complexity requirements in computer
>> # management while rpeparing the cloud image!
>> # Remember to run "Set-ExecutionPolicy bypass -force" before this!
>>
>> --
>> André Monteiro
>>
>>
>> Carlos Martín Sánchez cmartin at opennebula.org
>> Thu May 12 02:22:09 PDT 2011
>>
>> Previous message: [one-users] How config Windows vm template?
>> Next message: [one-users] having a problem when shut down a VM
>> Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>>
>> ________________________________
>>
>> Hi there,
>>
>> The contextualization offered by OpenNebula is creating that cdrom and
>> context.sh script, but it's up to the guest OS to read that file and
>> configure itself.
>>
>> We only provide linux scripts; you would have to create similar ones. I'm
>> not sure how difficult that can be since I don't have experience with
>> Windows scripting.
>>
>>
>> If you only need to configure the right IP for your VM, then you can try
>> to
>> configure a DHCP server in your network (it can be placed in a VM in the
>> same VNet). This has been discussed in the list, hopefully these threads
>> will help:
>>
>> [1] http://www.mail-archive.com/users@lists.opennebula.org/msg01143.html
>> [2] http://www.mail-archive.com/users@lists.opennebula.org/msg01395.html
>>
>> Regards
>>
>> --
>> Carlos Martín, MSc
>> Project Major Contributor
>> OpenNebula - The Open Source Toolkit for Cloud Computing
>> www.OpenNebula.org <http://www.opennebula.org/> | cmartin at
>> opennebula.org
>>
>>
>> 2011/5/6 ddd <xrchina2008 at 163.com>
>>
>> >  hi,all
>> >        now,my winxp vm is running.but,config's ip and hostname is not
>> > right.
>> >        now,windows vm's cd-rom is existing context.sh.
>> >        This is my vm config file:
>> >                 NAME=WinVista
>> >                 CPU=1
>> >                 MEMORY=1024
>> >                 OS=[boot=hd]
>> >                 DISK =[source="/root/images/winxp_test.img", clone=yes,
>> > target=hda, readonly=no]
>> >                 NIC=[network ="Small network"]
>> >                 CONTEXT=[
>> >                        hostname   = "$NAME$VMID",
>> >                        ip_public  = "$NIC[IP, NETWORK=\"Small
>> > network\"]",
>> >                        target     ="hdb"
>> >                 ]
>> >                 GRAPHICS =[type ="vnc",listen ="127.0.0.1", port = "1"]
>> >        windows template  need config?how?
>> >        Please help me.
>> >                                                             ---Rong
>> > Xiong
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Users mailing list
>> > Users at lists.opennebula.org
>> > http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>> >
>> >
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.opennebula.org
>> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opennebula.org
> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>
>



-- 
Robert E. Parrott, Ph.D. (Phys. '06)
Director, Academic Computing
Harvard University Sch. of Eng. and App. Sci.
Maxwell-Dworkin  211,
33 Oxford St.
Cambridge, MA 02138
(617)-496-1520



More information about the Users mailing list