2016-09-26 00:43:46 +03:00
|
|
|
# Copyright (c) 2016 Mirantis, Inc.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2018-05-17 13:40:15 +02:00
|
|
|
import os
|
|
|
|
|
2016-09-26 00:43:46 +03:00
|
|
|
from kuryr.lib import utils
|
2019-02-20 18:15:12 +01:00
|
|
|
from openstack import connection
|
2016-09-26 00:43:46 +03:00
|
|
|
|
|
|
|
from kuryr_kubernetes import config
|
|
|
|
from kuryr_kubernetes import k8s_client
|
2019-03-27 20:05:32 +03:00
|
|
|
from kuryr_kubernetes.pod_resources import client as pr_client
|
2016-09-26 00:43:46 +03:00
|
|
|
|
|
|
|
_clients = {}
|
|
|
|
_NEUTRON_CLIENT = 'neutron-client'
|
|
|
|
_KUBERNETES_CLIENT = 'kubernetes-client'
|
2019-02-20 18:15:12 +01:00
|
|
|
_OPENSTACKSDK = 'openstacksdk'
|
2019-03-27 20:05:32 +03:00
|
|
|
_POD_RESOURCES_CLIENT = 'pod-resources-client'
|
2016-09-26 00:43:46 +03:00
|
|
|
|
|
|
|
|
2019-10-18 07:43:00 +00:00
|
|
|
def get_network_client():
|
|
|
|
return _clients[_OPENSTACKSDK].network
|
|
|
|
|
|
|
|
|
2016-09-26 00:43:46 +03:00
|
|
|
def get_neutron_client():
|
|
|
|
return _clients[_NEUTRON_CLIENT]
|
|
|
|
|
|
|
|
|
2019-02-20 18:15:12 +01:00
|
|
|
def get_openstacksdk():
|
|
|
|
return _clients[_OPENSTACKSDK]
|
|
|
|
|
|
|
|
|
2018-04-11 16:02:39 +02:00
|
|
|
def get_loadbalancer_client():
|
2019-02-20 18:15:12 +01:00
|
|
|
return get_openstacksdk().load_balancer
|
2018-04-11 16:02:39 +02:00
|
|
|
|
|
|
|
|
2016-09-26 00:43:46 +03:00
|
|
|
def get_kubernetes_client():
|
|
|
|
return _clients[_KUBERNETES_CLIENT]
|
|
|
|
|
|
|
|
|
2019-03-27 20:05:32 +03:00
|
|
|
def get_pod_resources_client():
|
|
|
|
return _clients[_POD_RESOURCES_CLIENT]
|
|
|
|
|
|
|
|
|
2016-09-26 00:43:46 +03:00
|
|
|
def setup_clients():
|
2016-11-29 09:34:37 +03:00
|
|
|
setup_neutron_client()
|
|
|
|
setup_kubernetes_client()
|
2019-02-20 18:15:12 +01:00
|
|
|
setup_openstacksdk()
|
2016-11-29 09:34:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
def setup_neutron_client():
|
2016-09-26 00:43:46 +03:00
|
|
|
_clients[_NEUTRON_CLIENT] = utils.get_neutron_client()
|
2016-11-29 09:34:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
def setup_kubernetes_client():
|
2018-05-17 13:40:15 +02:00
|
|
|
if config.CONF.kubernetes.api_root:
|
|
|
|
api_root = config.CONF.kubernetes.api_root
|
|
|
|
else:
|
|
|
|
# NOTE(dulek): This is for containerized deployments, i.e. running in
|
|
|
|
# K8s Pods.
|
|
|
|
host = os.environ['KUBERNETES_SERVICE_HOST']
|
|
|
|
port = os.environ['KUBERNETES_SERVICE_PORT_HTTPS']
|
|
|
|
api_root = "https://%s:%s" % (host, port)
|
|
|
|
_clients[_KUBERNETES_CLIENT] = k8s_client.K8sClient(api_root)
|
2019-02-20 18:15:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def setup_openstacksdk():
|
|
|
|
auth_plugin = utils.get_auth_plugin('neutron')
|
|
|
|
session = utils.get_keystone_session('neutron', auth_plugin)
|
2019-09-10 14:55:36 +02:00
|
|
|
conn = connection.Connection(
|
|
|
|
session=session,
|
|
|
|
region_name=getattr(config.CONF.neutron, 'region_name', None))
|
2019-02-20 18:15:12 +01:00
|
|
|
_clients[_OPENSTACKSDK] = conn
|
2019-03-27 20:05:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
def setup_pod_resources_client():
|
|
|
|
root_dir = config.CONF.sriov.kubelet_root_dir
|
|
|
|
_clients[_POD_RESOURCES_CLIENT] = pr_client.PodResourcesClient(root_dir)
|