From d570011c62dac9844c80af8f5e0f8777d572f5ea Mon Sep 17 00:00:00 2001 From: Wilson Ng Date: Mon, 22 Jan 2018 19:08:26 -0800 Subject: [PATCH] Add setters and getters for dns server and domain in OnlBootConfig. --- .../src/python/onl/bootconfig/__init__.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/bootconfig/__init__.py b/packages/base/all/vendor-config-onl/src/python/onl/bootconfig/__init__.py index 2f0e3518..a9f86293 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/bootconfig/__init__.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/bootconfig/__init__.py @@ -111,6 +111,8 @@ class OnlBootConfigNet(OnlBootConfig): self.delete('NETIP') self.delete('NETMASK') self.delete('NETGW') + self.delete('NETDNS') + self.delete('NETDOMAIN') self.set('NETAUTO', 'dhcp') def netauto_get(self): @@ -137,13 +139,27 @@ class OnlBootConfigNet(OnlBootConfig): def netgw_get(self): return self.keys.get('NETGW', None) + def netdns_set(self, dns): + self.delete('NETAUTO') + self.keys['NETDNS'] = dns + + def netdns_get(self): + return self.keys.get('NETDNS', None) + + def netdomain_set(self, domain): + self.delete('NETAUTO') + self.keys['NETDOMAIN'] = domain + + def netdomain_get(self): + return self.keys.get('NETDOMAIN', None) + def __validate(self): if 'NETAUTO' not in self.keys: netip = self.keys.get('NETIP', None) if netip: if not self.is_ip_address(netip): - raise ValueError("NETIP=%s is not a valid ip-address" % (netup)) + raise ValueError("NETIP=%s is not a valid ip-address" % (netip)) elif self.NET_REQUIRED: raise ValueError("No IP configuration set for the management interface.") @@ -168,6 +184,11 @@ class OnlBootConfigNet(OnlBootConfig): elif netip or netmask or netgw: raise ValueError("Incomplete static network configuration. NETIP, NETMASK, and NETGW must all be set.") + netdns = self.keys.get('NETDNS', None) + if netdns: + if not self.is_ip_address(netdns): + raise ValueError("NETDNS=%s is not a valid ip-address" % (netdns)) + elif self.keys['NETAUTO'] not in ['dhcp', 'up']: raise ValueError("The NETAUTO value '%s' is invalid." % self.keys['NETAUTO']) elif self.keys['NETAUTO'] == 'up' and self.NET_REQUIRED: @@ -214,7 +235,8 @@ class OnlBootConfigNet(OnlBootConfig): ap.add_argument("--ip", help='Set static IP address for the management interface.', type=OnlBootConfigNet.argparse_type_is_ip_address) ap.add_argument("--netmask", help='Set the static netmask for the management interface.', type=OnlBootConfigNet.argparse_type_is_netmask) ap.add_argument("--gateway", help='Set the gateway address.', type=OnlBootConfigNet.argparse_type_is_ip_address) - + ap.add_argument("--dns", help='Set the dns server.', type=OnlBootConfigNet.argparse_type_is_ip_address) + ap.add_argument("--domain", help='Set the dns domain.') def __argparse_process(self, ops): if ops.dhcp: @@ -229,6 +251,12 @@ class OnlBootConfigNet(OnlBootConfig): if ops.gateway: self.netgw_set(ops.gateway) + if ops.dns: + self.netdns_set(ops.dns) + + if ops.domain: + self.netdomain_set(ops.domain) + if __name__ == '__main__': bc = OnlBootConfigNet()