Skip to content

Commit

Permalink
Closes-Bug: #1641850 - Do DHCP Subnet validation only if feature is used
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nitishkrishna committed Nov 16, 2016
1 parent 8bf8bb1 commit 3889b74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/cobbler/bootup_dhcp.template.u
Expand Up @@ -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__;
}

Expand Down
16 changes: 12 additions & 4 deletions src/server_mgr_main.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3889b74

Please sign in to comment.