mirror of
https://github.com/kemko/nomad.git
synced 2026-01-09 03:45:41 +03:00
nomad: adding copy helpers
This commit is contained in:
@@ -539,6 +539,18 @@ type Resources struct {
|
||||
Networks []*NetworkResource
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of the resources
|
||||
func (r *Resources) Copy() *Resources {
|
||||
newR := new(Resources)
|
||||
*newR = *r
|
||||
n := len(r.Networks)
|
||||
newR.Networks = make([]*NetworkResource, n)
|
||||
for i := 0; i < n; i++ {
|
||||
newR.Networks[i] = r.Networks[i].Copy()
|
||||
}
|
||||
return newR
|
||||
}
|
||||
|
||||
// NetIndex finds the matching net index either using IP or
|
||||
// CIDR block lookup
|
||||
func (r *Resources) NetIndex(n *NetworkResource) int {
|
||||
@@ -664,6 +676,15 @@ type NetworkResource struct {
|
||||
DynamicPorts int // Dynamically assigned ports
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of the network resource
|
||||
func (n *NetworkResource) Copy() *NetworkResource {
|
||||
newR := new(NetworkResource)
|
||||
*newR = *n
|
||||
newR.ReservedPorts = make([]int, len(n.ReservedPorts))
|
||||
copy(newR.ReservedPorts, n.ReservedPorts)
|
||||
return newR
|
||||
}
|
||||
|
||||
// Add adds the resources of the delta to this, potentially
|
||||
// returning an error if not possible.
|
||||
func (n *NetworkResource) Add(delta *NetworkResource) {
|
||||
|
||||
Reference in New Issue
Block a user