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

Implement smarter merge mechanism #56

Closed
nemesisdesign opened this Issue Jan 16, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@nemesisdesign
Member

nemesisdesign commented Jan 16, 2017

When two lists are merged with netjsonconfig.utils.merge_config, the result is the sum of the elements contained in the two lists.

However, often these lists are list of dictionaries representing interfaces and radios, and with the current implementation it is not possible to override the value of one of the dicts, this is best explained with an example.

We have a template in which radio0 has tx_power set to 20:

template = {
    "radios": [
        {
            "name": "radio0",
            "tx_power": 20
        }
    ]
}

And a configuration object in which radio0 has tx_power set to 10 (much lower than what's set in template):

config = {
    "radios": [
        {
            "name": "radio0",
            "tx_power": 10
        }
    ]
}

When we merge the two:

from netjsonconfig.utils import merge_config

result = merge_config(template, config)

result will look like the following:

config = {
    "radios": [
         {
            "name": "radio0",
            "tx_power": 20
        },
        {
            "name": "radio0",
            "tx_power": 10
        }
    ]
}

But what we want is:

config = {
    "radios": [
        {
            "name": "radio0",
            "tx_power": 10
        }
    ]
}

That is, we want to be able to override specifc attributes of dictionaries contained in lists.

@nemesisdesign nemesisdesign self-assigned this Jan 16, 2017

nemesisdesign added a commit that referenced this issue Jan 16, 2017

nemesisdesign added a commit that referenced this issue Jan 16, 2017

@nemesisdesign

This comment has been minimized.

Member

nemesisdesign commented Jan 17, 2017

The implementation introduced in f91b7b5 seems good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment