github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/docs/cli.md (about)

     1  # Utitliy Commands
     2  
     3  Gohan provides various utitliy commands.
     4  
     5  Run ``gohan -h`` to list available commands
     6  
     7  ```
     8  NAME:
     9     gohan - Gohan
    10  
    11  USAGE:
    12     gohan [global options] command [command options] [arguments...]
    13  
    14  COMMANDS:
    15     client			Manage Gohan resources
    16     validate, v			Validate document
    17     init-db, idb			Initialize DB backend with given schema file
    18     convert, conv		Convert DB
    19     server, srv			Run API Server
    20     test_extensions, test_ex	Run extension tests
    21     migrate, mig			Generate goose migration script
    22     template, template		Convert gohan schema using pongo2 template
    23     run, run			Run Gohan script Code
    24     test, test			Run Gohan script Test
    25     openapi, openapi		Convert gohan schema to OpenAPI
    26     markdown, markdown		Convert gohan schema to markdown doc
    27     dot, dot			Convert gohan schema to dot file for graphviz
    28     glace-server, gsrv		Run API Server with graceful restart support
    29     help, h			Shows a list of commands or help for one command
    30  
    31  GLOBAL OPTIONS:
    32     --debug, -d		Show debug messages
    33     --help, -h		show help
    34     --version, -v	print the version
    35  ```
    36  
    37  ## Validate
    38  
    39  ```
    40    NAME:
    41       validate - Validate Json Schema file
    42  
    43    USAGE:
    44       command validate [command options] [arguments...]
    45  
    46    DESCRIPTION:
    47  
    48  
    49    OPTIONS:
    50       --schema, -s '../schema/core.json'   Json schema path
    51       --json, -i '../example/example.json' json path
    52  ```
    53  
    54  ## Template
    55  
    56  ```
    57      NAME:
    58          template - Convert gohan schema using pongo2 template
    59  
    60      USAGE:
    61          command template [command options] [arguments...]
    62  
    63      DESCRIPTION:
    64          Convert gohan schema using pongo2 template
    65  
    66      OPTIONS:
    67          --config-file "gohan.yaml"	Server config File
    68          --template, -t 		Template File
    69  ```
    70  
    71  ## OpenAPI
    72  
    73  ```
    74      NAME:
    75          openapi - Convert gohan schema to OpenAPI
    76  
    77      USAGE:
    78          command openapi [command options] [arguments...]
    79  
    80      DESCRIPTION:
    81          Convert gohan schema to OpenAPI
    82  
    83      OPTIONS:
    84          --config-file "gohan.yaml"				Server config File
    85          --template, -t "embed://etc/templates/openapi.tmpl"	Template File
    86  ```
    87  
    88  ## MarkDown
    89  
    90  ```
    91      NAME:
    92          markdown - Convert gohan schema using pongo2 template
    93  
    94      USAGE:
    95          command markdown [command options] [arguments...]
    96  
    97      DESCRIPTION:
    98          Convert gohan schema using pongo2 template
    99  
   100      OPTIONS:
   101          --config-file "gohan.yaml"				Server config File
   102          --template, -t "embed://etc/templates/markdown.tmpl"	Template File
   103  ```
   104  
   105  ## CLI Client
   106  
   107  You can use gohan client command to connect to gohan.
   108  
   109  Gohan client will show quick help for sub command for current
   110  server schema.
   111  
   112  ### Configuration
   113  
   114  Gohan CLI Client is configured though environment variables. Configuration can be divided into few sections.
   115  You can use default configuraion for client with: source ./etc/gohan_client.rc
   116  
   117  ### Keystone
   118  
   119  To configure keystone access for Gohan Client CLI, only few options should be set (they are compatible with those
   120  from rackspace/gophercloud:
   121  
   122  * `OS_AUTH_URL` - keystone url
   123  * `OS_USERNAME` - keystone username
   124  * `OS_PASSWORD` - keystone password
   125  * `OS_TENANT_NAME` or `OS_TENANT_ID` - keystone tenant name or id
   126  * `OS_DOMAIN_NAME` or `OS_DOMAIN_ID` - keystone domain name or id (for keystone v3 only)
   127  * `OS_TOKEN_ID` - token ID used to authenticate requests
   128  
   129  ### Endpoint
   130  
   131  Gohan enpoint url can be specified directly or Gohan Client can get it from configured keystone.
   132  
   133  To specify endpoint directly, set `GOHAN_ENDPOINT_URL` to proper url.
   134  
   135  When using keystone:
   136  
   137  * `GOHAN_SERVICE_NAME` - Gohan service name in keystone
   138  * `GOHAN_REGION` - Gohan region name in keystone
   139  
   140  **Note:** setting all above options will result in using `GOHAN_ENDPOINT_URL`!
   141  
   142  ### Schemas
   143  
   144  Gohan CLI Client is fetching available schemas from Gohan endpoint and can cache them in temp file for performance:
   145  
   146  * `GOHAN_SCHEMA_URL` - Gohan schema url
   147  * `GOHAN_CACHE_SCHEMAS` - should cache schemas (default - true)
   148  * `GOHAN_CACHE_TIMEOUT` - how long cache is valid, uses 1h20m10s format (default - 5m)
   149  * `GOHAN_CACHE_PATH` - where to store cache schemas (default - `/tmp/.cached_gohan_schemas`)
   150  
   151  ### Usage
   152  
   153  Usage can be briefly described with:
   154  
   155  ```
   156  gohan client schema_id command [arguments...] [resource_identifier]
   157  ```
   158  
   159  Each part of above command is described below.
   160  
   161  ### Schema_id
   162  
   163  `schema_id` determines which resource type we want to manage.
   164  
   165  If used `schema_id` is not defined in Gohan, Gohan CLI Client will return `Command not found` error.
   166  
   167  ### Command
   168  
   169  Commands are identical for each resources:
   170  
   171  * `list` - List all resources
   172  * `show` - Show resource details
   173  * `create` - Create resource
   174  * `set` - Update existing resource
   175  * `delete` - Delete resource
   176  
   177  ### Arguments
   178  
   179  Arguments should be specified in `--name value` format.
   180  Passing JSON null value `--name "<null>"`
   181  Passing JSON not null value `--name '{"name": [{"name": "value"}, {"name": "value"}]}'`
   182  
   183  ### Common arguments
   184  
   185  In addition to resource related commands, some formatting commands are available:
   186  
   187  * `--output-format [json/table]` - specifies in which format results should be shown. Can also be specified with :code:`GOHAN_OUTPUT_FORMAT` environment variable.
   188  
   189    - `json`, e.g:
   190  
   191  ```
   192        {
   193          "name": "Resource name",
   194          "description": "Resource very long and meaningful description",
   195          "some_list": [
   196            "list_element_1",
   197            "list_element_2"
   198          ]
   199        }
   200      ..
   201  ```
   202  
   203    - :code:`table`, e.g:
   204  
   205  ```
   206        +-------------+--------------------------------------+
   207        |    FIELD    |               TYPE                   |
   208        +-------------+--------------------------------------+
   209        | name        | Resource name                        |
   210        | description | Resource description                 |
   211        | some_list   | ["list_element_1", "list_element_2"] |
   212        +-------------+--------------------------------------+
   213  ```
   214  
   215  * :code:`--verbosity [0-3]` - specifies how much information Gohan Client should show - handy for dubugging. Can also be specified with :code:`GOHAN_VERBOSITY` environment variable.
   216  
   217    - :code:`0` - no additional debug information is shown
   218    - :code:`1` - Sent request url and method is shown
   219    - :code:`2` - same as level :code:`1` + request & response body
   220    - :code:`3` - same as level :code:`2` + used auth token
   221  
   222  ### Resource identifier
   223  
   224  Some commands (:code:`show, set, delete`) are executed on one resource only. To identify whis reource,
   225  it's name or id could be used:
   226  
   227  ```
   228    gohan client network show network-id
   229    gohan client network show "Network Name"
   230    gohan client subnet create --network "Network Name"
   231    gohan client subnet create --network network-id
   232    gohan client subnet create --network_id network-id
   233  ```
   234  
   235  ### Custom commands
   236  
   237  Any custom actions specified in schema are also supported as commands by gohan client and should be invoked as follows:
   238  
   239  ```
   240  gohan client schema_id command [common arguments] [command input] [resource identifier]
   241  ```
   242  
   243  Where `common arguments` and `resource identifier` are described aboved and `command input` is passed as JSON value.
   244  
   245  # Sync with backend
   246  
   247  Gohan stores an event log recording create, update and delete database operations.
   248  This is done in the database transaction, so we can assume that
   249  this event log data is consistent with the resource data.
   250  
   251  The event log data contains the following information. (see schema in gohan.json)
   252  
   253  - id -- an unique ID of the event
   254  - type -- the type of the event
   255  - path -- the path of the resource related to the event
   256  - timestamp -- the time at which the event occurred
   257  - version -- the version of the resource after this event occurred
   258  - body -- the contents of the resource after this event occurred
   259  
   260  The Gohan server will select one master node using the etcd backend CAS API.
   261  Only the master node will then poll the event log table, pushing to the backend.
   262  
   263  We may support mysql binlog api for better performance in future.
   264  
   265  ## State updates
   266  
   267  Gohan will keep track of the state version of any resource associated to
   268  a schema with metadata containing the key ``state_versioning`` set to
   269  ``true``. In such a case Gohan will remember the config version and
   270  the state version of the resource. During creation the config version of
   271  such a resource will be set to ``1``. On delete and update the version is
   272  bumped by one. The state version is ``0`` originally and later read from
   273  the sync backend and updated asynchronously. Both the versions are returned
   274  in GET requests, together with additional information about the state.
   275  
   276  For example say a simplistic resource with the following schema is created:
   277  
   278  ```
   279      - description: Just a named object
   280        id: named_object
   281        parent: ""
   282        metadata:
   283          state_versioning: true
   284        singular: named_object
   285        plural: named_object
   286        prefix: /v1.0
   287        schema:
   288          properties:
   289            name:
   290              default: ""
   291              permission:
   292              - create
   293              - update
   294              title: Name
   295              type: string
   296              unique: false
   297            id:
   298              permission:
   299              - create
   300              title: ID
   301              type: string
   302              format: uuid
   303          properties_order:
   304          - id
   305          - name
   306          required:
   307          - name
   308          type: object
   309        title: Named Object
   310  ```
   311  
   312  and the ``name`` is set to ``Alice``. Then Gohan, through the standard event sync,
   313  writes the following JSON object to the backend under the key
   314  ``config/v1.0/named_object/someGeneratedUuid``:
   315  
   316  ```
   317      {
   318        "body": {
   319          "id": "someGeneratedUuid",
   320          "name": "Alice"
   321        },
   322        "version": 1
   323      }
   324  ```
   325  
   326  A worker program might now read this information, create a corresponding
   327  southbound resource and write the following to the backend under the key
   328  ``state/v1.0/named_object/someGeneratedUuid``:
   329  
   330  ```
   331      {
   332        "version": 1,
   333        "error": "",
   334        "state": "Alice exists"
   335      }
   336  ```
   337  
   338  Gohan will read this information and update the database accordingly.
   339  
   340  Any state updates made when the state version already equals the config version
   341  will be ignored.
   342  
   343  ## Monitoring updates
   344  
   345  After a resource has been created in the southbound, one might monitor its
   346  status. This is done using a very similar approach to status updates.
   347  Monitoring updates the ``monitoring`` field in the database, which is returned
   348  together with the rest of the state.
   349  
   350  A continuation of the above example follows. After the resource has been created
   351  in the southbound a worker program might monitor its status and then write
   352  the result of this monitoring under the key
   353  ``monitoring/v1.0/named_object/someGeneratedUuid`` as the following JSON:
   354  
   355  ```
   356      {
   357        "version": 1,
   358        "monitoring": "Alice is well"
   359      }
   360  ```
   361  
   362  Gohan will read this information and update the database accordingly.
   363  
   364  Any monitoring updates made when the state version does not yet equal
   365  the config version or the version in the JSON data doesn't match with
   366  the config version will be ignored.