Added func ZonesToSet

An admin shall be able to configure a comma separated list of zones for a StorageClass.

That's why the func ZonesToSet (string) (set.String, error) is added. The func ZonesToSet converts a string containing a comma separated list of zones to a set. In case the list contains an empty zone an error is returned.
This commit is contained in:
pospispa
2016-11-10 12:32:35 +01:00
parent c1c7365e7c
commit 0f3a9cfc5f
2 changed files with 48 additions and 0 deletions

View File

@@ -410,3 +410,17 @@ func JoinMountOptions(userOptions []string, systemOptions []string) []string {
}
return allMountOptions.UnsortedList()
}
// ZonesToSet converts a string containing a comma separated list of zones to set
func ZonesToSet(zonesString string) (sets.String, error) {
zonesSlice := strings.Split(zonesString, ",")
zonesSet := make(sets.String)
for _, zone := range zonesSlice {
trimmedZone := strings.TrimSpace(zone)
if trimmedZone == "" {
return make(sets.String), fmt.Errorf("comma separated list of zones (%q) must not contain an empty zone", zonesString)
}
zonesSet.Insert(trimmedZone)
}
return zonesSet, nil
}