mirror of https://github.com/jumpserver/jumpserver
parent
ab76d8cce0
commit
e3d1474b9b
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from urllib3.exceptions import MaxRetryError
|
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
from urllib3.exceptions import MaxRetryError, LocationParseError
|
||||||
|
|
||||||
from kubernetes import client
|
from kubernetes import client
|
||||||
from kubernetes.client import api_client
|
from kubernetes.client import api_client
|
||||||
|
@ -8,7 +8,7 @@ from kubernetes.client.api import core_v1_api
|
||||||
from kubernetes.client.exceptions import ApiException
|
from kubernetes.client.exceptions import ApiException
|
||||||
|
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
|
from common.exceptions import JMSException
|
||||||
from ..const import CloudTypes, Category
|
from ..const import CloudTypes, Category
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
@ -58,15 +58,21 @@ class KubernetesClient:
|
||||||
api = self.get_api()
|
api = self.get_api()
|
||||||
try:
|
try:
|
||||||
ret = api.list_pod_for_all_namespaces(watch=False, _request_timeout=(3, 3))
|
ret = api.list_pod_for_all_namespaces(watch=False, _request_timeout=(3, 3))
|
||||||
|
except LocationParseError as e:
|
||||||
|
logger.warning("Kubernetes API request url error: {}".format(e))
|
||||||
|
raise JMSException(code='k8s_tree_error', detail=e)
|
||||||
except MaxRetryError:
|
except MaxRetryError:
|
||||||
logger.warning('Kubernetes connection timed out')
|
msg = "Kubernetes API request timeout"
|
||||||
return
|
logger.warning(msg)
|
||||||
|
raise JMSException(code='k8s_tree_error', detail=msg)
|
||||||
except ApiException as e:
|
except ApiException as e:
|
||||||
if e.status == 401:
|
if e.status == 401:
|
||||||
logger.warning('Kubernetes User not authenticated')
|
msg = "Kubernetes API request unauthorized"
|
||||||
|
logger.warning(msg)
|
||||||
else:
|
else:
|
||||||
logger.warning(e)
|
msg = e
|
||||||
return
|
logger.warning(msg)
|
||||||
|
raise JMSException(code='k8s_tree_error', detail=msg)
|
||||||
data = {}
|
data = {}
|
||||||
for i in ret.items:
|
for i in ret.items:
|
||||||
namespace = i.metadata.namespace
|
namespace = i.metadata.namespace
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ConnectionTokenSerializer(OrgResourceModelSerializerMixin):
|
||||||
label=_("Input secret"), max_length=40960, required=False, allow_blank=True
|
label=_("Input secret"), max_length=40960, required=False, allow_blank=True
|
||||||
)
|
)
|
||||||
from_ticket_info = serializers.SerializerMethodField(label=_("Ticket info"))
|
from_ticket_info = serializers.SerializerMethodField(label=_("Ticket info"))
|
||||||
actions = ActionChoicesField()
|
actions = ActionChoicesField(read_only=True, label=_("Actions"))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ConnectionToken
|
model = ConnectionToken
|
||||||
|
|
Loading…
Reference in New Issue