use of org.platformlayer.ops.networks.NetworkPoint in project platformlayer by platformlayer.
the class PlatformLayerFirewallEntry method addChildren.
@Override
protected void addChildren() throws OpsException {
// TODO: Need to register a dependency on destItem?
MachineResolver dest = MachineResolver.build(destItem);
addChild(dest);
List<Transport> transports;
if (transport == null) {
String cidr = sourceCidr;
if (!Strings.isNullOrEmpty(sourceCidr)) {
IpRange range = IpRange.parse(cidr);
if (range.isIpv6()) {
transport = Transport.Ipv6;
} else {
transport = Transport.Ipv4;
}
}
}
if (transport == null) {
transports = Transport.all();
} else {
transports = Collections.singletonList(transport);
}
for (final Transport transport : transports) {
if (!Strings.isNullOrEmpty(sourceCidr)) {
IptablesFilterEntry entry = dest.addChild(IptablesFilterEntry.class);
entry.port = port;
entry.sourceCidr = sourceCidr;
entry.protocol = protocol;
entry.transport = transport;
entry.ruleKey = uniqueId;
} else if (sourceItemKey != null) {
LateBound<IptablesFilterEntry> entry = new LateBound<IptablesFilterEntry>() {
@Override
public IptablesFilterEntry get() throws OpsException {
ItemBase sourceItem = platformLayerHelpers.getItem(sourceItemKey);
NetworkPoint targetNetworkPoint = NetworkPoint.forTargetInContext();
boolean required = !OpsContext.isDelete();
Machine sourceMachine = instanceHelpers.getMachine(sourceItem, required);
if (sourceMachine == null) {
// TODO: Store by key? Delete by key?
log.warn("Source machine not found for firewall rule; assuming already deleted");
return null;
}
String sourceCidr = null;
List<InetAddress> addresses = sourceMachine.getNetworkPoint().findAddresses(targetNetworkPoint);
if (transport == Transport.Ipv4) {
Iterables.removeIf(addresses, InetAddressUtils.IS_IPV6);
if (addresses.size() == 1) {
sourceCidr = addresses.get(0).getHostAddress() + "/32";
} else {
if (addresses.isEmpty()) {
return null;
}
throw new IllegalStateException("Not implemented");
}
} else {
Iterables.removeIf(addresses, InetAddressUtils.IS_IPV4);
if (addresses.size() == 1) {
sourceCidr = addresses.get(0).getHostAddress() + "/128";
} else {
if (addresses.isEmpty()) {
return null;
}
throw new IllegalStateException("Not implemented");
}
}
IptablesFilterEntry entry = injected(IptablesFilterEntry.class);
entry.port = port;
entry.sourceCidr = sourceCidr;
entry.protocol = protocol;
entry.transport = transport;
entry.ruleKey = uniqueId;
return entry;
}
@Override
public String getDescription() throws Exception {
return "Firewall rules";
}
};
dest.addChild(entry);
} else {
// Both empty => wildcard
IptablesFilterEntry entry = dest.addChild(IptablesFilterEntry.class);
entry.port = port;
entry.protocol = protocol;
entry.transport = transport;
entry.ruleKey = uniqueId;
}
}
// TODO: Add source rules??
}
use of org.platformlayer.ops.networks.NetworkPoint in project platformlayer by platformlayer.
the class PrivateNetworkHelpers method findTunnelAddress.
public ThrowingProvider<String> findTunnelAddress(final PlatformLayerKey machineKey) {
final NetworkPoint src = NetworkPoint.forPublicInternet();
return new ThrowingProvider<String>() {
@Override
public String build() throws OpsException {
ItemBase dest = platformLayer.getItem(machineKey);
Machine machine = instanceHelpers.getMachine(dest, true);
String address = machine.getNetworkPoint().getBestAddress(src);
return address;
}
};
}
use of org.platformlayer.ops.networks.NetworkPoint in project platformlayer by platformlayer.
the class SimpleApp method getConfigurationProperties.
protected Map<String, String> getConfigurationProperties() throws OpsException {
Map<String, String> config = Maps.newHashMap();
if (context.links != null) {
NetworkPoint networkPoint = NetworkPoint.forTargetInContext();
InetAddressChooser inetAddressChooser = NearestAddressChooser.build(networkPoint);
SimpleLinkConsumer consumer = new SimpleLinkConsumer(consumerKey, inetAddressChooser);
config.putAll(consumeHelper.buildLinkTargetProperties(consumer, context.links.getLinks()));
}
return config;
}
use of org.platformlayer.ops.networks.NetworkPoint in project platformlayer by platformlayer.
the class DirectHostController method getCasStore.
@Override
public CasStore getCasStore() throws OpsException {
// TODO: Getting the IP like this is evil
NetworkPoint targetAddress;
// if (host.getIpv6() != null) {
// IpRange ipv6Range = IpV6Range.parse(host.getIpv6());
// targetAddress = NetworkPoint.forPublicHostname(ipv6Range.getGatewayAddress());
// } else {
targetAddress = NetworkPoint.forPublicHostname(model.host);
// }
Machine machine = new OpaqueMachine(targetAddress);
OpsTarget machineTarget = machine.getTarget(sshKeys.findOtherServiceKey(new ServiceType("machines-direct")));
CasStoreInfo casStoreOptions = new CasStoreInfo(true);
FilesystemCasStore store = new FilesystemCasStore(casStoreOptions, new OpsCasTarget(machineTarget));
return store;
}
use of org.platformlayer.ops.networks.NetworkPoint in project platformlayer by platformlayer.
the class CollectdModelBuilder method getCollectdServer.
@Deprecated
public String getCollectdServer() throws OpsException {
Iterable<CollectdService> collectdServices = platformLayer.listItems(CollectdService.class);
for (CollectdService collectdService : collectdServices) {
// TODO: Use DNS name when it works
NetworkPoint target = network.getNetworkPoint(collectdService);
if (target != null) {
NetworkPoint targetNetworkPoint = NetworkPoint.forTargetInContext();
InetAddress address = target.findBestAddress(targetNetworkPoint, InetAddressChooser.preferIpv6());
if (address != null) {
return address.getHostAddress();
}
}
}
log.warn("Unable to find collectd server; defaulting to 127.0.0.1");
return "127.0.0.1";
}
Aggregations