From 57e919d7e57b8bc1e3b3e9baec2e3f0e580e23d1 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 13 Feb 2017 15:29:54 -0500 Subject: [PATCH] resources: Remove "NewRes" constructors Remove the New constructors since calling Init should be done by the engine, and not by the user even when using mgmt as a lib. This is also the case in tests! It used to be the case that a user might want to call Init manually, but that is no longer the case! --- resources/augeas.go | 10 ---------- resources/exec.go | 19 ------------------- resources/file.go | 18 ------------------ resources/hostname.go | 13 ------------- resources/msg.go | 21 --------------------- resources/noop.go | 11 ----------- resources/nspawn.go | 11 ----------- resources/password.go | 11 ----------- resources/pkg.go | 14 -------------- resources/svc.go | 12 ------------ resources/timer.go | 11 ----------- resources/virt.go | 16 ---------------- 12 files changed, 167 deletions(-) diff --git a/resources/augeas.go b/resources/augeas.go index 544f7556..09ec17ac 100644 --- a/resources/augeas.go +++ b/resources/augeas.go @@ -69,16 +69,6 @@ type AugeasSet struct { Value string `yaml:"value"` // The value to be set on the given Path. } -// NewAugeasRes is a constructor for this resource. It also calls Init() for you. -func NewAugeasRes(name string) (*AugeasRes, error) { - obj := &AugeasRes{ - BaseRes: BaseRes{ - Name: name, - }, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *AugeasRes) Default() Res { return &AugeasRes{} diff --git a/resources/exec.go b/resources/exec.go index f14dc960..8d9ffa33 100644 --- a/resources/exec.go +++ b/resources/exec.go @@ -50,25 +50,6 @@ type ExecRes struct { PollInt int `yaml:"pollint"` // the poll interval for the ifcmd } -// NewExecRes is a constructor for this resource. It also calls Init() for you. -func NewExecRes(name, cmd, shell string, timeout int, watchcmd, watchshell, ifcmd, ifshell string, pollint int, state string) (*ExecRes, error) { - obj := &ExecRes{ - BaseRes: BaseRes{ - Name: name, - }, - Cmd: cmd, - Shell: shell, - Timeout: timeout, - WatchCmd: watchcmd, - WatchShell: watchshell, - IfCmd: ifcmd, - IfShell: ifshell, - PollInt: pollint, - State: state, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *ExecRes) Default() Res { return &ExecRes{} diff --git a/resources/file.go b/resources/file.go index de47946d..539dde9c 100644 --- a/resources/file.go +++ b/resources/file.go @@ -65,24 +65,6 @@ type FileRes struct { recWatcher *recwatch.RecWatcher } -// NewFileRes is a constructor for this resource. It also calls Init() for you. -func NewFileRes(name, path, dirname, basename string, content *string, source, state string, recurse, force bool) (*FileRes, error) { - obj := &FileRes{ - BaseRes: BaseRes{ - Name: name, - }, - Path: path, - Dirname: dirname, - Basename: basename, - Content: content, - Source: source, - State: state, - Recurse: recurse, - Force: force, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *FileRes) Default() Res { return &FileRes{ diff --git a/resources/hostname.go b/resources/hostname.go index f50ba908..909fac50 100644 --- a/resources/hostname.go +++ b/resources/hostname.go @@ -69,19 +69,6 @@ type HostnameRes struct { conn *dbus.Conn } -// NewHostnameRes is a constructor for this resource. It also calls Init() for you. -func NewHostnameRes(name, staticHostname, transientHostname, prettyHostname string) (*HostnameRes, error) { - obj := &HostnameRes{ - BaseRes: BaseRes{ - Name: name, - }, - PrettyHostname: prettyHostname, - StaticHostname: staticHostname, - TransientHostname: transientHostname, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *HostnameRes) Default() Res { return &HostnameRes{} diff --git a/resources/msg.go b/resources/msg.go index b121cdc1..5a3fb004 100644 --- a/resources/msg.go +++ b/resources/msg.go @@ -52,27 +52,6 @@ type MsgUID struct { body string } -// NewMsgRes is a constructor for this resource. -func NewMsgRes(name, body, priority string, journal, syslog bool, fields map[string]string) (*MsgRes, error) { - message := name - if body != "" { - message = body - } - - obj := &MsgRes{ - BaseRes: BaseRes{ - Name: name, - }, - Body: message, - Priority: priority, - Fields: fields, - Journal: journal, - Syslog: syslog, - } - - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *MsgRes) Default() Res { return &MsgRes{} diff --git a/resources/noop.go b/resources/noop.go index 83714b7d..2a3ed853 100644 --- a/resources/noop.go +++ b/resources/noop.go @@ -35,17 +35,6 @@ type NoopRes struct { Comment string `yaml:"comment"` // extra field for example purposes } -// NewNoopRes is a constructor for this resource. It also calls Init() for you. -func NewNoopRes(name string) (*NoopRes, error) { - obj := &NoopRes{ - BaseRes: BaseRes{ - Name: name, - }, - Comment: "", - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *NoopRes) Default() Res { return &NoopRes{} diff --git a/resources/nspawn.go b/resources/nspawn.go index b26ed37e..41328e36 100644 --- a/resources/nspawn.go +++ b/resources/nspawn.go @@ -57,17 +57,6 @@ type NspawnRes struct { svc *SvcRes } -// NewNspawnRes is the constructor for this resource -func NewNspawnRes(name string, state string) (*NspawnRes, error) { - obj := &NspawnRes{ - BaseRes: BaseRes{ - Name: name, - }, - State: state, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *NspawnRes) Default() Res { return &NspawnRes{ diff --git a/resources/password.go b/resources/password.go index b1f034b0..e5e5ad75 100644 --- a/resources/password.go +++ b/resources/password.go @@ -56,17 +56,6 @@ type PasswordRes struct { recWatcher *recwatch.RecWatcher } -// NewPasswordRes is a constructor for this resource. It also calls Init() for you. -func NewPasswordRes(name string, length uint16) (*PasswordRes, error) { - obj := &PasswordRes{ - BaseRes: BaseRes{ - Name: name, - }, - Length: length, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *PasswordRes) Default() Res { return &PasswordRes{ diff --git a/resources/pkg.go b/resources/pkg.go index 67ddfa72..cb50035e 100644 --- a/resources/pkg.go +++ b/resources/pkg.go @@ -46,20 +46,6 @@ type PkgRes struct { fileList []string // FIXME: update if pkg changes } -// NewPkgRes is a constructor for this resource. It also calls Init() for you. -func NewPkgRes(name, state string, allowuntrusted, allownonfree, allowunsupported bool) (*PkgRes, error) { - obj := &PkgRes{ - BaseRes: BaseRes{ - Name: name, - }, - State: state, - AllowUntrusted: allowuntrusted, - AllowNonFree: allownonfree, - AllowUnsupported: allowunsupported, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *PkgRes) Default() Res { return &PkgRes{ diff --git a/resources/svc.go b/resources/svc.go index ec8b4009..b1f30248 100644 --- a/resources/svc.go +++ b/resources/svc.go @@ -44,18 +44,6 @@ type SvcRes struct { Startup string `yaml:"startup"` // enabled, disabled, undefined } -// NewSvcRes is a constructor for this resource. It also calls Init() for you. -func NewSvcRes(name, state, startup string) (*SvcRes, error) { - obj := &SvcRes{ - BaseRes: BaseRes{ - Name: name, - }, - State: state, - Startup: startup, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *SvcRes) Default() Res { return &SvcRes{} diff --git a/resources/timer.go b/resources/timer.go index cf07083b..41b12440 100644 --- a/resources/timer.go +++ b/resources/timer.go @@ -44,17 +44,6 @@ type TimerUID struct { name string } -// NewTimerRes is a constructor for this resource. It also calls Init() for you. -func NewTimerRes(name string, interval uint32) (*TimerRes, error) { - obj := &TimerRes{ - BaseRes: BaseRes{ - Name: name, - }, - Interval: interval, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *TimerRes) Default() Res { return &TimerRes{} diff --git a/resources/virt.go b/resources/virt.go index fab188c5..8a1dad63 100644 --- a/resources/virt.go +++ b/resources/virt.go @@ -79,22 +79,6 @@ type VirtRes struct { uriScheme virtURISchemeType } -// NewVirtRes is a constructor for this resource. It also calls Init() for you. -func NewVirtRes(name string, uri, state string, transient bool, cpus uint, memory uint64, osinit string) (*VirtRes, error) { - obj := &VirtRes{ - BaseRes: BaseRes{ - Name: name, - }, - URI: uri, - State: state, - Transient: transient, - CPUs: cpus, - Memory: memory, - OSInit: osinit, - } - return obj, obj.Init() -} - // Default returns some sensible defaults for this resource. func (obj *VirtRes) Default() Res { return &VirtRes{}