Use mtl init
to initialize the environment for mtl. Creates a workspace in current working directory.
mtl init
Default values are: --name $(hostname) --dir $(pwd)
Initialize mtl with a specific name and base directory.
mtl init --name Targa.local --dir /home/alexh/mtl
Return a metadata value by specifying the name of the property.
mtl info --name|-n <property>
Get the value of the name property.
mtl info --name name
returns ...
web1.local
Get the value of the dir property.
mtl info -n dir
returns ...
/home/alexh/mtl
Use mtl attribute
to declare attributes about this instance.
Can describe properties and state.
mtl attribute -n listen_port -v 8080
mtl attribute -n mypath -v /my/path
mtl attribute -n status -v active
Return the value of an attribute.
mtl attribute -n listen_port
returns... 8080
Use a prefix in the attribute to organize them. Use machine-tags format.
mtl attribute -n namespace:predicate -v value
Declare some attributes across several namespaces.
mtl attribute -n packages:tomcat -v tomcat-7.0.42.zip
mtl attribute -n packages:estore -v estore-1.0.42.war
mtl attribute -n estore:customer -v acme.com
mtl attribute -n estore:url -v http://192.168.50.12:8080/estore
mtl attribute -n tomcat:listen_port -v 8080
mtl attribute -n tomcat:catalina_base -v /home/tomcat
Alternative mtl syntax using long option name for name and value parameters.
mtl attribute --name listen_port --value 8080
Use attributes to model metrics.
mtl attribute -n metrics:estore.deploys -v 5
mtl attribute -n metrics:estore.restarts -v 5
mtl attribute --name|-n <attribute> [--clear --remove]
Clear the value for status.
mtl attribute -n status --clear
Remove status.
mtl attribute -n status --remove
Use mtl attributes
to list all the attributes for this instance.
mtl attributes
List attribute names in foo namespace.
mtl attributes -n "tomcat:*"
returns...
tomcat:listen_port
tomcat:catalina_base
List attributes and show their values.
mtl attributes -n "tomcat:*" --value
returns...
tomcat:listen_port 8080
tomcat:catalina_base /home/tomcat
Declare new commands with mtl command
.
Define status command with an inline script:
mtl command -n status --script "curl -sf `mtl attribute -n estore:url`; exit $?"
A stop command that executes a script file:
mtl command -n stop --scriptfile $(mtl info -n dir)/bin/stop
Define stop command but scriptfile is a url address:
mtl command -n stop --scriptfile http://repo/script
Delegate command to another module. The other module must contain the same command.
mtl command -n start --delegate altmodule
List the commands with mtl commands
.
mtl commands
returns ...
start
status
stop
List commands starting with 'sto':
mtl commands -n "sto*"
returns ...
stop
Use mtl exec
to execute declared commands.
Execute start command defined in this instance:
mtl exec -n stop
Execute a command with options:
mtl exec -n status --url $(mtl attribute estore:url)
Execute a command in another mtl module
mtl exec -m othermodule -n command
Use mtl option
to declare an option for a command.
mtl option -n <name> --command <> --arguments <> --default <> --description <>
Create an option called --jumps for the command, dance:
mtl option -n jumps --command dance --arguments true --default 3 --description 'num times to jump'
Changes usage for the dance command to:
mtl exec dance --jumps <3>
Similar usage as stubbs:add-option.
Specify the command name:
mtl option --command dance
returns ...
jumps
The mtl init
initializes a directory structure and stores metadata for the new mtl instance
.
|-- attributes/
|-- commands/
`-- metadata
The metadata file contains the name and dir values used by mtl init
name="Targa.local"
dir="/home/alexh/mtl
created_at="Thu Jan 16 09:20:56 PST 2014"
created_by="alexh"
The attributes and commands directory are discussed in sections below.
Attribute metadata stored in flat files
.
|-- attributes/
| |-- listen_port/
| |-- mypath/
| `-- status/
| `-- metadata
|-- commands/
`-- metadata
The metadata file contains the properties about the attribute
cat ./attributes/status/metadata
NAME="status"
VALUE="myvalue"
Command metadata stored in flat files
.
|-- attributes/
|-- commands/
| |-- start/
| |-- status/
| `-- stop/
| `-- metadata
`-- metadata
The metadata file contains the properties about the attribute
cat ./commands/stop/metadata
NAME="stop"
DESCRIPTION="stop command"
OPTIONS=""
mtl data can be shared with other nodes through synchronization of the mtl metadata. How synchronization is done depends on the backend.
Module containing backend implementation is defaulted to ... env_var or attribute?
The publish flag synchronizes mtl state with the backend.
Publish a single attribute to a backing store
mtl attribute -n myvar --publish
Push all attributes matching pattern
mtl attributes -n "stuff:*" --publish
Push the commands
mtl commands --publish
The refresh flag retrieves the latest update from the backing store.
Refresh value for attribute myvar
mtl attribute -n myvar --refresh
Pull all the attributes
mtl attributes --refresh
A defaults system could store handlers for invoking user defined mtl commands.
Here a script handles calls to mtl defined commands.
mtl defaults handler --script "$(mtl exec ${1} ${2} ${@:3})"
Turns user defined commands into mtl sub commands.
mtl stop --foo bar
Default handler resolves to: mtl exec stop --foo bar
Alternative names to mtl.
meta.
meta attribute -n sayhi -v hi
meta command -n sayhi -script "echo ${1:-$(yo:attribute sayhi:message)}"
meta exec sayhi --message "hello"
meta sayhi --message "hello"
node.
node attribute sayhi hi
node command sayhi -script "echo ${1:-$(yo:attribute sayhi:message)}"
node exec sayhi "hello"
node sayhi "hello"
self.
self attribute sayhi:message hi
self attribute --name sayhi:message --value hi
self exec status
yo. Yo is self in spanish:
yo:attribute sayhi:message hi
yo:command sayhi -script "echo ${1:-$(yo:attribute sayhi:message)}"
yo:exec sayhi "hello"
yo:sayhi "hello"
proto. because it's a prototype object system design:
proto:attribute fooattry value_1 ;# alternative namespace ideas
object. object system:
object:attribute fooattry value_1 ;# ditto
instance. same as object:
instance:attribute fooattry value_1 ;# ditto
mtl exec mtl command -n stop