2 * Copyright (C) 2018 Bell Canada. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
14 package org.onap.so.heatbridge.utils;
16 import com.google.common.base.Preconditions;
17 import com.google.common.base.Strings;
18 import java.util.Optional;
19 import javax.annotation.Nonnull;
21 public class HeatBridgeUtils {
23 private HeatBridgeUtils() {
24 throw new IllegalStateException("Trying to instantiate a utility class.");
28 * IaaS naming convention for compute/p-interface to openstack/physical-network name mapping
30 private static final String OS_SIDE_SHARED_SRIOV_PREFIX = "shared-";
31 private static final String OS_SIDE_DEDICATED_SRIOV_PREFIX = "dedicated-";
32 private static final String COMPUTE_SIDE_SHARED_SRIOV_PREFIX = "sriov-s-";
33 private static final String COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX = "sriov-d-";
35 public static Optional<String> getMatchingPserverPifName(@Nonnull final String physicalNetworkName) {
36 Preconditions.checkState(!Strings.isNullOrEmpty(physicalNetworkName),
37 "Physical network name is null or " + "empty!");
38 if (physicalNetworkName.contains(OS_SIDE_DEDICATED_SRIOV_PREFIX)) {
40 physicalNetworkName.replace(OS_SIDE_DEDICATED_SRIOV_PREFIX, COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX));
41 } else if (physicalNetworkName.contains(OS_SIDE_SHARED_SRIOV_PREFIX)) {
43 .of(physicalNetworkName.replace(OS_SIDE_SHARED_SRIOV_PREFIX, COMPUTE_SIDE_SHARED_SRIOV_PREFIX));
45 return Optional.empty();