Disallow use of entire mgmt subnet for Distributed Cloud

Changes to config_controller to ensure user has left some mgmt network
address space for gateway(s), with appropriate warnings.

Story: 2002870
Task: 22820

Change-Id: Ib3f08d86e015cf614457b2284fe497b04caf5585
Signed-off-by: Jack Ding <jack.ding@windriver.com>
This commit is contained in:
Kevin Smith 2018-06-22 14:19:38 -04:00 committed by Jack Ding
parent e028fd70dd
commit d2da0ddd1e
3 changed files with 67 additions and 18 deletions

View File

@ -123,6 +123,7 @@ class Network(object):
self.multicast_cidr = None
self.start_address = None
self.end_address = None
self.start_end_in_config = False
self.floating_address = None
self.address_0 = None
self.address_1 = None
@ -312,6 +313,7 @@ class Network(object):
raise ConfigFail("Address range for %s must contain at "
"least %d addresses." %
(network_name, min_addresses))
self.start_end_in_config = True
if floating_address_str or address_0_str or address_1_str:
if not floating_address_str:

View File

@ -4,10 +4,10 @@ Copyright (c) 2015-2017 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
from configobjects import DEFAULT_NAMES, NETWORK_PREFIX_NAMES, OAM_TYPE, \
MGMT_TYPE, Network, REGION_CONFIG, VALID_LINK_SPEED, INFRA_TYPE, \
DEFAULT_DOMAIN_NAME, HP_NAMES, SUBCLOUD_CONFIG
from netaddr import IPRange
from utils import lag_mode_to_str, validate_network_str, \
check_network_overlap, is_mtu_valid, is_speed_valid, get_service, \
get_optional
@ -382,6 +382,33 @@ class ConfigValidator(object):
"network" %
(mgmt_prefix, str(self.mgmt_network.cidr)))
if (self.system_dc_role ==
DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER):
# For Distributed Cloud SystemController, we require the setting
# of the IP_START_ADDRESS/IP_END_ADDRESS config settings so as to
# raise awareness that some space in MGMT subnet must be set aside
# for gateways to reach subclouds.
if not self.mgmt_network.start_end_in_config:
raise ConfigFail("IP_START_ADDRESS and IP_END_ADDRESS required"
" for %s network as this configuration "
"requires address space left for gateway "
"address(es)" % mgmt_prefix)
else:
# Warn user that some space in the management subnet must
# be reserved for the system controller gateway address(es)
# used to communicate with the subclouds. - 2 because of
# subnet and broadcast addresses.
address_range = \
IPRange(str(self.mgmt_network.start_address),
str(self.mgmt_network.end_address)).size
if address_range >= (self.mgmt_network.cidr.size - 2):
raise ConfigFail(
"Address range for %s network too large, no addresses"
" left for gateway(s), required in this "
"configuration." % mgmt_prefix)
if self.mgmt_network.logical_interface.lag_interface:
supported_lag_mode = [1, 4]
if (self.mgmt_network.logical_interface.lag_mode not in

View File

@ -1116,22 +1116,31 @@ class ConfigAssistant():
except ValidateFail as e:
print "{}".format(e)
while True:
user_input = raw_input(
"Use entire management subnet [Y/n]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input.lower() == 'y':
self.use_entire_mgmt_subnet = True
break
elif user_input.lower() == 'n':
self.use_entire_mgmt_subnet = False
break
elif user_input == "":
break
else:
print "Invalid choice"
continue
if (self.system_dc_role !=
sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER):
while True:
user_input = raw_input(
"Use entire management subnet [Y/n]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input.lower() == 'y':
self.use_entire_mgmt_subnet = True
break
elif user_input.lower() == 'n':
self.use_entire_mgmt_subnet = False
break
elif user_input == "":
break
else:
print "Invalid choice"
continue
else:
self.use_entire_mgmt_subnet = False
print textwrap.fill(
"Configured as Distributed Cloud System Controller,"
" disallowing use of entire management subnet. "
"Ensure management ip range does not include System"
" Controller gateway address(es)", 80)
if not self.use_entire_mgmt_subnet:
while True:
@ -1183,8 +1192,19 @@ class ConfigAssistant():
"Address range must contain at least %d addresses. " %
min_addresses)
continue
break
sc = sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER
if (self.system_dc_role == sc):
# Warn user that some space in the management subnet must
# be reserved for the system controller gateway address(es)
# used to communicate with the subclouds. - 2 because of
# subnet and broadcast addresses.
if address_range.size >= (self.management_subnet.size - 2):
print textwrap.fill(
"Address range too large, no addresses left "
"for System Controller gateway(s). ", 80)
continue
break
while True:
print
print textwrap.fill(