mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-26 09:47:13 +00:00
Merge pull request #297 from wilmo119/master
Add setters and getters for dns server and domain in OnlBootConfig.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user