Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a application like system #1665

Closed
ripienaar opened this issue May 10, 2022 · 4 comments
Closed

create a application like system #1665

ripienaar opened this issue May 10, 2022 · 4 comments

Comments

@ripienaar
Copy link
Member

mco applications were ruby plugins that was used to build CLI tools, primarily they were used to render results differently and less frequently about doing multiple chained requests (puppet runall)

For a large portion of things really all thats needed now is a way to construct complex choria req commands.

I imagine that:

someapp machine report check_load --lt 1.0.0

Would just do, and it would be enough:

choria req choria_util machine_state name=check_load --reply-filter 'ok() && semver(data("version"), "< 1.0.0")'

If there was a way to create dynamically a cli thats essentially just macros around rpc, kv, external commands etc it would allow them to make a local utility that has easy to discover features without that is just a wrapper.

$ ./myco --help
usage: ./myco [<flags>] <command> [<args> ...]

A thing that does Foo

Flags:
  --help  Show context-sensitive help (also try --help-long and --help-man).

Commands:
  help [<command>...]
    Show help.

  machines [<flags>] <machine>
    Query Autonomous Agents
$ ./myco machines --help
usage: ./myco machines [<flags>] <machine>

Query Autonomous Agents

Flags:
  --help         Show context-sensitive help (also try --help-long and --help-man).
  --not=VERSION  Matches instances that are not this version
  --le=VERSION   Matches instances that are older than or same as
  --lt=VERSION   Matches instances that are older than
  --ge=VERSION   Matches instances that are newer than or same as
  --gt=VERSION   Matches instances that are older than
  --eq=VERSION   Matches instances that are same as

Args:
  <machine>  Autonomous Agent to report on
$ ./myco machines check_bacula_fd --eq 1.0.0
2022/05/09 14:40:35 choria req choria_util machine_state name=check_bacula_fd --filter-replies ok() && semver(data("version"), "= 1.0.0")
Discovering nodes using the choria method .... 29

29 / 29    0s [==============================================================================] 100%

...

Summary of Name:

   check_bacula_fd: 16

Summary of State:

   OK: 16

Summary of Version:

   1.0.0: 16

Finished processing 29 / 29 hosts in 1.304s

This could be defined using a YAML file like this:

name: Foo Thing
description: A thing that does Foo
version: 0.0.1
author: R.I.Pienaar <[email protected]>
commands:
  - name: machines
    description: Query Autonomous Agents
    std_filter: true
    request:
      agent: choria_util
      action: machine_state
      params:
        name: "{{.Arguments.machine}}"

    args:
      - name: machine
        description: Autonomous Agent to report on
        required: true

    flags:
      - name: not
        description: Matches instances that are not this version
        place_holder: VERSION
        filter: ok() && semver(data("version"), "!= {{.Flags.not}}")

      - name: le
        description: Matches instances that are older than or same as
        place_holder: VERSION
        filter: ok() && semver(data("version"), "<= {{.Flags.le}}")

      - name: lt
        description: Matches instances that are older than
        place_holder: VERSION
        filter: ok() && semver(data("version"), "< {{.Flags.lt}}")

      - name: ge
        description: Matches instances that are newer than or same as
        place_holder: VERSION
        filter: ok() && semver(data("version"), ">= {{.Flags.ge}}")

      - name: gt
        description: Matches instances that are older than
        place_holder: VERSION
        filter: ok() && semver(data("version"), "> {{.Flags.gt}}")

      - name: eq
        description: Matches instances that are same as
        place_holder: VERSION
        filter: ok() && semver(data("version"), "= {{.Flags.eq}}")
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 10, 2022
@ripienaar
Copy link
Member Author

ripienaar commented May 10, 2022

#1666 adds a super basic version of this with no input validation etc,

-rwxr-xr-x 1 rip rip 37412864 May 10 18:06 choria
lrwxrwxrwx 1 rip rip        6 May 10 17:58 mycorp -> choria
-rw-r--r-- 1 rip rip     3601 May 10 15:23 mycorp.yaml

Simply symlink mycorp to the choria binary and create mycorp.yaml in either ., ~/config/choria/builder/ or /etc/choria/builder. It also supports loading a config from those directories in config.yaml

% ./mycorp
usage: mycorp [<flags>] <command> [<args> ...]

A thing that does Foo

Flags:
  --help  Show context-sensitive help (also try --help-long and --help-man).

Commands:
  help [<command>...]
    Show help.

  fleet info [<flags>]
    Get Choria Versions, broker distribution and more

  provisioning reprovision [<flags>]
    Re-provision running nodes

    Reprovisioning will remove the node from the network and reset it's configuration to factory default, it will then get a new configuration, credentials and more from the Choria Provisioner.

  provisioning restart [<flags>]
    Restarts running nodes

  provisioner force-election
    Force a leader election

  provisioner leader
    Obtain the name of the current cluster leader

  machines [<flags>] <machine>
    Query Autonomous Agents

ripienaar added a commit to ripienaar/go-choria that referenced this issue May 11, 2022
This allows applications to be built that wraps RPC and KV
components.

Application definitions are documented using a schema and
are validated on loading, from the definition a CLI app is
built that can have nested sub commands and more.

Application definitions goes in files called x-app.yaml,
a symlink from x to choria would then load x-app.yaml and
construct the CLI when x is invoked.

An additional config file can be read called applications.yaml
that can be accessed via go templates in the definition in a few
places.

The config and definitions can live in ., ~/.config/choria/builder
or /etc/choria/builder.

Paths are using XDG, but its a super primitive implementation
for the moment, will be refined via issue 1624, thus paths
and file names are subject to change

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 11, 2022
This allows applications to be built that wraps RPC and KV
components.

Application definitions are documented using a schema and
are validated on loading, from the definition a CLI app is
built that can have nested sub commands and more.

Application definitions goes in files called x-app.yaml,
a symlink from x to choria would then load x-app.yaml and
construct the CLI when x is invoked.

An additional config file can be read called applications.yaml
that can be accessed via go templates in the definition in a few
places.

The config and definitions can live in ., ~/.config/choria/builder
or /etc/choria/builder.

Paths are using XDG, but its a super primitive implementation
for the moment, will be refined via issue 1624, thus paths
and file names are subject to change

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit that referenced this issue May 11, 2022
(#1665) initial basic working app framework
@ripienaar
Copy link
Member Author

Draft docs PR here choria-io/website#90

ripienaar added a commit to ripienaar/go-choria that referenced this issue May 12, 2022
 * Adds specified batching
 * Adds specified filters
 * Adds specified display
 * Adds a progress bar and support disabling

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit that referenced this issue May 12, 2022
(#1665) expand the rpc command for builder
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 12, 2022
ripienaar added a commit that referenced this issue May 12, 2022
(#1665) adds a escape function to handle user input
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 12, 2022
ripienaar added a commit that referenced this issue May 12, 2022
(#1665) allow output format to be forced
@ripienaar
Copy link
Member Author

ripienaar commented May 13, 2022

Some notes on enhancements while trying to build something with this:

  • should have a discovery type that can show matching hosts
  • should template parse filters
  • -S filters should have semver match also
  • kv should have an optional array of map[string]string for keys, so on a get you can do keys: {B1: K1, B2: K2} and it should render all the keys in a table or something
  • should support boolean flags
  • kv should have JSON output via a --json flag thats always added
  • setting std_filters shouldnt disable filters, they should merge, you may only want to hit all machines of a class and then allow users to add additional filters like country/location/dc/cluster etc. You may also want to force a certain discovery method etc
  • standard command should have a confirm option that will prompt people to confirm, should be a string used in the prompt
  • rpc command should have a confirm option that will prompt when an empty filter is given, should be a string used in the prompt
  • kv should have history
  • kv put should be able to read a file - should actually be a template function to a read a file

ripienaar added a commit to ripienaar/go-choria that referenced this issue May 14, 2022
 * Adds a prompt to confirm any action
 * Adds a prompt to confirm rpc without a filter
 * Adds kv history

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 14, 2022
 * Adds a prompt to confirm any action
 * Adds a prompt to confirm rpc without a filter
 * Adds kv history

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 14, 2022
 * Adds a prompt to confirm any action
 * Adds a prompt to confirm rpc without a filter
 * Adds kv history

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit that referenced this issue May 14, 2022
(#1665) Additions to application builder
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 15, 2022
Will merge settings allowing for hard coded filters
augmented with cli supplied ones

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit that referenced this issue May 15, 2022
(#1665) allow filter and std filter to be used together
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 16, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 16, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 16, 2022
ripienaar added a commit that referenced this issue May 16, 2022
(#1665) support rendering json in kv history and get
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 16, 2022
ripienaar added a commit that referenced this issue May 16, 2022
(#1665) various bug fixes and template parse filters
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 16, 2022
ripienaar added a commit that referenced this issue May 16, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 16, 2022
ripienaar added a commit that referenced this issue May 17, 2022
(#1665) move filter to a more appropriate place
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 17, 2022
ripienaar added a commit that referenced this issue May 17, 2022
(#1665) fix json rendering of kv history
ripienaar added a commit that referenced this issue May 19, 2022
(#1665) Update builder.json: small schema fixes
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 23, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 23, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 23, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 23, 2022
ripienaar added a commit that referenced this issue May 23, 2022
(#1665) use choria-io/appbuilder for core appbuilder behaviors
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 25, 2022
Also update dependencies

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit that referenced this issue May 25, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 25, 2022
ripienaar added a commit that referenced this issue May 25, 2022
(#1665) add transforms to kv and some bug fixes
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 25, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue May 25, 2022
ripienaar added a commit that referenced this issue May 25, 2022
(#1665) improve kv validate error message
ripienaar added a commit that referenced this issue May 26, 2022
ripienaar added a commit that referenced this issue May 26, 2022
(#1665) use appbuilder transform, add rpc validations
ripienaar added a commit that referenced this issue May 26, 2022
ripienaar added a commit that referenced this issue May 26, 2022
(#1665) allow discovery method and options to be templat parsed
ripienaar added a commit to ripienaar/go-choria that referenced this issue Jun 2, 2022
ripienaar added a commit to ripienaar/go-choria that referenced this issue Jun 2, 2022
ripienaar added a commit that referenced this issue Jun 2, 2022
(#1665) allow kv bucket and key to be templates
@ripienaar
Copy link
Member Author

Closing this, future enhancements as new issues.

ripienaar added a commit to ripienaar/go-choria that referenced this issue Jun 10, 2022
Also update dependencies

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit to ripienaar/go-choria that referenced this issue Jun 10, 2022
Also update dependencies

Signed-off-by: R.I.Pienaar <[email protected]>
ripienaar added a commit that referenced this issue Jun 10, 2022
(#1665) ensure batching works in app builder rpc command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant