Make MAAS2 constraint matches lists #51

Merged
merged 3 commits into from Apr 28, 2016

Conversation

Projects
None yet
4 participants
Member

babbageclunk commented Apr 28, 2016

In APIv2 the constraint matches are actually label -> [id, id...]. This makes sense because in v1 they were id -> label, which meant that label could appear more than once; there could be multiple interfaces or storage devices that fulfil a specific constraint.

Change ConstraintMatches and the parsing to handle this.

babbageclunk added some commits Apr 28, 2016

Constraint matches are lists
In APIv2 the constraint matches are actually label -> [id, id...]. This
makes sense because in v1 they were id -> label, which meant that label
could appear more than once; there could be multiple interfaces or
storage devices that fulfil a specific constraint.

Change ConstraintMatches and the parsing to handle this.
controller.go
+ matches := values.([]interface{})
+ interfaces := make([]Interface, 0, len(matches))
+ for _, value := range matches {
+ id := value.(int)
@babbageclunk

babbageclunk Apr 28, 2016

Member

This block is really clunky because of all the extra casting needed - is there a better way of doing this?

@dimitern

dimitern Apr 28, 2016

Contributor

As discussed on IRC, I think it will be a lot simpler to parse the constraints map via an internal struct type (with possibly embedded types for storage and interfaces) with JSON tags on the fields.

Member

babbageclunk commented Apr 28, 2016

That seems a bit better without going quite so far.

Contributor

voidspace commented Apr 28, 2016

LGTM

Member

babbageclunk commented Apr 28, 2016

$$merge$$

Contributor

jujubot commented Apr 28, 2016

@jujubot jujubot merged commit 3b0458b into juju:master Apr 28, 2016

@babbageclunk babbageclunk deleted the babbageclunk:maas2-constraint-matches branch Apr 28, 2016

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