Skip to main content

Create

Write a new behavior's standard layout in an osapi checkout.

Before you change anything, the result builds, validates and passes every test. Then change the types, the provider and the examples to what the behavior manages. Writes nothing when the name is taken. The behavior is directly under node: its routes are /api/node/{hostname}/<name> and its commands osapi client node <name>. To nest it under a parent, add behavior.Of or behavior.Under to its definition. Your first behavior walks through the rest.

A new behavior is one an operator calls, with an API and commands. Work that two behaviors share, such as writing a file, becomes an internal behavior that the two require: add behavior.Internal to it then, and behavior.Requires to each user. osapi dsl behavior validate fails an internal behavior that no behavior requires.

--requires names the behaviors that the new one is built on. For each, it writes behavior.Requires, the host.Require in the builder and a field of the provider. You write each behavior.Call: until an example calls a required behavior, the tests fail the rule used.

osapi dsl behavior create [flags]

Examples​

osapi dsl behavior create --name motd --description "The message shown at login"
osapi dsl behavior create --name motd --description "The message shown at login" --root ~/src/osapi
osapi dsl behavior create --name ntpconf --description "The NTP config" --requires managedfile

Result​

The command prints:

$ osapi dsl behavior create --name motd --description "The message shown at login"
Behavior:
  Name:  motd

Files (6):
  PATH
  internal/behaviors/motd/behavior.go
  internal/behaviors/motd/behavior_public_test.go
  internal/behaviors/motd/debian.go
  internal/behaviors/motd/methods.go
  internal/behaviors/motd/provider.go
  internal/behaviors/all/all.go

Next (5):
  STEP
  go generate ./internal/behaviors/motd/mocks ./internal/behaviors/all
  change the types, the provider and the examples in internal/behaviors/motd
  go generate ./internal/behaviors/all
  osapi dsl behavior validate
  just test

With --json, the command prints:

{
"name": "motd",
"files": [
{
"path": "internal/behaviors/motd/behavior.go"
},
{
"path": "internal/behaviors/motd/behavior_public_test.go"
},
{
"path": "internal/behaviors/motd/debian.go"
},
{
"path": "internal/behaviors/motd/methods.go"
},
{
"path": "internal/behaviors/motd/provider.go"
},
{
"path": "internal/behaviors/all/all.go"
}
],
"next": [
{
"step": "go generate ./internal/behaviors/motd/mocks ./internal/behaviors/all"
},
{
"step": "change the types, the provider and the examples in internal/behaviors/motd"
},
{
"step": "go generate ./internal/behaviors/all"
},
{
"step": "osapi dsl behavior validate"
},
{
"step": "just test"
}
]
}

Flags​

FlagDescriptionDefault
--descriptionWhat it manages, in one line (required)
--nameThe behavior's name: lowercase letters and digits (required)
--packageThe Go package and directory, when it is not the name: package is a Go keyword, so --name package --package packages
--requiresBehaviors it is built on, such as managedfile: it writes the Requires, the host.Require and a provider field of each
--rootThe osapi checkout to write into.

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml

Output tells how the result is printed, and what --json gives.