use of org.onap.aai.domain.yang.PInterface in project so by onap.
the class ServicePluginFactory method getTPInfo.
private Map<String, Object> getTPInfo(AAIResourcesClient client, AAIResourceUri localTP, AAIResourceUri remoteTP) {
Map<String, Object> tpInfo = new HashMap<>();
if (localTP != null && remoteTP != null) {
// give local tp
String tpUrl = localTP.build().toString();
String localNodeId = tpUrl.split("/")[4];
tpInfo.put("local-access-node-id", localNodeId);
logger.info("Get info for local TP :{}", localNodeId);
Optional<Pnf> optLocalPnf = client.get(Pnf.class, AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().pnf(localNodeId)));
getTpInfoFromLocalTp(tpInfo, optLocalPnf);
String ltpIdStr = tpUrl.substring(tpUrl.lastIndexOf("/") + 1);
if (ltpIdStr.contains("-")) {
tpInfo.put("local-access-ltp-id", ltpIdStr.substring(ltpIdStr.lastIndexOf("-") + 1));
}
// give remote tp
tpUrl = remoteTP.build().toString();
PInterface intfRemote = client.get(PInterface.class, remoteTP).get();
String remoteNodeId = tpUrl.split("/")[4];
tpInfo.put("remote-access-node-id", remoteNodeId);
logger.info("Get info for remote TP:{}", remoteNodeId);
String[] networkRefRemote = intfRemote.getNetworkRef().split("-");
Optional<Pnf> optRemotePnf = client.get(Pnf.class, AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().pnf(remoteNodeId)));
getTpInfoFromRemoteTp(tpInfo, networkRefRemote, optRemotePnf);
String ltpIdStrR = tpUrl.substring(tpUrl.lastIndexOf("/") + 1);
if (ltpIdStrR.contains("-")) {
tpInfo.put("remote-access-ltp-id", ltpIdStrR.substring(ltpIdStr.lastIndexOf("-") + 1));
}
}
return tpInfo;
}
use of org.onap.aai.domain.yang.PInterface in project so by onap.
the class HeatBridgeImpl method createTransactionToDeleteSriovPfFromPserver.
private void createTransactionToDeleteSriovPfFromPserver(List<AAIResourceUri> vserverUris) {
Map<String, List<String>> pserverToPciIdMap = getPserverToPciIdMap(vserverUris);
for (Map.Entry<String, List<String>> entry : pserverToPciIdMap.entrySet()) {
String pserverName = entry.getKey();
List<String> pciIds = entry.getValue();
Optional<Pserver> pserver = resourcesClient.get(Pserver.class, AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(pserverName)).depth(Depth.TWO));
if (pserver.isPresent()) {
// For each pserver/p-interface match sriov-vfs by pic-id and delete them.
pserver.get().getPInterfaces().getPInterface().stream().filter(pIf -> pIf.getSriovPfs() != null && CollectionUtils.isNotEmpty(pIf.getSriovPfs().getSriovPf())).forEach(pIf -> pIf.getSriovPfs().getSriovPf().forEach(sriovPf -> {
if (pciIds.contains(sriovPf.getPfPciId())) {
logger.debug("creating transaction to delete SR-IOV PF: " + pIf.getInterfaceName() + " from PServer: " + pserverName);
if (env.getProperty("heatBridgeDryrun", Boolean.class, false)) {
logger.debug("Would delete Sriov Pf: {}", AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(pserverName).pInterface(pIf.getInterfaceName()).sriovPf(sriovPf.getPfPciId())).build());
} else {
resourcesClient.delete(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(pserverName).pInterface(pIf.getInterfaceName()).sriovPf(sriovPf.getPfPciId())));
}
}
}));
}
}
}
use of org.onap.aai.domain.yang.PInterface in project so by onap.
the class HeatBridgeImplTest method testUpdateLInterfaceVlan.
@Test
public void testUpdateLInterfaceVlan() throws HeatBridgeException {
// Arrange
List<Resource> stackResources = (List<Resource>) extractTestStackResources();
Port port = mock(Port.class);
when(port.getId()).thenReturn("test-port-id");
when(port.getName()).thenReturn("test-port-name");
when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
when(port.getDeviceId()).thenReturn("test-device-id");
LInterface lIf = new LInterface();
lIf.setInterfaceId("test-port-id");
lIf.setInterfaceType("SRIOV");
lIf.setInterfaceName("name");
String pfPciId = "0000:08:00.0";
when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id"));
IP ip = mock(IP.class);
Set<IP> ipSet = new HashSet<>();
ipSet.add(ip);
when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
when(ip.getSubnetId()).thenReturn("testSubnetId");
when(port.getFixedIps()).thenAnswer(x -> ipSet);
Subnet subnet = mock(Subnet.class);
when(subnet.getCidr()).thenReturn("169.254.100.0/24");
when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
Network network = mock(Network.class);
when(network.getId()).thenReturn("test-network-id");
when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
when(network.getProviderSegID()).thenReturn("2345");
when(network.getProviderPhyNet()).thenReturn("ovsnet");
doNothing().when(heatbridge).processOVS(any(), any(), any());
when(osClient.getNetworkById(anyString())).thenReturn(network);
SriovPf sriovPf = new SriovPf();
sriovPf.setPfPciId(pfPciId);
PInterface pIf = mock(PInterface.class);
when(pIf.getInterfaceName()).thenReturn("test-port-id");
when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf));
// Act
heatbridge.createVlanAndSriovVF(port, lIf, "hostname");
// Assert
verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
verify(osClient, times(1)).getNetworkById(anyString());
verify(heatbridge, times(0)).processOVS(any(), any(), any());
}
use of org.onap.aai.domain.yang.PInterface in project so by onap.
the class HeatBridgeImplTest method testUpdateVserverLInterfacesToAai_skipVlans.
@Test
public void testUpdateVserverLInterfacesToAai_skipVlans() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
// Arrange
List<Resource> stackResources = (List<Resource>) extractTestStackResources();
Port port = mock(Port.class);
when(port.getId()).thenReturn("test-port-id");
when(port.getName()).thenReturn("test-port-name");
when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
when(port.getDeviceId()).thenReturn("test-device-id");
String pfPciId = "0000:08:00.0";
when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id"));
Network network = mock(Network.class);
when(network.getId()).thenReturn("test-network-id");
when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
when(network.getProviderSegID()).thenReturn("2345");
when(osClient.getPortById("212a203a-9764-4f42-84ea-731536a8f13a")).thenReturn(port);
when(osClient.getPortById("387e3904-8948-43d1-8635-b6c2042b54da")).thenReturn(port);
when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port);
when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port);
when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port);
when(osClient.getNetworkById(anyString())).thenReturn(network);
PInterface pIf = mock(PInterface.class);
when(pIf.getInterfaceName()).thenReturn("test-port-id");
doNothing().when(heatbridge).updateSriovPfToSriovVF(any(), any());
// Act
heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");
// Assert
verify(transaction, times(5)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
verify(osClient, times(5)).getPortById(anyString());
verify(osClient, times(5)).getNetworkById(anyString());
}
use of org.onap.aai.domain.yang.PInterface in project so by onap.
the class AaiHelper method buildPInterface.
/**
* Transform Openstack Server object to AAI PInterface object
*
* @param port Openstack port object
* @return AAI PInterface object
*/
public PInterface buildPInterface(Port port) {
Map<String, Object> portProfile = port.getProfile();
PInterface pInterface = new PInterface();
pInterface.setInterfaceName(portProfile.get(HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY).toString());
pInterface.setInMaint(false);
pInterface.setInterfaceRole(HeatBridgeConstants.OS_PHYSICAL_INTERFACE_KEY);
return pInterface;
}
Aggregations