2017-06-08 15:30:40 +03:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
import abc
|
|
|
|
|
|
|
|
from kuryr.lib import exceptions as kl_exc
|
2019-11-29 14:56:31 +01:00
|
|
|
from openstack import exceptions as os_exc
|
2017-06-08 15:30:40 +03:00
|
|
|
from oslo_config import cfg as oslo_cfg
|
|
|
|
from oslo_log import log as logging
|
|
|
|
|
2019-12-18 20:40:21 +01:00
|
|
|
from kuryr_kubernetes import clients
|
2020-12-23 17:39:11 +01:00
|
|
|
from kuryr_kubernetes.controller.drivers import base
|
2017-06-08 15:30:40 +03:00
|
|
|
from kuryr_kubernetes.controller.drivers import neutron_vif
|
|
|
|
|
|
|
|
|
2020-12-14 10:01:51 +01:00
|
|
|
CONF = oslo_cfg.CONF
|
2017-06-08 15:30:40 +03:00
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-02-28 12:00:19 +01:00
|
|
|
class NestedPodVIFDriver(neutron_vif.NeutronPodVIFDriver,
|
|
|
|
metaclass=abc.ABCMeta):
|
2017-06-08 15:30:40 +03:00
|
|
|
"""Skeletal handler driver for VIFs for Nested Pods."""
|
|
|
|
|
2020-12-23 17:39:11 +01:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.nodes_subnets_driver = base.NodesSubnetsDriver.get_instance()
|
|
|
|
|
2019-12-18 20:40:21 +01:00
|
|
|
def _get_parent_port_by_host_ip(self, node_fixed_ip):
|
2019-11-29 14:56:31 +01:00
|
|
|
os_net = clients.get_network_client()
|
2020-12-23 17:39:11 +01:00
|
|
|
node_subnet_ids = self.nodes_subnets_driver.get_nodes_subnets(
|
|
|
|
raise_on_empty=True)
|
2017-06-08 15:30:40 +03:00
|
|
|
|
2020-12-14 10:01:51 +01:00
|
|
|
fixed_ips = ['ip_address=%s' % str(node_fixed_ip)]
|
|
|
|
filters = {'fixed_ips': fixed_ips}
|
|
|
|
tags = CONF.neutron_defaults.resource_tags
|
|
|
|
if tags:
|
|
|
|
filters['tags'] = tags
|
2017-06-08 15:30:40 +03:00
|
|
|
try:
|
2020-12-14 10:01:51 +01:00
|
|
|
ports = os_net.ports(**filters)
|
2019-11-29 14:56:31 +01:00
|
|
|
except os_exc.SDKException:
|
2020-12-14 10:01:51 +01:00
|
|
|
LOG.error("Parent VM port with fixed IPs %s not found!", fixed_ips)
|
2019-01-24 17:34:50 +01:00
|
|
|
raise
|
2017-06-08 15:30:40 +03:00
|
|
|
|
2020-12-14 10:01:51 +01:00
|
|
|
for port in ports:
|
|
|
|
for fip in port.fixed_ips:
|
|
|
|
if fip.get('subnet_id') in node_subnet_ids:
|
|
|
|
return port
|
|
|
|
|
|
|
|
LOG.error("Neutron port for VM port with fixed IPs %s not found!",
|
|
|
|
fixed_ips)
|
|
|
|
raise kl_exc.NoResourceException()
|
2017-02-22 12:44:46 +01:00
|
|
|
|
2019-12-18 20:40:21 +01:00
|
|
|
def _get_parent_port(self, pod):
|
2017-02-22 12:44:46 +01:00
|
|
|
try:
|
|
|
|
# REVISIT(vikasc): Assumption is being made that hostIP is the IP
|
|
|
|
# of trunk interface on the node(vm).
|
|
|
|
node_fixed_ip = pod['status']['hostIP']
|
|
|
|
except KeyError:
|
|
|
|
if pod['status']['conditions'][0]['type'] != "Initialized":
|
|
|
|
LOG.debug("Pod condition type is not 'Initialized'")
|
|
|
|
|
|
|
|
LOG.error("Failed to get parent vm port ip")
|
|
|
|
raise
|
2019-12-18 20:40:21 +01:00
|
|
|
return self._get_parent_port_by_host_ip(node_fixed_ip)
|