Skip to content

Commit 5a623bc

Browse files
benjamreisIgor Druzhinin
authored andcommitted
Use XAPI to edit DNS entries within xsconsole
Instead of directly editing `/etc/resolv.conf`, use XAPI to edit it. This fixes an issue where the changes weren't retained after a reboot because XAPI would override the changes with what was stored in its DB. Using XAPI to edit the DNS entries also applies the changes in XAPI's DB and so changes are kept after reboots. Signed-off-by: BenjiReis <[email protected]>
1 parent 9d4e22c commit 5a623bc

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

XSConsoleData.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,18 +524,16 @@ def SaveToResolveConf(self):
524524
# Double-check authentication
525525
Auth.Inst().AssertAuthenticated()
526526

527-
file = None
528-
try:
529-
file = open("/etc/resolv.conf", "w")
530-
now = datetime.datetime.now().strftime("; created by xsconsole %I:%M%p on %B %d, %Y\n")
531-
file.write(now)
532-
for other in self.dns.othercontents([]):
533-
file.write(other+"\n")
534-
for server in self.dns.nameservers([]):
535-
file.write("nameserver "+server+"\n")
536-
finally:
537-
if file is not None: file.close()
538-
self.UpdateFromResolveConf()
527+
for pif in Data.Inst().derived.managementpifs([]):
528+
ipv6 = pif['primary_address_type'].lower() == 'ipv6'
529+
mode = pif['ipv6_configuration_mode'] if ipv6 else pif['ip_configuration_mode']
530+
ip = pif['IPv6'][0].split('/')[0] if ipv6 else pif['IP']
531+
netmask = pif['IPv6'][0].split('/')[1] if ipv6 else pif['netmask']
532+
gw = pif['ipv6_gateway'] if ipv6 else pif['gateway']
533+
dns = ','.join(self.dns.nameservers([]))
534+
self.ReconfigureManagement(pif, mode, ip, netmask, gw, dns)
535+
536+
self.UpdateFromResolveConf()
539537

540538

541539
def ScanDmiDecode(self, inLines):

0 commit comments

Comments
 (0)