Search in sources :

Example 1 with HeatBridgeApi

use of org.onap.so.heatbridge.HeatBridgeApi in project so by onap.

the class CreateAAIInventory method heatbridge.

public void heatbridge(CloudInformation cloudInformation) throws HeatBridgeException, MsoCloudSiteNotFound {
    CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()).orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
    if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) {
        logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE);
        return;
    }
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
    List<String> oobMgtNetNames = new ArrayList<>();
    HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
    heatBridgeClient.authenticate();
    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);
    List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
    List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
    logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
    // os images
    if (osImages != null && !osImages.isEmpty()) {
        heatBridgeClient.buildAddImagesToAaiAction(osImages);
        logger.debug("Successfully built AAI actions to add images.");
    } else {
        logger.debug("No images to update to AAI.");
    }
    // flavors
    if (osFlavors != null && !osFlavors.isEmpty()) {
        heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
        logger.debug("Successfully built AAI actions to add flavors.");
    } else {
        logger.debug("No flavors to update to AAI.");
    }
    // compute resources
    heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osServers);
    logger.debug("Successfully queried compute resources and built AAI vserver actions.");
    // neutron resources
    List<String> oobMgtNetIds = new ArrayList<>();
    // if no network-id list is provided, however network-name list is
    if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
        oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
    }
    heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds, cloudInformation.getOwner());
    logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
    heatBridgeClient.buildAddVolumes(stackResources);
    // Update AAI
    logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
    heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Server(org.openstack4j.model.compute.Server) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) ArrayList(java.util.ArrayList) Resource(org.openstack4j.model.heat.Resource) Image(org.openstack4j.model.compute.Image) Flavor(org.openstack4j.model.compute.Flavor) CloudSite(org.onap.so.db.catalog.beans.CloudSite) HeatBridgeApi(org.onap.so.heatbridge.HeatBridgeApi) Network(org.openstack4j.model.network.Network)

Example 2 with HeatBridgeApi

use of org.onap.so.heatbridge.HeatBridgeApi in project so by onap.

the class DeleteAAIInventory method heatbridge.

public void heatbridge(CloudInformation cloudInformation) throws MsoCloudSiteNotFound, HeatBridgeException {
    logger.debug("Heatbridge delete executing");
    CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()).orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
    if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) {
        logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE);
        return;
    }
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
    heatBridgeClient.authenticate();
    heatBridgeClient.deleteVfModuleData(cloudInformation.getVnfId(), cloudInformation.getVfModuleId());
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) CloudSite(org.onap.so.db.catalog.beans.CloudSite) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) HeatBridgeApi(org.onap.so.heatbridge.HeatBridgeApi)

Aggregations

CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)2 CloudSite (org.onap.so.db.catalog.beans.CloudSite)2 HeatBridgeApi (org.onap.so.heatbridge.HeatBridgeApi)2 MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)2 ArrayList (java.util.ArrayList)1 Flavor (org.openstack4j.model.compute.Flavor)1 Image (org.openstack4j.model.compute.Image)1 Server (org.openstack4j.model.compute.Server)1 Resource (org.openstack4j.model.heat.Resource)1 Network (org.openstack4j.model.network.Network)1