Total Complexity | 4 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """Translate cli commands to non-cli code.""" |
||
2 | import logging |
||
3 | from urllib.error import HTTPError, URLError |
||
4 | |||
5 | import requests |
||
6 | |||
7 | from kytos.utils.config import KytosConfig |
||
8 | |||
9 | LOG = logging.getLogger(__name__) |
||
10 | |||
11 | |||
12 | class WebAPI: # pylint: disable=too-few-public-methods |
||
13 | """An API for the command-line interface.""" |
||
14 | |||
15 | @classmethod |
||
16 | def update(cls, args): |
||
17 | """Call the method to update the Web UI.""" |
||
18 | kytos_api = KytosConfig().config.get('kytos', 'api') |
||
19 | url = f"{kytos_api}api/kytos/core/web/update" |
||
20 | version = args["<version>"] |
||
21 | if version: |
||
22 | url += f"/{version}" |
||
23 | |||
24 | try: |
||
25 | result = requests.post(url, timeout=20) |
||
26 | except (HTTPError, URLError, requests.exceptions.ConnectionError, |
||
27 | requests.exceptions.Timeout): |
||
28 | LOG.error("Can't connect to server: %s", kytos_api) |
||
29 | return |
||
30 | |||
31 | if result.status_code != 200: |
||
32 | LOG.info("Error while updating web ui: %s", result.content) |
||
33 | else: |
||
34 | LOG.info("Web UI updated.") |
||
35 |