def __init__(self, k8s, port=10255): """ @param k8s - a KubernetesApi object """ pod_name = k8s.get_pod_name() pod = k8s.query_pod(k8s.namespace, pod_name) spec = pod.get('spec', {}) status = pod.get('status', {}) host_ip = status.get('hostIP', None) if host_ip is None: raise KubeletApiException("Unable to get host IP for pod: %s/%s" % (k8s.namespace, pod_name)) self._session = requests.Session() headers = { 'Accept': 'application/json', } self._session.headers.update(headers) self._http_host = "http://%s:%d" % (host_ip, port) self._timeout = 10.0
def _ensure_session(self): """Create the session if it doesn't exist, otherwise do nothing """ if not self._session: self._session = requests.Session() self._session.headers.update(self._standard_headers)
def __check_session(self): if not self.__session: self.__session = requests.Session() if self.__proxies is not None: self.__session.proxies = self.__proxies self.__session.headers.update(self._standard_headers)