engine, gapi, lang, lib: Plumb through new local API
This is a new API that is similar in spirit and plumbing to the World API, but it intended for all local machine operations and will likely only ever have one implementation.
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/purpleidea/mgmt/engine"
|
||||
"github.com/purpleidea/mgmt/engine/local"
|
||||
"github.com/purpleidea/mgmt/lang/funcs/structs"
|
||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
@@ -44,6 +45,7 @@ type Engine struct {
|
||||
Name string
|
||||
|
||||
Hostname string
|
||||
Local *local.API
|
||||
World engine.World
|
||||
|
||||
Debug bool
|
||||
@@ -289,6 +291,7 @@ func (obj *Engine) addVertex(f interfaces.Func) error {
|
||||
Input: node.input,
|
||||
Output: node.output,
|
||||
Txn: node.txn,
|
||||
Local: obj.Local,
|
||||
World: obj.World,
|
||||
Debug: obj.Debug,
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
|
||||
@@ -259,6 +259,7 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
|
||||
LexParser: parser.LexParse,
|
||||
Downloader: downloader,
|
||||
StrInterpolater: interpolate.StrInterpolate,
|
||||
//Local: obj.Local, // TODO: do we need this?
|
||||
//World: obj.World, // TODO: do we need this?
|
||||
|
||||
Prefix: prefix,
|
||||
@@ -467,6 +468,7 @@ func (obj *GAPI) LangInit() error {
|
||||
Input: input,
|
||||
|
||||
Hostname: obj.data.Hostname,
|
||||
Local: obj.data.Local,
|
||||
World: obj.data.World,
|
||||
Debug: obj.data.Debug,
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
@@ -747,6 +749,7 @@ func (obj *GAPI) Get(getInfo *gapi.GetInfo) error {
|
||||
LexParser: parser.LexParse,
|
||||
Downloader: downloader,
|
||||
StrInterpolater: interpolate.StrInterpolate,
|
||||
//Local: obj.Local, // TODO: do we need this?
|
||||
//World: obj.World, // TODO: do we need this?
|
||||
|
||||
Prefix: prefix,
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/purpleidea/mgmt/engine"
|
||||
"github.com/purpleidea/mgmt/engine/local"
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
"github.com/purpleidea/mgmt/pgraph"
|
||||
)
|
||||
@@ -61,6 +62,8 @@ type Init struct {
|
||||
Txn Txn
|
||||
|
||||
// TODO: should we pass in a *Scope here for functions like template() ?
|
||||
|
||||
Local *local.API
|
||||
World engine.World
|
||||
|
||||
Debug bool
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/purpleidea/mgmt/engine"
|
||||
"github.com/purpleidea/mgmt/engine/graph"
|
||||
"github.com/purpleidea/mgmt/engine/graph/autoedge"
|
||||
"github.com/purpleidea/mgmt/engine/local"
|
||||
engineUtil "github.com/purpleidea/mgmt/engine/util"
|
||||
"github.com/purpleidea/mgmt/etcd"
|
||||
"github.com/purpleidea/mgmt/lang/ast"
|
||||
@@ -717,6 +718,15 @@ func TestAstFunc2(t *testing.T) {
|
||||
afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil
|
||||
fs := &util.Fs{Afero: afs}
|
||||
|
||||
// implementation of the Local API (we only expect just this single one)
|
||||
localAPI := &local.API{
|
||||
Prefix: fmt.Sprintf("%s/", filepath.Join(tmpdir, "local")),
|
||||
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
logf("local: api: "+format, v...)
|
||||
},
|
||||
}
|
||||
|
||||
// implementation of the World API (alternatives can be substituted in)
|
||||
world := &etcd.World{
|
||||
//Hostname: hostname,
|
||||
@@ -1011,6 +1021,7 @@ func TestAstFunc2(t *testing.T) {
|
||||
funcs := &dage.Engine{
|
||||
Name: "test",
|
||||
Hostname: "", // NOTE: empty b/c not used
|
||||
Local: localAPI, // used partially in some tests
|
||||
World: world, // used partially in some tests
|
||||
//Prefix: fmt.Sprintf("%s/", filepath.Join(tmpdir, "funcs")),
|
||||
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||
@@ -1479,6 +1490,15 @@ func TestAstFunc3(t *testing.T) {
|
||||
afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil
|
||||
fs := &util.Fs{Afero: afs}
|
||||
|
||||
// implementation of the Local API (we only expect just this single one)
|
||||
localAPI := &local.API{
|
||||
Prefix: fmt.Sprintf("%s/", filepath.Join(tmpdir, "local")),
|
||||
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
logf("local: api: "+format, v...)
|
||||
},
|
||||
}
|
||||
|
||||
// implementation of the World API (alternatives can be substituted in)
|
||||
world := &etcd.World{
|
||||
//Hostname: hostname,
|
||||
@@ -1773,6 +1793,7 @@ func TestAstFunc3(t *testing.T) {
|
||||
funcs := &dage.Engine{
|
||||
Name: "test",
|
||||
Hostname: "", // NOTE: empty b/c not used
|
||||
Local: localAPI, // used partially in some tests
|
||||
World: world, // used partially in some tests
|
||||
//Prefix: fmt.Sprintf("%s/", filepath.Join(tmpdir, "funcs")),
|
||||
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||
@@ -2004,6 +2025,7 @@ func TestAstFunc3(t *testing.T) {
|
||||
//Version: obj.Version,
|
||||
Hostname: "localhost",
|
||||
Converger: converger,
|
||||
Local: localAPI,
|
||||
World: world,
|
||||
Prefix: fmt.Sprintf("%s/", filepath.Join(tmpdir, "engine")),
|
||||
Debug: testing.Verbose(),
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/purpleidea/mgmt/engine"
|
||||
"github.com/purpleidea/mgmt/engine/local"
|
||||
"github.com/purpleidea/mgmt/lang/ast"
|
||||
_ "github.com/purpleidea/mgmt/lang/funcs/core" // import so the funcs register
|
||||
"github.com/purpleidea/mgmt/lang/funcs/dage"
|
||||
@@ -57,6 +58,7 @@ type Lang struct {
|
||||
Input string
|
||||
|
||||
Hostname string
|
||||
Local *local.API
|
||||
World engine.World
|
||||
Prefix string
|
||||
Debug bool
|
||||
@@ -139,6 +141,7 @@ func (obj *Lang) Init() error {
|
||||
LexParser: parser.LexParse,
|
||||
Downloader: nil, // XXX: is this used here?
|
||||
StrInterpolater: interpolate.StrInterpolate,
|
||||
//Local: obj.Local, // TODO: do we need this?
|
||||
//World: obj.World, // TODO: do we need this?
|
||||
|
||||
Prefix: obj.Prefix,
|
||||
@@ -237,6 +240,7 @@ func (obj *Lang) Init() error {
|
||||
obj.funcs = &dage.Engine{
|
||||
Name: "lang", // TODO: arbitrary name for now
|
||||
Hostname: obj.Hostname,
|
||||
Local: obj.Local,
|
||||
World: obj.World,
|
||||
//Prefix: fmt.Sprintf("%s/", path.Join(obj.Prefix, "funcs")),
|
||||
Debug: obj.Debug,
|
||||
|
||||
Reference in New Issue
Block a user