-
Notifications
You must be signed in to change notification settings - Fork 21
Handle IPv6 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Handle IPv6 #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,18 +365,23 @@ def Commit(self): | |
inventory['CURRENT_INTERFACES'] = '' | ||
write_inventory(inventory) | ||
|
||
ipv6 = self.IP.find(':') > -1 | ||
|
||
# Rewrite firstboot management.conf file, which will be picked it by xcp-networkd on restart (if used) | ||
f = open(management_conf, 'w') | ||
try: | ||
f.write("LABEL='" + self.device + "'\n") | ||
f.write("MODE='" + self.mode + "'\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will get hairy with dual-stack ip, it needs a rethinking when that is introduced so both ipv4 and ipv6 can b written independently. As it is, it will get difficult to read with 3 modes. |
||
f.write(("MODEV6" if ipv6 else "MODE") + "='" + self.mode + "'\n") | ||
if self.vlan != '': | ||
f.write("VLAN='" + self.vlan + "'\n") | ||
if self.mode == 'static': | ||
f.write("IP='" + self.IP + "'\n") | ||
f.write("NETMASK='" + self.netmask + "'\n") | ||
if ipv6: | ||
f.write("IPv6='" + self.IP + "/" + self.netmask + "'\n") | ||
else: | ||
f.write("IP='" + self.IP + "'\n") | ||
f.write("NETMASK='" + self.netmask + "'\n") | ||
if self.gateway != '': | ||
f.write("GATEWAY='" + self.gateway + "'\n") | ||
f.write(("IPv6_GATEWAY" if ipv6 else "GATEWAY") + "='" + self.gateway + "'\n") | ||
if self.dns != '': | ||
f.write("DNS='" + self.dns + "'\n") | ||
finally: | ||
|
@@ -386,14 +391,17 @@ def Commit(self): | |
f = open(network_reset, 'w') | ||
try: | ||
f.write('DEVICE=' + self.device + '\n') | ||
f.write('MODE=' + self.mode + '\n') | ||
f.write(('MODE_V6' if ipv6 else 'MODE') + '=' + self.mode + '\n') | ||
if self.vlan != '': | ||
f.write('VLAN=' + self.vlan + '\n') | ||
if self.mode == 'static': | ||
f.write('IP=' + self.IP + '\n') | ||
f.write('NETMASK=' + self.netmask + '\n') | ||
if ipv6: | ||
f.write('IPV6=' + self.IP + '/' + self.netmask + '\n') | ||
else: | ||
f.write('IP=' + self.IP + '\n') | ||
f.write('NETMASK=' + self.netmask + '\n') | ||
if self.gateway != '': | ||
f.write('GATEWAY=' + self.gateway + '\n') | ||
f.write(('GATEWAY_V6' if ipv6 else 'GATEWAY') + '=' + self.gateway + '\n') | ||
if self.dns != '': | ||
f.write('DNS=' + self.dns + '\n') | ||
finally: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ def test_min(self): | |
self.assertTrue(IPUtils.ValidateIP('0.0.0.1')) | ||
|
||
def test_beyond_min(self): | ||
self.assertFalse(IPUtils.ValidateIP('0.0.0.0')) | ||
self.assertTrue(IPUtils.ValidateIP('0.0.0.0')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this test being changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because changing the validate method hasa changed how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't other code depend on this property? |
||
|
||
def test_max(self): | ||
self.assertTrue(IPUtils.ValidateIP('255.255.255.255')) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expressions in the two ifs can raise exceptions when the keys are not defined, please add presence checks before checking the contents.