Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InterfaceMetric: Configure a static metric for an IPv4 Interface #472

Merged
merged 10 commits into from
Oct 13, 2020

Conversation

cohdjn
Copy link
Contributor

@cohdjn cohdjn commented Oct 4, 2020

Pull Request (PR) description

Adds InterfaceMetric to NetIPInterface to statically configure a metric on an IPv4 interface. I need this for multi-homed computers to give preference to one interface over another.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry under the Unreleased section of the change log in the CHANGELOG.md.
    Entry should say what was changed, and how that affects users (if applicable).
  • Resource documentation added/updated in README.md in resource folder.
  • Resource parameter descriptions added/updated in schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Resource Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

@johlju johlju added the needs review The pull request needs a code review. label Oct 5, 2020
@johlju johlju requested a review from PlagueHO October 5, 2020 05:36
@PlagueHO
Copy link
Member

PlagueHO commented Oct 5, 2020

Thanks @cohdjn - will get onto the review tomorrow

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8 of 8 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @cohdjn)


CHANGELOG.md, line 16 at r1 (raw file):

- NetIPInterface
  - Added `InterfaceMetric` parameter.

Can you add link to issue - e.g.

 - Added `InterfaceMetric` parameter - fixes [Issue #473](https://github.com/PowerShell/xNetworking/issues/473).

source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1, line 433 at r1 (raw file):

        [Parameter()]
        [System.UInt32]
        $InterfaceMetric

If InterfaceMetric is specified, will AutomaticMetric be automatically set to 'Disabled'? If that is the case, is the reverse true? My thinking here is that if I have an adapter that currently has InterfaceMetric specified and AutomaticMetric is set to 'Disabled' but the desired state should be AutomaticMetric is 'Enabled' then how would this be set?

I'm wondering if we need to expose the AutomaticMetric parameter as well? What do you think?

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 6, 2020

I added the issue link to the CHANGELOG.md.

So here's the default state:

Get-NetIPInterface | Select-Object ifIndex,InterfaceAlias,InterfaceMetric,AutomaticMetric

ifIndex InterfaceAlias              InterfaceMetric AutomaticMetric
------- --------------              --------------- ---------------
      4 Ethernet                                 15         Enabled
      1 Loopback Pseudo-Interface 1              75         Enabled
      4 Ethernet                                 15         Enabled
      1 Loopback Pseudo-Interface 1              75         Enabled

If I issue the following nonsense command, this is what happens:

Set-NetIPInterface -InterfaceIndex 4 -AddressFamily IPv4 -AutomaticMetric Enabled -InterfaceMetric 20

Get-NetIPInterface | Select-Object ifIndex,InterfaceAlias,InterfaceMetric,AutomaticMetric

ifIndex InterfaceAlias              InterfaceMetric AutomaticMetric
------- --------------              --------------- ---------------
      4 Ethernet                                 15         Enabled
      1 Loopback Pseudo-Interface 1              75         Enabled
      4 Ethernet                                 20        Disabled
      1 Loopback Pseudo-Interface 1              75         Enabled

Notice I explicitly enabled AutomaticMetric and specified InterfaceMetric which resulted in PowerShell ignoring the AutomaticMetric altogether. Guessing Microsoft gives preference to the interface metric over the automatic metric setting and adjusts accordingly?

I suppose there's 2 ways to go here. We could have the module throw() if there are conflicting settings which strikes me as pretty ugly. Or we could call out something in the documentation saying if you specify a value for InterfaceMetric it implies AutomaticMetric is disabled by default. I think this is the better road to take since that appears to be how PowerShell handles it anyway.

AutomaticMetric is already exposed in the module. Maybe I missed something or didn't understand what you were trying to bring to my atttention?

@PlagueHO
Copy link
Member

PlagueHO commented Oct 6, 2020

Hi @cohdjn - what I'm thinking though is that how would I set the state to -AutomaticMetric Enabled based on the currently exposed parameters.

The resource could assume that if InterfaceMetric parameter is not specified then AutomaticMetric should be set to Disabled, but that is risky DSC resource behavior- because omitting a parameter usually indicates the value should be ignored - not that a value should be set/unset.

There should always be a way to explicitly set the resource to any valid combination of values. However, only some of these combinations will be valid as you point out. So the questions I have:

  1. Do we expose the AutomaticMetric parameter? My feeling is yes, because otherwise there is no way to set AutomaticMetric to Enabled without making an assumption (that omitting InterfaceMetric means you want to set AutomaticMetric to Enabled)
  2. Do we detect the invalid conditions and throw an error or do we simply document the combination and leave it up to the user's knowledge. I'm OK either way here as we've done both before. Some resources contain a generic function Assert-ResourceProperty that is used to check the resource property combination is valid.

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 7, 2020

Hey there @PlagueHO - I think we're missing each other on the AutomaticMetric parameter. AutomaticMetric is already an exposed DSC resource in this module and can be set to either Enabled or Disabled. For example:

        NetIPInterface EthernetMetric
        {
            InterfaceAlias  = 'Ethernet'
            AddressFamily   = 'IPv4'
            AutomaticMetric = 'Disabled'
            InterfaceMetric = 20
        }

        NetIPInterface Ethernet2Metric
        {
            InterfaceAlias  = 'Ethernet 2'
            AddressFamily   = 'IPv4'
            AutomaticMetric = 'Enabled'
            InterfaceMetric = 20
        }

These resource definitions are functionally equivalent because PowerShell will essentially ignore AutomaticMetric in favor of the statically configured a value for InterfaceMetric. I think the "right" answer is to call out the combination in documentation. The behavior I showed before is how PowerShell does it so it would make sense that the DSC resource use the same behavior.

@PlagueHO
Copy link
Member

PlagueHO commented Oct 7, 2020

Doh!!! Haha I'm sorry- you are right. I should have checked- just assumed I hadn't exposed it. So yep, I'm happy to just note the combination in the README.md for the resource.

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 7, 2020

Awesome! Anything else you need from me at this point?

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - once you've added the entry to the README.md I'll merge. Thanks again!

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 8, 2020

Which README.md do you want me to make the additions to? The main one at the top of the hierarchy or the one under NetIPInterface?

@PlagueHO
Copy link
Member

PlagueHO commented Oct 8, 2020

The one under NetIPInterface - just add a section for ## Known Issues. Thanks again

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 9, 2020

Just pushed the updated README.md to the PR. This should close #473 and looking around might resolve #391 too?

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cohdjn - can you check the push occurred? The README.md change hasn't showed up. And yes, I think you're right about #391.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 12, 2020

That's weird. The push didn't go through on my side. I just pushed it and it looks better now.

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @cohdjn)


source/DSCResources/DSC_NetIPInterface/README.MD, line 7 at r3 (raw file):

## Known Issues

- If you define a value for `InterfaceMetric`, the `AutomaticMetric` setting is ignored.  PowerShell ignores `AutomaticMetric` when you use both arguments with the   `Set-NetIPInterface` cmdlet.

Minor nit pick: Can you reduce line length to < 80 chars (around end of sentence) and remove double spaces?

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 12, 2020

Minor nit pick picked. :)

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 8 of 9 files reviewed, 1 unresolved discussion (waiting on @cohdjn and @PlagueHO)


source/DSCResources/DSC_NetIPInterface/README.MD, line 7 at r3 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Minor nit pick: Can you reduce line length to < 80 chars (around end of sentence) and remove double spaces?

Doh - seems one of the double spaces turned to tipple and the line is still wrapping 😁

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @cohdjn)


source/DSCResources/DSC_NetIPInterface/README.MD, line 9 at r4 (raw file):

- If you define a value for `InterfaceMetric`, the `AutomaticMetric`
 setting is ignored. PowerShell ignores `AutomaticMetric` when you
 use both arguments with the   `Set-NetIPInterface` cmdlet.

Sorry- correction - it is just this like that is triple spaced :) I know it is such a nitpick 😢

@cohdjn
Copy link
Contributor Author

cohdjn commented Oct 13, 2020

It's all good! More nits picked! :)

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@PlagueHO PlagueHO merged commit ea0d306 into dsccommunity:master Oct 13, 2020
@johlju johlju removed the needs review The pull request needs a code review. label Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants