Skip to content

Commit 0f8d639

Browse files
author
Rohit Yadav
committed
Merge pull request #6 from shapeblue/outofbandmanagement-4.5
oobm: Out-of-band Management support in CloudStack
2 parents 7ba881b + a5de271 commit 0f8d639

File tree

78 files changed

+5149
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5149
-47
lines changed

api/src/com/cloud/event/EventTypes.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ public class EventTypes {
310310
// Host
311311
public static final String EVENT_HOST_RECONNECT = "HOST.RECONNECT";
312312

313+
// Host Out-of-band management
314+
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_ENABLEDISABLE = "HOST.OOBM.ENABLEDISABLE";
315+
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_CONFIGURE = "HOST.OOBM.CONFIGURE";
316+
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_ACTION = "HOST.OOBM.ACTION";
317+
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_CHANGE_PASSWORD = "HOST.OOBM.CHANGEPASSWORD";
318+
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_POWERSTATE_TRANSITION = "HOST.OOBM.POWERSTATE.TRANSITION";
319+
313320
// Maintenance
314321
public static final String EVENT_MAINTENANCE_CANCEL = "MAINT.CANCEL";
315322
public static final String EVENT_MAINTENANCE_CANCEL_PRIMARY_STORAGE = "MAINT.CANCEL.PS";
@@ -738,6 +745,13 @@ public class EventTypes {
738745
// Host
739746
entityEventDetails.put(EVENT_HOST_RECONNECT, Host.class);
740747

748+
// Host Out-of-band management
749+
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_ENABLEDISABLE, Host.class);
750+
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_CONFIGURE, Host.class);
751+
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_ACTION, Host.class);
752+
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_CHANGE_PASSWORD, Host.class);
753+
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_POWERSTATE_TRANSITION, Host.class);
754+
741755
// Maintenance
742756
entityEventDetails.put(EVENT_MAINTENANCE_CANCEL, Host.class);
743757
entityEventDetails.put(EVENT_MAINTENANCE_CANCEL_PRIMARY_STORAGE, Host.class);

api/src/com/cloud/resource/ResourceService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.List;
2020

21+
import com.cloud.dc.DataCenter;
2122
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
2223
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
2324
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
@@ -90,6 +91,8 @@ public interface ResourceService {
9091

9192
Cluster getCluster(Long clusterId);
9293

94+
DataCenter getZone(Long zoneId);
95+
9396
List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId);
9497

9598
boolean releaseHostReservation(Long hostId);

api/src/org/apache/cloudstack/alert/AlertService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private AlertType(short type, String name, boolean isDefault) {
6565
public static final AlertType ALERT_TYPE_LOCAL_STORAGE = new AlertType((short)25, "ALERT.STORAGE.LOCAL", true);
6666
public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType((short)26, "ALERT.RESOURCE.EXCEED", true);
6767
public static final AlertType ALERT_TYPE_SYNC = new AlertType((short)27, "ALERT.TYPE.SYNC", true);
68+
public static final AlertType ALERT_TYPE_OOBM_AUTH_ERROR = new AlertType((short)29, "ALERT.OOBM.AUTHERROR", true);
6869

6970
public short getType() {
7071
return type;

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ApiConstants {
2121
public static final String ACCOUNTS = "accounts";
2222
public static final String ACCOUNT_TYPE = "accounttype";
2323
public static final String ACCOUNT_ID = "accountid";
24+
public static final String ADDRESS = "address";
2425
public static final String ALGORITHM = "algorithm";
2526
public static final String ALLOCATED_ONLY = "allocatedonly";
2627
public static final String API_KEY = "apikey";
@@ -75,6 +76,7 @@ public class ApiConstants {
7576
public static final String DEVICE_ID = "deviceid";
7677
public static final String DISK_OFFERING_ID = "diskofferingid";
7778
public static final String DISK_SIZE = "disksize";
79+
public static final String DRIVER = "driver";
7880
public static final String ROOT_DISK_SIZE = "rootdisksize";
7981
public static final String DISPLAY_NAME = "displayname";
8082
public static final String DISPLAY_NETWORK = "displaynetwork";
@@ -176,6 +178,8 @@ public class ApiConstants {
176178
public static final String OS_TYPE_ID = "ostypeid";
177179
public static final String OS_DISPLAY_NAME = "osdisplayname";
178180
public static final String OS_NAME_FOR_HYPERVISOR = "osnameforhypervisor";
181+
public static final String OUTOFBANDMANAGEMENT_POWERSTATE = "outofbandmanagementpowerstate";
182+
public static final String OUTOFBANDMANAGEMENT_ENABLED = "outofbandmanagementenabled";
179183
public static final String PARAMS = "params";
180184
public static final String PARENT_DOMAIN_ID = "parentdomainid";
181185
public static final String PASSWORD = "password";
@@ -191,6 +195,7 @@ public class ApiConstants {
191195
public static final String PORTABLE_IP_ADDRESS = "portableipaddress";
192196
public static final String PORT_FORWARDING_SERVICE_ID = "portforwardingserviceid";
193197
public static final String PARENT = "parent";
198+
public static final String POWER_STATE = "powerstate";
194199
public static final String PRIVATE_INTERFACE = "privateinterface";
195200
public static final String PRIVATE_IP = "privateip";
196201
public static final String PRIVATE_PORT = "privateport";

api/src/org/apache/cloudstack/api/BaseResponse.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,38 @@ public abstract class BaseResponse implements ResponseObject {
2424
private transient String responseName;
2525
private transient String objectName;
2626

27+
@SerializedName(ApiConstants.JOB_ID)
28+
@Param(description = "the UUID of the latest async job acting on this object")
29+
protected String jobId;
30+
31+
@SerializedName(ApiConstants.JOB_STATUS)
32+
@Param(description = "the current status of the latest async job acting on this object")
33+
private Integer jobStatus;
34+
35+
public BaseResponse() {
36+
}
37+
38+
public BaseResponse(final String objectName) {
39+
this.objectName = objectName;
40+
}
41+
2742
@Override
28-
public String getResponseName() {
43+
public final String getResponseName() {
2944
return responseName;
3045
}
3146

3247
@Override
33-
public void setResponseName(String responseName) {
48+
public final void setResponseName(String responseName) {
3449
this.responseName = responseName;
3550
}
3651

3752
@Override
38-
public String getObjectName() {
53+
public final String getObjectName() {
3954
return objectName;
4055
}
4156

4257
@Override
43-
public void setObjectName(String objectName) {
58+
public final void setObjectName(String objectName) {
4459
this.objectName = objectName;
4560
}
4661

@@ -49,14 +64,6 @@ public String getObjectId() {
4964
return null;
5065
}
5166

52-
@SerializedName(ApiConstants.JOB_ID)
53-
@Param(description = "the UUID of the latest async job acting on this object")
54-
protected String jobId;
55-
56-
@SerializedName(ApiConstants.JOB_STATUS)
57-
@Param(description = "the current status of the latest async job acting on this object")
58-
private Integer jobStatus;
59-
6067
@Override
6168
public String getJobId() {
6269
return jobId;

api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ public class ListHostsCmd extends BaseListCmd {
8181
description = "lists hosts in the same cluster as this VM and flag hosts with enough CPU/RAm to host this VM")
8282
private Long virtualMachineId;
8383

84+
@Parameter(name = ApiConstants.OUTOFBANDMANAGEMENT_ENABLED,
85+
type = CommandType.BOOLEAN,
86+
description = "list hosts for which out-of-band management is enabled")
87+
private Boolean outOfBandManagementEnabled;
88+
89+
@Parameter(name = ApiConstants.OUTOFBANDMANAGEMENT_POWERSTATE,
90+
type = CommandType.STRING,
91+
description = "list hosts by its out-of-band management interface's power state. Its value can be one of [On, Off, Unknown]")
92+
private String outOfBandManagementPowerState;
93+
8494
@Parameter(name = ApiConstants.RESOURCE_STATE,
8595
type = CommandType.STRING,
86-
description = "list hosts by resource state. Resource state represents current state determined by admin of host, valule can be one of [Enabled, Disabled, Unmanaged, PrepareForMaintenance, ErrorInMaintenance, Maintenance, Error]")
96+
description = "list hosts by resource state. Resource state represents current state determined by admin of host, value can be one of [Enabled, Disabled, Unmanaged, PrepareForMaintenance, ErrorInMaintenance, Maintenance, Error]")
8797
private String resourceState;
8898

8999
@Parameter(name = ApiConstants.DETAILS,
@@ -165,6 +175,15 @@ public String getResourceState() {
165175
return resourceState;
166176
}
167177

178+
179+
public Boolean isOutOfBandManagementEnabled() {
180+
return outOfBandManagementEnabled;
181+
}
182+
183+
public String getHostOutOfBandManagementPowerState() {
184+
return outOfBandManagementPowerState;
185+
}
186+
168187
/////////////////////////////////////////////////////
169188
/////////////// API Implementation///////////////////
170189
/////////////////////////////////////////////////////
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.outofbandmanagement;
18+
19+
import com.cloud.event.EventTypes;
20+
import com.cloud.exception.ConcurrentOperationException;
21+
import com.cloud.exception.InsufficientCapacityException;
22+
import com.cloud.exception.NetworkRuleConflictException;
23+
import com.cloud.exception.ResourceAllocationException;
24+
import com.cloud.exception.ResourceUnavailableException;
25+
import com.cloud.host.Host;
26+
import com.google.common.base.Strings;
27+
import org.apache.cloudstack.acl.RoleType;
28+
import org.apache.cloudstack.api.APICommand;
29+
import org.apache.cloudstack.api.ApiArgValidator;
30+
import org.apache.cloudstack.api.ApiConstants;
31+
import org.apache.cloudstack.api.ApiErrorCode;
32+
import org.apache.cloudstack.api.BaseAsyncCmd;
33+
import org.apache.cloudstack.api.BaseCmd;
34+
import org.apache.cloudstack.api.Parameter;
35+
import org.apache.cloudstack.api.ServerApiException;
36+
import org.apache.cloudstack.api.response.HostResponse;
37+
import org.apache.cloudstack.api.response.OutOfBandManagementResponse;
38+
import org.apache.cloudstack.context.CallContext;
39+
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService;
40+
41+
import javax.inject.Inject;
42+
43+
@APICommand(name = ChangeOutOfBandManagementPasswordCmd.APINAME, description = "Changes out-of-band management interface password on the host and updates the interface configuration in CloudStack if the operation succeeds, else reverts the old password",
44+
responseObject = OutOfBandManagementResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false,
45+
since = "4.9.0", authorized = {RoleType.Admin})
46+
public class ChangeOutOfBandManagementPasswordCmd extends BaseAsyncCmd {
47+
public static final String APINAME = "changeOutOfBandManagementPassword";
48+
49+
@Inject
50+
private OutOfBandManagementService outOfBandManagementService;
51+
52+
/////////////////////////////////////////////////////
53+
//////////////// API parameters /////////////////////
54+
/////////////////////////////////////////////////////
55+
56+
@Parameter(name = ApiConstants.HOST_ID, type = CommandType.UUID, entityType = HostResponse.class, required = true,
57+
validations = {ApiArgValidator.PositiveNumber}, description = "the ID of the host")
58+
private Long hostId;
59+
60+
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "the new host management interface password of maximum length 16, if none is provided a random password would be used")
61+
private String password;
62+
63+
/////////////////////////////////////////////////////
64+
/////////////// API Implementation///////////////////
65+
/////////////////////////////////////////////////////
66+
67+
@Override
68+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
69+
final Host host = _resourceService.getHost(getHostId());
70+
if (host == null) {
71+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
72+
}
73+
74+
CallContext.current().setEventDetails("Host Id: " + host.getId() + " Password: " + getPassword().charAt(0) + "****");
75+
CallContext.current().putContextParameter(Host.class, host.getUuid());
76+
77+
final OutOfBandManagementResponse response = outOfBandManagementService.changeOutOfBandManagementPassword(host, getPassword());
78+
response.setResponseName(getCommandName());
79+
setResponseObject(response);
80+
}
81+
82+
@Override
83+
public String getCommandName() {
84+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
85+
}
86+
87+
@Override
88+
public long getEntityOwnerId() {
89+
return CallContext.current().getCallingAccountId();
90+
}
91+
92+
public Long getHostId() {
93+
return hostId;
94+
}
95+
96+
public String getPassword() {
97+
if (Strings.isNullOrEmpty(password)) {
98+
password = _mgr.generateRandomPassword();
99+
}
100+
return password;
101+
}
102+
103+
@Override
104+
public String getEventType() {
105+
return EventTypes.EVENT_HOST_OUTOFBAND_MANAGEMENT_CHANGE_PASSWORD;
106+
}
107+
108+
@Override
109+
public String getEventDescription() {
110+
return "change out-of-band management password for host: " + getHostId();
111+
}
112+
}

0 commit comments

Comments
 (0)