github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/internals/plugins/base.mdx (about) 1 --- 2 layout: docs 3 page_title: Base Plugin 4 sidebar_title: Base 5 description: Learn about how to author a Nomad plugin. 6 --- 7 8 # Base Plugin 9 10 The base plugin is a special plugin type implemented by all plugins. It allows 11 for common plugin operations such as defining a configuration schema and 12 version information. 13 14 ## Plugin API 15 16 #### `PluginInfo() (*PluginInfoResponse, error)` 17 18 A `PluginInfoResponse` contains meta data about the plugin. 19 20 ```go 21 PluginInfoResponse{ 22 // Type is the plugin type which is implemented 23 Type: PluginTypeDriver, 24 // Plugin API versions supported by the plugin 25 PluginApiVersions: []string{drivers.ApiVersion010}, 26 // Version of the plugin 27 PluginVersion: "0.1.0", 28 // Name of the plugin 29 Name: "foodriver", 30 } 31 ``` 32 33 #### `ConfigSchema() (*hclspec.Spec, error)` 34 35 The `ConfigSchema` function allows a plugin to tell Nomad the schema for its 36 configuration. This configuration is given in a [plugin block][pluginblock] of 37 the client configuration. The schema is defined with the [hclspec][hclspec] 38 package. 39 40 #### `SetConfig(config *Config) error` 41 42 The `SetConfig` function is called when starting the plugin for the first 43 time. The `Config` given has two different configuration fields. The first 44 `PluginConfig`, is an encoded configuration from the `plugin` block of the 45 client config. The second, `AgentConfig`, is the Nomad agent's configuration 46 which is given to all plugins. 47 48 ## HCL Specifications 49 50 `*hclspec.Spec` is a struct that defines the schema to validate an HCL entity 51 against. The full documentation of the different hcl attribute types can be 52 found on the [hclspec godoc][hclspec]. 53 54 For a basic example, lets look at the driver configuration for the raw_exec 55 driver: 56 57 ```hcl 58 job "example" { 59 ... 60 driver = "raw_exec" 61 config { 62 command = "/bin/sleep" 63 args = ["100"] 64 } 65 } 66 ``` 67 68 The `config` block is what is validated against the `hclspec.Spec`. It has two 69 keys, command which takes a string attribute and args which takes an array 70 attribute. The corresponding `*hclspec.Spec` would be: 71 72 ```go 73 spec := hclspec.NewObject(map[string]*hclspec.Spec{ 74 "command": hclspec.NewAttr("command", "string", true), 75 "args": hclspec.NewAttr("args", "list(string)", false), 76 }) 77 ``` 78 79 [hclspec]: https://godoc.org/github.com/hashicorp/nomad/plugins/shared/hclspec 80 [pluginblock]: /docs/configuration/plugin