To manage multiple Hyper-V nodes remotely I'm implementing WMI.
Most Hyper-V features already work: create, remove machines, network adapter and more. But I can't seem to figure out why adding extended ACL rules won't work. I'm quite surprised how little I can find about the subject.
The error says: "Failed while applying switch port settings 'Ethernet Switch Port Extended ACL Settings' on switch 'Custom Switch': One or more arguments are invalid (0x80070057)" and I can't figure out what's wrong with the argument.
If I use the powershell equivalent "add-VMNetworkAdapterExtendedAcl" there's not problem. I'm aware of constants like unique weights for each extended acl.
The AddFeatureSettings method in the Msvm_VirtualSystemManagementService object only requires two parameters AffectedConfiguration and FeatureSettings. If the first contains an invalid reference I get a different error, same applies when FeatureSettings is not a string array. So the contents of the string array seem to be the problem. The odd thing is, while ModifyFeatureSettings doesn't work either, I can remove existing extended ACL rules through the RemoveFeatureSettings method...
The string array should contain a textual representation of a Msvm_EthernetSwitchPortFeatureSettingData object. In this case a Msvm_EthernetSwitchPortExtendedAclSettingData object.
This is my demo set up for the extended ACL rule:
var defaultFeatureSetting = new ManagementObject(<path to default extended acl definition>)
defaultFeatureSetting["Direction"] = 1;
defaultFeatureSetting["Weight"] = 1;
...
How I submit the extended ACL rule:
using (ManagementBaseObject inParams = managementService.GetMethodParameters("AddFeatureSettings"))
{
inParams["AffectedConfiguration"] = ethernetConnectionSetting.Path.Path;
inParams["FeatureSettings"] = new string[] { defaultFeatureSetting.GetText(TextFormat.WmiDtd20) };
using (ManagementBaseObject outParams = managementService.InvokeMethod("AddFeatureSettings", inParams, null))
{
var code = outParams["ReturnValue"];
var jobStr = outParams["Job"] as String;
if (jobStr != null)
{
var job = new ManagementObject(jobStr);
var error = (UInt16)job["ErrorCode"];
var error1 = job["ErrorDescription"] as String;
var error2 = job["ErrorSummaryDescription"] as String;
Console.WriteLine("Error: {0}: {1} [{2}]", error, error1, error2);
}
}
}
User contributions licensed under CC BY-SA 3.0