def remove(self, vlan, raiseError=False): """Remove specific vlan.""" out = [] if identifyL23(vlan) == 'L2': self.logger.info('Called VInterface remove for %s' % str(vlan)) for command in [ "ip link delete dev vlan.%s" % (vlan['vlan']), "ip link delete dev vlan.%s-ifb" % (vlan['vlan']) ]: out.append(execute(command, self.logger, raiseError)) else: self.logger.info('Called VInterface remove L3 for %s' % str(vlan)) for routel in vlan['routes']: if 'routeTo' in list(routel.keys()) and 'nextHop' in list( routel.keys()): if 'value' in list( routel['routeTo'].keys()) and 'value' in list( routel['nextHop'].keys()): command = "ip route del %s via %s" % ( routel['routeTo']['value'], routel['nextHop']['value'].split('/')[0]) out.append(execute(command, self.logger, raiseError)) else: self.logger.info( 'Parsed delta did not had routeTo or nextHop keys in route info. Route details: %s' % routel) return out
def stop(self, vlan, raiseError=False): """ Stop specific vlan """ if identifyL23(vlan) == 'L2': self.logger.info('Called VInterface L2 stop for %s' % str(vlan)) command = "ip link set vlan.%s down" % (vlan['vlan']) return execute(command, self.logger, raiseError) return None
def add(self, vlan, raiseError=False): """ Add specific vlan """ if identifyL23(vlan) == 'L2': self.logger.info('Called VInterface add L2 for %s' % str(vlan)) command = "ip link add link %s name vlan.%s type vlan id %s" % ( vlan['destport'], vlan['vlan'], vlan['vlan']) return execute(command, self.logger, raiseError) return None
def stop(self, vlan, raiseError=False): """Stop specific vlan.""" out = [] if identifyL23(vlan) == 'L2': self.logger.info('Called VInterface L2 stop for %s' % str(vlan)) for command in [ "ip link set dev vlan.%s down" % (vlan['vlan']), "ip link set dev vlan.%s-ifb down" % (vlan['vlan']) ]: out.append(execute(command, self.logger, raiseError)) return out
def start(self, vlan, raiseError=False): """ Start specific vlan """ if identifyL23(vlan) == 'L2': self.logger.info('Called VInterface start L2 for %s' % str(vlan)) command = "ip link set vlan.%s up" % (vlan['vlan']) return execute(command, self.logger, raiseError) else: self.logger.info('Called VInterface start L3 for %s' % str(vlan)) for routel in vlan['routes']: if 'routeTo' in routel.keys() and 'nextHop' in routel.keys(): if 'value' in routel['routeTo'].keys( ) and 'value' in routel['nextHop'].keys(): command = "ip route add %s via %s" % ( routel['routeTo']['value'], routel['nextHop']['value'].split('/')[0]) execute(command, self.logger, raiseError) else: self.logger.info( 'Parsed delta did not had routeTo or nextHop keys in route info. Route details: %s' % routel) return None
def stop(self, vlan, raiseError=False): """ Stop specific vlan """ level = self.__identifyL23(vlan) if level == 'L2': self.logger.info('Called VInterface L2 stop for %s' % str(vlan)) command = "ip link set %s.%s down" % (vlan['destport'], vlan['vlan']) return execute(command, self.logger, raiseError) if level == 'L3': self.logger.info('Called VInterface stop L3 for %s' % str(vlan)) return None return None
def status(self, vlan, raiseError=False): """ Get status of specific vlan """ out = None if identifyL23(vlan) == 'L2': self.logger.info('Called VInterface status for %s' % str(vlan)) command = "ip link show dev vlan.%s" % (vlan['vlan']) out = execute(command, self.logger, raiseError) self.checkInterfacePresense(vlan, raiseError) else: self.logger.info('Called VInterface status L3 for %s' % str(vlan)) for routel in vlan['routes']: if 'routeTo' in routel.keys() and 'nextHop' in routel.keys(): if 'value' in routel['routeTo'].keys( ) and 'value' in routel['nextHop'].keys(): command = "ip route get %s" % ( routel['routeTo']['value']) out = execute(command, self.logger, raiseError) else: self.logger.info( 'Parsed delta did not had routeTo or nextHop keys in route info. Route details: %s' % routel) return out
def status(self, vlan, raiseError=False): """ Get status of specific vlan """ level = self.__identifyL23(vlan) if level == 'L2': self.logger.info('Called VInterface status for %s' % str(vlan)) command = "ip link show dev %s.%s" % (vlan['destport'], vlan['vlan']) return execute(command, self.logger, raiseError) if level == 'L3': self.logger.info('Called VInterface status L3 for %s' % str(vlan)) for routel in vlan['routes']: if 'routeTo' in routel.keys() and 'nextHop' in routel.keys(): if 'value' in routel['routeTo'].keys( ) and 'value' in routel['nextHop'].keys(): command = "ip route get %s" % ( routel['routeTo']['value']) execute(command, self.logger, raiseError) else: self.logger.info( 'Parsed delta did not had routeTo or nextHop keys in route info. Route details: %s' % routel) return None
def remove(self, vlan, raiseError=False): """ Remove specific vlan """ level = self.__identifyL23(vlan) if level == 'L2': self.logger.info('Called VInterface remove for %s' % str(vlan)) command = "ip link delete %s.%s" % (vlan['destport'], vlan['vlan']) return execute(command, self.logger, raiseError) if level == 'L3': self.logger.info('Called VInterface remove L3 for %s' % str(vlan)) for routel in vlan['routes']: if 'routeTo' in routel.keys() and 'nextHop' in routel.keys(): if 'value' in routel['routeTo'].keys( ) and 'value' in routel['nextHop'].keys(): command = "ip route del %s via %s" % ( routel['routeTo']['value'], routel['nextHop']['value'].split('/')[0]) execute(command, self.logger, raiseError) else: self.logger.info( 'Parsed delta did not had routeTo or nextHop keys in route info. Route details: %s' % routel) return None
def setup(self, vlan, raiseError=False): """Setup vlan.""" if identifyL23(vlan) == 'L2': if 'ip' in list(vlan.keys()): self.logger.info('Called VInterface setup L2 for %s' % str(vlan)) command = "ip addr add %s broadcast %s dev vlan.%s" % ( vlan['ip'], getBroadCast(vlan['ip']), vlan['vlan']) return execute(command, self.logger, raiseError) self.logger.info( 'Called VInterface setup for %s, but ip key is not present.' % str(vlan)) self.logger.info('Continue as nothing happened') return None
def setup(self, vlan, raiseError=False): """ Setup vlan """ level = self.__identifyL23(vlan) if level == 'L2': if 'ip' in vlan.keys(): self.logger.info('Called VInterface setup L2 for %s' % str(vlan)) command = "ip addr add %s broadcast %s dev %s.%s" % ( vlan['ip'], getBroadCast(vlan['ip'], self.logger), vlan['destport'], vlan['vlan']) return execute(command, self.logger, raiseError) else: self.logger.info( 'Called VInterface setup for %s, but ip key is not present.' % str(vlan)) self.logger.info('Continue as nothing happened') if level == 'L3': self.logger.info('Called VInterface setup L3 for %s' % str(vlan)) return None return None