def action(self, params): if len(params) != 0: return WrongParamResp() ret = {} try: for family in self.supported_families: ret[family] = self.api.get_single_rib_routes(family) return CommandsResponse(STATUS_OK, ret) except ActivityException as e: return CommandsResponse(STATUS_ERROR, e)
def action(self, params): if len(params) != 0: return WrongParamResp() ret = {} for family in self.supported_families: ret[family] = self.api.get_single_rib_routes(family) return CommandsResponse(STATUS_OK, ret)
def action(self, params): if len(params) != 2: return WrongParamResp() vrf_name = params[0] vrf_rf = params[1] if vrf_rf not in ('ipv4', 'ipv6'): return WrongParamResp('route-family not one of (ipv4, ipv6)') from ryu.services.protocols.bgp.operator.internal_api import \ WrongParamError try: return CommandsResponse( STATUS_OK, self.api.get_single_vrf_routes(vrf_name, vrf_rf)) except WrongParamError as e: return CommandsResponse(STATUS_ERROR, 'wrong parameters: %s' % str(e))
def action(self, params): if len(params) != 1: return WrongParamResp() core_service = self.api.get_core_service() core_service_view = CoreServiceDetailView(core_service) importmap_manager = core_service_view.rel('importmap_manager') importmaps_view = importmap_manager.rel('importmaps') importmap_name = params[0] if importmap_name == 'all': encoded = importmaps_view.encode() else: encoded = importmaps_view.encode().get(importmap_name) if encoded is None: return CommandsResponse(STATUS_ERROR, 'Wrong importmap name.') return CommandsResponse(STATUS_OK, encoded)
def action(self, params): if self.api.check_logging(): ret = { 'logging': self.api.check_logging(), 'level': self.api.check_logging_level() } else: ret = {'logging': self.api.check_logging(), 'level': None} return CommandsResponse(STATUS_OK, ret)
def action(self, params): if len(params) < 1: return CommandsResponse(STATUS_ERROR, 'Not enough params') else: vrf_name = params[0] if len(params) == 2: vrf_rf = params[1] else: vrf_rf = 'ipv4' from ryu.services.protocols.bgp.operator.internal_api import \ WrongParamError try: return CommandsResponse( STATUS_OK, self.api.count_single_vrf_routes(vrf_name, vrf_rf)) except WrongParamError as e: return WrongParamResp(e)
def action(self, params): vrf_confs = self.api.get_vrfs_conf() view = ConfDictView(vrf_confs) encoded = view.encode() for vrf_key, conf in encoded.items(): vrf_name, vrf_rf = vrf_key conf['routes_count'] = self._count_routes(vrf_name, vrf_rf) encoded = dict([(str(k), v) for k, v in encoded.items()]) return CommandsResponse(STATUS_OK, encoded)
def action(self, params): peer = afi = safi = None try: afi = params[0] safi = params[1] except IndexError: pass self.api.route_refresh(peer, afi, safi) return CommandsResponse(STATUS_OK, '')
def action(self, params): if len(params) != 1 or params[0] not in self.supported_families: return WrongParamResp() from ryu.services.protocols.bgp.operator.internal_api \ import WrongParamError try: return CommandsResponse(STATUS_OK, self.api.get_single_rib_routes(params[0])) except WrongParamError as e: return WrongParamResp(e)
def action(self, params): core_service = self.api.get_core_service() core_service_view = CoreServiceDetailView(core_service) peers_view = core_service_view.rel('peer_manager').rel('peers') ret = peers_view.encode() return CommandsResponse(STATUS_OK, [{'ip_addr': k, 'as_num': str(v['remote_as']), 'bgp_state': v['stats']['bgp_state']} for k, v in ret.iteritems()])
def action(self, params): lvls = { 'debug': logging.DEBUG, 'error': logging.ERROR, 'info': logging.INFO } if len(params) == 1 and params[0] in lvls: self.api.log_handler.setLevel( lvls.get(params[0], logging.ERROR)) return CommandsResponse(STATUS_OK, True) else: return WrongParamResp()
def action(self, params): if len(params) == 0: return WrongParamResp() peer = afi = safi = None try: peer = params[0] afi = params[1] safi = params[2] except IndexError: pass self.api.route_refresh(peer, afi, safi) return CommandsResponse(STATUS_OK, '')
def action(self, params): requested_peers = [] if len(params) > 0: requested_peers = [str(p) for p in params] core_service = self.api.get_core_service() core_service_view = CoreServiceDetailView(core_service) peers_view = core_service_view.rel('peer_manager').rel('peers_summary') def filter_requested(peer_id, peer_obj): return not requested_peers or peer_id in requested_peers peers_view.apply_filter(filter_requested) ret = peers_view.encode() return CommandsResponse(STATUS_OK, ret)
def action(self, params): count = {} size = {} total_size = 0 unreachable = gc.collect() for obj in gc.get_objects(): inst_name = type(obj).__name__ c = count.get(inst_name, None) if not c: count[inst_name] = 0 s = size.get(inst_name, None) if not s: size[inst_name] = 0 count[inst_name] += 1 s = sys.getsizeof(obj) size[inst_name] += s total_size += s # Total size in MB total_size = total_size / 1000000 ret = { 'unreachable': unreachable, 'total': total_size, 'summary': [] } for class_name, s in size.items(): # Calculate size in MB size_mb = s / 1000000 # We are only interested in class which take-up more than a MB if size_mb > 0: ret['summary'].append({ 'class': class_name, 'instances': count.get(class_name, None), 'size': size_mb }) return CommandsResponse(STATUS_OK, ret)
def action(self, params): if len(params) != 2: return WrongParamResp() ip_addr, addr_family = params if addr_family == 'ipv4': rf = RF_IPv4_UC elif addr_family == 'ipv6': rf = RF_IPv6_UC elif addr_family == 'vpnv4': rf = RF_IPv4_VPN elif addr_family == 'vpnv6': rf = RF_IPv6_VPN elif addr_family == 'all': rf = None else: return WrongParamResp('wrong addr_family name') ret = self._retrieve_paths(addr_family, rf, ip_addr).encode() return CommandsResponse(STATUS_OK, ret)
def action(self, params): if len(params) == 0: return WrongParamResp('Not enough params') vrf_confs = self.api.get_vrfs_conf() if len(params) < 2: vrf_rf = 'ipv4' else: vrf_rf = params[1] vrf_key = params[0], vrf_rf if vrf_key in vrf_confs: view = ConfDetailView(vrf_confs[vrf_key]) encoded = view.encode() encoded['routes_count'] = self._count_routes(params[0], vrf_rf) else: return WrongParamResp('No vrf matched by %s' % str(vrf_key)) return CommandsResponse(STATUS_OK, encoded)
def action(self, params): self.api.sshserver.end_session() return CommandsResponse(STATUS_OK, True)
def action(self, params): if len(params) != 0: return WrongParamResp() return CommandsResponse(STATUS_OK, self.api.get_all_vrf_routes())
def wrong_param_resp_factory(e=None): if not e: e = WrongParamError() desc = 'wrong parameters: %s' % str(e) return CommandsResponse(STATUS_ERROR, desc)
def action(self, params): return CommandsResponse(STATUS_ERROR, 'Command incomplete')
def action(self, params): logging.getLogger('bgpspeaker').removeHandler(self.api.log_handler) return CommandsResponse(STATUS_OK, True)
def action(self, params): return CommandsResponse(STATUS_OK, True)