Allow CIDR instead of iterface name
This patch implements translation from CIDR to interface name, which should allow deployments to heretogenous infrastructure. Package openstack-packstack-puppet will need new require, which is rubygem-ippaddress. Workaround for rhbz#1200604 Change-Id: Id27881f616781e5a24a1bdb1e169915b7619eebd
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import netaddr
|
||||
|
||||
from ..installer import utils
|
||||
|
||||
|
||||
@@ -49,3 +51,37 @@ def is_all_in_one(config):
|
||||
# with them when checking all-in-one. MariaDB host should however be
|
||||
# omitted if we are not installing MariaDB.
|
||||
return len(filtered_hosts(config, exclude=False, dbhost=True)) == 1
|
||||
|
||||
|
||||
def cidr_to_ifname(cidr, host, config):
|
||||
"""
|
||||
Returns appropriate host's interface name from given CIDR subnet. Passed
|
||||
config dict has to contain discovered hosts details.
|
||||
"""
|
||||
if not config or not config['HOST_DETAILS'] or '/' not in cidr:
|
||||
raise ValueError(
|
||||
'Cannot translate CIDR to interface, invalid parameters '
|
||||
'were given.'
|
||||
)
|
||||
info = config['HOST_DETAILS'][host]
|
||||
|
||||
result = []
|
||||
for item in cidr.split(','):
|
||||
translated = []
|
||||
for fragment in item.split(':'):
|
||||
try:
|
||||
subnet_a = netaddr.IPNetwork(fragment)
|
||||
except netaddr.AddrFormatError:
|
||||
translated.append(fragment)
|
||||
continue
|
||||
|
||||
for interface in info['interfaces'].split(','):
|
||||
interface = interface.strip()
|
||||
ipaddr = info['ipaddress_{}'.format(interface)]
|
||||
netmask = info['netmask_{}'.format(interface)]
|
||||
subnet_b = netaddr.IPNetwork('{ipaddr}/{netmask}'.format(**locals()))
|
||||
if subnet_a == subnet_b:
|
||||
translated.append(interface)
|
||||
break
|
||||
result.append(':'.join(translated))
|
||||
return ','.join(result)
|
||||
|
||||
@@ -24,28 +24,6 @@ PUPPET_TEMPLATE_DIR = os.path.join(PUPPET_DIR, "templates")
|
||||
HIERA_DEFAULTS_YAML = os.path.join(basedefs.HIERADATA_DIR, "defaults.yaml")
|
||||
|
||||
|
||||
class NovaConfig(object):
|
||||
"""
|
||||
Helper class to create puppet manifest entries for nova_config
|
||||
"""
|
||||
def __init__(self):
|
||||
self.options = {}
|
||||
|
||||
def addOption(self, n, v):
|
||||
self.options[n] = v
|
||||
|
||||
def getManifestEntry(self):
|
||||
entry = ""
|
||||
if not self.options:
|
||||
return entry
|
||||
|
||||
entry += "nova_config{\n"
|
||||
for k, v in self.options.items():
|
||||
entry += ' "%s": value => "%s";\n' % (k, v)
|
||||
entry += "}"
|
||||
return entry
|
||||
|
||||
|
||||
class ManifestFiles(object):
|
||||
def __init__(self):
|
||||
self.filelist = []
|
||||
|
||||
Reference in New Issue
Block a user