Java源码示例:org.onosproject.cli.AbstractShellCommand
示例1
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class);
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
SortedSet<String> strings = delegate.getStrings();
stream(deviceService.getDevices())
.map(d -> netCfgService.getConfig(d.id(), Srv6DeviceConfig.class))
.filter(Objects::nonNull)
.map(Srv6DeviceConfig::mySid)
.filter(Objects::nonNull)
.forEach(sid -> strings.add(sid.toString()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例2
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class);
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
SortedSet<String> strings = delegate.getStrings();
stream(deviceService.getDevices())
.map(d -> netCfgService.getConfig(d.id(), Srv6DeviceConfig.class))
.filter(Objects::nonNull)
.map(Srv6DeviceConfig::mySid)
.filter(Objects::nonNull)
.forEach(sid -> strings.add(sid.toString()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例3
@Override
protected List<String> choices() {
NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class);
checkArgument(commandLine.getCursorArgumentIndex() >= 2);
String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 2];
SubjectFactory<?> subjectFactory = service.getSubjectFactory(subjectClassKey);
if (subjectFactory == null) {
return ImmutableList.of();
}
String subjectKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
Object subject = subjectFactory.createSubject(subjectKey);
Set<? extends Config<Object>> configs = service.getConfigs(subject);
return configs.stream().map(Config::key).collect(Collectors.toList());
}
示例4
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
IntentService service = AbstractShellCommand.get(IntentService.class);
SortedSet<String> strings = delegate.getStrings();
service.getIntents()
.forEach(intent ->
strings.add(intent.appId().name()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例5
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
HostService service = AbstractShellCommand.get(HostService.class);
Iterator<Host> it = service.getHosts().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next().id().toString());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例6
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
DeviceService service = AbstractShellCommand.get(DeviceService.class);
// Generate the device ID/port number identifiers
for (Device device : service.getDevices()) {
SortedSet<String> strings = delegate.getStrings();
for (Port port : service.getPorts(device.id())) {
if (!port.number().isLogical()) {
strings.add(device.id().toString() + "/" + port.number());
}
}
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例7
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
TopologyService service = AbstractShellCommand.get(TopologyService.class);
Topology topology = service.currentTopology();
SortedSet<String> strings = delegate.getStrings();
for (TopologyCluster cluster : service.getClusters(topology)) {
strings.add(Integer.toString(cluster.id().index()));
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例8
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
DeviceService service = AbstractShellCommand.get(DeviceService.class);
// Generate the device ID/port number identifiers
for (Device device : service.getDevices()) {
SortedSet<String> strings = delegate.getStrings();
for (Port port : service.getPorts(device.id())) {
if (!port.number().isLogical() && (port.type().equals(Port.Type.OCH) ||
port.type().equals(Port.Type.OMS) || port.type().equals(Port.Type.OTU))) {
strings.add(device.id().toString() + "/" + port.number());
}
}
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例9
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
DeviceService service = AbstractShellCommand.get(DeviceService.class);
Iterator<Device> it = service.getDevices().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next().id().toString());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例10
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
LinkService service = AbstractShellCommand.get(LinkService.class);
// Link source the previous argument.
String srcArg = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
// Generate the device ID/port number identifiers
SortedSet<String> strings = delegate.getStrings();
try {
ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg);
service.getEgressLinks(src)
.forEach(link -> strings.add(link.dst().elementId().toString() +
"/" + link.dst().port()));
} catch (NumberFormatException e) {
System.err.println("Invalid connect-point");
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例11
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
DomainService service = AbstractShellCommand.get(DomainService.class);
Iterator<DomainId> it = service.getDomainIds().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next().id());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例12
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
LinkService service = AbstractShellCommand.get(LinkService.class);
// Generate the device ID/port number identifiers
SortedSet<String> strings = delegate.getStrings();
service.getLinks()
.forEach(link -> strings.add(link.src().elementId().toString() +
"/" + link.src().port()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例13
@Override
protected void doExecute() {
EvpnRouteStore evpnRouteStore = AbstractShellCommand.get(EvpnRouteStore.class);
evpnRouteStore.getRouteTables().forEach(routeTableId -> {
Collection<EvpnRouteSet> routes
= evpnRouteStore.getRoutes(routeTableId);
if (routes != null) {
routes.forEach(route -> {
Collection<EvpnRoute> evpnRoutes = route.routes();
print(FORMAT_HEADER);
evpnRoutes.forEach(evpnRoute -> {
print(FORMAT_PUBLIC_ROUTE, evpnRoute.prefixMac(),
evpnRoute.prefixIp().address().getIp4Address(),
evpnRoute.ipNextHop());
});
});
}
});
}
示例14
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
IntentService service = AbstractShellCommand.get(IntentService.class);
SortedSet<String> strings = delegate.getStrings();
service.getIntents()
.forEach(intent ->
strings.add(intent.appId().name()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例15
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
IntentService service = AbstractShellCommand.get(IntentService.class);
SortedSet<String> strings = delegate.getStrings();
service.getIntents().forEach(intent -> {
if (intent instanceof LinkCollectionIntent
|| intent instanceof PointToPointIntent) {
strings.add(intent.key().toString());
}
});
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例16
@Override
protected void doExecute() {
RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class);
IpPrefix prefix = IpPrefix.valueOf(prefixString);
IpAddress nextHop = IpAddress.valueOf(nextHopString);
// Routes through cli without mentioning source then it is created as STATIC,
// otherwise routes are created with corresponding source.
Route route = source == null ?
new Route(Route.Source.STATIC, prefix, nextHop) :
new Route(Route.Source.valueOf(source), prefix, nextHop);
service.withdraw(Collections.singleton(route));
}
示例17
@Override
protected void doExecute() {
BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class);
Collection<BgpSession> bgpSessions = service.getBgpSessions();
if (bgpNeighbor != null) {
// Print a single neighbor (if found)
BgpSession foundBgpSession = null;
for (BgpSession bgpSession : bgpSessions) {
if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) {
foundBgpSession = bgpSession;
break;
}
}
if (foundBgpSession != null) {
printNeighbor(foundBgpSession);
} else {
print("BGP neighbor %s not found", bgpNeighbor);
}
return;
}
// Print all neighbors
printNeighbors(bgpSessions);
}
示例18
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
HostService service = AbstractShellCommand.get(HostService.class);
Iterator<Host> it = service.getHosts().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
for (IpAddress ip : it.next().ipAddresses()) {
strings.add(ip.toString() + CIDR);
}
}
return delegate.complete(session, commandLine, candidates);
}
示例19
@Override
protected void doExecute() {
DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class);
try {
MacAddress macID = MacAddress.valueOf(macAddr);
Ip4Address ipAddress = Ip4Address.valueOf(ipAddr);
IpAssignment ipAssignment = IpAssignment.builder()
.ipAddress(ipAddress)
.leasePeriod(dhcpService.getLeaseTime())
.timestamp(new Date())
.assignmentStatus(Option_Requested)
.build();
if (dhcpService.setStaticMapping(macID, ipAssignment)) {
print(DHCP_SUCCESS);
} else {
print(DHCP_FAILURE);
}
} catch (IllegalArgumentException e) {
print(e.getMessage());
}
}
示例20
@Override
protected void doExecute() {
DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class);
try {
MacAddress macID = MacAddress.valueOf(macAddr);
if (dhcpService.removeStaticMapping(macID)) {
print(DHCP_SUCCESS);
} else {
print(DHCP_FAILURE);
}
} catch (IllegalArgumentException e) {
print(e.getMessage());
}
}
示例21
/**
* Display tunnel information on the terminal.
*
* @param tunnel pce tunnel
*/
void display(Tunnel tunnel) {
List<ExplicitPathInfo> explicitPathInfoList = AbstractShellCommand.get(PceService.class)
.explicitPathInfoList(tunnel.tunnelName().value());
print("\npath-id : %s \n" +
"source : %s \n" +
"destination : %s \n" +
"path-type : %s \n" +
"symbolic-path-name : %s \n" +
"constraints: \n" +
" cost : %s \n" +
" bandwidth : %s",
tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(),
tunnel.path().dst().deviceId().toString(),
tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE),
tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
if (explicitPathInfoList != null) {
for (ExplicitPathInfo e : explicitPathInfoList) {
print("explicitPathObjects : \n" +
" type : %s \n" +
" value : %s ",
String.valueOf(e.type().type()), e.value().toString());
}
}
}
示例22
@Override
public void modifyHostDetails(PropertyPanel pp, HostId hostId) {
pp.title(MY_HOST_TITLE);
pp.removeAllProps();
PortPairService portPairService = AbstractShellCommand.get(PortPairService.class);
VirtualPortService virtualPortService = AbstractShellCommand.get(VirtualPortService.class);
HostService hostService = AbstractShellCommand.get(HostService.class);
Iterable<PortPair> portPairs = portPairService.getPortPairs();
for (PortPair portPair : portPairs) {
VirtualPort vPort = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress()));
MacAddress dstMacAddress = vPort.macAddress();
Host host = hostService.getHost(HostId.hostId(dstMacAddress));
if (hostId.toString().equals(host.id().toString())) {
pp.addProp("SF Name", portPair.name());
pp.addProp("SF Ip", vPort.fixedIps().iterator().next().ip());
}
}
pp.addProp("SF host Address", hostId.toString());
}
示例23
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
DeviceService service = AbstractShellCommand.get(DeviceService.class);
Iterator<Device> it = service.getDevices().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
Device device = it.next();
if (device.is(CfmMepProgrammable.class)) {
strings.add(device.id().toString());
}
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例24
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
InstancePortService instancePortService =
AbstractShellCommand.get(InstancePortService.class);
Set<IpAddress> set = instancePortService.instancePorts().stream()
.map(InstancePort::ipAddress)
.collect(Collectors.toSet());
set.add(IpAddress.valueOf(EXTERNAL_IP));
SortedSet<String> strings = delegate.getStrings();
Iterator<IpAddress> it = set.iterator();
while (it.hasNext()) {
strings.add(it.next().toString());
}
return delegate.complete(session, commandLine, candidates);
}
示例25
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
VirtualNetworkAdminService service = AbstractShellCommand.get(VirtualNetworkAdminService.class);
List<VirtualNetwork> virtualNetworks = new ArrayList<>();
Set<TenantId> tenantSet = service.getTenantIds();
tenantSet.forEach(tenantId -> virtualNetworks.addAll(service.getVirtualNetworks(tenantId)));
Collections.sort(virtualNetworks, Comparators.VIRTUAL_NETWORK_COMPARATOR);
SortedSet<String> strings = delegate.getStrings();
virtualNetworks.forEach(virtualNetwork -> strings.add(virtualNetwork.id().toString()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例26
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
VirtualNetworkAdminService service = AbstractShellCommand.get(VirtualNetworkAdminService.class);
SortedSet<String> strings = delegate.getStrings();
for (TenantId tenantId : service.getTenantIds()) {
strings.add(tenantId.id());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例27
@Override
protected void doExecute() {
SegmentRoutingService srService =
AbstractShellCommand.get(SegmentRoutingService.class);
Tunnel tunnel = new DefaultTunnel(tunnelId, Lists.newArrayList());
TunnelHandler.Result result = srService.removeTunnel(tunnel);
switch (result) {
case TUNNEL_IN_USE:
print("ERROR: the tunnel is still in use");
break;
case TUNNEL_NOT_FOUND:
print("ERROR: the tunnel is not found");
break;
default:
break;
}
}
示例28
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
SegmentRoutingService srService =
AbstractShellCommand.get(SegmentRoutingService.class);
List<L2Tunnel> tunnels = srService.getL2Tunnels();
// combine polices and tunnels to pseudowires
Iterator<String> pseudowires = tunnels.stream()
.map(l2Tunnel -> Long.toString(l2Tunnel.tunnelId()))
.collect(Collectors.toList()).iterator();
SortedSet<String> strings = delegate.getStrings();
while (pseudowires.hasNext()) {
strings.add(pseudowires.next());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
示例29
@Override
public int complete(String buffer, int cursor, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
NetworkService service = AbstractShellCommand.get(NetworkService.class);
delegate.getStrings().addAll(service.getNetworks());
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(buffer, cursor, candidates);
}
示例30
@Override
protected List<String> choices() {
NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class);
String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
if (subjectFactory == null) {
return Collections.emptyList();
}
// get all registered subject objects.
Set<Object> subjects = service.getSubjects(subjectFactory.subjectClass());
return subjects.stream().map(subjectFactory::subjectKey).collect(Collectors.toList());
}