From 3889b740bd1c51a2256f8e1bd5f3ec7d540df3c6 Mon Sep 17 00:00:00 2001 From: nitishkrishna Date: Tue, 15 Nov 2016 16:49:13 -0800 Subject: [PATCH] Closes-Bug: #1641850 - Do DHCP Subnet validation only if feature is used If feature is not used, the manually edited dhcp template file is taken as correct. Also, the dhcp list for validations was not being correctly populated. Once the user starts using the dhcp management feature we have to continue using that and cannot go back to manual file without deleting all hosts and subnets and then pasting the manually editing files and restarting. Change-Id: I6173bc06478174959846e9a822da1588d5a0a3dc Related-Bug: #1634275 - DHCP Feature --- src/cobbler/bootup_dhcp.template.u | 1 - src/server_mgr_main.py | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cobbler/bootup_dhcp.template.u b/src/cobbler/bootup_dhcp.template.u index a9a25555..8daa0b35 100644 --- a/src/cobbler/bootup_dhcp.template.u +++ b/src/cobbler/bootup_dhcp.template.u @@ -21,7 +21,6 @@ host __$HOSTFQDN__ { fixed-address __$IPADDRESS__; option host-name "__$HOSTNAME__"; filename "/pxelinux.0"; - option ntp-servers __$NTP_SERVER_LIST__; next-server __$IPADDRESS__; } diff --git a/src/server_mgr_main.py b/src/server_mgr_main.py index 08e7f447..470726ad 100755 --- a/src/server_mgr_main.py +++ b/src/server_mgr_main.py @@ -479,7 +479,12 @@ def __init__(self, args_str=None): gevent.spawn(self._monitoring_base_plugin_obj.setup_keys, self._serverDb) #Generate the DHCP template for the SM host only such that cobbler works correctly + self._using_dhcp_management = False self._dhcp_template_obj = DHCPTemplateGenerator(self._serverDb) + dhcp_hosts = self._serverDb.get_dhcp_host() + dhcp_subnets = self._serverDb.get_dhcp_subnet() + if len(dhcp_hosts) > 1 and len(dhcp_subnets): + self._using_dhcp_management = True self._base_url = "http://%s:%s" % (self._args.listen_ip_addr, self._args.listen_port) @@ -1914,6 +1919,7 @@ def put_dhcp_host(self): msg = "Keys missing from the config sent: " + str(list(set(self._dhcp_host_key_list)-set(dhcp_host.keys()))) + "\n" self.log_and_raise_exception(msg) stanza = self._dhcp_template_obj.generate_dhcp_template() + self._using_dhcp_management = True # Sync the above information if self._smgr_cobbler: self._smgr_cobbler.sync() @@ -1970,6 +1976,7 @@ def put_dhcp_subnet(self): msg = "Keys missing from the config sent: " + str(set(self._dhcp_subnet_key_list)) + " " + str(set(dhcp_subnet.keys())) + "\n" self.log_and_raise_exception(msg) stanza = self._dhcp_template_obj.generate_dhcp_template() + self._using_dhcp_management = True except ServerMgrException as e: self._smgr_trans_log.log(bottle.request, self._smgr_trans_log.PUT_SMGR_CFG_SERVER, False) @@ -3241,8 +3248,8 @@ def reimage_server(self): if cluster and cluster[0]['parameters']: cluster_parameters = eval(cluster[0]['parameters']) - if 'ip_address' in server and server['ip_address']: - if server['ip_address'] not in valid_dhcp_ip_list: + if 'ip_address' in server and server['ip_address'] and self._using_dhcp_management: + if str(server['ip_address']) not in valid_dhcp_ip_list: msg = "The server with id %s cannot be reimaged. \ There is no cobbler DHCP configuration for the ip address of this server \ : %s" % (server['id'], server['ip_address']) @@ -3764,11 +3771,12 @@ def get_dhcp_ips(self): dhcp_ips = [] db_dhcp_hosts = self._serverDb.get_dhcp_host() for host in db_dhcp_hosts: - dhcp_ips.append(host['ip_address']) + dhcp_ips.append(str(host['ip_address'])) db_dhcp_subnets = self._serverDb.get_dhcp_subnet() for subnet in db_dhcp_subnets: subnet_cidr = self._serverDb.get_cidr(subnet['subnet_address'], subnet['subnet_mask']) - dhcp_ips.append(IPNetwork(str(subnet_cidr))) + subnet_ip_list = [str(x) for x in IPNetwork(str(subnet_cidr))] + dhcp_ips+=subnet_ip_list return set(dhcp_ips) # Function to get map server name to server ip