diff --git a/examples/lang/exchange0.mcl b/examples/lang/exchange0.mcl index 552095c9..a6d1f3bf 100644 --- a/examples/lang/exchange0.mcl +++ b/examples/lang/exchange0.mcl @@ -6,9 +6,10 @@ # time ./mgmt run --hostname h4 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2385 --server-urls http://127.0.0.1:2386 --tmp-prefix --no-pgp lang --lang examples/lang/exchange0.mcl import "sys" +import "world" $rand = random1(8) -$exchanged = exchange("keyns", $rand) +$exchanged = world.exchange("keyns", $rand) file "/tmp/mgmt/exchange-${sys.hostname()}" { content => template("Found: {{ . }}\n", $exchanged), diff --git a/examples/lang/schedule0.mcl b/examples/lang/schedule0.mcl index 2b4979b9..a8fbd8a8 100644 --- a/examples/lang/schedule0.mcl +++ b/examples/lang/schedule0.mcl @@ -1,4 +1,5 @@ import "sys" +import "world" # here are all the possible options: #$opts = struct{strategy => "rr", max => 3, reuse => false, ttl => 10,} @@ -10,10 +11,10 @@ import "sys" $opts = struct{strategy => "rr", max => 2, ttl => 10,} # schedule in a particular namespace with options: -$set = schedule("xsched", $opts) +$set = world.schedule("xsched", $opts) # and if you want, you can omit the options entirely: -#$set = schedule("xsched") +#$set = world.schedule("xsched") file "/tmp/mgmt/scheduled-${sys.hostname()}" { content => template("set: {{ . }}\n", $set), diff --git a/examples/lang/sendrecv3.mcl b/examples/lang/sendrecv3.mcl index 17c998bf..1a791d1f 100644 --- a/examples/lang/sendrecv3.mcl +++ b/examples/lang/sendrecv3.mcl @@ -1,7 +1,8 @@ import "fmt" +import "world" $ns = "estate" -$exchanged = kvlookup($ns) +$exchanged = world.kvlookup($ns) $state = maplookup($exchanged, $hostname, "default") exec "exec0" { diff --git a/examples/lang/states0.mcl b/examples/lang/states0.mcl index d3e46fc9..eb3d0155 100644 --- a/examples/lang/states0.mcl +++ b/examples/lang/states0.mcl @@ -1,5 +1,7 @@ +import "world" + $ns = "estate" -$exchanged = kvlookup($ns) +$exchanged = world.kvlookup($ns) $state = maplookup($exchanged, $hostname, "default") diff --git a/lang/funcs/core/core.go b/lang/funcs/core/core.go index 485373a4..b818979c 100644 --- a/lang/funcs/core/core.go +++ b/lang/funcs/core/core.go @@ -26,4 +26,5 @@ import ( _ "github.com/purpleidea/mgmt/lang/funcs/core/os" _ "github.com/purpleidea/mgmt/lang/funcs/core/strings" _ "github.com/purpleidea/mgmt/lang/funcs/core/sys" + _ "github.com/purpleidea/mgmt/lang/funcs/core/world" ) diff --git a/lang/funcs/core/exchange_func.go b/lang/funcs/core/world/exchange_func.go similarity index 96% rename from lang/funcs/core/exchange_func.go rename to lang/funcs/core/world/exchange_func.go index 7a9848c2..3a232668 100644 --- a/lang/funcs/core/exchange_func.go +++ b/lang/funcs/core/world/exchange_func.go @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -package core // TODO: should this be in its own individual package? +package coreworld import ( "fmt" @@ -28,7 +28,7 @@ import ( ) func init() { - funcs.Register("exchange", func() interfaces.Func { return &ExchangeFunc{} }) // must register the func and name + funcs.ModuleRegister(moduleName, "exchange", func() interfaces.Func { return &ExchangeFunc{} }) } // ExchangeFunc is special function which returns all the values of a given key diff --git a/lang/funcs/core/kvlookup_func.go b/lang/funcs/core/world/kvlookup_func.go similarity index 96% rename from lang/funcs/core/kvlookup_func.go rename to lang/funcs/core/world/kvlookup_func.go index f595fedf..b7590a8c 100644 --- a/lang/funcs/core/kvlookup_func.go +++ b/lang/funcs/core/world/kvlookup_func.go @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -package core // TODO: should this be in its own individual package? +package coreworld import ( "fmt" @@ -28,7 +28,7 @@ import ( ) func init() { - funcs.Register("kvlookup", func() interfaces.Func { return &KVLookupFunc{} }) // must register the func and name + funcs.ModuleRegister(moduleName, "kvlookup", func() interfaces.Func { return &KVLookupFunc{} }) } // KVLookupFunc is special function which returns all the values of a given key diff --git a/lang/funcs/core/schedule_func.go b/lang/funcs/core/world/schedule_func.go similarity index 98% rename from lang/funcs/core/schedule_func.go rename to lang/funcs/core/world/schedule_func.go index 3a8a9593..d977f6b4 100644 --- a/lang/funcs/core/schedule_func.go +++ b/lang/funcs/core/world/schedule_func.go @@ -27,7 +27,7 @@ // kill h2 // kill h1... all done! -package core // TODO: should this be in its own individual package? +package coreworld import ( "context" @@ -47,7 +47,7 @@ const ( ) func init() { - funcs.Register("schedule", func() interfaces.Func { return &SchedulePolyFunc{} }) // must register the func and name + funcs.ModuleRegister(moduleName, "schedule", func() interfaces.Func { return &SchedulePolyFunc{} }) } // SchedulePolyFunc is special function which determines where code should run diff --git a/lang/funcs/core/world/world.go b/lang/funcs/core/world/world.go new file mode 100644 index 00000000..d9d27df7 --- /dev/null +++ b/lang/funcs/core/world/world.go @@ -0,0 +1,23 @@ +// Mgmt +// Copyright (C) 2013-2018+ James Shubin and the project contributors +// Written by James Shubin and the project contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package coreworld + +const ( + // moduleName is the prefix given to all the functions in this module. + moduleName = "world" +)