VMware Cloud Community
ultra01
Contributor
Contributor
Jump to solution

vmreconfig.pl adding a network adapter with port group

I have trawled the net looking for a way to add a network adapter to a virtual machine and specify the port group/ network name from the command line or with vi perl and have found no examples (Or change the port group of an existing VM network adapter). Adding an adapter with vmreconfig.pl is easy but there's no where to set the port group (which contains a vlan id specifically for the new VM that's just been cloned). I am creating a full automated system and this feature seems to be missing or I've just plan missed it. Can anyone help ?

0 Kudos
1 Solution

Accepted Solutions
mcowger
Immortal
Immortal
Jump to solution

Here's code thats close to what we use:

#$netname is a string of the network name, host view is the moref of the host you are deploying to

my $net_vm_dev_conf_spec = create_net_device(netname => $networkname, hostview => $host_view);

  1. create virtual device config spec for network card

  2. ================================================

sub create_net_device {

my %args = @_;

my $network_name = $args{netname};

my $host_view = $args;

if($network_name) {

my $network_list = Vim::get_views(mo_ref_array => $host_view->network);

foreach (@$network_list) {

if($network_name eq $_->name) {

my $network = $_;

my $nic_backing_info =

VirtualEthernetCardNetworkBackingInfo->new(deviceName => $network_name,

network => $network);

my $vd_connect_info =

VirtualDeviceConnectInfo->new(allowGuestControl => 1,

connected => 1,

startConnected => 1);

my $nic = VirtualE1000->new(backing => $nic_backing_info,

key => 9999,

unitNumber => undef,

addressType => 'generated',

connectable => $vd_connect_info);

my $nic_vm_dev_conf_spec =

VirtualDeviceConfigSpec->new(device => $nic,

operation => VirtualDeviceConfigSpecOperation->new('add'));

return $nic_vm_dev_conf_spec;

}

}

}

}

#then create a config spec

my $config_spec = VirtualMachineConfigSpec->new(

deviceChange => ,

);

#Then apply this config spec to a clone spec or something.






--Matt

VCP, vExpert, Unix Geek

--Matt VCDX #52 blog.cowger.us

View solution in original post

0 Kudos
1 Reply
mcowger
Immortal
Immortal
Jump to solution

Here's code thats close to what we use:

#$netname is a string of the network name, host view is the moref of the host you are deploying to

my $net_vm_dev_conf_spec = create_net_device(netname => $networkname, hostview => $host_view);

  1. create virtual device config spec for network card

  2. ================================================

sub create_net_device {

my %args = @_;

my $network_name = $args{netname};

my $host_view = $args;

if($network_name) {

my $network_list = Vim::get_views(mo_ref_array => $host_view->network);

foreach (@$network_list) {

if($network_name eq $_->name) {

my $network = $_;

my $nic_backing_info =

VirtualEthernetCardNetworkBackingInfo->new(deviceName => $network_name,

network => $network);

my $vd_connect_info =

VirtualDeviceConnectInfo->new(allowGuestControl => 1,

connected => 1,

startConnected => 1);

my $nic = VirtualE1000->new(backing => $nic_backing_info,

key => 9999,

unitNumber => undef,

addressType => 'generated',

connectable => $vd_connect_info);

my $nic_vm_dev_conf_spec =

VirtualDeviceConfigSpec->new(device => $nic,

operation => VirtualDeviceConfigSpecOperation->new('add'));

return $nic_vm_dev_conf_spec;

}

}

}

}

#then create a config spec

my $config_spec = VirtualMachineConfigSpec->new(

deviceChange => ,

);

#Then apply this config spec to a clone spec or something.






--Matt

VCP, vExpert, Unix Geek

--Matt VCDX #52 blog.cowger.us
0 Kudos