Network check

This commit is contained in:
Alex Dadgar
2016-02-02 12:07:16 -08:00
parent 1151133271
commit 0d1b5f8d8e

View File

@@ -602,6 +602,7 @@ func DefaultResources() *Resources {
}
}
// Merge merges this resource with another resource.
func (r *Resources) Merge(other *Resources) {
if other.CPU != 0 {
r.CPU = other.CPU
@@ -620,6 +621,8 @@ func (r *Resources) Merge(other *Resources) {
}
}
// MeetsMinResources returns an error if the resources specified are less than
// the minimum allowed.
func (r *Resources) MeetsMinResources() error {
var mErr multierror.Error
if r.CPU < 100 {
@@ -634,6 +637,11 @@ func (r *Resources) MeetsMinResources() error {
if r.IOPS < 1 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum IOPS value is 1; got %d", r.IOPS))
}
for i, n := range r.Networks {
if err := n.MeetsMinResources(); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("network resource at index %d failed: %v", i, err))
}
}
return mErr.ErrorOrNil()
}
@@ -722,6 +730,16 @@ type NetworkResource struct {
DynamicPorts []Port // Dynamically assigned ports
}
// MeetsMinResources returns an error if the resources specified are less than
// the minimum allowed.
func (n *NetworkResource) MeetsMinResources() error {
var mErr multierror.Error
if n.MBits < 1 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum MBits value is 1; got %d", n.MBits))
}
return mErr.ErrorOrNil()
}
// Copy returns a deep copy of the network resource
func (n *NetworkResource) Copy() *NetworkResource {
newR := new(NetworkResource)