Seed code for hostcli
[ta/hostcli.git] / README.rst
1 ::
2
3    Copyright 2019 Nokia
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17
18
19 ==============================
20 Host CLI
21 ==============================
22
23 .. raw:: pdf
24
25    PageBreak
26
27 .. sectnum::
28
29 .. contents::
30
31 .. raw:: pdf
32
33    PageBreak
34
35 Introduction
36 ============
37
38 Cloud infratructure is openstack based, openstack services already utilize 
39 a common framework for openstack own commands. These commands are accessed via 
40 the **openstack** command. The syntax used in this command is the following:
41
42 ::
43
44   openstack <openstack domain> <operation> [<options>]
45
46
47 Below is an example of some **openstack** commands.
48
49 ::
50
51   openstack server list
52
53   openstack server show <server-name>
54
55   openstack network list
56
57   ...
58
59 The **openstack** command is implemented ontop of the python **cliff** framework.
60
61 **cliff** framework supports the following:
62
63 - structure the commands tokens.
64
65 - map command tokens to command handlers.
66
67 - parse command arguments.
68
69 - format commands output.
70
71 - bash auto-completion of commands.
72
73 A well integrated platform is expected to provide a common way to access the 
74 interfaces provided by the platform. As such cloud infrastructure utilizes 
75 the same **cliff** framework to implement the infrastrcture own middleware CLIs. 
76
77 The infrastrcutre CLIs can be accessed via the **hostcli** command. 
78
79 The syntax used in this command is the following:
80
81 ::
82
83  hostcli <middleware domain> <operation> [<options>]
84
85 Below is an example of some **hostcli** commands.
86
87 ::
88
89  hostcli has show nodes
90
91  hostcli has show services --node <node-name>
92
93  hostcli motd show
94
95  hostcli motd set --motd <message of the day text>
96
97  ...
98
99 In addition to providing the common look and feel for the end user, the 
100 *hostcli* takes care of authorizing with keystone and provide a token
101 for authentication usage
102
103 The following diagram describes the highlevel design for **hostcli** CLI 
104 frameowk.
105
106 .. image:: docs/hostcli.png
107
108
109 When using yarf restful framework to implement the backend for middleware
110 the frame provides a RestRequest class to make the authentication transperant
111 to a module.
112
113 Example of using this request:
114
115 .. code:: python
116
117     def take_action(self, parsed_args):
118         req = self.app.client_manager.resthandler
119         ret = req.get("has/v1/cluster", decode_json=True)
120         status = ret['data']
121         columns = ('admin-state',
122                    'running-state',
123                    'role'
124                   )
125         data = (status['admin-state'],
126                 status['running-state'],
127                 status['role']
128                 )
129         return (columns, data)
130
131 The beef is ot get the resthandler from client_manager that is defined in the app.
132 This will return the object RestRequest for you that has the HTTP operations predefined.
133 The only thing needed is the path of the url. The actual address should not be defined, 
134 since it's extracted from the keystone session from the endpoints.