コード例 #1
0
ファイル: NetworkPrefix.py プロジェクト: neoyogi/onepk
 def _set_address(self, addr):
     val = HostIpCheck(addr).is_ipaddress()
     if val:
         self._address = addr
     else:
         raise OnepIllegalArgumentException(
             'The address provided to NetworkPrefix class is invalid')
コード例 #2
0
ファイル: AppRouteTable.py プロジェクト: neoyogi/onepk
    def get_static_route_list(self):
        """
                Return a dictionary of manually configured static routes
        
                Keys
                ----
                destination -- string - destination IP address
                mask        -- int - prefix length
                metric      -- int - administrative distance
                next_hop    -- string - next hop IP address
                interface   -- string - outgoing interface
                router      -- string - next hop router
        
                """
        routes = self.vty.show('run | inc ip route').splitlines()
        retlist = []
        for item in routes:
            items = item.split()
            rts = {}
            if items[2] == 'vrf':
                rts['vrf'] = items[3]
                items = items[:2] + items[4:]
            rts['destination'] = items[2]
            rts['mask'] = HostIpCheck.mask2len(items[3])
            if HostIpCheck(items[4]).is_ipaddress():
                rts['next_hop'] = items[4]
                rts['interface'] = None
            else:
                rts['next_hop'] = None
                rts['interface'] = items[4]
            rts['metric'] = None
            rts['router'] = None
            if len(items) > 5:
                if HostIpCheck(items[5]).is_ipaddress():
                    rts['router'] = items[5]
                    if len(items) > 6:
                        rts['metric'] = int(items[6])
                else:
                    rts['metric'] = int(items[5])
            retlist.append(rts)

        return retlist
コード例 #3
0
 def __init__0(self, network_interface, address, metric):
     super(L3UnicastNextHop, self).__init__()
     if network_interface == None and address == None:
         raise OnepIllegalArgumentException(
             'networkInterface and address invalid')
     if network_interface and not isinstance(network_interface,
                                             NetworkInterface):
         raise OnepIllegalArgumentException('networkInterface invalid')
     if address and not HostIpCheck(address).is_ipaddress():
         raise OnepIllegalArgumentException('address invalid')
     if metric is not None and not isinstance(metric, int):
         raise OnepIllegalArgumentException('metric invalid')
     self._network_interface = network_interface
     self._address = address
     self._scope = L3UnicastScope()
     self._metric = metric
コード例 #4
0
 def __init__(self,
              network_interface,
              address,
              scope=None,
              error_code=None,
              metric=None):
     """Constructor. 
     This constructor can be used for convenience when the Scope is not 
     required, for example, when the route operation is REMOVE.
     
     @param network_interface: The network interface in the next hop to set.
     @type network_interface: L{NetworkInterface<onep.interfaces.NetworkInterface>}
     @param address: The address in the next hop to set.
     @type address: C{str}
     @param scope: The the next hop scope to set.
     @type scope: L{L3UnicastScope<onep.routing.L3UnicastScope>}
     @raise OnepIllegalArgumentException:
     The exception is thrown when both networkInterface and
     address are not valid.
     """
     if scope is None and error_code is None:
         self.__init__0(network_interface, address, metric)
     elif error_code is None:
         super(L3UnicastNextHop, self).__init__()
         if network_interface == None and address == None:
             raise OnepIllegalArgumentException(
                 'networkInterface and address invalid')
         if network_interface and not isinstance(network_interface,
                                                 NetworkInterface):
             raise OnepIllegalArgumentException('networkInterface invalid')
         if address and not HostIpCheck(address).is_ipaddress():
             raise OnepIllegalArgumentException('address invalid')
         if metric is not None and not isinstance(metric, int):
             raise OnepIllegalArgumentException('invalid metric')
         self._network_interface = network_interface
         self._address = address
         self._scope = scope
         self._metric = metric
     else:
         self.__init__1(network_interface, address, scope, error_code,
                        metric)
コード例 #5
0
ファイル: AppRouteTable.py プロジェクト: neoyogi/onepk
    def update_routes(self, scope, opList):
        """     
                Add or remove static routes
        
                @param scope: Indicate which table in the Static Route Table
                to send the route operation too.
                @type scope: L{L3UnicastScope<onep.routing.L3UnicastScope>}
                
                @param opList: The list of route operation. If API succeeds,
                per route per next hop status are returned and could be accessed 
                using Route.error_code and NextHop.eror_code
                @type opList: C{list} of 
                L{L3UnicastRouteOperation<onep.routing.L3UnicastRouteOperation>}
                
                @return: A dictionary of the route operation which contains a copy of the  
                routes in the input parameter, with 'SUCCESS', 'FAIL', or 'NOT_SUPPORTED'
                @rtype: dictionary of 
                L{L3UnicastRouteOperation<onep.routing.L3UnicastRouteOperation> : 'SUCCESS'}
                
                @raise OnepIllegalArgumentException: This exception is thrown  
                if the scope and route are not consistent
                
                @raise OnepConnectionException: The exception is thrown when connection
                to the network element has failed. 
                
                @raise OnepRemoteProcedureException: The exception is thrown when an 
                error has occurred in the remote procedure call made to a network 
                element 
        
                """
        if opList == None or len(opList) == 0:
            return
        oplistout = {}
        for rop in opList:
            if rop != None:
                vrf = scope._vrf
                address = rop.route.prefix.address
                mask = ipchk.len2mask(rop.route.prefix.prefix_length)
                if rop.route.next_hop_list:
                    next_hop = rop.route.next_hop_list[0].address
                    interface = rop.route.next_hop_list[0].network_interface
                    metric = rop.route.next_hop_list[0].metric
                else:
                    next_hop = interface = metric = None
                op = rop.op_type
                if vrf:
                    cli = 'ip route vrf %s %s %s ' % (vrf, address, mask)
                else:
                    cli = 'ip route %s %s ' % (address, mask)
                if interface:
                    cli = cli + interface.name + ' '
                if next_hop:
                    cli = cli + ' ' + next_hop + ' '
                if metric:
                    cli = cli + str(metric)
                if rop.op_type == RouteOperation.RouteOperationType.ADD:
                    try:
                        ret = self.vty.config(cli)
                        if ret.find('Inconsistent address and mask') > 0:
                            oplistout[rop] = 'FAIL'
                        else:
                            oplistout[rop] = 'SUCCESS'
                    except:
                        oplistout[rop] = 'FAIL'
                if rop.op_type == RouteOperation.RouteOperationType.REMOVE:
                    try:
                        self.vty.no_config(cli)
                        oplistout[rop] = 'SUCCESS'
                    except:
                        oplistout[rop] = 'FAIL'
                if rop.op_type == RouteOperation.RouteOperationType.REPLACE:
                    oplistout[rop] = 'NOT_SUPPORTED'

        return oplistout
コード例 #6
0
 def _set_address(self, address):
     if address is None or not HostIpCheck(address).is_ipaddress():
         raise OnepIllegalArgumentException('address invalid')
     self._address = address