|
24 | 24 |
|
25 | 25 | from __future__ import print_function
|
26 | 26 |
|
| 27 | +import collections |
27 | 28 | import configparser
|
28 |
| -import json |
| 29 | +import inspect |
29 | 30 | import os
|
30 | 31 | import sys
|
31 | 32 | from collections import OrderedDict
|
| 33 | +from textwrap import dedent |
32 | 34 |
|
33 | 35 | import fire
|
34 |
| - |
35 |
| -from jinja2 import Environment |
36 | 36 | import six
|
37 |
| -import yaml |
| 37 | +from jinja2 import Environment |
38 | 38 |
|
39 |
| -from hpecp.logger import Logger |
40 |
| -from textwrap import dedent |
41 |
| -import inspect |
42 |
| -import collections |
43 |
| -from hpecp.user import User |
44 |
| -from hpecp.role import Role |
45 |
| -from hpecp.cli import base |
| 39 | +from hpecp import ContainerPlatformClient |
46 | 40 | from hpecp.cli.catalog import CatalogProxy
|
47 | 41 | from hpecp.cli.gateway import GatewayProxy
|
48 |
| -from hpecp.cli.k8sworker import K8sWorkerProxy |
| 42 | +from hpecp.cli.httpclient import HttpClientProxy |
49 | 43 | from hpecp.cli.k8scluster import K8sClusterProxy
|
50 |
| -from hpecp.cli.tenant import TenantProxy |
| 44 | +from hpecp.cli.k8sworker import K8sWorkerProxy |
51 | 45 | from hpecp.cli.license import LicenseProxy
|
52 |
| - |
53 |
| -from hpecp import ContainerPlatformClient |
54 |
| - |
55 |
| - |
56 |
| -if sys.version_info[0] >= 3: |
57 |
| - unicode = str |
58 |
| - |
59 |
| -_log = Logger.get_logger() |
60 |
| - |
61 |
| - |
62 |
| -class LockProxy(object): |
63 |
| - """Proxy object to :py:attr:`<hpecp.client.lock>`.""" |
64 |
| - |
65 |
| - def __dir__(self): |
66 |
| - """Return the CLI method names.""" |
67 |
| - return [ |
68 |
| - "create", |
69 |
| - "delete", |
70 |
| - "delete_all", |
71 |
| - "list", |
72 |
| - ] |
73 |
| - |
74 |
| - def list( |
75 |
| - self, output="yaml", |
76 |
| - ): |
77 |
| - """Get the system and user locks. |
78 |
| -
|
79 |
| - :param output: how to display the output ['yaml'|'json'] |
80 |
| - """ |
81 |
| - if output not in ["yaml", "json"]: |
82 |
| - print( |
83 |
| - "'output' parameter must be 'yaml' or 'json'", file=sys.stderr |
84 |
| - ) |
85 |
| - sys.exit(1) |
86 |
| - |
87 |
| - response = base.get_client().lock.get() |
88 |
| - |
89 |
| - if output == "yaml": |
90 |
| - print( |
91 |
| - yaml.dump( |
92 |
| - yaml.load(json.dumps(response), Loader=yaml.FullLoader,) |
93 |
| - ) |
94 |
| - ) |
95 |
| - else: |
96 |
| - print(json.dumps(response)) |
97 |
| - |
98 |
| - @base.intercept_exception |
99 |
| - def create( |
100 |
| - self, reason, |
101 |
| - ): |
102 |
| - """Create a lock.""" |
103 |
| - print(base.get_client().lock.create(reason), file=sys.stdout) |
104 |
| - |
105 |
| - @base.intercept_exception |
106 |
| - def delete( |
107 |
| - self, id, |
108 |
| - ): |
109 |
| - """Delete a user lock.""" |
110 |
| - base.get_client().lock.delete(id) |
111 |
| - |
112 |
| - @base.intercept_exception |
113 |
| - def delete_all( |
114 |
| - self, timeout_secs=300, |
115 |
| - ): |
116 |
| - """Delete all locks.""" |
117 |
| - success = base.get_client().lock.delete_all(timeout_secs=timeout_secs) |
118 |
| - if not success: |
119 |
| - print("Could not delete locks.", file=sys.stderr) |
120 |
| - sys.exit(1) |
121 |
| - |
122 |
| - |
123 |
| -class HttpClientProxy(object): |
124 |
| - """Proxy object to :py:attr:`<hpecp.client._request>`.""" |
125 |
| - |
126 |
| - def __dir__(self): |
127 |
| - """Return the CLI method names.""" |
128 |
| - return ["delete", "get", "post", "put"] |
129 |
| - |
130 |
| - @base.intercept_exception |
131 |
| - def get( |
132 |
| - self, url, |
133 |
| - ): |
134 |
| - """Make HTTP GET request. |
135 |
| -
|
136 |
| - Examples |
137 |
| - -------- |
138 |
| - $ hpecp httpclient get /api/v1/workers |
139 |
| - """ |
140 |
| - response = base.get_client()._request( |
141 |
| - url, http_method="get", description="CLI HTTP GET", |
142 |
| - ) |
143 |
| - print(response.text, file=sys.stdout) |
144 |
| - |
145 |
| - @base.intercept_exception |
146 |
| - def delete( |
147 |
| - self, url, |
148 |
| - ): |
149 |
| - """Make HTTP DELETE request. |
150 |
| -
|
151 |
| - Examples |
152 |
| - -------- |
153 |
| - $ hpecp httpclient delete /api/v1/workers/1 |
154 |
| - """ |
155 |
| - base.get_client()._request( |
156 |
| - url, http_method="delete", description="CLI HTTP DELETE", |
157 |
| - ) |
158 |
| - |
159 |
| - @base.intercept_exception |
160 |
| - def post( |
161 |
| - self, url, json_file="", |
162 |
| - ): |
163 |
| - """Make HTTP POST request. |
164 |
| -
|
165 |
| - Examples |
166 |
| - -------- |
167 |
| - $ cat > my.json <<-EOF |
168 |
| - { |
169 |
| - "external_identity_server": { |
170 |
| - "bind_pwd":"5ambaPwd@", |
171 |
| - "user_attribute":"sAMAccountName", |
172 |
| - "bind_type":"search_bind", |
173 |
| - "bind_dn":"cn=Administrator,CN=Users,DC=samdom,DC=example,DC=com", |
174 |
| - "host":"10.1.0.77", |
175 |
| - "security_protocol":"ldaps", |
176 |
| - "base_dn":"CN=Users,DC=samdom,DC=example,DC=com", |
177 |
| - "verify_peer": false, |
178 |
| - "type":"Active Directory", |
179 |
| - "port":636 |
180 |
| - } |
181 |
| - } |
182 |
| - EOF |
183 |
| -
|
184 |
| - hpecp httpclient post /api/v2/config/auth --json-file my.json |
185 |
| - """ |
186 |
| - with open(json_file, "r",) as f: |
187 |
| - data = json.load(f) |
188 |
| - |
189 |
| - response = base.get_client()._request( |
190 |
| - url, http_method="post", data=data, description="CLI HTTP POST", |
191 |
| - ) |
192 |
| - print(response.text, file=sys.stdout) |
193 |
| - |
194 |
| - @base.intercept_exception |
195 |
| - def put( |
196 |
| - self, url, json_file="", |
197 |
| - ): |
198 |
| - """Make HTTP PUT request. |
199 |
| -
|
200 |
| - Examples |
201 |
| - -------- |
202 |
| - $ hpecp httpclient put /api/v2/config/auth --json-file my.json |
203 |
| - """ # noqa: W293 |
204 |
| - with open(json_file, "r",) as f: |
205 |
| - data = json.load(f) |
206 |
| - |
207 |
| - response = base.get_client()._request( |
208 |
| - url, http_method="put", data=data, description="CLI HTTP PUT", |
209 |
| - ) |
210 |
| - print(response.text, file=sys.stdout) |
211 |
| - |
212 |
| - |
213 |
| -class UserProxy(base.BaseProxy): |
214 |
| - """Proxy object to :py:attr:`<hpecp.client.user>`.""" |
215 |
| - |
216 |
| - def __dir__(self): |
217 |
| - """Return the CLI method names.""" |
218 |
| - return ["create", "get", "delete", "examples", "list"] |
219 |
| - |
220 |
| - def __init__(self): |
221 |
| - """Create instance of proxy class with the client module name.""" |
222 |
| - super(UserProxy, self).new_instance("user", User) |
223 |
| - |
224 |
| - @base.intercept_exception |
225 |
| - def create( |
226 |
| - self, name, password, description, is_external=False, |
227 |
| - ): |
228 |
| - """Create a User. |
229 |
| -
|
230 |
| - :param name: the user name |
231 |
| - :param password: the password |
232 |
| - :param description: the user descripton |
233 |
| -
|
234 |
| - """ |
235 |
| - user_id = base.get_client().user.create( |
236 |
| - name=name, |
237 |
| - password=password, |
238 |
| - description=description, |
239 |
| - is_external=is_external, |
240 |
| - ) |
241 |
| - print(user_id) |
242 |
| - |
243 |
| - def examples(self): |
244 |
| - """Show usage_examples of the list method.""" |
245 |
| - print( |
246 |
| - dedent( |
247 |
| - """\ |
248 |
| -
|
249 |
| - hpecp user list --query '[?is_external]' --output json-pp |
250 |
| - """ # noqa: E501 |
251 |
| - ) |
252 |
| - ) |
253 |
| - |
254 |
| - |
255 |
| -class RoleProxy(base.BaseProxy): |
256 |
| - """Proxy object to :py:attr:`<hpecp.client.role>`.""" |
257 |
| - |
258 |
| - def __dir__(self): |
259 |
| - """Return the CLI method names.""" |
260 |
| - return ["delete", "examples", "get", "list"] |
261 |
| - |
262 |
| - def __init__(self): |
263 |
| - """Create instance of proxy class with the client module name.""" |
264 |
| - super(RoleProxy, self).new_instance("role", Role) |
265 |
| - |
266 |
| - def examples(self): |
267 |
| - """Show examples for working with roles.""" |
268 |
| - print( |
269 |
| - dedent( |
270 |
| - """\ |
271 |
| - |
272 |
| - # Retrieve the role ID for 'Admin' |
273 |
| - $ hpecp role list --query "[?label.name == 'Admin'][_links.self.href] | [0][0]" --output json | tr -d '"' |
274 |
| - /api/v1/role/2 |
275 |
| - """ # noqa: E501 |
276 |
| - ) |
277 |
| - ) |
| 46 | +from hpecp.cli.lock import LockProxy |
| 47 | +from hpecp.cli.role import RoleProxy |
| 48 | +from hpecp.cli.tenant import TenantProxy |
| 49 | +from hpecp.cli.user import UserProxy |
| 50 | +from hpecp.logger import Logger |
278 | 51 |
|
279 | 52 |
|
280 | 53 | def configure_cli():
|
@@ -424,6 +197,7 @@ def _get_metadata(self):
|
424 | 197 | modules[module_name] = function_parameters
|
425 | 198 | columns[module_name] = all_fields
|
426 | 199 |
|
| 200 | + # _log = Logger.get_logger() |
427 | 201 | # _log.debug(modules)
|
428 | 202 | # _log.debug(columns)
|
429 | 203 |
|
|
0 commit comments