[ovs-dev] [PATCH] WMI Script Support for setting Hyper-V friendly port name from NOVA driver

Eitan Eliahu eliahue at vmware.com
Tue Nov 4 23:33:39 UTC 2014


Hi Nithin,
Actually the function does throw an exception in both cases when the parameter is not specified and in the case an empty string is sent as the VM name:

S C:\script> import-module .\OVS.psm1
S C:\script> $vnic = Get-VMNetworkAdapter WinVM1
S C:\script>   $vnic | Set-VMNetworkAdapterOVSPort -OVSPortName
et-VMNetworkAdapterOVSPort : Missing an argument for parameter 'OVSPortName'. Specify a parameter of type
System.String' and try again.
t line:1 char:39
   $vnic | Set-VMNetworkAdapterOVSPort -OVSPortName
                                       ~~~~~~~~~~~~
   + CategoryInfo          : InvalidArgument: (:) [Set-VMNetworkAdapterOVSPort], ParameterBindingException
   + FullyQualifiedErrorId : MissingArgument,Set-VMNetworkAdapterOVSPort

S C:\script>   $vnic | Set-VMNetworkAdapterOVSPort -OVSPortName  ""
et-VMNetworkAdapterOVSPort : Cannot validate argument on parameter 'OVSPortName'. The number of characters (0) in the
rgument is too small. Specify an argument whose length is greater than or equal to "1" and then try the command again
t line:1 char:53
   $vnic | Set-VMNetworkAdapterOVSPort -OVSPortName  ""
                                                     ~~
   + CategoryInfo          : InvalidData: (:) [Set-VMNetworkAdapterOVSPort], ParameterBindingValidationException
   + FullyQualifiedErrorId : ParameterArgumentValidationError,Set-VMNetworkAdapterOVSPort


The link you listed here is to C++ cmdlet. For PS WMI script the comment delimeter is #.
We can add the comment that this function assumes a single vnic. (This function should be extended so the caller provides the index of the vnic).
Thanks,
Eitan

-----Original Message-----
From: Nithin Raju 
Sent: Tuesday, November 04, 2014 3:20 PM
To: Eitan Eliahu
Cc: Ankur Sharma; dev at openvswitch.org
Subject: Re: [ovs-dev] [PATCH] WMI Script Support for setting Hyper-V friendly port name from NOVA driver

On Nov 3, 2014, at 2:33 PM, Eitan Eliahu <eliahue at vmware.com> wrote:

> Thank for the review.
> " Since you have declared $vmName as mandatory, is this check required?"
> As I understand the "mandatory" parameter definition of PS means that the parameter must be provided by the caller. If the parameter is not provided PS prompts the use. 
> This is different than checking that the parameter is not zero.

Thanks for the explanation. I suppose you are trying to handle the case where the name of the VM is "". In that case, maybe it is better to add a:
ValidateLength(1, MAXLEN), where MAXLEN can be any large length like 2048.

Code code as it stands, does not handle "" very well anyway. It accesses $vnet[0] with $vnet = 0. It does not even throw an error when vm name is "".

> " Here, there's an assumption that we'll set it only on the first VIF and ignore the rest. Is that the right thing? Can we document this somewhere?"
> Yes, it assumed a single VNIC per VM. I thought to document it but I 
> didn't find a single comment on the whole script :-) Perhaps, I will add the comment to the commit message.

We were in a hurry earlier, hence no comments :) Looks like adding comments is very straight forward:
http://msdn.microsoft.com/en-us/library/dd901838(v=vs.85).aspx

-- Nithin



More information about the dev mailing list