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