api: safely access legacy MBits field

This commit is contained in:
Seth Hoenig
2020-09-16 12:35:51 -05:00
parent 7d1f294baf
commit d5a422e320
3 changed files with 23 additions and 1 deletions

View File

@@ -111,6 +111,17 @@ type NetworkResource struct {
MBits *int `hcl:"mbits,optional"`
}
// COMPAT(0.13)
// XXX Deprecated. Please do not use. The method will be removed in Nomad
// 0.13 and is only being kept to allow any references to be removed before
// then.
func (n *NetworkResource) Megabits() int {
if n == nil || n.MBits == nil {
return 0
}
return *n.MBits
}
func (n *NetworkResource) Canonicalize() {
// COMPAT(0.13)
// Noop to maintain backwards compatibility

View File

@@ -1211,7 +1211,7 @@ func ApiNetworkResourceToStructs(in []*api.NetworkResource) []*structs.NetworkRe
Mode: nw.Mode,
CIDR: nw.CIDR,
IP: nw.IP,
MBits: *nw.MBits,
MBits: nw.Megabits(),
}
if nw.DNS != nil {

View File

@@ -111,6 +111,17 @@ type NetworkResource struct {
MBits *int `hcl:"mbits,optional"`
}
// COMPAT(0.13)
// XXX Deprecated. Please do not use. The method will be removed in Nomad
// 0.13 and is only being kept to allow any references to be removed before
// then.
func (n *NetworkResource) Megabits() int {
if n == nil || n.MBits == nil {
return 0
}
return *n.MBits
}
func (n *NetworkResource) Canonicalize() {
// COMPAT(0.13)
// Noop to maintain backwards compatibility