VMware Cloud Community
Jeremie_R
Contributor
Contributor

Change network setting on VM

Hi,

I'm trying to create a workflow to change network settings, ex : I deploy a template, this template is already on port group (vLan_xxx), but I need to propose to change port group (ex: DMZ) and modify the IP settings (different subnet mask and gateway).

In first time I already do a customization task (Set : VM name, temp IP, etc..) because I need to make some actions just after and I change port group but I would like to set the good IP settings, I try to create a scriptable task just before another customization task but no success.

Here my scriptable task :

var DMZ = DMZ_Network.name;

if (DMZ == "LAN_DMZ_aaa.aaa.aaa.aaa"){
Sysprep_subnetMask_DMZ="255.255.255.xxx";
Sysprep_gateway_DMZ[0]="xxx.xxx.xxx.xxx";
}

if (DMZ == "LAN_DMZ_bbb.bbb.bbb.bbb"){

Sysprep_subnetMask_DMZ="255.255.255.xxx";

Sysprep_gateway_DMZ[0]="xxx.xxx.xxx.xxx";

}

if (DMZ == "LAN_DMZ_ccc.ccc.ccc.ccc"){

Sysprep_subnetMask_DMZ="255.255.255.xxx";

Sysprep_gateway_DMZ[0]="xxx.xxx.xxx.xxx";

}


If someone have a solution or a better idea...

THX in advance

Reply
0 Kudos
4 Replies
robrtb12
Enthusiast
Enthusiast

Hello,

I'm not following where you may be having the issue.

If you're having an issue setting the DVPortgroup, check out this thread:
http://communities.vmware.com/message/1731492#1731492

If you're having an issue with the customization, have a look at this provided workflow:

"Clone, Windows with single NIC and credential"

PS - Most likely, a workflow should only perform 1 OS Customization.  I can't think of a reason you would want or need to do more  :smileyconfused:

Reply
0 Kudos
Jeremie_R
Contributor
Contributor


Hi,

I have create an action to change port group and it's working but now I need to change the network settings on guest (IP, subnetmask, gateway)

I give you my little action :

var psScript = ''

psScript +='Add-PSSnapin VMware.VimAutomation.Core\n';

psScript +='$username = "USERNAME"\n';

psScript +='$password = "PASSWORD"\n';

psScript +='\n';

psScript +='Connect-VIServer -Server "VCENTERSERVER" -User $username -Password $password\n';

psScript +='Get-VM '+ VMNAME + ' | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "PORTGROUP" -Confirm:$false\n';

psScript +='Disconnect-VIServer -Confirm:$False\n';

return System.getModule("com.vmware.library.powershell").invokeScript( host,psScript,sessionId) ;

Reply
0 Kudos
Jeremie_R
Contributor
Contributor

An idea ???

I only need to set subnetmask and gateway on VM guest, directly with vco action or powercli (I create an action with)

Reply
0 Kudos
ChristianWehner
VMware Employee
VMware Employee

Hi Jeremie,

I would'nt use a ps script, running on the vCenter server to configure the network adapter of a VM. Instead you can do this direct within orchestrator which prevents you from additional error which can occur with powershell invoking.

To your problem to change the in guest network settings you could try the following:

1. pipe the following vbs script local to your vCO server and replace the IP, subnetask and gateway:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _

    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array("192.168.1.141")

strSubnetMask = Array("255.255.255.0")

strGateway = Array("192.168.1.100")

strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters

    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

    If errEnable = 0 Then

        WScript.Echo "The IP address has been changed."

    Else

        WScript.Echo "The IP address could not be changed."

    End If

Next

2. copy the lokal file to the target server using "Copy file from vCO to guest" workflow

3. run the script on target server using "Run program in guest" workflow

Example: pass parameters to run in guest workflow

Hope this helps and regards,

Chris

Reply
0 Kudos