use of com.sequenceiq.cloudbreak.cloud.model.CloudNetwork in project cloudbreak by hortonworks.
the class CloudNetworksToPlatformNetworksResponseConverter method convert.
@Override
public PlatformNetworksResponse convert(CloudNetworks source) {
Map<String, Set<PlatformNetworkResponse>> result = new HashMap<>();
for (Entry<String, Set<CloudNetwork>> entry : source.getCloudNetworkResponses().entrySet()) {
Set<PlatformNetworkResponse> networks = new HashSet<>();
for (CloudNetwork cloudNetwork : entry.getValue()) {
PlatformNetworkResponse actual = new PlatformNetworkResponse(cloudNetwork.getName(), cloudNetwork.getId(), cloudNetwork.getSubnets(), cloudNetwork.getProperties());
networks.add(actual);
}
result.put(entry.getKey(), networks);
}
return new PlatformNetworksResponse(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetwork in project cloudbreak by hortonworks.
the class AwsPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudNetwork>> result = new HashMap<>();
Set<CloudNetwork> cloudNetworks = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value());
// create vpc filter view
PlatformResourceVpcFilterView filter = new PlatformResourceVpcFilterView(filters);
DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest();
// If the filtervalue is provided then we should filter only for those vpc
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeVpcsRequest.withVpcIds(filter.getVpcId());
}
for (Vpc vpc : ec2Client.describeVpcs(describeVpcsRequest).getVpcs()) {
Map<String, String> subnetMap = new HashMap<>();
List<Subnet> subnets = ec2Client.describeSubnets(createVpcDescribeRequest(vpc)).getSubnets();
Map<String, Object> properties = new HashMap<>();
properties.put("cidrBlock", vpc.getCidrBlock());
properties.put("default", vpc.getIsDefault());
properties.put("dhcpOptionsId", vpc.getDhcpOptionsId());
properties.put("instanceTenancy", vpc.getInstanceTenancy());
properties.put("state", vpc.getState());
for (Subnet subnet : subnets) {
subnetMap.put(subnet.getSubnetId(), subnet.getSubnetId());
}
cloudNetworks.add(new CloudNetwork(vpc.getVpcId(), vpc.getVpcId(), subnetMap, properties));
}
result.put(region.value(), cloudNetworks);
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetwork in project cloudbreak by hortonworks.
the class GcpPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<CloudNetwork>> result = new HashMap<>();
Set<CloudNetwork> cloudNetworks = new HashSet<>();
if (compute != null) {
NetworkList networkList = compute.networks().list(projectId).execute();
List<Subnetwork> subnetworkList = compute.subnetworks().list(projectId, region.value()).execute().getItems();
for (Network network : networkList.getItems()) {
Map<String, Object> properties = new HashMap<>();
properties.put("gatewayIPv4", Strings.nullToEmpty(network.getGatewayIPv4()));
properties.put("description", Strings.nullToEmpty(network.getDescription()));
properties.put("IPv4Range", Strings.nullToEmpty(network.getIPv4Range()));
properties.put("creationTimestamp", Strings.nullToEmpty(network.getCreationTimestamp()));
Map<String, String> subnets = new HashMap<>();
if (subnetworkList != null && network.getSubnetworks() != null) {
for (Subnetwork subnetwork : subnetworkList) {
if (network.getSubnetworks().contains(subnetwork.getSelfLink())) {
subnets.put(subnetwork.getName(), subnetwork.getName());
}
}
}
CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId().toString(), subnets, properties);
cloudNetworks.add(cloudNetwork);
}
result.put(region.value(), cloudNetworks);
}
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetwork in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
Set<CloudNetwork> cloudNetworks = new HashSet<>();
List<? extends Network> networks = getNetworks(osClient);
for (Network network : networks) {
Map<String, Object> properties = new HashMap<>();
properties.put("networkType", network.getNetworkType());
properties.put("providerPhyNet", network.getProviderPhyNet());
properties.put("providerSegID", network.getProviderSegID());
properties.put("tenantId", network.getTenantId());
Map<String, String> subnets = new HashMap<>();
List<? extends Subnet> neutronSubnets = network.getNeutronSubnets();
LOGGER.info("neutron subnets for {}: {}", network.getName(), neutronSubnets);
if (neutronSubnets != null) {
for (Subnet neutronSubnet : neutronSubnets) {
if (neutronSubnet != null) {
subnets.put(neutronSubnet.getId(), neutronSubnet.getName());
}
}
}
CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId(), subnets, properties);
cloudNetworks.add(cloudNetwork);
}
Map<String, Set<CloudNetwork>> result = new HashMap<>(1);
result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudNetworks);
LOGGER.info("openstack cloud networks result: {}", result);
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetwork in project cloudbreak by hortonworks.
the class AzurePlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AzureClient client = azureClientService.getClient(cloudCredential);
Map<String, Set<CloudNetwork>> result = new HashMap<>();
for (Network network : client.getNetworks()) {
String actualRegion = network.region().label();
if (regionMatch(actualRegion, region)) {
Map<String, String> subnets = new HashMap<>();
for (Entry<String, Subnet> subnet : network.subnets().entrySet()) {
subnets.put(subnet.getKey(), subnet.getKey());
}
Map<String, Object> properties = new HashMap<>();
properties.put("addressSpaces", network.addressSpaces());
properties.put("dnsServerIPs", network.dnsServerIPs());
properties.put("resourceGroupName", network.resourceGroupName());
CloudNetwork cloudNetwork = new CloudNetwork(network.name(), network.id(), subnets, properties);
result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudNetwork);
}
}
if (result.isEmpty() && Objects.nonNull(region)) {
result.put(region.value(), new HashSet<>());
}
return new CloudNetworks(result);
}
Aggregations