VMWare SDK C# VirtualMachine Interface Type -
i have code gets virtualmachine network connections , retrieves connected switch information.
the code have seems work "virtualethernetcardnetworkbackinginfo" type interfaces, fails when server connected vd switch 1 needs use "virtualethernetcarddistributedvirtualportbackinginfo" type in scenario.
question is, how detect interface type before try cast object? or should 1 try cast , see 1 works?
this code have i'm looking cleaner...
bool vswitch = false, vds = false; virtualethernetcard _workloadnic = (virtualethernetcard)_virtualdevice; //first check if vm connected vswitch try { virtualethernetcardnetworkbackinginfo _nic_backing = (virtualethernetcardnetworkbackinginfo)_workloadnic.backing; network_moid = _nic_backing.network.value; vswitch = true; } catch (exception ex) { } //if not vswitch should vds if (!vswitch) { try { virtualethernetcarddistributedvirtualportbackinginfo _nic_backing = (virtualethernetcarddistributedvirtualportbackinginfo)_workloadnic.backing; network_moid = _nic_backing.port.switchuuid vds = true; } catch (exception ex) { } } if (!vswitch || !vds) { logger.log(string.format("updatevmwareworkload: not determine workload network backing type"), logger.severity.error); }
it think work fine...
if (_workloadnic.backing virtualethernetcardnetworkbackinginfo) { } else if (_workloadnic.backing virtualethernetcarddistributedvirtualportbackinginfo) { }
Comments
Post a Comment