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:
@@ -93,7 +93,7 @@ func (obj *NspawnRes) Init() error {
|
||||
if err := obj.svc.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
obj.BaseRes.kind = "nspawn"
|
||||
obj.BaseRes.Kind = "nspawn"
|
||||
return obj.BaseRes.Init()
|
||||
}
|
||||
|
||||
@@ -134,11 +134,11 @@ func (obj *NspawnRes) Watch() error {
|
||||
case event := <-buschan:
|
||||
// process org.freedesktop.machine1 events for this resource's name
|
||||
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 {
|
||||
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 {
|
||||
log.Printf("%s[%s]: Machine stopped", obj.Kind(), obj.GetName())
|
||||
log.Printf("%s[%s]: Machine stopped", obj.GetKind(), obj.GetName())
|
||||
} else {
|
||||
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 {
|
||||
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
|
||||
// be stopped or the state matches we're done
|
||||
if !exists && obj.State == stopped || properties["State"] == obj.State {
|
||||
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
|
||||
}
|
||||
@@ -212,12 +212,12 @@ func (obj *NspawnRes) CheckApply(apply bool) (checkOK bool, err error) {
|
||||
}
|
||||
|
||||
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 {
|
||||
// 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
|
||||
if _, err := obj.svc.CheckApply(apply); err != nil {
|
||||
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 {
|
||||
// terminate the machine with
|
||||
// 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 {
|
||||
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
|
||||
func (obj *NspawnRes) UIDs() []ResUID {
|
||||
x := &NspawnUID{
|
||||
BaseUID: BaseUID{name: obj.GetName(), kind: obj.Kind()},
|
||||
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||
name: obj.Name, // svc name
|
||||
}
|
||||
return append([]ResUID{x}, obj.svc.UIDs()...)
|
||||
|
||||
Reference in New Issue
Block a user