Commit f6f75326 authored by vaibhav-rbs's avatar vaibhav-rbs Committed by GitHub
Browse files

Merge pull request #230 from freenas/FIX-23248

Fix hostname save logic in HostnameForm and network's GeneralConfigur…
parents 3a04d864 87f5edf7
No related merge requests found
Showing with 20 additions and 11 deletions
+20 -11
......@@ -694,7 +694,11 @@ class HostnameForm(Form):
def save(self):
host, domain = self.cleaned_data.get('hostname')
self.instance.gc_hostname = host
_n = notifier()
if not _n.is_freenas() and _n.failover_node() == 'B':
self.instance.gc_hostname_b = host
else:
self.instance.gc_hostname = host
orig_gc_domain = self.instance.gc_domain
self.instance.gc_domain = domain
self.instance.save()
......
......@@ -26,7 +26,7 @@
import os
import random
import string
import logging
from django.core.validators import RegexValidator
from django.db import models, transaction
from django.utils.translation import ugettext_lazy as _
......@@ -41,6 +41,9 @@ from freenasUI.middleware.notifier import notifier
from freenasUI.services.models import CIFS
log = logging.getLogger('network.models')
class GlobalConfiguration(Model):
gc_hostname = models.CharField(
max_length=120,
......@@ -133,8 +136,10 @@ class GlobalConfiguration(Model):
def __init__(self, *args, **kwargs):
super(GlobalConfiguration, self).__init__(*args, **kwargs)
self._n = notifier()
for name in (
'gc_hostname',
'gc_hostname_b',
'gc_ipv4gateway',
'gc_ipv6gateway',
'gc_domain',
......@@ -149,24 +154,24 @@ class GlobalConfiguration(Model):
return str(self.id)
def get_hostname(self):
_n = notifier()
if not _n.is_freenas():
if _n.failover_node() == 'B':
return self.gc_hostname_b
else:
return self.gc_hostname
if not self._n.is_freenas() and self._n.failover_node() == 'B':
return self.gc_hostname_b
else:
return self.gc_hostname
def save(self, *args, **kwargs):
# See #3437
if self._orig_gc_hostname != self.gc_hostname:
if (
self._orig_gc_hostname != self.gc_hostname or
self._orig_gc_hostname_b != self.gc_hostname_b
):
try:
cifs = CIFS.objects.order_by('-id')[0]
cifs.cifs_srv_netbiosname = self.gc_hostname
cifs.cifs_srv_netbiosname_b = self.gc_hostname_b
cifs.save()
except:
pass
except Exception:
log.debug("Setting netbios names failed", exc_info=True)
return super(GlobalConfiguration, self).save(*args, **kwargs)
class Meta:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment