-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create DvrRouter and HaRouter as a sub-class of Router
This commit creates them as simple sub-classes and instantiates them when appropriate. It also moves the basic mixin classes from RouterInfo. Since all of the properties and attributes from these mixins are only used in the ha or dvr contexts, this is safe. Future refactoring will further tease things out until they are properly encapsulated. They inherit everything else from their base class so that they all still share the same code. Creating them up front provides a place for dvr and ha specific logic to land as methods are moved from the L3 agent and mixins to the new router classes. Eventually, all of the specific logic will be teased in to the specific classes. Change-Id: I8c485e74ae06b10fd284797359bc6d1115361713 Partially-Implements: blueprint restructure-l3-agent
- Loading branch information
Carl Baldwin
committed
Jan 17, 2015
1 parent
6e5762b
commit 522695e
Showing
9 changed files
with
168 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) 2015 Openstack Foundation | ||
# | ||
# 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. | ||
|
||
from neutron.agent.l3 import router_info as router | ||
|
||
|
||
class DvrRouter(router.RouterInfo): | ||
def __init__(self, *args, **kwargs): | ||
super(DvrRouter, self).__init__(*args, **kwargs) | ||
|
||
self.floating_ips_dict = {} | ||
self.snat_iptables_manager = None | ||
# Linklocal subnet for router and floating IP namespace link | ||
self.rtr_fip_subnet = None | ||
self.dist_fip_count = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2015 Openstack Foundation | ||
# | ||
# 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 shutil | ||
|
||
from neutron.agent.l3 import router_info as router | ||
from neutron.agent.linux import keepalived | ||
from neutron.openstack.common import log as logging | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class HaRouter(router.RouterInfo): | ||
def __init__(self, *args, **kwargs): | ||
super(HaRouter, self).__init__(*args, **kwargs) | ||
|
||
self.ha_port = None | ||
self.keepalived_manager = None | ||
|
||
def _verify_ha(self): | ||
# TODO(Carl) Remove when is_ha below is removed. | ||
if not self.is_ha: | ||
raise ValueError(_('Router %s is not a HA router') % | ||
self.router_id) | ||
|
||
@property | ||
def is_ha(self): | ||
# TODO(Carl) Remove when refactoring to use sub-classes is complete. | ||
return self.router is not None | ||
|
||
@property | ||
def ha_priority(self): | ||
self._verify_ha() | ||
return self.router.get('priority', keepalived.HA_DEFAULT_PRIORITY) | ||
|
||
@property | ||
def ha_vr_id(self): | ||
self._verify_ha() | ||
return self.router.get('ha_vr_id') | ||
|
||
@property | ||
def ha_state(self): | ||
self._verify_ha() | ||
ha_state_path = self.keepalived_manager._get_full_config_file_path( | ||
'state') | ||
try: | ||
with open(ha_state_path, 'r') as f: | ||
return f.read() | ||
except (OSError, IOError): | ||
LOG.debug('Error while reading HA state for %s', self.router_id) | ||
return None | ||
|
||
def spawn_keepalived(self): | ||
self.keepalived_manager.spawn_or_restart() | ||
|
||
def disable_keepalived(self): | ||
self.keepalived_manager.disable() | ||
conf_dir = self.keepalived_manager.get_conf_dir() | ||
shutil.rmtree(conf_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2015 Openstack Foundation | ||
# | ||
# 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. | ||
|
||
from neutron.agent.l3 import router_info as router | ||
|
||
|
||
class LegacyRouter(router.RouterInfo): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters