Github user jburwell commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1502#discussion_r61789411 --- Diff: plugins/outofbandmanagement-drivers/ipmitool/src/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapper.java --- @@ -0,0 +1,166 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.outofbandmanagement.driver.ipmitool; + +import com.cloud.utils.StringUtils; +import com.cloud.utils.exception.CloudRuntimeException; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement; +import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse; +import org.apache.cloudstack.utils.process.ProcessRunner; +import org.apache.log4j.Logger; + +import java.util.ArrayList; +import java.util.List; + +public class IpmitoolWrapper { + public static final Logger LOG = Logger.getLogger(IpmitoolWrapper.class); + + public static String parsePowerCommand(OutOfBandManagement.PowerOperation operation) { + if (operation == null) { + throw new IllegalStateException("Invalid power operation requested"); + } + switch (operation) { + case ON: + case OFF: + case CYCLE: + case RESET: + case SOFT: + case STATUS: + break; + default: + throw new IllegalStateException("Invalid power operation requested"); + } + return operation.toString().toLowerCase(); + } + + public static OutOfBandManagement.PowerState parsePowerState(final String standardOutput) { + if (Strings.isNullOrEmpty(standardOutput)) { + return OutOfBandManagement.PowerState.Unknown; + } + if (standardOutput.equals("Chassis Power is on")) { + return OutOfBandManagement.PowerState.On; + } else if (standardOutput.equals("Chassis Power is off")) { + return OutOfBandManagement.PowerState.Off; + } + return OutOfBandManagement.PowerState.Unknown; + } + + public static List<String> getIpmiToolCommandArgs(final String ipmiToolPath, final String ipmiInterface, final String retries, + final ImmutableMap<OutOfBandManagement.Option, String> options, String... commands) { + + ImmutableList.Builder<String> ipmiToolCommands = ImmutableList.<String>builder() + .add(ipmiToolPath) + .add("-I") + .add(ipmiInterface) + .add("-R") + .add(retries) + .add("-v"); + + if (options != null) { + for (ImmutableMap.Entry<OutOfBandManagement.Option, String> option : options.entrySet()) { + switch (option.getKey()) { + case ADDRESS: + ipmiToolCommands.add("-H"); + break; + case PORT: + ipmiToolCommands.add("-p"); + break; + case USERNAME: + ipmiToolCommands.add("-U"); + break; + case PASSWORD: + ipmiToolCommands.add("-P"); + break; + default: + continue; + } + ipmiToolCommands.add(option.getValue()); + } + } + for (String command : commands) { + ipmiToolCommands.add(command); + } + return ipmiToolCommands.build(); + } + + public static String findIpmiUser(final String usersList, final String username) { + // Expected usersList string contains legends on first line and users on rest + // ID Name Callin Link Auth IPMI Msg Channel Priv Limit + // 1 admin true true true ADMINISTRATOR --- End diff -- Move this documentation to Javadoc for the method.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---