File: api.py

package info (click to toggle)
kytos-utils 2019.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 396 kB
  • sloc: python: 1,310; sh: 15; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Translate cli commands to non-cli code."""
import logging
from urllib.error import HTTPError, URLError

import requests

from kytos.utils.config import KytosConfig

LOG = logging.getLogger(__name__)


class WebAPI:  # pylint: disable=too-few-public-methods
    """An API for the command-line interface."""

    @classmethod
    def update(cls, args):
        """Call the method to update the Web UI."""
        kytos_api = KytosConfig().config.get('kytos', 'api')
        url = f"{kytos_api}api/kytos/core/web/update"
        version = args["<version>"]
        if version:
            url += f"/{version}"

        try:
            result = requests.post(url)
        except(HTTPError, URLError, requests.exceptions.ConnectionError):
            LOG.error("Can't connect to server: %s", kytos_api)
            return

        if result.status_code != 200:
            LOG.info("Error while updating web ui: %s", result.content)
        else:
            LOG.info("Web UI updated.")