2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 * Copyright (C) 2018 Bell Canada. All rights reserved.
24 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
25 * the License. You may obtain a copy of the License at
27 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
30 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
31 * specific language governing permissions and limitations under the License.
34 package org.onap.so.heatbridge.utils;
36 import com.google.common.base.Preconditions;
37 import com.google.common.base.Strings;
38 import java.util.Collections;
39 import java.util.List;
40 import java.util.Optional;
41 import java.util.stream.Collectors;
42 import javax.annotation.Nonnull;
43 import org.apache.commons.collections.CollectionUtils;
44 import org.onap.aai.domain.yang.SriovVf;
45 import org.onap.aai.domain.yang.Vserver;
47 public final class HeatBridgeUtils {
50 * IaaS naming convention for compute/p-interface to openstack/physical-network name mapping
52 private static final String OS_SIDE_SHARED_SRIOV_PREFIX = "shared-";
53 private static final String OS_SIDE_DEDICATED_SRIOV_PREFIX = "dedicated-";
54 private static final String COMPUTE_SIDE_SHARED_SRIOV_PREFIX = "sriov-s-";
55 private static final String COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX = "sriov-d-";
57 private HeatBridgeUtils() {
58 throw new IllegalStateException("Trying to instantiate a utility class.");
61 public static Optional<String> getMatchingPserverPifName(@Nonnull final String physicalNetworkName) {
62 Preconditions.checkState(!Strings.isNullOrEmpty(physicalNetworkName),
63 "Physical network name is null or empty!");
64 if (physicalNetworkName.contains(OS_SIDE_DEDICATED_SRIOV_PREFIX)) {
66 physicalNetworkName.replace(OS_SIDE_DEDICATED_SRIOV_PREFIX, COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX));
67 } else if (physicalNetworkName.contains(OS_SIDE_SHARED_SRIOV_PREFIX)) {
69 .of(physicalNetworkName.replace(OS_SIDE_SHARED_SRIOV_PREFIX, COMPUTE_SIDE_SHARED_SRIOV_PREFIX));
71 return Optional.of(physicalNetworkName);
74 public static List<String> extractPciIdsFromVServer(Vserver vserver) {
75 if (vserver.getLInterfaces() == null) {
76 return Collections.emptyList();
78 return vserver.getLInterfaces().getLInterface().stream()
79 .filter(lInterface -> lInterface.getSriovVfs() != null
80 && CollectionUtils.isNotEmpty(lInterface.getSriovVfs().getSriovVf()))
81 .flatMap(lInterface -> lInterface.getSriovVfs().getSriovVf().stream()).map(SriovVf::getPciId)
82 .collect(Collectors.toList());