Assaf Muller has posted comments on this change.

Change subject: WIP: Multiple Gateways Feature
......................................................................


Patch Set 2: (10 inline comments)

Uploading patch set 3 that should address all of the minor comments.

For the next patch set: Better error handling, logging, ConfigWriter, ip 
route/rule wrapping.

....................................................
File vdsm/multipleGateways.py
Line 1: import os
Done
Line 2: import sys
Line 3: import netaddr
Line 4: from vdsm import utils
Line 5: 


Line 1: import os
Line 2: import sys
Line 3: import netaddr
Done
Line 4: from vdsm import utils
Line 5: 
Line 6: 
Line 7: NETWORK_SCRIPTS = '/etc/sysconfig/network-scripts/'


Line 3: import netaddr
Line 4: from vdsm import utils
Line 5: 
Line 6: 
Line 7: NETWORK_SCRIPTS = '/etc/sysconfig/network-scripts/'
Done
Line 8: 
Line 9: 
Line 10: class MultipleGatewaysConfigurator(object):
Line 11:     def __init__(self, isStatic, device):


Line 26:         return ["from %s table %s" % (self.network, self.table),
Line 27:                 "to %s table %s" % (self.network, self.table)]
Line 28: 
Line 29:     def _writeCommands(self, commands, type='route'):
Line 30:         filePath = NETWORK_SCRIPTS + '%s-%s' % (type, self.device)
Done
Line 31:         with open(filePath, 'w') as file:
Line 32:             for command in commands:
Line 33:                 file.write(command + '\n')
Line 34: 


Line 28: 
Line 29:     def _writeCommands(self, commands, type='route'):
Line 30:         filePath = NETWORK_SCRIPTS + '%s-%s' % (type, self.device)
Line 31:         with open(filePath, 'w') as file:
Line 32:             for command in commands:
Done
Line 33:                 file.write(command + '\n')
Line 34: 
Line 35:     def _addRoutesStatic(self, routes):
Line 36:         self._writeCommands(routes, type='route')


Line 49:     def _addRulesDHCP(self, rules):
Line 50:         rules = ['ip rule add ' + rule for rule in rules]
Line 51:         self._runCommands(rules)
Line 52: 
Line 53:     def up(self, ip, mask, gateway):
Done
Line 54:         try:
Line 55:             self.ip = netaddr.IPAddress(ip)
Line 56:             self.mask = netaddr.IPAddress(mask)
Line 57:             self.gateway = netaddr.IPAddress(gateway)


Line 49:     def _addRulesDHCP(self, rules):
Line 50:         rules = ['ip rule add ' + rule for rule in rules]
Line 51:         self._runCommands(rules)
Line 52: 
Line 53:     def up(self, ip, mask, gateway):
Done
Line 54:         try:
Line 55:             self.ip = netaddr.IPAddress(ip)
Line 56:             self.mask = netaddr.IPAddress(mask)
Line 57:             self.gateway = netaddr.IPAddress(gateway)


Line 57:             self.gateway = netaddr.IPAddress(gateway)
Line 58:         except netaddr.core.AddrFormatError:
Line 59:             print ("IP, subnet mask or gateway not properly 
formatted.")
Line 60:             return
Line 61:         self.table = self._generateTableId()
Done
Line 62:         network = netaddr.IPNetwork(str(self.ip) + '/' + 
str(self.mask))
Line 63:         self.network = "%s/%s" % (network.network, network.prefixlen)
Line 64: 
Line 65:         print (("Bringing up - ip: %s, network: %s, subnet: %s " +


Line 99:         return rules
Line 100: 
Line 101:     def _getNetwork(self, device):
Line 102:         _, output, _ = utils.execCmd(["/sbin/ip", "route"])
Line 103:         relevantLines = [line for line in output if self.device in 
line]
Done
Line 104: 
Line 105:         entry = relevantLines[0] if relevantLines else None
Line 106:         if entry:
Line 107:             network = entry.split()[0]


Line 101:     def _getNetwork(self, device):
Line 102:         _, output, _ = utils.execCmd(["/sbin/ip", "route"])
Line 103:         relevantLines = [line for line in output if self.device in 
line]
Line 104: 
Line 105:         entry = relevantLines[0] if relevantLines else None
Done
Line 106:         if entry:
Line 107:             network = entry.split()[0]
Line 108:             return network
Line 109:         else:


--
To view, visit http://gerrit.ovirt.org/15207
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I0224d896724b9cdc44215e92f0da0be71fd19038
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Assaf Muller <amul...@redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegu...@redhat.com>
Gerrit-Reviewer: Assaf Muller <amul...@redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <dan...@redhat.com>
Gerrit-Reviewer: Livnat Peer <lp...@redhat.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to