So after my dismal licencing failure... see other help me! question... thought I'd try updating host networking... start off easy and set up new vswitch on single NIC... a few lines of script in C# turns out to be mammoth! So I have found all my hosts, looping through them getting managed object reference to the host's networkSystem object from the host configuration manager. So far so good. Then jump out to separate class/func to set up the networking as per func below. However.. of course it isnt doing anything! Error returned and shown in VC events is as follows:
"A specified parameter was not correct. "
Very useful... not. Anybody spot what I am not setting? or setting incorrectly? Have stepped through the HostNetworkConfig and cant see anything wrong or mandatory field missing. One thing I cant find is when doing manually you have 3 types of vswitch to create - Virtual Machine, VMKernel, Service Console? Havent set this anywhere. Any help gratefully received as this SDK is starting to do my head in!!!! Aaaarrgggggghhhhhh....
public void UpdateHostNetworking(ManagedObjectReference HostNetSys, VimService service)
{
// instantiate batch change class for networking and set modify
// will set up each vswitch in turn, applying modifications
try
{
string changeMode = "modify";
HostNetworkConfig netConf = new HostNetworkConfig();
netConf.vswitch = new HostVirtualSwitchConfig[1];
// set up vswitch for Virtual Machines
HostVirtualSwitchConfig vswitch1 = new HostVirtualSwitchConfig();
vswitch1.name = "Virtual Machine Network";
vswitch1.changeOperation = "add";
// set up specification
HostVirtualSwitchSpec vswitch1Spec = new HostVirtualSwitchSpec();
vswitch1Spec.numPorts = 128;
// set up physical networking
// Number of types of bridge that extend HostVirtualSwitchBridge:
// HostVirtualSwitchSimpleBridge -
// A bridge that is statically bound to a single physical network adapter
// HostVirtualSwitchBondBridge -
// This data object type describes a bridge that provides network adapter teaming capabilities
// HostVirtualSwitchAutoBridge -
// This data type describes a bridge that automatically selects a particular physical network adapter
// on the host according to some predetermined policy. Used primarily to support mobility scenarios.
HostVirtualSwitchSimpleBridge vswitch1Bridge = new HostVirtualSwitchSimpleBridge();
vswitch1Bridge.nicDevice = "vmnic1";
// set switchbridge info in vswitch spec
vswitch1Spec.bridge = vswitch1Bridge;
// set specifcation in vswitch config
vswitch1.spec = vswitch1Spec;
// set vswitch config back into netconf
netConf.vswitch[0] = vswitch1;
// apply vswitch1 changes;
service.UpdateNetworkConfig(HostNetSys, netConf, changeMode);
}
catch (Exception e)
{
_log.WriteEvent("VirtualCenter Update Host Network Failed::" + e.Message, 1);
}
The more I use this SDK.. the more I think how apalling it is!!!!
So I have now got the vswitch to add. It turns out that the SimpleBridge is not supported yet... what a POS. This is mentioned on the ref pages although cant find it now - came across it late last night. Why put the call in the SDK if it doesnt work????
The code I have now which made it work is as follows. The HostVirtualSwitchBondBridge works OK.. only have 1 nic to bind it to, so even though dont have team still have to use Bond rather than Simple for the bridge.
HostVirtualSwitchBondBridge vswitchBridge = new HostVirtualSwitchBondBridge();
string[] nics = { "vmnic1" };
vswitchBridge.nicDevice = nics;
So to continue back to where I was with the update networkconfig bit...as have tirm code apart to get this thing to work :smileymischief: