resources: Make resource kind and baseuid fields public
This is required if we're going to have out of package resources. In particular for third party packages, and also for if we decide to split out each resource into a separate sub package.
This commit is contained in:
@@ -80,7 +80,7 @@ work, and finish by calling the `Init` method of the base resource.
|
|||||||
```golang
|
```golang
|
||||||
// Init initializes the Foo resource.
|
// Init initializes the Foo resource.
|
||||||
func (obj *FooRes) Init() error {
|
func (obj *FooRes) Init() error {
|
||||||
obj.BaseRes.kind = "foo" // must lower case resource kind
|
obj.BaseRes.Kind = "foo" // must lower case resource kind
|
||||||
// run the resource specific initialization, and error if anything fails
|
// run the resource specific initialization, and error if anything fails
|
||||||
if some_error {
|
if some_error {
|
||||||
return err // something went wrong!
|
return err // something went wrong!
|
||||||
@@ -516,7 +516,7 @@ This can _only_ be done inside of the `CheckApply` function!
|
|||||||
```golang
|
```golang
|
||||||
// inside CheckApply, probably near the top
|
// inside CheckApply, probably near the top
|
||||||
if val, exists := obj.Recv["SomeKey"]; exists {
|
if val, exists := obj.Recv["SomeKey"]; exists {
|
||||||
log.Printf("SomeKey was sent to us from: %s[%s].%s", val.Res.Kind(), val.Res.GetName(), val.Key)
|
log.Printf("SomeKey was sent to us from: %s[%s].%s", val.Res.GetKind(), val.Res.GetName(), val.Key)
|
||||||
if val.Changed {
|
if val.Changed {
|
||||||
log.Printf("SomeKey was just updated!")
|
log.Printf("SomeKey was just updated!")
|
||||||
// you may want to invalidate some local cache
|
// you may want to invalidate some local cache
|
||||||
|
|||||||
10
etcd/etcd.go
10
etcd/etcd.go
@@ -2147,10 +2147,10 @@ func SetResources(obj *EmbdEtcd, hostname string, resourceList []resources.Res)
|
|||||||
ifs := []etcd.Cmp{} // list matching the desired state
|
ifs := []etcd.Cmp{} // list matching the desired state
|
||||||
ops := []etcd.Op{} // list of ops in this transaction
|
ops := []etcd.Op{} // list of ops in this transaction
|
||||||
for _, res := range resourceList {
|
for _, res := range resourceList {
|
||||||
if res.Kind() == "" {
|
if res.GetKind() == "" {
|
||||||
log.Fatalf("Etcd: SetResources: Error: Empty kind: %v", res.GetName())
|
log.Fatalf("Etcd: SetResources: Error: Empty kind: %v", res.GetName())
|
||||||
}
|
}
|
||||||
uid := fmt.Sprintf("%s/%s", res.Kind(), res.GetName())
|
uid := fmt.Sprintf("%s/%s", res.GetKind(), res.GetName())
|
||||||
path := fmt.Sprintf("/%s/exported/%s/resources/%s", NS, hostname, uid)
|
path := fmt.Sprintf("/%s/exported/%s/resources/%s", NS, hostname, uid)
|
||||||
if data, err := resources.ResToB64(res); err == nil {
|
if data, err := resources.ResToB64(res); err == nil {
|
||||||
ifs = append(ifs, etcd.Compare(etcd.Value(path), "=", data)) // desired state
|
ifs = append(ifs, etcd.Compare(etcd.Value(path), "=", data)) // desired state
|
||||||
@@ -2162,7 +2162,7 @@ func SetResources(obj *EmbdEtcd, hostname string, resourceList []resources.Res)
|
|||||||
|
|
||||||
match := func(res resources.Res, resourceList []resources.Res) bool { // helper lambda
|
match := func(res resources.Res, resourceList []resources.Res) bool { // helper lambda
|
||||||
for _, x := range resourceList {
|
for _, x := range resourceList {
|
||||||
if res.Kind() == x.Kind() && res.GetName() == x.GetName() {
|
if res.GetKind() == x.GetKind() && res.GetName() == x.GetName() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2172,10 +2172,10 @@ func SetResources(obj *EmbdEtcd, hostname string, resourceList []resources.Res)
|
|||||||
hasDeletes := false
|
hasDeletes := false
|
||||||
// delete old, now unused resources here...
|
// delete old, now unused resources here...
|
||||||
for _, res := range originals {
|
for _, res := range originals {
|
||||||
if res.Kind() == "" {
|
if res.GetKind() == "" {
|
||||||
log.Fatalf("Etcd: SetResources: Error: Empty kind: %v", res.GetName())
|
log.Fatalf("Etcd: SetResources: Error: Empty kind: %v", res.GetName())
|
||||||
}
|
}
|
||||||
uid := fmt.Sprintf("%s/%s", res.Kind(), res.GetName())
|
uid := fmt.Sprintf("%s/%s", res.GetKind(), res.GetName())
|
||||||
path := fmt.Sprintf("/%s/exported/%s/resources/%s", NS, hostname, uid)
|
path := fmt.Sprintf("/%s/exported/%s/resources/%s", NS, hostname, uid)
|
||||||
|
|
||||||
if match(res, resourceList) { // if we match, no need to delete!
|
if match(res, resourceList) { // if we match, no need to delete!
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (g *Graph) OKTimestamp(v *Vertex) bool {
|
|||||||
// b/c we should let our pre-req's go first...
|
// b/c we should let our pre-req's go first...
|
||||||
x, y := v.GetTimestamp(), n.GetTimestamp()
|
x, y := v.GetTimestamp(), n.GetTimestamp()
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: OKTimestamp: (%v) >= %s[%s](%v): !%v", v.Kind(), v.GetName(), x, n.Kind(), n.GetName(), y, x >= y)
|
log.Printf("%s[%s]: OKTimestamp: (%v) >= %s[%s](%v): !%v", v.GetKind(), v.GetName(), x, n.GetKind(), n.GetName(), y, x >= y)
|
||||||
}
|
}
|
||||||
if x >= y {
|
if x >= y {
|
||||||
return false
|
return false
|
||||||
@@ -82,7 +82,7 @@ func (g *Graph) Poke(v *Vertex) error {
|
|||||||
// TODO: does this need an || activity flag?
|
// TODO: does this need an || activity flag?
|
||||||
if n.Res.GetState() != resources.ResStateProcess {
|
if n.Res.GetState() != resources.ResStateProcess {
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Poke: %s[%s]", v.Kind(), v.GetName(), n.Kind(), n.GetName())
|
log.Printf("%s[%s]: Poke: %s[%s]", v.GetKind(), v.GetName(), n.GetKind(), n.GetName())
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(nn *Vertex) error {
|
go func(nn *Vertex) error {
|
||||||
@@ -94,7 +94,7 @@ func (g *Graph) Poke(v *Vertex) error {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Poke: %s[%s]: Skipped!", v.Kind(), v.GetName(), n.Kind(), n.GetName())
|
log.Printf("%s[%s]: Poke: %s[%s]: Skipped!", v.GetKind(), v.GetName(), n.GetKind(), n.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ func (g *Graph) BackPoke(v *Vertex) {
|
|||||||
// happens earlier in the state cycle and that doesn't wrap nil
|
// happens earlier in the state cycle and that doesn't wrap nil
|
||||||
if x >= y && (s != resources.ResStateProcess && s != resources.ResStateCheckApply) {
|
if x >= y && (s != resources.ResStateProcess && s != resources.ResStateCheckApply) {
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: BackPoke: %s[%s]", v.Kind(), v.GetName(), n.Kind(), n.GetName())
|
log.Printf("%s[%s]: BackPoke: %s[%s]", v.GetKind(), v.GetName(), n.GetKind(), n.GetName())
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(nn *Vertex) error {
|
go func(nn *Vertex) error {
|
||||||
@@ -127,7 +127,7 @@ func (g *Graph) BackPoke(v *Vertex) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: BackPoke: %s[%s]: Skipped!", v.Kind(), v.GetName(), n.Kind(), n.GetName())
|
log.Printf("%s[%s]: BackPoke: %s[%s]: Skipped!", v.GetKind(), v.GetName(), n.GetKind(), n.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ func (g *Graph) SetDownstreamRefresh(v *Vertex, b bool) {
|
|||||||
func (g *Graph) Process(v *Vertex) error {
|
func (g *Graph) Process(v *Vertex) error {
|
||||||
obj := v.Res
|
obj := v.Res
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Process()", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Process()", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
// FIXME: should these SetState methods be here or after the sema code?
|
// FIXME: should these SetState methods be here or after the sema code?
|
||||||
defer obj.SetState(resources.ResStateNil) // reset state when finished
|
defer obj.SetState(resources.ResStateNil) // reset state when finished
|
||||||
@@ -187,7 +187,7 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
}
|
}
|
||||||
// timestamp must be okay...
|
// timestamp must be okay...
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: OKTimestamp(%v)", obj.Kind(), obj.GetName(), v.GetTimestamp())
|
log.Printf("%s[%s]: OKTimestamp(%v)", obj.GetKind(), obj.GetName(), v.GetTimestamp())
|
||||||
}
|
}
|
||||||
|
|
||||||
// semaphores!
|
// semaphores!
|
||||||
@@ -199,7 +199,7 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
// TODO: Add a close mechanism to close/unblock zero count semaphores...
|
// TODO: Add a close mechanism to close/unblock zero count semaphores...
|
||||||
semas := obj.Meta().Sema
|
semas := obj.Meta().Sema
|
||||||
if g.Flags.Debug && len(semas) > 0 {
|
if g.Flags.Debug && len(semas) > 0 {
|
||||||
log.Printf("%s[%s]: Sema: P(%s)", obj.Kind(), obj.GetName(), strings.Join(semas, ", "))
|
log.Printf("%s[%s]: Sema: P(%s)", obj.GetKind(), obj.GetName(), strings.Join(semas, ", "))
|
||||||
}
|
}
|
||||||
if err := g.SemaLock(semas); err != nil { // lock
|
if err := g.SemaLock(semas); err != nil { // lock
|
||||||
// NOTE: in practice, this might not ever be truly necessary...
|
// NOTE: in practice, this might not ever be truly necessary...
|
||||||
@@ -207,7 +207,7 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
}
|
}
|
||||||
defer g.SemaUnlock(semas) // unlock
|
defer g.SemaUnlock(semas) // unlock
|
||||||
if g.Flags.Debug && len(semas) > 0 {
|
if g.Flags.Debug && len(semas) > 0 {
|
||||||
defer log.Printf("%s[%s]: Sema: V(%s)", obj.Kind(), obj.GetName(), strings.Join(semas, ", "))
|
defer log.Printf("%s[%s]: Sema: V(%s)", obj.GetKind(), obj.GetName(), strings.Join(semas, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
var ok = true
|
var ok = true
|
||||||
@@ -231,7 +231,7 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: CheckApply(%t)", obj.Kind(), obj.GetName(), !noop)
|
log.Printf("%s[%s]: CheckApply(%t)", obj.GetKind(), obj.GetName(), !noop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup the refresh (notification) variable
|
// lookup the refresh (notification) variable
|
||||||
@@ -256,9 +256,9 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
// if this fails, don't UpdateTimestamp()
|
// if this fails, don't UpdateTimestamp()
|
||||||
checkOK, err = obj.CheckApply(!noop)
|
checkOK, err = obj.CheckApply(!noop)
|
||||||
|
|
||||||
if promErr := obj.Prometheus().UpdateCheckApplyTotal(obj.Kind(), !noop, !checkOK, err != nil); promErr != nil {
|
if promErr := obj.Prometheus().UpdateCheckApplyTotal(obj.GetKind(), !noop, !checkOK, err != nil); promErr != nil {
|
||||||
// TODO: how to error correctly
|
// TODO: how to error correctly
|
||||||
log.Printf("%s[%s]: Prometheus.UpdateCheckApplyTotal() errored: %v", v.Kind(), v.GetName(), err)
|
log.Printf("%s[%s]: Prometheus.UpdateCheckApplyTotal() errored: %v", v.GetKind(), v.GetName(), err)
|
||||||
}
|
}
|
||||||
// TODO: Can the `Poll` converged timeout tracking be a
|
// TODO: Can the `Poll` converged timeout tracking be a
|
||||||
// more general method for all converged timeouts? this
|
// more general method for all converged timeouts? this
|
||||||
@@ -268,17 +268,17 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
cuid, _, _ := v.Res.ConvergerUIDs() // get the converger uid used to report status
|
cuid, _, _ := v.Res.ConvergerUIDs() // get the converger uid used to report status
|
||||||
cuid.ResetTimer() // activity!
|
cuid.ResetTimer() // activity!
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Converger: ResetTimer", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Converger: ResetTimer", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkOK && err != nil { // should never return this way
|
if checkOK && err != nil { // should never return this way
|
||||||
log.Fatalf("%s[%s]: CheckApply(): %t, %+v", obj.Kind(), obj.GetName(), checkOK, err)
|
log.Fatalf("%s[%s]: CheckApply(): %t, %+v", obj.GetKind(), obj.GetName(), checkOK, err)
|
||||||
}
|
}
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: CheckApply(): %t, %v", obj.Kind(), obj.GetName(), checkOK, err)
|
log.Printf("%s[%s]: CheckApply(): %t, %v", obj.GetKind(), obj.GetName(), checkOK, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if CheckApply ran without noop and without error, state should be good
|
// if CheckApply ran without noop and without error, state should be good
|
||||||
@@ -372,7 +372,7 @@ Loop:
|
|||||||
// if process started, but no action yet, skip!
|
// if process started, but no action yet, skip!
|
||||||
if v.Res.GetState() == resources.ResStateProcess {
|
if v.Res.GetState() == resources.ResStateProcess {
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Skipped event!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: Skipped event!", v.GetKind(), v.GetName())
|
||||||
}
|
}
|
||||||
ev.ACK() // ready for next message
|
ev.ACK() // ready for next message
|
||||||
v.Res.QuiesceGroup().Done()
|
v.Res.QuiesceGroup().Done()
|
||||||
@@ -383,7 +383,7 @@ Loop:
|
|||||||
// if waiting, we skip running a new execution!
|
// if waiting, we skip running a new execution!
|
||||||
if running || waiting {
|
if running || waiting {
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Playback added!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: Playback added!", v.GetKind(), v.GetName())
|
||||||
}
|
}
|
||||||
playback = true
|
playback = true
|
||||||
ev.ACK() // ready for next message
|
ev.ACK() // ready for next message
|
||||||
@@ -393,7 +393,7 @@ Loop:
|
|||||||
|
|
||||||
// catch invalid rates
|
// catch invalid rates
|
||||||
if v.Meta().Burst == 0 && !(v.Meta().Limit == rate.Inf) { // blocked
|
if v.Meta().Burst == 0 && !(v.Meta().Limit == rate.Inf) { // blocked
|
||||||
e := fmt.Errorf("%s[%s]: Permanently limited (rate != Inf, burst: 0)", v.Kind(), v.GetName())
|
e := fmt.Errorf("%s[%s]: Permanently limited (rate != Inf, burst: 0)", v.GetKind(), v.GetName())
|
||||||
ev.ACK() // ready for next message
|
ev.ACK() // ready for next message
|
||||||
v.Res.QuiesceGroup().Done()
|
v.Res.QuiesceGroup().Done()
|
||||||
v.SendEvent(event.EventExit, &SentinelErr{e})
|
v.SendEvent(event.EventExit, &SentinelErr{e})
|
||||||
@@ -411,7 +411,7 @@ Loop:
|
|||||||
if d > 0 { // delay
|
if d > 0 { // delay
|
||||||
limited = true
|
limited = true
|
||||||
playback = true
|
playback = true
|
||||||
log.Printf("%s[%s]: Limited (rate: %v/sec, burst: %d, next: %v)", v.Kind(), v.GetName(), v.Meta().Limit, v.Meta().Burst, d)
|
log.Printf("%s[%s]: Limited (rate: %v/sec, burst: %d, next: %v)", v.GetKind(), v.GetName(), v.Meta().Limit, v.Meta().Burst, d)
|
||||||
// start the timer...
|
// start the timer...
|
||||||
timer.Reset(d)
|
timer.Reset(d)
|
||||||
waiting = true // waiting for retry timer
|
waiting = true // waiting for retry timer
|
||||||
@@ -429,11 +429,11 @@ Loop:
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if e := g.Process(v); e != nil {
|
if e := g.Process(v); e != nil {
|
||||||
playback = true
|
playback = true
|
||||||
log.Printf("%s[%s]: CheckApply errored: %v", v.Kind(), v.GetName(), e)
|
log.Printf("%s[%s]: CheckApply errored: %v", v.GetKind(), v.GetName(), e)
|
||||||
if retry == 0 {
|
if retry == 0 {
|
||||||
if err := obj.Prometheus().UpdateState(fmt.Sprintf("%s[%s]", v.Kind(), v.GetName()), v.Kind(), prometheus.ResStateHardFail); err != nil {
|
if err := obj.Prometheus().UpdateState(fmt.Sprintf("%s[%s]", v.GetKind(), v.GetName()), v.GetKind(), prometheus.ResStateHardFail); err != nil {
|
||||||
// TODO: how to error this?
|
// TODO: how to error this?
|
||||||
log.Printf("%s[%s]: Prometheus.UpdateState() errored: %v", v.Kind(), v.GetName(), err)
|
log.Printf("%s[%s]: Prometheus.UpdateState() errored: %v", v.GetKind(), v.GetName(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap the error in the sentinel
|
// wrap the error in the sentinel
|
||||||
@@ -444,11 +444,11 @@ Loop:
|
|||||||
if retry > 0 { // don't decrement the -1
|
if retry > 0 { // don't decrement the -1
|
||||||
retry--
|
retry--
|
||||||
}
|
}
|
||||||
if err := obj.Prometheus().UpdateState(fmt.Sprintf("%s[%s]", v.Kind(), v.GetName()), v.Kind(), prometheus.ResStateSoftFail); err != nil {
|
if err := obj.Prometheus().UpdateState(fmt.Sprintf("%s[%s]", v.GetKind(), v.GetName()), v.GetKind(), prometheus.ResStateSoftFail); err != nil {
|
||||||
// TODO: how to error this?
|
// TODO: how to error this?
|
||||||
log.Printf("%s[%s]: Prometheus.UpdateState() errored: %v", v.Kind(), v.GetName(), err)
|
log.Printf("%s[%s]: Prometheus.UpdateState() errored: %v", v.GetKind(), v.GetName(), err)
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: CheckApply: Retrying after %.4f seconds (%d left)", v.Kind(), v.GetName(), delay.Seconds(), retry)
|
log.Printf("%s[%s]: CheckApply: Retrying after %.4f seconds (%d left)", v.GetKind(), v.GetName(), delay.Seconds(), retry)
|
||||||
// start the timer...
|
// start the timer...
|
||||||
timer.Reset(delay)
|
timer.Reset(delay)
|
||||||
waiting = true // waiting for retry timer
|
waiting = true // waiting for retry timer
|
||||||
@@ -469,7 +469,7 @@ Loop:
|
|||||||
if !timer.Stop() {
|
if !timer.Stop() {
|
||||||
//<-timer.C // blocks, docs are wrong!
|
//<-timer.C // blocks, docs are wrong!
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: CheckApply delay expired!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: CheckApply delay expired!", v.GetKind(), v.GetName())
|
||||||
close(done)
|
close(done)
|
||||||
|
|
||||||
// a CheckApply run (with possibly retry pause) finished
|
// a CheckApply run (with possibly retry pause) finished
|
||||||
@@ -478,7 +478,7 @@ Loop:
|
|||||||
wcuid.SetConverged(false)
|
wcuid.SetConverged(false)
|
||||||
}
|
}
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: CheckApply finished!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: CheckApply finished!", v.GetKind(), v.GetName())
|
||||||
}
|
}
|
||||||
done = make(chan struct{}) // reset
|
done = make(chan struct{}) // reset
|
||||||
// re-send this event, to trigger a CheckApply()
|
// re-send this event, to trigger a CheckApply()
|
||||||
@@ -521,8 +521,8 @@ func (g *Graph) Worker(v *Vertex) error {
|
|||||||
// running on, which isolates things nicely...
|
// running on, which isolates things nicely...
|
||||||
obj := v.Res
|
obj := v.Res
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("%s[%s]: Worker: Running", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: Worker: Running", v.GetKind(), v.GetName())
|
||||||
defer log.Printf("%s[%s]: Worker: Stopped", v.Kind(), v.GetName())
|
defer log.Printf("%s[%s]: Worker: Stopped", v.GetKind(), v.GetName())
|
||||||
}
|
}
|
||||||
// run the init (should match 1-1 with Close function)
|
// run the init (should match 1-1 with Close function)
|
||||||
if err := obj.Init(); err != nil {
|
if err := obj.Init(); err != nil {
|
||||||
@@ -610,7 +610,7 @@ func (g *Graph) Worker(v *Vertex) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
timer.Stop() // it's nice to cleanup
|
timer.Stop() // it's nice to cleanup
|
||||||
log.Printf("%s[%s]: Watch delay expired!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: Watch delay expired!", v.GetKind(), v.GetName())
|
||||||
// NOTE: we can avoid the send if running Watch guarantees
|
// NOTE: we can avoid the send if running Watch guarantees
|
||||||
// one CheckApply event on startup!
|
// one CheckApply event on startup!
|
||||||
//if pendingSendEvent { // TODO: should this become a list in the future?
|
//if pendingSendEvent { // TODO: should this become a list in the future?
|
||||||
@@ -638,7 +638,7 @@ func (g *Graph) Worker(v *Vertex) error {
|
|||||||
err = sentinelErr.err
|
err = sentinelErr.err
|
||||||
break // sentinel means, perma-exit
|
break // sentinel means, perma-exit
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Watch errored: %v", v.Kind(), v.GetName(), e)
|
log.Printf("%s[%s]: Watch errored: %v", v.GetKind(), v.GetName(), e)
|
||||||
if watchRetry == 0 {
|
if watchRetry == 0 {
|
||||||
err = fmt.Errorf("Permanent watch error: %v", e)
|
err = fmt.Errorf("Permanent watch error: %v", e)
|
||||||
break
|
break
|
||||||
@@ -647,7 +647,7 @@ func (g *Graph) Worker(v *Vertex) error {
|
|||||||
watchRetry--
|
watchRetry--
|
||||||
}
|
}
|
||||||
watchDelay = time.Duration(v.Meta().Delay) * time.Millisecond
|
watchDelay = time.Duration(v.Meta().Delay) * time.Millisecond
|
||||||
log.Printf("%s[%s]: Watch: Retrying after %.4f seconds (%d left)", v.Kind(), v.GetName(), watchDelay.Seconds(), watchRetry)
|
log.Printf("%s[%s]: Watch: Retrying after %.4f seconds (%d left)", v.GetKind(), v.GetName(), watchDelay.Seconds(), watchRetry)
|
||||||
// We need to trigger a CheckApply after Watch restarts, so that
|
// We need to trigger a CheckApply after Watch restarts, so that
|
||||||
// we catch any lost events that happened while down. We do this
|
// we catch any lost events that happened while down. We do this
|
||||||
// by getting the Watch resource to send one event once it's up!
|
// by getting the Watch resource to send one event once it's up!
|
||||||
@@ -721,12 +721,12 @@ func (g *Graph) Start(first bool) { // start or continue
|
|||||||
// TODO: if a sufficient number of workers error,
|
// TODO: if a sufficient number of workers error,
|
||||||
// should something be done? Should these restart
|
// should something be done? Should these restart
|
||||||
// after perma-failure if we have a graph change?
|
// after perma-failure if we have a graph change?
|
||||||
log.Printf("%s[%s]: Started", vv.Kind(), vv.GetName())
|
log.Printf("%s[%s]: Started", vv.GetKind(), vv.GetName())
|
||||||
if err := g.Worker(vv); err != nil { // contains the Watch and CheckApply loops
|
if err := g.Worker(vv); err != nil { // contains the Watch and CheckApply loops
|
||||||
log.Printf("%s[%s]: Exited with failure: %v", vv.Kind(), vv.GetName(), err)
|
log.Printf("%s[%s]: Exited with failure: %v", vv.GetKind(), vv.GetName(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Exited", vv.Kind(), vv.GetName())
|
log.Printf("%s[%s]: Exited", vv.GetKind(), vv.GetName())
|
||||||
}(v)
|
}(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (g *Graph) addEdgesByMatchingUIDS(v *Vertex, uids []resources.ResUID) []boo
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
log.Printf("Compile: AutoEdge: Match: %s[%s] with UID: %s[%s]", vv.Kind(), vv.GetName(), uid.Kind(), uid.GetName())
|
log.Printf("Compile: AutoEdge: Match: %s[%s] with UID: %s[%s]", vv.GetKind(), vv.GetName(), uid.GetKind(), uid.GetName())
|
||||||
}
|
}
|
||||||
// we must match to an effective UID for the resource,
|
// we must match to an effective UID for the resource,
|
||||||
// that is to say, the name value of a res is a helpful
|
// that is to say, the name value of a res is a helpful
|
||||||
@@ -47,12 +47,12 @@ func (g *Graph) addEdgesByMatchingUIDS(v *Vertex, uids []resources.ResUID) []boo
|
|||||||
// remember, resources can return multiple UID's each!
|
// remember, resources can return multiple UID's each!
|
||||||
if resources.UIDExistsInUIDs(uid, vv.UIDs()) {
|
if resources.UIDExistsInUIDs(uid, vv.UIDs()) {
|
||||||
// add edge from: vv -> v
|
// add edge from: vv -> v
|
||||||
if uid.Reversed() {
|
if uid.IsReversed() {
|
||||||
txt := fmt.Sprintf("AutoEdge: %s[%s] -> %s[%s]", vv.Kind(), vv.GetName(), v.Kind(), v.GetName())
|
txt := fmt.Sprintf("AutoEdge: %s[%s] -> %s[%s]", vv.GetKind(), vv.GetName(), v.GetKind(), v.GetName())
|
||||||
log.Printf("Compile: Adding %s", txt)
|
log.Printf("Compile: Adding %s", txt)
|
||||||
g.AddEdge(vv, v, NewEdge(txt))
|
g.AddEdge(vv, v, NewEdge(txt))
|
||||||
} else { // edges go the "normal" way, eg: pkg resource
|
} else { // edges go the "normal" way, eg: pkg resource
|
||||||
txt := fmt.Sprintf("AutoEdge: %s[%s] -> %s[%s]", v.Kind(), v.GetName(), vv.Kind(), vv.GetName())
|
txt := fmt.Sprintf("AutoEdge: %s[%s] -> %s[%s]", v.GetKind(), v.GetName(), vv.GetKind(), vv.GetName())
|
||||||
log.Printf("Compile: Adding %s", txt)
|
log.Printf("Compile: Adding %s", txt)
|
||||||
g.AddEdge(v, vv, NewEdge(txt))
|
g.AddEdge(v, vv, NewEdge(txt))
|
||||||
}
|
}
|
||||||
@@ -74,14 +74,14 @@ func (g *Graph) AutoEdges() {
|
|||||||
}
|
}
|
||||||
autoEdgeObj := v.AutoEdges()
|
autoEdgeObj := v.AutoEdges()
|
||||||
if autoEdgeObj == nil {
|
if autoEdgeObj == nil {
|
||||||
log.Printf("%s[%s]: Config: No auto edges were found!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: Config: No auto edges were found!", v.GetKind(), v.GetName())
|
||||||
continue // next vertex
|
continue // next vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
for { // while the autoEdgeObj has more uids to add...
|
for { // while the autoEdgeObj has more uids to add...
|
||||||
uids := autoEdgeObj.Next() // get some!
|
uids := autoEdgeObj.Next() // get some!
|
||||||
if uids == nil {
|
if uids == nil {
|
||||||
log.Printf("%s[%s]: Config: The auto edge list is empty!", v.Kind(), v.GetName())
|
log.Printf("%s[%s]: Config: The auto edge list is empty!", v.GetKind(), v.GetName())
|
||||||
break // inner loop
|
break // inner loop
|
||||||
}
|
}
|
||||||
if g.Flags.Debug {
|
if g.Flags.Debug {
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ func (ag *baseGrouper) vertexCmp(v1, v2 *Vertex) error {
|
|||||||
if v1 == v2 { // skip yourself
|
if v1 == v2 { // skip yourself
|
||||||
return fmt.Errorf("the vertices are the same")
|
return fmt.Errorf("the vertices are the same")
|
||||||
}
|
}
|
||||||
if v1.Kind() != v2.Kind() { // we must group similar kinds
|
if v1.GetKind() != v2.GetKind() { // we must group similar kinds
|
||||||
// TODO: maybe future resources won't need this limitation?
|
// TODO: maybe future resources won't need this limitation?
|
||||||
return fmt.Errorf("the two resources aren't the same kind")
|
return fmt.Errorf("the two resources aren't the same kind")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func (g *Graph) Graphviz() (out string) {
|
|||||||
//out += "\tnode [shape=box];\n"
|
//out += "\tnode [shape=box];\n"
|
||||||
str := ""
|
str := ""
|
||||||
for i := range g.Adjacency { // reverse paths
|
for i := range g.Adjacency { // reverse paths
|
||||||
out += fmt.Sprintf("\t\"%s\" [label=\"%s[%s]\"];\n", i.GetName(), i.Kind(), i.GetName())
|
out += fmt.Sprintf("\t\"%s\" [label=\"%s[%s]\"];\n", i.GetName(), i.GetKind(), i.GetName())
|
||||||
for j := range g.Adjacency[i] {
|
for j := range g.Adjacency[i] {
|
||||||
k := g.Adjacency[i][j]
|
k := g.Adjacency[i][j]
|
||||||
// use str for clearer output ordering
|
// use str for clearer output ordering
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ func (g *Graph) String() string {
|
|||||||
|
|
||||||
// String returns the canonical form for a vertex
|
// String returns the canonical form for a vertex
|
||||||
func (v *Vertex) String() string {
|
func (v *Vertex) String() string {
|
||||||
return fmt.Sprintf("%s[%s]", v.Res.Kind(), v.Res.GetName())
|
return fmt.Sprintf("%s[%s]", v.Res.GetKind(), v.Res.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncomingGraphVertices returns an array (slice) of all directed vertices to
|
// IncomingGraphVertices returns an array (slice) of all directed vertices to
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func (obj *AugeasRes) Validate() error {
|
|||||||
|
|
||||||
// Init initiates the resource.
|
// Init initiates the resource.
|
||||||
func (obj *AugeasRes) Init() error {
|
func (obj *AugeasRes) Init() error {
|
||||||
obj.BaseRes.kind = "augeas"
|
obj.BaseRes.Kind = "augeas"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ func (obj *AugeasRes) Watch() error {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: Watching: %s", obj.Kind(), obj.GetName(), obj.File) // attempting to watch...
|
log.Printf("%s[%s]: Watching: %s", obj.GetKind(), obj.GetName(), obj.File) // attempting to watch...
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -128,10 +128,10 @@ func (obj *AugeasRes) Watch() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := event.Error; err != nil {
|
if err := event.Error; err != nil {
|
||||||
return errwrap.Wrapf(err, "Unknown %s[%s] watcher error", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "Unknown %s[%s] watcher error", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
if obj.debug { // don't access event.Body if event.Error isn't nil
|
if obj.debug { // don't access event.Body if event.Error isn't nil
|
||||||
log.Printf("%s[%s]: Event(%s): %v", obj.Kind(), obj.GetName(), event.Body.Name, event.Body.Op)
|
log.Printf("%s[%s]: Event(%s): %v", obj.GetKind(), obj.GetName(), event.Body.Name, event.Body.Op)
|
||||||
}
|
}
|
||||||
send = true
|
send = true
|
||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
@@ -178,7 +178,7 @@ func (obj *AugeasRes) checkApplySet(apply bool, ag *augeas.Augeas, set AugeasSet
|
|||||||
|
|
||||||
// CheckApply method for Augeas resource.
|
// CheckApply method for Augeas resource.
|
||||||
func (obj *AugeasRes) CheckApply(apply bool) (bool, error) {
|
func (obj *AugeasRes) CheckApply(apply bool) (bool, error) {
|
||||||
log.Printf("%s[%s]: CheckApply: %s", obj.Kind(), obj.GetName(), obj.File)
|
log.Printf("%s[%s]: CheckApply: %s", obj.GetKind(), obj.GetName(), obj.File)
|
||||||
// By default we do not set any option to augeas, we use the defaults.
|
// By default we do not set any option to augeas, we use the defaults.
|
||||||
opts := augeas.None
|
opts := augeas.None
|
||||||
if obj.Lens != "" {
|
if obj.Lens != "" {
|
||||||
@@ -226,7 +226,7 @@ func (obj *AugeasRes) CheckApply(apply bool) (bool, error) {
|
|||||||
return checkOK, nil
|
return checkOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%s[%s]: changes needed, saving", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: changes needed, saving", obj.GetKind(), obj.GetName())
|
||||||
if err = ag.Save(); err != nil {
|
if err = ag.Save(); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "augeas: error while saving augeas values")
|
return false, errwrap.Wrapf(err, "augeas: error while saving augeas values")
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ func (obj *AugeasRes) AutoEdges() AutoEdge {
|
|||||||
// UIDs includes all params to make a unique identification of this object.
|
// UIDs includes all params to make a unique identification of this object.
|
||||||
func (obj *AugeasRes) UIDs() []ResUID {
|
func (obj *AugeasRes) UIDs() []ResUID {
|
||||||
x := &AugeasUID{
|
x := &AugeasUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (obj *ExecRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *ExecRes) Init() error {
|
func (obj *ExecRes) Init() error {
|
||||||
obj.BaseRes.kind = "exec"
|
obj.BaseRes.Kind = "exec"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ func (obj *ExecRes) Watch() error {
|
|||||||
select {
|
select {
|
||||||
case text := <-bufioch:
|
case text := <-bufioch:
|
||||||
// each time we get a line of output, we loop!
|
// each time we get a line of output, we loop!
|
||||||
log.Printf("%s[%s]: Watch output: %s", obj.Kind(), obj.GetName(), text)
|
log.Printf("%s[%s]: Watch output: %s", obj.GetKind(), obj.GetName(), text)
|
||||||
if text != "" {
|
if text != "" {
|
||||||
send = true
|
send = true
|
||||||
obj.StateOK(false) // something made state dirty
|
obj.StateOK(false) // something made state dirty
|
||||||
@@ -220,7 +220,7 @@ func (obj *ExecRes) CheckApply(apply bool) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply portion
|
// apply portion
|
||||||
log.Printf("%s[%s]: Apply", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Apply", obj.GetKind(), obj.GetName())
|
||||||
var cmdName string
|
var cmdName string
|
||||||
var cmdArgs []string
|
var cmdArgs []string
|
||||||
if obj.Shell == "" {
|
if obj.Shell == "" {
|
||||||
@@ -288,10 +288,10 @@ func (obj *ExecRes) CheckApply(apply bool) (bool, error) {
|
|||||||
// would be nice, but it would require terminal log output that doesn't
|
// would be nice, but it would require terminal log output that doesn't
|
||||||
// interleave all the parallel parts which would mix it all up...
|
// interleave all the parallel parts which would mix it all up...
|
||||||
if s := out.String(); s == "" {
|
if s := out.String(); s == "" {
|
||||||
log.Printf("%s[%s]: Command output is empty!", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Command output is empty!", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%s[%s]: Command output is:", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Command output is:", obj.GetKind(), obj.GetName())
|
||||||
log.Printf(out.String())
|
log.Printf(out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ func (obj *ExecRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *ExecRes) UIDs() []ResUID {
|
func (obj *ExecRes) UIDs() []ResUID {
|
||||||
x := &ExecUID{
|
x := &ExecUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
Cmd: obj.Cmd,
|
Cmd: obj.Cmd,
|
||||||
IfCmd: obj.IfCmd,
|
IfCmd: obj.IfCmd,
|
||||||
// TODO: add more params here
|
// TODO: add more params here
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func (obj *FileRes) Init() error {
|
|||||||
obj.path = obj.GetPath() // compute once
|
obj.path = obj.GetPath() // compute once
|
||||||
obj.isDir = strings.HasSuffix(obj.path, "/") // dirs have trailing slashes
|
obj.isDir = strings.HasSuffix(obj.path, "/") // dirs have trailing slashes
|
||||||
|
|
||||||
obj.BaseRes.kind = "file"
|
obj.BaseRes.Kind = "file"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ func (obj *FileRes) Watch() error {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: Watching: %s", obj.Kind(), obj.GetName(), obj.path) // attempting to watch...
|
log.Printf("%s[%s]: Watching: %s", obj.GetKind(), obj.GetName(), obj.path) // attempting to watch...
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -208,10 +208,10 @@ func (obj *FileRes) Watch() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := event.Error; err != nil {
|
if err := event.Error; err != nil {
|
||||||
return errwrap.Wrapf(err, "unknown %s[%s] watcher error", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "unknown %s[%s] watcher error", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
if obj.debug { // don't access event.Body if event.Error isn't nil
|
if obj.debug { // don't access event.Body if event.Error isn't nil
|
||||||
log.Printf("%s[%s]: Event(%s): %v", obj.Kind(), obj.GetName(), event.Body.Name, event.Body.Op)
|
log.Printf("%s[%s]: Event(%s): %v", obj.GetKind(), obj.GetName(), event.Body.Name, event.Body.Op)
|
||||||
}
|
}
|
||||||
send = true
|
send = true
|
||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
@@ -636,7 +636,7 @@ func (obj *FileRes) syncCheckApply(apply bool, src, dst string) (bool, error) {
|
|||||||
|
|
||||||
// contentCheckApply performs a CheckApply for the file existence and content.
|
// contentCheckApply performs a CheckApply for the file existence and content.
|
||||||
func (obj *FileRes) contentCheckApply(apply bool) (checkOK bool, _ error) {
|
func (obj *FileRes) contentCheckApply(apply bool) (checkOK bool, _ error) {
|
||||||
log.Printf("%s[%s]: contentCheckApply(%t)", obj.Kind(), obj.GetName(), apply)
|
log.Printf("%s[%s]: contentCheckApply(%t)", obj.GetKind(), obj.GetName(), apply)
|
||||||
|
|
||||||
if obj.State == "absent" {
|
if obj.State == "absent" {
|
||||||
if _, err := os.Stat(obj.path); os.IsNotExist(err) {
|
if _, err := os.Stat(obj.path); os.IsNotExist(err) {
|
||||||
@@ -698,7 +698,7 @@ func (obj *FileRes) contentCheckApply(apply bool) (checkOK bool, _ error) {
|
|||||||
|
|
||||||
// chmodCheckApply performs a CheckApply for the file permissions.
|
// chmodCheckApply performs a CheckApply for the file permissions.
|
||||||
func (obj *FileRes) chmodCheckApply(apply bool) (checkOK bool, _ error) {
|
func (obj *FileRes) chmodCheckApply(apply bool) (checkOK bool, _ error) {
|
||||||
log.Printf("%s[%s]: chmodCheckApply(%t)", obj.Kind(), obj.GetName(), apply)
|
log.Printf("%s[%s]: chmodCheckApply(%t)", obj.GetKind(), obj.GetName(), apply)
|
||||||
|
|
||||||
if obj.State == "absent" {
|
if obj.State == "absent" {
|
||||||
// File is absent
|
// File is absent
|
||||||
@@ -744,7 +744,7 @@ func (obj *FileRes) chmodCheckApply(apply bool) (checkOK bool, _ error) {
|
|||||||
// chownCheckApply performs a CheckApply for the file ownership.
|
// chownCheckApply performs a CheckApply for the file ownership.
|
||||||
func (obj *FileRes) chownCheckApply(apply bool) (checkOK bool, _ error) {
|
func (obj *FileRes) chownCheckApply(apply bool) (checkOK bool, _ error) {
|
||||||
var expectedUID, expectedGID int
|
var expectedUID, expectedGID int
|
||||||
log.Printf("%s[%s]: chownCheckApply(%t)", obj.Kind(), obj.GetName(), apply)
|
log.Printf("%s[%s]: chownCheckApply(%t)", obj.GetKind(), obj.GetName(), apply)
|
||||||
|
|
||||||
if obj.State == "absent" {
|
if obj.State == "absent" {
|
||||||
// File is absent or no owner specified
|
// File is absent or no owner specified
|
||||||
@@ -906,9 +906,9 @@ func (obj *FileRes) AutoEdges() AutoEdge {
|
|||||||
var reversed = true // cheat by passing a pointer
|
var reversed = true // cheat by passing a pointer
|
||||||
data = append(data, &FileUID{
|
data = append(data, &FileUID{
|
||||||
BaseUID: BaseUID{
|
BaseUID: BaseUID{
|
||||||
name: obj.GetName(),
|
Name: obj.GetName(),
|
||||||
kind: obj.Kind(),
|
Kind: obj.GetKind(),
|
||||||
reversed: &reversed,
|
Reversed: &reversed,
|
||||||
},
|
},
|
||||||
path: x, // what matters
|
path: x, // what matters
|
||||||
}) // build list
|
}) // build list
|
||||||
@@ -924,7 +924,7 @@ func (obj *FileRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *FileRes) UIDs() []ResUID {
|
func (obj *FileRes) UIDs() []ResUID {
|
||||||
x := &FileUID{
|
x := &FileUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
path: obj.path,
|
path: obj.path,
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func (obj *HostnameRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *HostnameRes) Init() error {
|
func (obj *HostnameRes) Init() error {
|
||||||
obj.BaseRes.kind = "hostname"
|
obj.BaseRes.Kind = "hostname"
|
||||||
if obj.PrettyHostname == "" {
|
if obj.PrettyHostname == "" {
|
||||||
obj.PrettyHostname = obj.Hostname
|
obj.PrettyHostname = obj.Hostname
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ func (obj *HostnameRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *HostnameRes) UIDs() []ResUID {
|
func (obj *HostnameRes) UIDs() []ResUID {
|
||||||
x := &HostnameUID{
|
x := &HostnameUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
prettyHostname: obj.PrettyHostname,
|
prettyHostname: obj.PrettyHostname,
|
||||||
staticHostname: obj.StaticHostname,
|
staticHostname: obj.StaticHostname,
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func (obj *KVRes) Validate() error {
|
|||||||
|
|
||||||
// Init initializes the resource.
|
// Init initializes the resource.
|
||||||
func (obj *KVRes) Init() error {
|
func (obj *KVRes) Init() error {
|
||||||
obj.BaseRes.kind = "kv"
|
obj.BaseRes.Kind = "kv"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +113,10 @@ func (obj *KVRes) Watch() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errwrap.Wrapf(err, "unknown %s[%s] watcher error", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "unknown %s[%s] watcher error", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
if obj.Data().Debug {
|
if obj.Data().Debug {
|
||||||
log.Printf("%s[%s]: Event!", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Event!", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
send = true
|
send = true
|
||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
@@ -177,7 +177,7 @@ func (obj *KVRes) lessThanCheck(value string) (checkOK bool, err error) {
|
|||||||
|
|
||||||
// CheckApply method for Password resource. Does nothing, returns happy!
|
// CheckApply method for Password resource. Does nothing, returns happy!
|
||||||
func (obj *KVRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *KVRes) CheckApply(apply bool) (checkOK bool, err error) {
|
||||||
log.Printf("%s[%s]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply)
|
log.Printf("%s[%s]: CheckApply(%t)", obj.GetKind(), obj.GetName(), apply)
|
||||||
|
|
||||||
if val, exists := obj.Recv["Value"]; exists && val.Changed {
|
if val, exists := obj.Recv["Value"]; exists && val.Changed {
|
||||||
// if we received on Value, and it changed, wooo, nothing to do.
|
// if we received on Value, and it changed, wooo, nothing to do.
|
||||||
@@ -235,7 +235,7 @@ func (obj *KVRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *KVRes) UIDs() []ResUID {
|
func (obj *KVRes) UIDs() []ResUID {
|
||||||
x := &KVUID{
|
x := &KVUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (obj *MsgRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *MsgRes) Init() error {
|
func (obj *MsgRes) Init() error {
|
||||||
obj.BaseRes.kind = "msg"
|
obj.BaseRes.Kind = "msg"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overrriding
|
return obj.BaseRes.Init() // call base init, b/c we're overrriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ func (obj *MsgRes) CheckApply(apply bool) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !obj.logStateOK {
|
if !obj.logStateOK {
|
||||||
log.Printf("%s[%s]: Body: %s", obj.Kind(), obj.GetName(), obj.Body)
|
log.Printf("%s[%s]: Body: %s", obj.GetKind(), obj.GetName(), obj.Body)
|
||||||
obj.logStateOK = true
|
obj.logStateOK = true
|
||||||
obj.updateStateOK()
|
obj.updateStateOK()
|
||||||
}
|
}
|
||||||
@@ -196,8 +196,8 @@ func (obj *MsgRes) CheckApply(apply bool) (bool, error) {
|
|||||||
func (obj *MsgRes) UIDs() []ResUID {
|
func (obj *MsgRes) UIDs() []ResUID {
|
||||||
x := &MsgUID{
|
x := &MsgUID{
|
||||||
BaseUID: BaseUID{
|
BaseUID: BaseUID{
|
||||||
name: obj.GetName(),
|
Name: obj.GetName(),
|
||||||
kind: obj.Kind(),
|
Kind: obj.GetKind(),
|
||||||
},
|
},
|
||||||
body: obj.Body,
|
body: obj.Body,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (obj *NoopRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *NoopRes) Init() error {
|
func (obj *NoopRes) Init() error {
|
||||||
obj.BaseRes.kind = "noop"
|
obj.BaseRes.Kind = "noop"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ func (obj *NoopRes) Watch() error {
|
|||||||
// CheckApply method for Noop resource. Does nothing, returns happy!
|
// CheckApply method for Noop resource. Does nothing, returns happy!
|
||||||
func (obj *NoopRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *NoopRes) CheckApply(apply bool) (checkOK bool, err error) {
|
||||||
if obj.Refresh() {
|
if obj.Refresh() {
|
||||||
log.Printf("%s[%s]: Received a notification!", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Received a notification!", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
return true, nil // state is always okay
|
return true, nil // state is always okay
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ func (obj *NoopRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *NoopRes) UIDs() []ResUID {
|
func (obj *NoopRes) UIDs() []ResUID {
|
||||||
x := &NoopUID{
|
x := &NoopUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func (obj *NspawnRes) Init() error {
|
|||||||
if err := obj.svc.Init(); err != nil {
|
if err := obj.svc.Init(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
obj.BaseRes.kind = "nspawn"
|
obj.BaseRes.Kind = "nspawn"
|
||||||
return obj.BaseRes.Init()
|
return obj.BaseRes.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,11 +134,11 @@ func (obj *NspawnRes) Watch() error {
|
|||||||
case event := <-buschan:
|
case event := <-buschan:
|
||||||
// process org.freedesktop.machine1 events for this resource's name
|
// process org.freedesktop.machine1 events for this resource's name
|
||||||
if event.Body[0] == obj.GetName() {
|
if event.Body[0] == obj.GetName() {
|
||||||
log.Printf("%s[%s]: Event received: %v", obj.Kind(), obj.GetName(), event.Name)
|
log.Printf("%s[%s]: Event received: %v", obj.GetKind(), obj.GetName(), event.Name)
|
||||||
if event.Name == machineNew {
|
if event.Name == machineNew {
|
||||||
log.Printf("%s[%s]: Machine started", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Machine started", obj.GetKind(), obj.GetName())
|
||||||
} else if event.Name == machineRemoved {
|
} else if event.Name == machineRemoved {
|
||||||
log.Printf("%s[%s]: Machine stopped", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Machine stopped", obj.GetKind(), obj.GetName())
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("unknown event: %s", event.Name)
|
return fmt.Errorf("unknown event: %s", event.Name)
|
||||||
}
|
}
|
||||||
@@ -195,13 +195,13 @@ func (obj *NspawnRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: properties: %v", obj.Kind(), obj.GetName(), properties)
|
log.Printf("%s[%s]: properties: %v", obj.GetKind(), obj.GetName(), properties)
|
||||||
}
|
}
|
||||||
// if the machine doesn't exist and is supposed to
|
// if the machine doesn't exist and is supposed to
|
||||||
// be stopped or the state matches we're done
|
// be stopped or the state matches we're done
|
||||||
if !exists && obj.State == stopped || properties["State"] == obj.State {
|
if !exists && obj.State == stopped || properties["State"] == obj.State {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: CheckApply() in valid state", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: CheckApply() in valid state", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@@ -212,12 +212,12 @@ func (obj *NspawnRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: CheckApply() applying '%s' state", obj.Kind(), obj.GetName(), obj.State)
|
log.Printf("%s[%s]: CheckApply() applying '%s' state", obj.GetKind(), obj.GetName(), obj.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State == running {
|
if obj.State == running {
|
||||||
// start the machine using svc resource
|
// start the machine using svc resource
|
||||||
log.Printf("%s[%s]: Starting machine", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Starting machine", obj.GetKind(), obj.GetName())
|
||||||
// assume state had to be changed at this point, ignore checkOK
|
// assume state had to be changed at this point, ignore checkOK
|
||||||
if _, err := obj.svc.CheckApply(apply); err != nil {
|
if _, err := obj.svc.CheckApply(apply); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "nested svc failed")
|
return false, errwrap.Wrapf(err, "nested svc failed")
|
||||||
@@ -226,7 +226,7 @@ func (obj *NspawnRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
if obj.State == stopped {
|
if obj.State == stopped {
|
||||||
// terminate the machine with
|
// terminate the machine with
|
||||||
// org.freedesktop.machine1.Manager.KillMachine
|
// org.freedesktop.machine1.Manager.KillMachine
|
||||||
log.Printf("%s[%s]: Stopping machine", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Stopping machine", obj.GetKind(), obj.GetName())
|
||||||
if err := conn.TerminateMachine(obj.GetName()); err != nil {
|
if err := conn.TerminateMachine(obj.GetName()); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "failed to stop machine")
|
return false, errwrap.Wrapf(err, "failed to stop machine")
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,7 @@ func (obj *NspawnUID) IFF(uid ResUID) bool {
|
|||||||
// most resources only return one although some resources can return multiple
|
// most resources only return one although some resources can return multiple
|
||||||
func (obj *NspawnRes) UIDs() []ResUID {
|
func (obj *NspawnRes) UIDs() []ResUID {
|
||||||
x := &NspawnUID{
|
x := &NspawnUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name, // svc name
|
name: obj.Name, // svc name
|
||||||
}
|
}
|
||||||
return append([]ResUID{x}, obj.svc.UIDs()...)
|
return append([]ResUID{x}, obj.svc.UIDs()...)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func (obj *PasswordRes) Validate() error {
|
|||||||
// Init generates a new password for this resource if one was not provided. It
|
// Init generates a new password for this resource if one was not provided. It
|
||||||
// will save this into a local file. It will load it back in from previous runs.
|
// will save this into a local file. It will load it back in from previous runs.
|
||||||
func (obj *PasswordRes) Init() error {
|
func (obj *PasswordRes) Init() error {
|
||||||
obj.BaseRes.kind = "password" // must be set before using VarDir
|
obj.BaseRes.Kind = "password" // must be set before using VarDir
|
||||||
|
|
||||||
dir, err := obj.VarDir("")
|
dir, err := obj.VarDir("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -188,7 +188,7 @@ func (obj *PasswordRes) Watch() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := event.Error; err != nil {
|
if err := event.Error; err != nil {
|
||||||
return errwrap.Wrapf(err, "unknown %s[%s] watcher error", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "unknown %s[%s] watcher error", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
send = true
|
send = true
|
||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
@@ -229,7 +229,7 @@ func (obj *PasswordRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
if !obj.CheckRecovery {
|
if !obj.CheckRecovery {
|
||||||
return false, errwrap.Wrapf(err, "check failed")
|
return false, errwrap.Wrapf(err, "check failed")
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Integrity check failed", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Integrity check failed", obj.GetKind(), obj.GetName())
|
||||||
generate = true // okay to build a new one
|
generate = true // okay to build a new one
|
||||||
write = true // make sure to write over the old one
|
write = true // make sure to write over the old one
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ func (obj *PasswordRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
}
|
}
|
||||||
// generate the actual password
|
// generate the actual password
|
||||||
var err error
|
var err error
|
||||||
log.Printf("%s[%s]: Generating new password...", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Generating new password...", obj.GetKind(), obj.GetName())
|
||||||
if password, err = obj.generate(); err != nil { // generate one!
|
if password, err = obj.generate(); err != nil { // generate one!
|
||||||
return false, errwrap.Wrapf(err, "could not generate password")
|
return false, errwrap.Wrapf(err, "could not generate password")
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ func (obj *PasswordRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
output = password
|
output = password
|
||||||
}
|
}
|
||||||
// write either an empty token, or the password
|
// write either an empty token, or the password
|
||||||
log.Printf("%s[%s]: Writing password token...", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Writing password token...", obj.GetKind(), obj.GetName())
|
||||||
if _, err := obj.write(output); err != nil {
|
if _, err := obj.write(output); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "can't write to file")
|
return false, errwrap.Wrapf(err, "can't write to file")
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,7 @@ func (obj *PasswordRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *PasswordRes) UIDs() []ResUID {
|
func (obj *PasswordRes) UIDs() []ResUID {
|
||||||
x := &PasswordUID{
|
x := &PasswordUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func (obj *PkgRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *PkgRes) Init() error {
|
func (obj *PkgRes) Init() error {
|
||||||
obj.BaseRes.kind = "pkg"
|
obj.BaseRes.Kind = "pkg"
|
||||||
if err := obj.BaseRes.Init(); err != nil { // call base init, b/c we're overriding
|
if err := obj.BaseRes.Init(); err != nil { // call base init, b/c we're overriding
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -179,9 +179,9 @@ func (obj *PkgRes) getNames() []string {
|
|||||||
// pretty print for header values
|
// pretty print for header values
|
||||||
func (obj *PkgRes) fmtNames(names []string) string {
|
func (obj *PkgRes) fmtNames(names []string) string {
|
||||||
if len(obj.GetGroup()) > 0 { // grouped elements
|
if len(obj.GetGroup()) > 0 { // grouped elements
|
||||||
return fmt.Sprintf("%s[autogroup:(%v)]", obj.Kind(), strings.Join(names, ","))
|
return fmt.Sprintf("%s[autogroup:(%v)]", obj.GetKind(), strings.Join(names, ","))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s[%s]", obj.Kind(), obj.GetName())
|
return fmt.Sprintf("%s[%s]", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *PkgRes) groupMappingHelper() map[string]string {
|
func (obj *PkgRes) groupMappingHelper() map[string]string {
|
||||||
@@ -190,7 +190,7 @@ func (obj *PkgRes) groupMappingHelper() map[string]string {
|
|||||||
for _, x := range g {
|
for _, x := range g {
|
||||||
pkg, ok := x.(*PkgRes) // convert from Res
|
pkg, ok := x.(*PkgRes) // convert from Res
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatalf("grouped member %v is not a %s", x, obj.Kind())
|
log.Fatalf("grouped member %v is not a %s", x, obj.GetKind())
|
||||||
}
|
}
|
||||||
result[pkg.Name] = pkg.State
|
result[pkg.Name] = pkg.State
|
||||||
}
|
}
|
||||||
@@ -356,9 +356,9 @@ func (obj *PkgResAutoEdges) Next() []ResUID {
|
|||||||
var reversed = false // cheat by passing a pointer
|
var reversed = false // cheat by passing a pointer
|
||||||
result = append(result, &FileUID{
|
result = append(result, &FileUID{
|
||||||
BaseUID: BaseUID{
|
BaseUID: BaseUID{
|
||||||
name: obj.name,
|
Name: obj.name,
|
||||||
kind: obj.kind,
|
Kind: obj.kind,
|
||||||
reversed: &reversed,
|
Reversed: &reversed,
|
||||||
},
|
},
|
||||||
path: x, // what matters
|
path: x, // what matters
|
||||||
}) // build list
|
}) // build list
|
||||||
@@ -430,9 +430,9 @@ func (obj *PkgRes) AutoEdges() AutoEdge {
|
|||||||
var reversed = false
|
var reversed = false
|
||||||
svcUIDs = append(svcUIDs, &SvcUID{
|
svcUIDs = append(svcUIDs, &SvcUID{
|
||||||
BaseUID: BaseUID{
|
BaseUID: BaseUID{
|
||||||
name: obj.GetName(),
|
Name: obj.GetName(),
|
||||||
kind: obj.Kind(),
|
Kind: obj.GetKind(),
|
||||||
reversed: &reversed,
|
Reversed: &reversed,
|
||||||
},
|
},
|
||||||
name: x, // the svc name itself in the SvcUID object!
|
name: x, // the svc name itself in the SvcUID object!
|
||||||
}) // build list
|
}) // build list
|
||||||
@@ -443,7 +443,7 @@ func (obj *PkgRes) AutoEdges() AutoEdge {
|
|||||||
svcUIDs: svcUIDs,
|
svcUIDs: svcUIDs,
|
||||||
testIsNext: false, // start with Next() call
|
testIsNext: false, // start with Next() call
|
||||||
name: obj.GetName(), // save data for PkgResAutoEdges obj
|
name: obj.GetName(), // save data for PkgResAutoEdges obj
|
||||||
kind: obj.Kind(),
|
kind: obj.GetKind(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ func (obj *PkgRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *PkgRes) UIDs() []ResUID {
|
func (obj *PkgRes) UIDs() []ResUID {
|
||||||
x := &PkgUID{
|
x := &PkgUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
state: obj.State,
|
state: obj.State,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,18 +101,18 @@ type Data struct {
|
|||||||
// ResUID is a unique identifier for a resource, namely it's name, and the kind ("type").
|
// ResUID is a unique identifier for a resource, namely it's name, and the kind ("type").
|
||||||
type ResUID interface {
|
type ResUID interface {
|
||||||
GetName() string
|
GetName() string
|
||||||
Kind() string
|
GetKind() string
|
||||||
IFF(ResUID) bool
|
IFF(ResUID) bool
|
||||||
|
|
||||||
Reversed() bool // true means this resource happens before the generator
|
IsReversed() bool // true means this resource happens before the generator
|
||||||
}
|
}
|
||||||
|
|
||||||
// The BaseUID struct is used to provide a unique resource identifier.
|
// The BaseUID struct is used to provide a unique resource identifier.
|
||||||
type BaseUID struct {
|
type BaseUID struct {
|
||||||
name string // name and kind are the values of where this is coming from
|
Name string // name and kind are the values of where this is coming from
|
||||||
kind string
|
Kind string
|
||||||
|
|
||||||
reversed *bool // piggyback edge information here
|
Reversed *bool // piggyback edge information here
|
||||||
}
|
}
|
||||||
|
|
||||||
// The AutoEdge interface is used to implement the autoedges feature.
|
// The AutoEdge interface is used to implement the autoedges feature.
|
||||||
@@ -170,7 +170,7 @@ type Base interface {
|
|||||||
GetName() string // can't be named "Name()" because of struct field
|
GetName() string // can't be named "Name()" because of struct field
|
||||||
SetName(string)
|
SetName(string)
|
||||||
SetKind(string)
|
SetKind(string)
|
||||||
Kind() string
|
GetKind() string
|
||||||
Meta() *MetaParams
|
Meta() *MetaParams
|
||||||
Events() chan *event.Event
|
Events() chan *event.Event
|
||||||
Data() *Data
|
Data() *Data
|
||||||
@@ -232,7 +232,7 @@ type BaseRes struct {
|
|||||||
MetaParams MetaParams `yaml:"meta"` // struct of all the metaparams
|
MetaParams MetaParams `yaml:"meta"` // struct of all the metaparams
|
||||||
Recv map[string]*Send // mapping of key to receive on from value
|
Recv map[string]*Send // mapping of key to receive on from value
|
||||||
|
|
||||||
kind string
|
Kind string
|
||||||
data Data
|
data Data
|
||||||
state ResState
|
state ResState
|
||||||
prefix string // base prefix for this resource
|
prefix string // base prefix for this resource
|
||||||
@@ -305,12 +305,12 @@ func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool {
|
|||||||
|
|
||||||
// GetName returns the name of the resource.
|
// GetName returns the name of the resource.
|
||||||
func (obj *BaseUID) GetName() string {
|
func (obj *BaseUID) GetName() string {
|
||||||
return obj.name
|
return obj.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind returns the kind of resource.
|
// GetKind returns the kind of the resource.
|
||||||
func (obj *BaseUID) Kind() string {
|
func (obj *BaseUID) GetKind() string {
|
||||||
return obj.kind
|
return obj.Kind
|
||||||
}
|
}
|
||||||
|
|
||||||
// IFF looks at two UID's and if and only if they are equivalent, returns true.
|
// IFF looks at two UID's and if and only if they are equivalent, returns true.
|
||||||
@@ -322,16 +322,16 @@ func (obj *BaseUID) IFF(uid ResUID) bool {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return obj.name == res.name
|
return obj.Name == res.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reversed is part of the ResUID interface, and true means this resource
|
// IsReversed is part of the ResUID interface, and true means this resource
|
||||||
// happens before the generator.
|
// happens before the generator.
|
||||||
func (obj *BaseUID) Reversed() bool {
|
func (obj *BaseUID) IsReversed() bool {
|
||||||
if obj.reversed == nil {
|
if obj.Reversed == nil {
|
||||||
log.Fatal("Programming error!")
|
log.Fatal("Programming error!")
|
||||||
}
|
}
|
||||||
return *obj.reversed
|
return *obj.Reversed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate reports any problems with the struct definition.
|
// Validate reports any problems with the struct definition.
|
||||||
@@ -346,9 +346,9 @@ func (obj *BaseRes) Validate() error {
|
|||||||
// Init initializes structures like channels if created without New constructor.
|
// Init initializes structures like channels if created without New constructor.
|
||||||
func (obj *BaseRes) Init() error {
|
func (obj *BaseRes) Init() error {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: Init()", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Init()", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
if obj.kind == "" {
|
if obj.Kind == "" {
|
||||||
return fmt.Errorf("resource did not set kind")
|
return fmt.Errorf("resource did not set kind")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ func (obj *BaseRes) Init() error {
|
|||||||
// TODO: this StatefulBool implementation could be eventually swappable
|
// TODO: this StatefulBool implementation could be eventually swappable
|
||||||
//obj.refreshState = &DiskBool{Path: path.Join(dir, refreshPathToken)}
|
//obj.refreshState = &DiskBool{Path: path.Join(dir, refreshPathToken)}
|
||||||
|
|
||||||
if err := obj.Prometheus().AddManagedResource(fmt.Sprintf("%s[%s]", obj.Kind(), obj.GetName()), obj.Kind()); err != nil {
|
if err := obj.Prometheus().AddManagedResource(fmt.Sprintf("%s[%s]", obj.GetKind(), obj.GetName()), obj.GetKind()); err != nil {
|
||||||
return errwrap.Wrapf(err, "could not increase prometheus counter!")
|
return errwrap.Wrapf(err, "could not increase prometheus counter!")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ func (obj *BaseRes) Init() error {
|
|||||||
// Close shuts down and performs any cleanup.
|
// Close shuts down and performs any cleanup.
|
||||||
func (obj *BaseRes) Close() error {
|
func (obj *BaseRes) Close() error {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: Close()", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Close()", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.pcuid.Unregister()
|
obj.pcuid.Unregister()
|
||||||
@@ -404,7 +404,7 @@ func (obj *BaseRes) Close() error {
|
|||||||
close(obj.stopped)
|
close(obj.stopped)
|
||||||
obj.waitGroup.Done()
|
obj.waitGroup.Done()
|
||||||
|
|
||||||
if err := obj.Prometheus().RemoveManagedResource(fmt.Sprintf("%s[%s]", obj.Kind(), obj.GetName()), obj.kind); err != nil {
|
if err := obj.Prometheus().RemoveManagedResource(fmt.Sprintf("%s[%s]", obj.GetKind(), obj.GetName()), obj.GetKind()); err != nil {
|
||||||
return errwrap.Wrapf(err, "could not decrease prometheus counter!")
|
return errwrap.Wrapf(err, "could not decrease prometheus counter!")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,12 +423,12 @@ func (obj *BaseRes) SetName(name string) {
|
|||||||
|
|
||||||
// SetKind sets the kind. This is used internally for exported resources.
|
// SetKind sets the kind. This is used internally for exported resources.
|
||||||
func (obj *BaseRes) SetKind(kind string) {
|
func (obj *BaseRes) SetKind(kind string) {
|
||||||
obj.kind = kind
|
obj.Kind = kind
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind returns the kind of resource this is.
|
// GetKind returns the kind of resource this is.
|
||||||
func (obj *BaseRes) Kind() string {
|
func (obj *BaseRes) GetKind() string {
|
||||||
return obj.kind
|
return obj.Kind
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta returns the MetaParams as a reference, which we can then get/set on.
|
// Meta returns the MetaParams as a reference, which we can then get/set on.
|
||||||
@@ -502,7 +502,7 @@ func (obj *BaseRes) GetState() ResState {
|
|||||||
// SetState sets the state of the resource.
|
// SetState sets the state of the resource.
|
||||||
func (obj *BaseRes) SetState(state ResState) {
|
func (obj *BaseRes) SetState(state ResState) {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
log.Printf("%s[%s]: State: %v -> %v", obj.Kind(), obj.GetName(), obj.GetState(), state)
|
log.Printf("%s[%s]: State: %v -> %v", obj.GetKind(), obj.GetName(), obj.GetState(), state)
|
||||||
}
|
}
|
||||||
obj.state = state
|
obj.state = state
|
||||||
}
|
}
|
||||||
@@ -644,7 +644,7 @@ func (obj *BaseRes) VarDir(extra string) (string, error) {
|
|||||||
if obj.prefix == "" {
|
if obj.prefix == "" {
|
||||||
return "", fmt.Errorf("the VarDir prefix is empty")
|
return "", fmt.Errorf("the VarDir prefix is empty")
|
||||||
}
|
}
|
||||||
if obj.Kind() == "" {
|
if obj.GetKind() == "" {
|
||||||
return "", fmt.Errorf("the VarDir kind is empty")
|
return "", fmt.Errorf("the VarDir kind is empty")
|
||||||
}
|
}
|
||||||
if obj.GetName() == "" {
|
if obj.GetName() == "" {
|
||||||
@@ -653,9 +653,9 @@ func (obj *BaseRes) VarDir(extra string) (string, error) {
|
|||||||
|
|
||||||
// FIXME: is obj.GetName() sufficiently unique to use as a UID here?
|
// FIXME: is obj.GetName() sufficiently unique to use as a UID here?
|
||||||
uid := obj.GetName()
|
uid := obj.GetName()
|
||||||
p := fmt.Sprintf("%s/", path.Join(obj.prefix, obj.Kind(), uid, extra))
|
p := fmt.Sprintf("%s/", path.Join(obj.prefix, obj.GetKind(), uid, extra))
|
||||||
if err := os.MkdirAll(p, 0770); err != nil {
|
if err := os.MkdirAll(p, 0770); err != nil {
|
||||||
return "", errwrap.Wrapf(err, "can't create prefix for %s[%s]", obj.Kind(), obj.GetName())
|
return "", errwrap.Wrapf(err, "can't create prefix for %s[%s]", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
@@ -689,7 +689,7 @@ func (obj *BaseRes) Poll() error {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C: // received the timer event
|
case <-ticker.C: // received the timer event
|
||||||
log.Printf("%s[%s]: polling...", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: polling...", obj.GetKind(), obj.GetName())
|
||||||
send = true
|
send = true
|
||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
|
|
||||||
|
|||||||
@@ -106,9 +106,9 @@ func TestMiscEncodeDecode2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIFF(t *testing.T) {
|
func TestIFF(t *testing.T) {
|
||||||
uid := &BaseUID{name: "/tmp/unit-test"}
|
uid := &BaseUID{Name: "/tmp/unit-test"}
|
||||||
same := &BaseUID{name: "/tmp/unit-test"}
|
same := &BaseUID{Name: "/tmp/unit-test"}
|
||||||
diff := &BaseUID{name: "/tmp/other-file"}
|
diff := &BaseUID{Name: "/tmp/other-file"}
|
||||||
|
|
||||||
if !uid.IFF(same) {
|
if !uid.IFF(same) {
|
||||||
t.Error("basic resource UIDs with the same name should satisfy each other's IFF condition.")
|
t.Error("basic resource UIDs with the same name should satisfy each other's IFF condition.")
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ func (obj *BaseRes) Event() error {
|
|||||||
func (obj *BaseRes) SendEvent(ev event.Kind, err error) error {
|
func (obj *BaseRes) SendEvent(ev event.Kind, err error) error {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("%s[%s]: SendEvent(%+v)", obj.Kind(), obj.GetName(), ev)
|
log.Printf("%s[%s]: SendEvent(%+v)", obj.GetKind(), obj.GetName(), ev)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%s[%s]: SendEvent(%+v): %v", obj.Kind(), obj.GetName(), ev, err)
|
log.Printf("%s[%s]: SendEvent(%+v): %v", obj.GetKind(), obj.GetName(), ev, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp := event.NewResp()
|
resp := event.NewResp()
|
||||||
@@ -129,7 +129,7 @@ func (obj *BaseRes) ReadEvent(ev *event.Event) (exit *error, send bool) {
|
|||||||
continue // silently discard this event while paused
|
continue // silently discard this event while paused
|
||||||
}
|
}
|
||||||
// if we get a poke event here, it's a bug!
|
// if we get a poke event here, it's a bug!
|
||||||
err = fmt.Errorf("%s[%s]: unknown event: %v, while paused", obj.Kind(), obj.GetName(), e)
|
err = fmt.Errorf("%s[%s]: unknown event: %v, while paused", obj.GetKind(), obj.GetName(), e)
|
||||||
panic(err) // TODO: return a special sentinel instead?
|
panic(err) // TODO: return a special sentinel instead?
|
||||||
//return &err, false
|
//return &err, false
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ type Send struct {
|
|||||||
func (obj *BaseRes) SendRecv(res Res) (map[string]bool, error) {
|
func (obj *BaseRes) SendRecv(res Res) (map[string]bool, error) {
|
||||||
if obj.debug {
|
if obj.debug {
|
||||||
// NOTE: this could expose private resource data like passwords
|
// NOTE: this could expose private resource data like passwords
|
||||||
log.Printf("%s[%s]: SendRecv: %+v", obj.Kind(), obj.GetName(), obj.Recv)
|
log.Printf("%s[%s]: SendRecv: %+v", obj.GetKind(), obj.GetName(), obj.Recv)
|
||||||
}
|
}
|
||||||
var updated = make(map[string]bool) // list of updated keys
|
var updated = make(map[string]bool) // list of updated keys
|
||||||
var err error
|
var err error
|
||||||
@@ -205,7 +205,7 @@ func (obj *BaseRes) SendRecv(res Res) (map[string]bool, error) {
|
|||||||
|
|
||||||
// i think we probably want the same kind, at least for now...
|
// i think we probably want the same kind, at least for now...
|
||||||
if kind1 != kind2 {
|
if kind1 != kind2 {
|
||||||
e := fmt.Errorf("kind mismatch between %s[%s]: %s and %s[%s]: %s", v.Res.Kind(), v.Res.GetName(), kind1, obj.Kind(), obj.GetName(), kind2)
|
e := fmt.Errorf("kind mismatch between %s[%s]: %s and %s[%s]: %s", v.Res.GetKind(), v.Res.GetName(), kind1, obj.GetKind(), obj.GetName(), kind2)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = multierr.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -213,21 +213,21 @@ func (obj *BaseRes) SendRecv(res Res) (map[string]bool, error) {
|
|||||||
// if the types don't match, we can't use send->recv
|
// if the types don't match, we can't use send->recv
|
||||||
// TODO: do we want to relax this for string -> *string ?
|
// TODO: do we want to relax this for string -> *string ?
|
||||||
if e := TypeCmp(value1, value2); e != nil {
|
if e := TypeCmp(value1, value2); e != nil {
|
||||||
e := errwrap.Wrapf(e, "type mismatch between %s[%s] and %s[%s]", v.Res.Kind(), v.Res.GetName(), obj.Kind(), obj.GetName())
|
e := errwrap.Wrapf(e, "type mismatch between %s[%s] and %s[%s]", v.Res.GetKind(), v.Res.GetName(), obj.GetKind(), obj.GetName())
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = multierr.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we can't set, then well this is pointless!
|
// if we can't set, then well this is pointless!
|
||||||
if !value2.CanSet() {
|
if !value2.CanSet() {
|
||||||
e := fmt.Errorf("can't set %s[%s].%s", obj.Kind(), obj.GetName(), k)
|
e := fmt.Errorf("can't set %s[%s].%s", obj.GetKind(), obj.GetName(), k)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = multierr.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we can't interface, we can't compare...
|
// if we can't interface, we can't compare...
|
||||||
if !value1.CanInterface() || !value2.CanInterface() {
|
if !value1.CanInterface() || !value2.CanInterface() {
|
||||||
e := fmt.Errorf("can't interface %s[%s].%s", obj.Kind(), obj.GetName(), k)
|
e := fmt.Errorf("can't interface %s[%s].%s", obj.GetKind(), obj.GetName(), k)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = multierr.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ func (obj *BaseRes) SendRecv(res Res) (map[string]bool, error) {
|
|||||||
value2.Set(value1) // do it for all types that match
|
value2.Set(value1) // do it for all types that match
|
||||||
updated[k] = true // we updated this key!
|
updated[k] = true // we updated this key!
|
||||||
v.Changed = true // tag this key as updated!
|
v.Changed = true // tag this key as updated!
|
||||||
log.Printf("SendRecv: %s[%s].%s -> %s[%s].%s", v.Res.Kind(), v.Res.GetName(), v.Key, obj.Kind(), obj.GetName(), k)
|
log.Printf("SendRecv: %s[%s].%s -> %s[%s].%s", v.Res.GetKind(), v.Res.GetName(), v.Key, obj.GetKind(), obj.GetName(), k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return updated, err
|
return updated, err
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func (obj *SvcRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *SvcRes) Init() error {
|
func (obj *SvcRes) Init() error {
|
||||||
obj.BaseRes.kind = "svc"
|
obj.BaseRes.Kind = "svc"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ func (obj *SvcRes) Watch() error {
|
|||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
|
|
||||||
case err := <-subErrors:
|
case err := <-subErrors:
|
||||||
return errwrap.Wrapf(err, "unknown %s[%s] error", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "unknown %s[%s] error", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
case event := <-obj.Events():
|
case event := <-obj.Events():
|
||||||
if exit, send = obj.ReadEvent(event); exit != nil {
|
if exit, send = obj.ReadEvent(event); exit != nil {
|
||||||
@@ -267,7 +267,7 @@ func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply portion
|
// apply portion
|
||||||
log.Printf("%s[%s]: Apply", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Apply", obj.GetKind(), obj.GetName())
|
||||||
var files = []string{svc} // the svc represented in a list
|
var files = []string{svc} // the svc represented in a list
|
||||||
if obj.Startup == "enabled" {
|
if obj.Startup == "enabled" {
|
||||||
_, _, err = conn.EnableUnitFiles(files, false, true)
|
_, _, err = conn.EnableUnitFiles(files, false, true)
|
||||||
@@ -289,7 +289,7 @@ func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
return false, errwrap.Wrapf(err, "failed to start unit")
|
return false, errwrap.Wrapf(err, "failed to start unit")
|
||||||
}
|
}
|
||||||
if refresh {
|
if refresh {
|
||||||
log.Printf("%s[%s]: Skipping reload, due to pending start", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Skipping reload, due to pending start", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
refresh = false // we did a start, so a reload is not needed
|
refresh = false // we did a start, so a reload is not needed
|
||||||
} else if obj.State == "stopped" {
|
} else if obj.State == "stopped" {
|
||||||
@@ -298,7 +298,7 @@ func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
return false, errwrap.Wrapf(err, "failed to stop unit")
|
return false, errwrap.Wrapf(err, "failed to stop unit")
|
||||||
}
|
}
|
||||||
if refresh {
|
if refresh {
|
||||||
log.Printf("%s[%s]: Skipping reload, due to pending stop", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Skipping reload, due to pending stop", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
refresh = false // we did a stop, so a reload is not needed
|
refresh = false // we did a stop, so a reload is not needed
|
||||||
}
|
}
|
||||||
@@ -313,7 +313,7 @@ func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
|
|
||||||
if refresh { // we need to reload the service
|
if refresh { // we need to reload the service
|
||||||
// XXX: run a svc reload here!
|
// XXX: run a svc reload here!
|
||||||
log.Printf("%s[%s]: Reloading...", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Reloading...", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: also set enabled on boot
|
// XXX: also set enabled on boot
|
||||||
@@ -390,9 +390,9 @@ func (obj *SvcRes) AutoEdges() AutoEdge {
|
|||||||
var reversed = true
|
var reversed = true
|
||||||
data = append(data, &FileUID{
|
data = append(data, &FileUID{
|
||||||
BaseUID: BaseUID{
|
BaseUID: BaseUID{
|
||||||
name: obj.GetName(),
|
Name: obj.GetName(),
|
||||||
kind: obj.Kind(),
|
Kind: obj.GetKind(),
|
||||||
reversed: &reversed,
|
Reversed: &reversed,
|
||||||
},
|
},
|
||||||
path: x, // what matters
|
path: x, // what matters
|
||||||
})
|
})
|
||||||
@@ -408,7 +408,7 @@ func (obj *SvcRes) AutoEdges() AutoEdge {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *SvcRes) UIDs() []ResUID {
|
func (obj *SvcRes) UIDs() []ResUID {
|
||||||
x := &SvcUID{
|
x := &SvcUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
name: obj.Name, // svc name
|
name: obj.Name, // svc name
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (obj *TimerRes) Validate() error {
|
|||||||
|
|
||||||
// Init runs some startup code for this resource.
|
// Init runs some startup code for this resource.
|
||||||
func (obj *TimerRes) Init() error {
|
func (obj *TimerRes) Init() error {
|
||||||
obj.BaseRes.kind = "timer"
|
obj.BaseRes.Kind = "timer"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overrriding
|
return obj.BaseRes.Init() // call base init, b/c we're overrriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ func (obj *TimerRes) Watch() error {
|
|||||||
select {
|
select {
|
||||||
case <-obj.ticker.C: // received the timer event
|
case <-obj.ticker.C: // received the timer event
|
||||||
send = true
|
send = true
|
||||||
log.Printf("%s[%s]: received tick", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: received tick", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
case event := <-obj.Events():
|
case event := <-obj.Events():
|
||||||
if exit, _ := obj.ReadEvent(event); exit != nil {
|
if exit, _ := obj.ReadEvent(event); exit != nil {
|
||||||
@@ -121,8 +121,8 @@ func (obj *TimerRes) CheckApply(apply bool) (bool, error) {
|
|||||||
func (obj *TimerRes) UIDs() []ResUID {
|
func (obj *TimerRes) UIDs() []ResUID {
|
||||||
x := &TimerUID{
|
x := &TimerUID{
|
||||||
BaseUID: BaseUID{
|
BaseUID: BaseUID{
|
||||||
name: obj.GetName(),
|
Name: obj.GetName(),
|
||||||
kind: obj.Kind(),
|
Kind: obj.GetKind(),
|
||||||
},
|
},
|
||||||
name: obj.Name,
|
name: obj.Name,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (obj *VirtRes) Init() error {
|
|||||||
var u *url.URL
|
var u *url.URL
|
||||||
var err error
|
var err error
|
||||||
if u, err = url.Parse(obj.URI); err != nil {
|
if u, err = url.Parse(obj.URI); err != nil {
|
||||||
return errwrap.Wrapf(err, "%s[%s]: Parsing URI failed: %s", obj.Kind(), obj.GetName(), obj.URI)
|
return errwrap.Wrapf(err, "%s[%s]: Parsing URI failed: %s", obj.GetKind(), obj.GetName(), obj.URI)
|
||||||
}
|
}
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case "lxc":
|
case "lxc":
|
||||||
@@ -148,7 +148,7 @@ func (obj *VirtRes) Init() error {
|
|||||||
|
|
||||||
obj.conn, err = obj.connect() // gets closed in Close method of Res API
|
obj.conn, err = obj.connect() // gets closed in Close method of Res API
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errwrap.Wrapf(err, "%s[%s]: Connection to libvirt failed in init", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "%s[%s]: Connection to libvirt failed in init", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for hard to change properties
|
// check for hard to change properties
|
||||||
@@ -156,14 +156,14 @@ func (obj *VirtRes) Init() error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
defer dom.Free()
|
defer dom.Free()
|
||||||
} else if !isNotFound(err) {
|
} else if !isNotFound(err) {
|
||||||
return errwrap.Wrapf(err, "%s[%s]: Could not lookup on init", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "%s[%s]: Could not lookup on init", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// maxCPUs, err := dom.GetMaxVcpus()
|
// maxCPUs, err := dom.GetMaxVcpus()
|
||||||
i, err := dom.GetVcpusFlags(libvirt.DOMAIN_VCPU_MAXIMUM)
|
i, err := dom.GetVcpusFlags(libvirt.DOMAIN_VCPU_MAXIMUM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errwrap.Wrapf(err, "%s[%s]: Could not lookup MaxCPUs on init", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "%s[%s]: Could not lookup MaxCPUs on init", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
maxCPUs := uint(i)
|
maxCPUs := uint(i)
|
||||||
if obj.MaxCPUs != maxCPUs { // max cpu slots is hard to change
|
if obj.MaxCPUs != maxCPUs { // max cpu slots is hard to change
|
||||||
@@ -176,11 +176,11 @@ func (obj *VirtRes) Init() error {
|
|||||||
// event handlers so that we don't miss any events via race?
|
// event handlers so that we don't miss any events via race?
|
||||||
xmlDesc, err := dom.GetXMLDesc(0) // 0 means no flags
|
xmlDesc, err := dom.GetXMLDesc(0) // 0 means no flags
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errwrap.Wrapf(err, "%s[%s]: Could not GetXMLDesc on init", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "%s[%s]: Could not GetXMLDesc on init", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
domXML := &libvirtxml.Domain{}
|
domXML := &libvirtxml.Domain{}
|
||||||
if err := domXML.Unmarshal(xmlDesc); err != nil {
|
if err := domXML.Unmarshal(xmlDesc); err != nil {
|
||||||
return errwrap.Wrapf(err, "%s[%s]: Could not unmarshal XML on init", obj.Kind(), obj.GetName())
|
return errwrap.Wrapf(err, "%s[%s]: Could not unmarshal XML on init", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// guest agent: domain->devices->channel->target->state == connected?
|
// guest agent: domain->devices->channel->target->state == connected?
|
||||||
@@ -192,7 +192,7 @@ func (obj *VirtRes) Init() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj.wg = &sync.WaitGroup{}
|
obj.wg = &sync.WaitGroup{}
|
||||||
obj.BaseRes.kind = "virt"
|
obj.BaseRes.Kind = "virt"
|
||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,22 +400,22 @@ func (obj *VirtRes) Watch() error {
|
|||||||
obj.guestAgentConnected = true
|
obj.guestAgentConnected = true
|
||||||
obj.StateOK(false) // dirty
|
obj.StateOK(false) // dirty
|
||||||
send = true
|
send = true
|
||||||
log.Printf("%s[%s]: Guest agent connected", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Guest agent connected", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
} else if state == libvirt.CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED {
|
} else if state == libvirt.CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED {
|
||||||
obj.guestAgentConnected = false
|
obj.guestAgentConnected = false
|
||||||
// ignore CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED
|
// ignore CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED
|
||||||
// events because they just tell you that guest agent channel was added
|
// events because they just tell you that guest agent channel was added
|
||||||
if reason == libvirt.CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL {
|
if reason == libvirt.CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL {
|
||||||
log.Printf("%s[%s]: Guest agent disconnected", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Guest agent disconnected", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("unknown %s[%s] guest agent state: %v", obj.Kind(), obj.GetName(), state)
|
return fmt.Errorf("unknown %s[%s] guest agent state: %v", obj.GetKind(), obj.GetName(), state)
|
||||||
}
|
}
|
||||||
|
|
||||||
case err := <-errorChan:
|
case err := <-errorChan:
|
||||||
return fmt.Errorf("unknown %s[%s] libvirt error: %s", obj.Kind(), obj.GetName(), err)
|
return fmt.Errorf("unknown %s[%s] libvirt error: %s", obj.GetKind(), obj.GetName(), err)
|
||||||
|
|
||||||
case event := <-obj.Events():
|
case event := <-obj.Events():
|
||||||
if exit, send = obj.ReadEvent(event); exit != nil {
|
if exit, send = obj.ReadEvent(event); exit != nil {
|
||||||
@@ -453,7 +453,7 @@ func (obj *VirtRes) domainCreate() (*libvirt.Domain, bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return dom, false, err // returned dom is invalid
|
return dom, false, err // returned dom is invalid
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Domain transient %s", state, obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain transient %s", state, obj.GetKind(), obj.GetName())
|
||||||
return dom, false, nil
|
return dom, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,20 +461,20 @@ func (obj *VirtRes) domainCreate() (*libvirt.Domain, bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return dom, false, err // returned dom is invalid
|
return dom, false, err // returned dom is invalid
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Domain defined", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain defined", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
if obj.State == "running" {
|
if obj.State == "running" {
|
||||||
if err := dom.Create(); err != nil {
|
if err := dom.Create(); err != nil {
|
||||||
return dom, false, err
|
return dom, false, err
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Domain started", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain started", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State == "paused" {
|
if obj.State == "paused" {
|
||||||
if err := dom.CreateWithFlags(libvirt.DOMAIN_START_PAUSED); err != nil {
|
if err := dom.CreateWithFlags(libvirt.DOMAIN_START_PAUSED); err != nil {
|
||||||
return dom, false, err
|
return dom, false, err
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Domain created paused", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain created paused", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
return dom, false, nil
|
return dom, false, nil
|
||||||
@@ -512,14 +512,14 @@ func (obj *VirtRes) stateCheckApply(apply bool, dom *libvirt.Domain) (bool, erro
|
|||||||
return false, errwrap.Wrapf(err, "domain.Resume failed")
|
return false, errwrap.Wrapf(err, "domain.Resume failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: Domain resumed", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain resumed", obj.GetKind(), obj.GetName())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err := dom.Create(); err != nil {
|
if err := dom.Create(); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "domain.Create failed")
|
return false, errwrap.Wrapf(err, "domain.Create failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: Domain created", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain created", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
case "paused":
|
case "paused":
|
||||||
if domInfo.State == libvirt.DOMAIN_PAUSED {
|
if domInfo.State == libvirt.DOMAIN_PAUSED {
|
||||||
@@ -533,14 +533,14 @@ func (obj *VirtRes) stateCheckApply(apply bool, dom *libvirt.Domain) (bool, erro
|
|||||||
return false, errwrap.Wrapf(err, "domain.Suspend failed")
|
return false, errwrap.Wrapf(err, "domain.Suspend failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: Domain paused", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain paused", obj.GetKind(), obj.GetName())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err := dom.CreateWithFlags(libvirt.DOMAIN_START_PAUSED); err != nil {
|
if err := dom.CreateWithFlags(libvirt.DOMAIN_START_PAUSED); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "domain.CreateWithFlags failed")
|
return false, errwrap.Wrapf(err, "domain.CreateWithFlags failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: Domain created paused", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain created paused", obj.GetKind(), obj.GetName())
|
||||||
|
|
||||||
case "shutoff":
|
case "shutoff":
|
||||||
if domInfo.State == libvirt.DOMAIN_SHUTOFF || domInfo.State == libvirt.DOMAIN_SHUTDOWN {
|
if domInfo.State == libvirt.DOMAIN_SHUTOFF || domInfo.State == libvirt.DOMAIN_SHUTDOWN {
|
||||||
@@ -554,7 +554,7 @@ func (obj *VirtRes) stateCheckApply(apply bool, dom *libvirt.Domain) (bool, erro
|
|||||||
return false, errwrap.Wrapf(err, "domain.Destroy failed")
|
return false, errwrap.Wrapf(err, "domain.Destroy failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: Domain destroyed", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain destroyed", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkOK, nil
|
return checkOK, nil
|
||||||
@@ -580,7 +580,7 @@ func (obj *VirtRes) attrCheckApply(apply bool, dom *libvirt.Domain) (bool, error
|
|||||||
if err := dom.SetMemory(obj.Memory); err != nil {
|
if err := dom.SetMemory(obj.Memory); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "domain.SetMemory failed")
|
return false, errwrap.Wrapf(err, "domain.SetMemory failed")
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Memory changed to %d", obj.Kind(), obj.GetName(), obj.Memory)
|
log.Printf("%s[%s]: Memory changed to %d", obj.GetKind(), obj.GetName(), obj.Memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check cpus
|
// check cpus
|
||||||
@@ -619,7 +619,7 @@ func (obj *VirtRes) attrCheckApply(apply bool, dom *libvirt.Domain) (bool, error
|
|||||||
return false, errwrap.Wrapf(err, "domain.SetVcpus failed")
|
return false, errwrap.Wrapf(err, "domain.SetVcpus failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: CPUs (hot) changed to %d", obj.Kind(), obj.GetName(), obj.CPUs)
|
log.Printf("%s[%s]: CPUs (hot) changed to %d", obj.GetKind(), obj.GetName(), obj.CPUs)
|
||||||
|
|
||||||
case libvirt.DOMAIN_SHUTOFF, libvirt.DOMAIN_SHUTDOWN:
|
case libvirt.DOMAIN_SHUTOFF, libvirt.DOMAIN_SHUTDOWN:
|
||||||
if !obj.Transient {
|
if !obj.Transient {
|
||||||
@@ -631,7 +631,7 @@ func (obj *VirtRes) attrCheckApply(apply bool, dom *libvirt.Domain) (bool, error
|
|||||||
return false, errwrap.Wrapf(err, "domain.SetVcpus failed")
|
return false, errwrap.Wrapf(err, "domain.SetVcpus failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: CPUs (cold) changed to %d", obj.Kind(), obj.GetName(), obj.CPUs)
|
log.Printf("%s[%s]: CPUs (cold) changed to %d", obj.GetKind(), obj.GetName(), obj.CPUs)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -662,7 +662,7 @@ func (obj *VirtRes) attrCheckApply(apply bool, dom *libvirt.Domain) (bool, error
|
|||||||
return false, errwrap.Wrapf(err, "domain.SetVcpus failed")
|
return false, errwrap.Wrapf(err, "domain.SetVcpus failed")
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
log.Printf("%s[%s]: CPUs (guest) changed to %d", obj.Kind(), obj.GetName(), obj.CPUs)
|
log.Printf("%s[%s]: CPUs (guest) changed to %d", obj.GetKind(), obj.GetName(), obj.CPUs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,7 +686,7 @@ func (obj *VirtRes) domainShutdownSync(apply bool, dom *libvirt.Domain) (bool, e
|
|||||||
return false, errwrap.Wrapf(err, "domain.GetInfo failed")
|
return false, errwrap.Wrapf(err, "domain.GetInfo failed")
|
||||||
}
|
}
|
||||||
if domInfo.State == libvirt.DOMAIN_SHUTOFF || domInfo.State == libvirt.DOMAIN_SHUTDOWN {
|
if domInfo.State == libvirt.DOMAIN_SHUTOFF || domInfo.State == libvirt.DOMAIN_SHUTDOWN {
|
||||||
log.Printf("%s[%s]: Shutdown", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Shutdown", obj.GetKind(), obj.GetName())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,7 +698,7 @@ func (obj *VirtRes) domainShutdownSync(apply bool, dom *libvirt.Domain) (bool, e
|
|||||||
obj.processExitChan = make(chan struct{})
|
obj.processExitChan = make(chan struct{})
|
||||||
// if machine shuts down before we call this, we error;
|
// if machine shuts down before we call this, we error;
|
||||||
// this isn't ideal, but it happened due to user error!
|
// this isn't ideal, but it happened due to user error!
|
||||||
log.Printf("%s[%s]: Running shutdown", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Running shutdown", obj.GetKind(), obj.GetName())
|
||||||
if err := dom.Shutdown(); err != nil {
|
if err := dom.Shutdown(); err != nil {
|
||||||
// FIXME: if machine is already shutdown completely, return early
|
// FIXME: if machine is already shutdown completely, return early
|
||||||
return false, errwrap.Wrapf(err, "domain.Shutdown failed")
|
return false, errwrap.Wrapf(err, "domain.Shutdown failed")
|
||||||
@@ -719,7 +719,7 @@ func (obj *VirtRes) domainShutdownSync(apply bool, dom *libvirt.Domain) (bool, e
|
|||||||
// https://libvirt.org/formatdomain.html#elementsEvents
|
// https://libvirt.org/formatdomain.html#elementsEvents
|
||||||
continue
|
continue
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return false, fmt.Errorf("%s[%s]: didn't shutdown after %d seconds", obj.Kind(), obj.GetName(), MaxShutdownDelayTimeout)
|
return false, fmt.Errorf("%s[%s]: didn't shutdown after %d seconds", obj.GetKind(), obj.GetName(), MaxShutdownDelayTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,7 +791,7 @@ func (obj *VirtRes) CheckApply(apply bool) (bool, error) {
|
|||||||
if err := dom.Undefine(); err != nil {
|
if err := dom.Undefine(); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "domain.Undefine failed")
|
return false, errwrap.Wrapf(err, "domain.Undefine failed")
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Domain undefined", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain undefined", obj.GetKind(), obj.GetName())
|
||||||
} else {
|
} else {
|
||||||
domXML, err := dom.GetXMLDesc(libvirt.DOMAIN_XML_INACTIVE)
|
domXML, err := dom.GetXMLDesc(libvirt.DOMAIN_XML_INACTIVE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -800,7 +800,7 @@ func (obj *VirtRes) CheckApply(apply bool) (bool, error) {
|
|||||||
if _, err = obj.conn.DomainDefineXML(domXML); err != nil {
|
if _, err = obj.conn.DomainDefineXML(domXML); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "conn.DomainDefineXML failed")
|
return false, errwrap.Wrapf(err, "conn.DomainDefineXML failed")
|
||||||
}
|
}
|
||||||
log.Printf("%s[%s]: Domain defined", obj.Kind(), obj.GetName())
|
log.Printf("%s[%s]: Domain defined", obj.GetKind(), obj.GetName())
|
||||||
}
|
}
|
||||||
checkOK = false
|
checkOK = false
|
||||||
}
|
}
|
||||||
@@ -848,7 +848,7 @@ func (obj *VirtRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// we had to do a restart, we didn't, and we should error if it was needed
|
// we had to do a restart, we didn't, and we should error if it was needed
|
||||||
if obj.restartScheduled && restart == true && obj.RestartOnDiverge == "error" {
|
if obj.restartScheduled && restart == true && obj.RestartOnDiverge == "error" {
|
||||||
return false, fmt.Errorf("%s[%s]: needed restart but didn't! (RestartOnDiverge: %v)", obj.Kind(), obj.GetName(), obj.RestartOnDiverge)
|
return false, fmt.Errorf("%s[%s]: needed restart but didn't! (RestartOnDiverge: %v)", obj.GetKind(), obj.GetName(), obj.RestartOnDiverge)
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkOK, nil // w00t
|
return checkOK, nil // w00t
|
||||||
@@ -1055,7 +1055,7 @@ type VirtUID struct {
|
|||||||
// Most resources only return one, although some resources can return multiple.
|
// Most resources only return one, although some resources can return multiple.
|
||||||
func (obj *VirtRes) UIDs() []ResUID {
|
func (obj *VirtRes) UIDs() []ResUID {
|
||||||
x := &VirtUID{
|
x := &VirtUID{
|
||||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||||
// TODO: add more properties here so we can link to vm dependencies
|
// TODO: add more properties here so we can link to vm dependencies
|
||||||
}
|
}
|
||||||
return []ResUID{x}
|
return []ResUID{x}
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
|
|||||||
log.Printf("Collect: %v; Pattern: %v", kind, t.Pattern)
|
log.Printf("Collect: %v; Pattern: %v", kind, t.Pattern)
|
||||||
|
|
||||||
// XXX: expand to more complex pattern matching here...
|
// XXX: expand to more complex pattern matching here...
|
||||||
if res.Kind() != kind {
|
if res.GetKind() != kind {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
|
|||||||
|
|
||||||
// Resources
|
// Resources
|
||||||
for _, res := range c.ResList {
|
for _, res := range c.ResList {
|
||||||
kind := res.Kind()
|
kind := res.GetKind()
|
||||||
if _, exists := lookup[kind]; !exists {
|
if _, exists := lookup[kind]; !exists {
|
||||||
lookup[kind] = make(map[string]*pgraph.Vertex)
|
lookup[kind] = make(map[string]*pgraph.Vertex)
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
|
|||||||
log.Printf("Collect: %v; Pattern: %v", kind, t.Pattern)
|
log.Printf("Collect: %v; Pattern: %v", kind, t.Pattern)
|
||||||
|
|
||||||
// XXX: expand to more complex pattern matching here...
|
// XXX: expand to more complex pattern matching here...
|
||||||
if res.Kind() != kind {
|
if res.GetKind() != kind {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user