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.List;
39 import java.util.Optional;
40 import java.util.stream.Collectors;
41 import javax.annotation.Nonnull;
42 import org.apache.commons.collections.CollectionUtils;
43 import org.onap.aai.domain.yang.SriovVf;
44 import org.onap.aai.domain.yang.Vserver;
46 public final class HeatBridgeUtils {
49 * IaaS naming convention for compute/p-interface to openstack/physical-network name mapping
51 private static final String OS_SIDE_SHARED_SRIOV_PREFIX = "shared-";
52 private static final String OS_SIDE_DEDICATED_SRIOV_PREFIX = "dedicated-";
53 private static final String COMPUTE_SIDE_SHARED_SRIOV_PREFIX = "sriov-s-";
54 private static final String COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX = "sriov-d-";
56 private HeatBridgeUtils() {
57 throw new IllegalStateException("Trying to instantiate a utility class.");
60 public static Optional<String> getMatchingPserverPifName(@Nonnull final String physicalNetworkName) {
61 Preconditions.checkState(!Strings.isNullOrEmpty(physicalNetworkName),
62 "Physical network name is null or empty!");
63 if (physicalNetworkName.contains(OS_SIDE_DEDICATED_SRIOV_PREFIX)) {
65 physicalNetworkName.replace(OS_SIDE_DEDICATED_SRIOV_PREFIX, COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX));
66 } else if (physicalNetworkName.contains(OS_SIDE_SHARED_SRIOV_PREFIX)) {
68 .of(physicalNetworkName.replace(OS_SIDE_SHARED_SRIOV_PREFIX, COMPUTE_SIDE_SHARED_SRIOV_PREFIX));
70 return Optional.of(physicalNetworkName);
73 public static List<String> extractPciIdsFromVServer(Vserver vserver) {
74 return vserver.getLInterfaces().getLInterface().stream()
75 .filter(lInterface -> lInterface.getSriovVfs() != null
76 && CollectionUtils.isNotEmpty(lInterface.getSriovVfs().getSriovVf()))
77 .flatMap(lInterface -> lInterface.getSriovVfs().getSriovVf().stream()).map(SriovVf::getPciId)
78 .collect(Collectors.toList());