Skip to content

Commit 81d6631

Browse files
authored
Merge branch 'main' into nasbnr
2 parents bf07a0b + 9bcd988 commit 81d6631

File tree

86 files changed

+4047
-412
lines changed

Some content is hidden

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

86 files changed

+4047
-412
lines changed

api/src/main/java/com/cloud/vm/UserVmService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.cloud.template.VirtualMachineTemplate;
6565
import com.cloud.user.Account;
6666
import com.cloud.uservm.UserVm;
67+
import com.cloud.utils.Pair;
6768
import com.cloud.utils.exception.ExecutionException;
6869

6970
public interface UserVmService {
@@ -538,9 +539,10 @@ UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemp
538539

539540
/**
540541
* Unmanage a guest VM from CloudStack
541-
* @return true if the VM is successfully unmanaged, false if not.
542+
*
543+
* @return (true if successful, false if not, hostUuid) if the VM is successfully unmanaged.
542544
*/
543-
boolean unmanageUserVM(Long vmId);
545+
Pair<Boolean, String> unmanageUserVM(Long vmId, Long targetHostId);
544546

545547
UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws InsufficientCapacityException, ResourceAllocationException, ResourceUnavailableException;
546548

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class ApiConstants {
8181
public static final String BYTES_WRITE_RATE_MAX = "byteswriteratemax";
8282
public static final String BYTES_WRITE_RATE_MAX_LENGTH = "byteswriteratemaxlength";
8383
public static final String BYPASS_VLAN_OVERLAP_CHECK = "bypassvlanoverlapcheck";
84+
public static final String CALLER = "caller";
8485
public static final String CAPACITY = "capacity";
8586
public static final String CATEGORY = "category";
8687
public static final String CAN_REVERT = "canrevert";

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.exception.ResourceUnavailableException;
2828
import com.cloud.user.Account;
2929
import com.cloud.uservm.UserVm;
30+
import com.cloud.utils.Pair;
3031
import com.cloud.vm.VirtualMachine;
3132
import org.apache.cloudstack.acl.RoleType;
3233
import org.apache.cloudstack.api.APICommand;
@@ -36,10 +37,12 @@
3637
import org.apache.cloudstack.api.BaseAsyncCmd;
3738
import org.apache.cloudstack.api.Parameter;
3839
import org.apache.cloudstack.api.ServerApiException;
40+
import org.apache.cloudstack.api.response.HostResponse;
3941
import org.apache.cloudstack.api.response.UnmanageVMInstanceResponse;
4042
import org.apache.cloudstack.api.response.UserVmResponse;
4143
import org.apache.cloudstack.context.CallContext;
4244
import org.apache.cloudstack.vm.UnmanagedVMsManager;
45+
import org.apache.commons.lang3.BooleanUtils;
4346

4447
import javax.inject.Inject;
4548

@@ -65,6 +68,20 @@ public class UnmanageVMInstanceCmd extends BaseAsyncCmd {
6568
description = "The ID of the virtual machine to unmanage")
6669
private Long vmId;
6770

71+
@Parameter(name = ApiConstants.HOST_ID, type = CommandType.UUID,
72+
entityType = HostResponse.class, required = false,
73+
description = "ID of the host which will be used for unmanaging the Instance. " +
74+
"Applicable only for KVM hypervisor and stopped Instances. Domain XML will be stored on this host.",
75+
since = "4.22.0")
76+
private Long hostId;
77+
78+
@Parameter(name = ApiConstants.FORCED,
79+
type = CommandType.BOOLEAN,
80+
required = false,
81+
description = "Force unmanaging Instance with config drive. Applicable only for KVM Hypervisor.",
82+
since = "4.22.0")
83+
private Boolean forced;
84+
6885
/////////////////////////////////////////////////////
6986
/////////////////// Accessors ///////////////////////
7087
/////////////////////////////////////////////////////
@@ -83,6 +100,18 @@ public String getEventDescription() {
83100
return "unmanaging VM. VM ID = " + vmId;
84101
}
85102

103+
public Long getHostId() {
104+
return hostId;
105+
}
106+
107+
public void setHostId(Long hostId) {
108+
this.hostId = hostId;
109+
}
110+
111+
public Boolean isForced() {
112+
return BooleanUtils.isTrue(forced);
113+
}
114+
86115
/////////////////////////////////////////////////////
87116
/////////////// API Implementation///////////////////
88117
/////////////////////////////////////////////////////
@@ -93,9 +122,10 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
93122
UnmanageVMInstanceResponse response = new UnmanageVMInstanceResponse();
94123
try {
95124
CallContext.current().setEventDetails("VM ID = " + vmId);
96-
boolean result = unmanagedVMsManager.unmanageVMInstance(vmId);
97-
response.setSuccess(result);
98-
if (result) {
125+
Pair<Boolean, String> result = unmanagedVMsManager.unmanageVMInstance(vmId, hostId, isForced());
126+
if (result.first()) {
127+
response.setSuccess(true);
128+
response.setHostId(result.second());
99129
response.setDetails("VM unmanaged successfully");
100130
}
101131
} catch (Exception e) {
@@ -124,5 +154,4 @@ public ApiCommandResourceType getApiResourceType() {
124154
public Long getApiResourceId() {
125155
return vmId;
126156
}
127-
128157
}

api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.cloudstack.context.CallContext;
3636
import org.apache.cloudstack.utils.consoleproxy.ConsoleAccessUtils;
3737
import org.apache.commons.collections.MapUtils;
38+
import org.apache.commons.lang3.ObjectUtils;
3839

3940
import javax.inject.Inject;
4041
import java.util.Map;
@@ -86,6 +87,10 @@ private CreateConsoleEndpointResponse createResponse(ConsoleEndpoint endpoint) {
8687
}
8788

8889
private ConsoleEndpointWebsocketResponse createWebsocketResponse(ConsoleEndpoint endpoint) {
90+
if (ObjectUtils.allNull(endpoint.getWebsocketHost(), endpoint.getWebsocketPort(), endpoint.getWebsocketPath(),
91+
endpoint.getWebsocketToken(), endpoint.getWebsocketExtra())) {
92+
return null;
93+
}
8994
ConsoleEndpointWebsocketResponse wsResponse = new ConsoleEndpointWebsocketResponse();
9095
wsResponse.setHost(endpoint.getWebsocketHost());
9196
wsResponse.setPort(endpoint.getWebsocketPort());

api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ public void setNetworkAvailable(String networkAvailable) {
569569

570570
@Override
571571
public void setVpcLimit(String vpcLimit) {
572-
this.vpcLimit = networkLimit;
572+
this.vpcLimit = vpcLimit;
573573
}
574574

575575
@Override

api/src/main/java/org/apache/cloudstack/api/response/UnmanageVMInstanceResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class UnmanageVMInstanceResponse extends BaseResponse {
3232
@Param(description = "details of the unmanage VM operation")
3333
private String details;
3434

35+
@SerializedName(ApiConstants.HOST_ID)
36+
@Param(description = "The ID of the host used for unmanaged Instance")
37+
private String hostId;
38+
3539
public UnmanageVMInstanceResponse() {
3640
}
3741

@@ -55,4 +59,12 @@ public String getDetails() {
5559
public void setDetails(String details) {
5660
this.details = details;
5761
}
62+
63+
public String getHostId() {
64+
return hostId;
65+
}
66+
67+
public void setHostId(String hostId) {
68+
this.hostId = hostId;
69+
}
5870
}

api/src/main/java/org/apache/cloudstack/backup/BackupManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
5555
ConfigKey<String> BackupProviderPlugin = new ConfigKey<>("Advanced", String.class,
5656
"backup.framework.provider.plugin",
5757
"dummy",
58-
"The backup and recovery provider plugin.", true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key());
58+
"The backup and recovery provider plugin. Valid plugin values: dummy, veeam, networker and nas", true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key());
5959

6060
ConfigKey<Long> BackupSyncPollingInterval = new ConfigKey<>("Advanced", Long.class,
6161
"backup.framework.sync.interval",

api/src/main/java/org/apache/cloudstack/vm/UnmanageVMService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
package org.apache.cloudstack.vm;
1919

20+
import com.cloud.utils.Pair;
21+
2022
public interface UnmanageVMService {
2123

2224
/**
2325
* Unmanage a guest VM from CloudStack
24-
* @return true if the VM is successfully unmanaged, false if not.
26+
*
27+
* @return (true if successful, false if not, hostUuid) if the VM is successfully unmanaged.
2528
*/
26-
boolean unmanageVMInstance(long vmId);
29+
Pair<Boolean, String> unmanageVMInstance(long vmId, Long paramHostId, boolean isForced);
2730
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
18+
package com.cloud.agent.api;
19+
20+
public class GetExternalConsoleAnswer extends Answer {
21+
22+
private String url;
23+
private String host;
24+
private Integer port;
25+
@LogLevel(LogLevel.Log4jLevel.Off)
26+
private String password;
27+
private String protocol;
28+
private boolean passwordOneTimeUseOnly;
29+
30+
public GetExternalConsoleAnswer(Command command, String details) {
31+
super(command, false, details);
32+
}
33+
34+
public GetExternalConsoleAnswer(Command command, String url, String host, Integer port, String password,
35+
boolean passwordOneTimeUseOnly, String protocol) {
36+
super(command, true, "");
37+
this.url = url;
38+
this.host = host;
39+
this.port = port;
40+
this.password = password;
41+
this.passwordOneTimeUseOnly = passwordOneTimeUseOnly;
42+
this.protocol = protocol;
43+
}
44+
45+
public String getUrl() {
46+
return url;
47+
}
48+
49+
public String getHost() {
50+
return host;
51+
}
52+
53+
public Integer getPort() {
54+
return port;
55+
}
56+
57+
public String getPassword() {
58+
return password;
59+
}
60+
61+
public String getProtocol() {
62+
return protocol;
63+
}
64+
65+
public boolean isPasswordOneTimeUseOnly() {
66+
return passwordOneTimeUseOnly;
67+
}
68+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
18+
package com.cloud.agent.api;
19+
20+
import com.cloud.agent.api.to.VirtualMachineTO;
21+
22+
public class GetExternalConsoleCommand extends Command {
23+
String vmName;
24+
VirtualMachineTO vm;
25+
protected boolean executeInSequence;
26+
27+
public GetExternalConsoleCommand(String vmName, VirtualMachineTO vm) {
28+
this.vmName = vmName;
29+
this.vm = vm;
30+
this.executeInSequence = false;
31+
}
32+
33+
public String getVmName() {
34+
return this.vmName;
35+
}
36+
37+
public void setVirtualMachine(VirtualMachineTO vm) {
38+
this.vm = vm;
39+
}
40+
41+
public VirtualMachineTO getVirtualMachine() {
42+
return vm;
43+
}
44+
45+
@Override
46+
public boolean executeInSequence() {
47+
return executeInSequence;
48+
}
49+
50+
public void setExecuteInSequence(boolean executeInSequence) {
51+
this.executeInSequence = executeInSequence;
52+
}
53+
}

0 commit comments

Comments
 (0)