carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package instancectl
2
3import (
4 "path"
5 "strings"
6
7 "github.com/carlosframework/platform/internal/provision"
8 "github.com/carlosframework/platform/internal/registry"
9)
10
11func BoundClaimUnitControlGroup(host, unit string) string {
12 return path.Join(parentSlices, SliceName(host), unit)
13}
14
15func (u ClaimUnits) Placement(host string) (string, string, error) {
16 if !provision.ValidHostShape(host) {
17 return "", "", ErrClaimUnit
18 }
19 if u.BoundHost == "" && u.BoundUnit == "" {
20 return UnitName(RoleRun, host), ClaimUnitControlGroup(host), nil
21 }
22 if u.BoundHost != host || !ValidBoundClaimUnit(u.BoundUnit) {
23 return "", "", ErrClaimUnit
24 }
25 return u.BoundUnit, BoundClaimUnitControlGroup(host, u.BoundUnit), nil
26}
27
28func ValidBoundClaimUnit(unit string) bool {
29 return registry.ValidUnitName(unit) && strings.HasSuffix(unit, ".service") &&
30 !strings.HasPrefix(unit, "-") && !strings.HasSuffix(unit, "@.service") &&
31 !strings.HasPrefix(unit, "carlos-instance") && !strings.ContainsAny(unit, "%\\ \t\n\r\x00/")
32}
33