diff options
author | Munir Ahmad <munir.ahmad@bell.ca> | 2020-07-30 10:24:50 -0400 |
---|---|---|
committer | Munir Ahmad <munir.ahmad@bell.ca> | 2020-08-04 11:19:24 -0400 |
commit | d9c694b4c4123bbd3e62f8a64484c27c6be1b100 (patch) | |
tree | 31754d1b6f4303fad8ce08e7e5fa2fe9018097b6 /adapters/mso-openstack-adapters/src/main/java/org/onap | |
parent | 4e81b212f66800fffbb06a1f6c55b5733a98c122 (diff) |
[SO] heatbridge implemention to populate AAI with openstack provider network/subnet
Issue-ID: SO-3109
Signed-off-by: Munir Ahmad <munir.ahmad@bell.ca>
Change-Id: Ibb8f5b994072b797783dba7ce412baecb9b64174
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main/java/org/onap')
5 files changed, 121 insertions, 0 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java index df4229c985..12751f8c27 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java @@ -35,6 +35,7 @@ import org.openstack4j.model.compute.Flavor; import org.openstack4j.model.compute.Image; import org.openstack4j.model.compute.Server; import org.openstack4j.model.heat.Resource; +import org.openstack4j.model.network.Network; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -72,6 +73,10 @@ public class CreateAAIInventory { List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId()); + List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources); + heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), + osNetworks); + List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources); heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java index 9c098863f2..a4e6cccc06 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java @@ -38,6 +38,7 @@ import org.openstack4j.model.compute.Flavor; import org.openstack4j.model.compute.Image; import org.openstack4j.model.compute.Server; import org.openstack4j.model.heat.Resource; +import org.openstack4j.model.network.Network; /** * Defines the contract to extract Heat Stack Resources from Openstack and inventory it to AAI. This API is used only to @@ -88,6 +89,14 @@ public interface HeatBridgeApi { List<Server> getAllOpenstackServers(List<Resource> stackResources); /** + * Query the Openstack provider network objects from the list of stack resources + * + * @param stackResources A list of stack based resources + * @return A list of Openstack Network objects + */ + List<Network> getAllOpenstackProviderNetworks(final List<Resource> stackResources); + + /** * Extract Openstack Image objects from a a list of Server objects * * @param servers A list of Openstack Server objects @@ -104,6 +113,15 @@ public interface HeatBridgeApi { List<Flavor> extractOpenstackFlavorsFromServers(List<Server> servers); /** + * Query and build AAI actions for Openstack Compute resources to AAI's l3-network objects with its subnets + * + * @param genericVnfId AAI generic-vnf-id + * @param vfModuleId AAI vf-module-id + * @param networks Openstack Network list + */ + void buildAddNetworksToAaiAction(final String genericVnfId, final String vfModuleId, List<Network> networks); + + /** * Query and build AAI actions for Openstack Image resources to AAI's image objects * * @param images List of Openstack Image objects diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java index e537b241c0..92958004ca 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java @@ -49,11 +49,15 @@ import org.apache.commons.validator.routines.InetAddressValidator; import org.onap.aai.domain.yang.Flavor; import org.onap.aai.domain.yang.Image; import org.onap.aai.domain.yang.L3InterfaceIpv4AddressList; +import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.LInterface; import org.onap.aai.domain.yang.PInterface; import org.onap.aai.domain.yang.Pserver; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.SriovPf; import org.onap.aai.domain.yang.SriovPfs; +import org.onap.aai.domain.yang.Subnets; import org.onap.aai.domain.yang.SriovVf; import org.onap.aai.domain.yang.SriovVfs; import org.onap.aai.domain.yang.VfModule; @@ -198,6 +202,16 @@ public class HeatBridgeImpl implements HeatBridgeApi { } @Override + public List<Network> getAllOpenstackProviderNetworks(final List<Resource> stackResources) { + Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT); + // Filter Openstack Compute resources + List<String> providerNetworkIds = + extractStackResourceIdsByResourceType(stackResources, HeatBridgeConstants.OS_NEUTRON_PROVIDERNET); + return providerNetworkIds.stream().map(providerNetworkId -> osClient.getNetworkById(providerNetworkId)) + .collect(Collectors.toList()); + } + + @Override public List<org.openstack4j.model.compute.Image> extractOpenstackImagesFromServers(final List<Server> servers) { Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT); return servers.stream().map(Server::getImage) @@ -211,6 +225,27 @@ public class HeatBridgeImpl implements HeatBridgeApi { .filter(distinctByProperty(org.openstack4j.model.compute.Flavor::getId)).collect(Collectors.toList()); } + public void buildAddNetworksToAaiAction(final String genericVnfId, final String vfModuleId, + List<Network> networks) { + networks.forEach(network -> { + L3Network l3Network = aaiHelper.buildNetwork(network); + if (l3Network != null) { + l3Network.setSubnets(buildSunets(network)); + + RelationshipList relationshipList = new RelationshipList(); + List<Relationship> relationships = relationshipList.getRelationship(); + + relationships.add(aaiHelper.getRelationshipToVfModule(genericVnfId, vfModuleId)); + relationships.add(aaiHelper.getRelationshipToTenant(cloudOwner, cloudRegionId, tenantId)); + + l3Network.setRelationshipList(relationshipList); + transaction.createIfNotExists( + AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, l3Network.getNetworkId()), + Optional.of(l3Network)); + } + }); + } + @Override public void buildAddImagesToAaiAction(final List<org.openstack4j.model.compute.Image> images) throws HeatBridgeException { @@ -338,6 +373,20 @@ public class HeatBridgeImpl implements HeatBridgeApi { return pserverMap; } + private Subnets buildSunets(Network network) { + Subnets aaiSubnets = new Subnets(); + List<String> subnetIds = network.getSubnets(); + + subnetIds.forEach(subnetId -> { + Subnet subnet = osClient.getSubnetById(subnetId); + org.onap.aai.domain.yang.Subnet aaiSubnet = aaiHelper.buildSubnet(subnet); + if (aaiSubnet != null) { + aaiSubnets.getSubnet().add(aaiSubnet); + } + }); + return aaiSubnets; + } + private void createPServerIfNotExists(Map<String, Pserver> serverHostnames) { for (Pserver pserver : serverHostnames.values()) { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, pserver.getHostname()); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java index fdf7ce38f1..71c6a96cd6 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java @@ -40,6 +40,7 @@ public class HeatBridgeConstants { public static final Integer OS_DEFAULT_HEAT_NESTING = 5; public static final String OS_SERVER_RESOURCE_TYPE = "OS::Nova::Server"; public static final String OS_PORT_RESOURCE_TYPE = "OS::Neutron::Port"; + public static final String OS_NEUTRON_PROVIDERNET = "OS::Neutron::ProviderNet"; public static final String OS_SRIOV_PORT_TYPE = "direct"; public static final String OS_PCI_SLOT_KEY = "pci_slot"; public static final String OS_PHYSICAL_NETWORK_KEY = "physical_network"; @@ -64,6 +65,8 @@ public class HeatBridgeConstants { public static final String AAI_VF_MODULE_ID = "vf-module.vf-module-id"; public static final String AAI_IMAGE = "image"; public static final String AAI_IMAGE_ID = "image.image-id"; + public static final String AAI_TENANT = "tenant"; + public static final String AAI_TENANT_ID = "tenant.tenant-id"; public static final String AAI_CLOUD_OWNER = "cloud-region.cloud-owner"; public static final String AAI_CLOUD_REGION_ID = "cloud-region.cloud-region-id"; public static final String AAI_FLAVOR = "flavor"; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java index c4d9cbe871..7d4e92d9ad 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java @@ -42,6 +42,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.aai.domain.yang.Flavor; import org.onap.aai.domain.yang.Image; +import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.PInterface; import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.Relationship; @@ -54,7 +55,9 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.so.heatbridge.constants.HeatBridgeConstants; import org.openstack4j.model.compute.Server; +import org.openstack4j.model.network.Network; import org.openstack4j.model.network.Port; +import org.openstack4j.model.network.Subnet; import com.google.common.base.Preconditions; /** @@ -131,6 +134,49 @@ public class AaiHelper { return relationshipList; } + public Relationship getRelationshipToVfModule(String vnfId, String vfModuleId) { + return buildRelationship(AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)); + } + + public Relationship getRelationshipToTenant(String cloudOwner, String cloudRegionId, String tenantId) { + return buildRelationship( + AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegionId, tenantId)); + } + + public org.onap.aai.domain.yang.Subnet buildSubnet(Subnet subnet) { + org.onap.aai.domain.yang.Subnet aaiSubnet = new org.onap.aai.domain.yang.Subnet(); + aaiSubnet.setSubnetId(subnet.getId()); + aaiSubnet.setDhcpEnabled(subnet.isDHCPEnabled()); + + aaiSubnet.setSubnetName(subnet.getName()); + aaiSubnet.setGatewayAddress(subnet.getGateway()); + aaiSubnet.setCidrMask(subnet.getCidr()); + aaiSubnet.setIpVersion(subnet.getIpVersion().name()); + return aaiSubnet; + } + + public L3Network buildNetwork(Network network) { + if (network.getId() == null) { + return null; + } + L3Network l3Network = new L3Network(); + l3Network.setNetworkId(network.getId()); + l3Network.setIsBoundToVpn(true); + l3Network.setIsProviderNetwork(true); + + // optional fields + l3Network.setIsSharedNetwork(network.isShared()); + l3Network.setIsExternalNetwork(network.isRouterExternal()); + l3Network.setOperationalStatus(String.valueOf(network.isAdminStateUp())); + if (network.getName() != null) { + l3Network.setNetworkName(network.getName()); + } + if (network.getProviderPhyNet() != null) { + l3Network.setPhysicalNetworkName(network.getProviderPhyNet()); + } + return l3Network; + } + /** * Transform Openstack Server object to AAI Vserver object * |