Skip to content

Commit f0dc5de

Browse files
abh1sardhslove
authored andcommitted
Create new Instance from VM backup (apache#10140)
This feature adds the ability to create a new instance from a VM backup for dummy, NAS and Veeam backup providers. It works even if the original instance used to create the backup was expunged or unmanaged. There are two parts to this functionality: Saving all configuration details that the VM had at the time of taking the backup. And using them to create an instance from backup. Enabling a user to expunge/unmanage an instance that has backups.
1 parent 36b3c94 commit f0dc5de

File tree

141 files changed

+10876
-1808
lines changed

Some content is hidden

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

141 files changed

+10876
-1808
lines changed

api/src/main/java/com/cloud/capacity/Capacity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ public interface Capacity extends InternalIdentity, Identity {
3636
public static final short CAPACITY_TYPE_MANAGEMENT_DATABASE_STORAGE = 30;
3737
public static final short CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = 10;
3838
public static final short CAPACITY_TYPE_GPU = 19;
39+
public static final short CAPACITY_TYPE_OBJECT_STORAGE = 20;
40+
public static final short CAPACITY_TYPE_BACKUP_STORAGE = 21;
3941

4042
public static final short CAPACITY_TYPE_CPU_CORE = 90;
4143

4244
public static final List<Short> STORAGE_CAPACITY_TYPES = List.of(CAPACITY_TYPE_STORAGE,
4345
CAPACITY_TYPE_STORAGE_ALLOCATED,
4446
CAPACITY_TYPE_SECONDARY_STORAGE,
45-
CAPACITY_TYPE_LOCAL_STORAGE);
47+
CAPACITY_TYPE_LOCAL_STORAGE,
48+
CAPACITY_TYPE_BACKUP_STORAGE,
49+
CAPACITY_TYPE_OBJECT_STORAGE);
4650

4751
public Long getHostOrPoolId();
4852

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,13 @@ public class EventTypes {
637637
public static final String EVENT_VM_BACKUP_CREATE = "BACKUP.CREATE";
638638
public static final String EVENT_VM_BACKUP_RESTORE = "BACKUP.RESTORE";
639639
public static final String EVENT_VM_BACKUP_DELETE = "BACKUP.DELETE";
640+
public static final String EVENT_VM_BACKUP_OFFERING_REMOVED_AND_BACKUPS_DELETED = "BACKUP.OFFERING.BACKUPS.DEL";
640641
public static final String EVENT_VM_BACKUP_RESTORE_VOLUME_TO_VM = "BACKUP.RESTORE.VOLUME.TO.VM";
641642
public static final String EVENT_VM_BACKUP_SCHEDULE_CONFIGURE = "BACKUP.SCHEDULE.CONFIGURE";
642643
public static final String EVENT_VM_BACKUP_SCHEDULE_DELETE = "BACKUP.SCHEDULE.DELETE";
643644
public static final String EVENT_VM_BACKUP_USAGE_METRIC = "BACKUP.USAGE.METRIC";
644645
public static final String EVENT_VM_BACKUP_EDIT = "BACKUP.OFFERING.EDIT";
646+
public static final String EVENT_VM_CREATE_FROM_BACKUP = "VM.CREATE.FROM.BACKUP";
645647

646648
// external network device events
647649
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_ADD = "PHYSICAL.NVPCONTROLLER.ADD";

api/src/main/java/com/cloud/network/NetworkService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,7 @@ Network createPrivateNetwork(String networkName, String displayText, long physic
272272

273273
boolean handleCksIsoOnNetworkVirtualRouter(Long virtualRouterId, boolean mount) throws ResourceUnavailableException;
274274

275+
IpAddresses getIpAddressesFromIps(String ipAddress, String ip6Address, String macAddress);
276+
275277
String getNicVlanValueForExternalVm(NicTO nic);
276278
}

api/src/main/java/com/cloud/offering/DiskOfferingInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public DiskOfferingInfo(DiskOffering diskOffering) {
3131
_diskOffering = diskOffering;
3232
}
3333

34+
public DiskOfferingInfo(DiskOffering diskOffering, Long size, Long minIops, Long maxIops) {
35+
_diskOffering = diskOffering;
36+
_size = size;
37+
_minIops = minIops;
38+
_maxIops = maxIops;
39+
}
40+
3441
public void setDiskOffering(DiskOffering diskOffering) {
3542
_diskOffering = diskOffering;
3643
}

api/src/main/java/com/cloud/storage/StorageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public interface StorageService {
134134

135135
void removeSecondaryStorageHeuristic(RemoveSecondaryStorageSelectorCmd cmd);
136136

137-
ObjectStore discoverObjectStore(String name, String url, String providerName, Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
137+
ObjectStore discoverObjectStore(String name, String url, Long size, String providerName, Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
138138

139139
boolean deleteObjectStore(DeleteObjectStoragePoolCmd cmd);
140140

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.api.command.user.vm.AllocateVbmcToVMCmd;
3131
import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
3232
import org.apache.cloudstack.api.command.user.vm.CloneVMCmd;
33+
import org.apache.cloudstack.api.command.user.vm.CreateVMFromBackupCmd;
3334
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
3435
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
3536
import org.apache.cloudstack.api.command.user.vm.DeployVMVolumeCmd;
@@ -238,7 +239,7 @@ void startVirtualMachineForHA(VirtualMachine vm, Map<VirtualMachineProfile.Param
238239
* available.
239240
*/
240241
UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList,
241-
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod,
242+
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, List<VmDiskInfo> dataDiskInfoList, String group, HypervisorType hypervisor, HTTPMethod httpmethod,
242243
String userData, Long userDataId, String userDataDetails, List<String> sshKeyPairs, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp, Boolean displayVm, String keyboard,
243244
List<Long> affinityGroupIdList, Map<String, String> customParameter, String customId, Map<String, Map<Integer, String>> dhcpOptionMap,
244245
Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap,
@@ -315,7 +316,7 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
315316
* available.
316317
*/
317318
UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
318-
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
319+
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, List<VmDiskInfo> dataDiskInfoList, String group, HypervisorType hypervisor,
319320
HTTPMethod httpmethod, String userData, Long userDataId, String userDataDetails, List<String> sshKeyPairs, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard,
320321
List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId, Map<String, Map<Integer, String>> dhcpOptionMap,
321322
Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, Map<String, String> userVmOVFProperties, boolean dynamicScalingEnabled, Long overrideDiskOfferingId, String vmType, Volume volume, Snapshot snapshot) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
@@ -387,7 +388,7 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
387388
* available.
388389
*/
389390
UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner,
390-
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData,
391+
String hostName, String displayName, Long diskOfferingId, Long diskSize, List<VmDiskInfo> dataDiskInfoList, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData,
391392
Long userDataId, String userDataDetails, List<String> sshKeyPairs, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList,
392393
Map<String, String> customParameters, String customId, Map<String, Map<Integer, String>> dhcpOptionMap, Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap,
393394
Map<String, String> templateOvfPropertiesMap, boolean dynamicScalingEnabled, String vmType, Long overrideDiskOfferingId, Volume volume, Snapshot snapshot)
@@ -544,4 +545,8 @@ UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemp
544545
UserVm removeVbmcToVM(RemoveVbmcToVMCmd cmd);
545546

546547
UserVm updateVmNicLinkState(UpdateVmNicLinkStateCmd cmd);
548+
549+
UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws InsufficientCapacityException, ResourceAllocationException, ResourceUnavailableException;
550+
551+
UserVm restoreVMFromBackup(CreateVMFromBackupCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException;
547552
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public static StateMachine2<State, VirtualMachine.Event, VirtualMachine> getStat
128128
s_fsm.addTransition(new Transition<State, Event>(State.Error, VirtualMachine.Event.DestroyRequested, State.Expunging, null));
129129
s_fsm.addTransition(new Transition<State, Event>(State.Error, VirtualMachine.Event.ExpungeOperation, State.Expunging, null));
130130
s_fsm.addTransition(new Transition<State, Event>(State.Stopped, Event.RestoringRequested, State.Restoring, null));
131-
s_fsm.addTransition(new Transition<State, Event>(State.Expunging, Event.RestoringRequested, State.Restoring, null));
132131
s_fsm.addTransition(new Transition<State, Event>(State.Destroyed, Event.RestoringRequested, State.Restoring, null));
133132
s_fsm.addTransition(new Transition<State, Event>(State.Restoring, Event.RestoringSuccess, State.Stopped, null));
134133
s_fsm.addTransition(new Transition<State, Event>(State.Restoring, Event.RestoringFailed, State.Stopped, null));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.vm;
20+
21+
import com.cloud.offering.DiskOffering;
22+
import com.cloud.offering.DiskOfferingInfo;
23+
24+
public class VmDiskInfo extends DiskOfferingInfo {
25+
private Long _deviceId;
26+
27+
public VmDiskInfo(DiskOffering diskOffering, Long size, Long minIops, Long maxIops) {
28+
super(diskOffering, size, minIops, maxIops);
29+
}
30+
31+
public VmDiskInfo(DiskOffering diskOffering, Long size, Long minIops, Long maxIops, Long deviceId) {
32+
super(diskOffering, size, minIops, maxIops);
33+
_deviceId = deviceId;
34+
}
35+
36+
public Long getDeviceId() {
37+
return _deviceId;
38+
}
39+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ private AlertType(short type, String name, boolean isDefault) {
7676
public static final AlertType EVENT_USER_SESSION_BLOCK = new AlertType((short)33, "USER.SESSION.BLOCK", true);
7777
public static final AlertType ALERT_TYPE_LOGIN = new AlertType((short)32, "ALERT.LOGIN", true);
7878
public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType((short)33, "ALERT.TYPE.EXTENSION.PATH.NOT.READY", true);
79+
public static final AlertType ALERT_TYPE_BACKUP_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_BACKUP_STORAGE, "ALERT.STORAGE.BACKUP", true);
80+
public static final AlertType ALERT_TYPE_OBJECT_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_OBJECT_STORAGE, "ALERT.STORAGE.OBJECT", true);
7981

8082
public short getType() {
8183
return type;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ApiConstants {
2929
public static final String ADDRESS = "address";
3030
public static final String ALGORITHM = "algorithm";
3131
public static final String ALIAS = "alias";
32+
public static final String ALLOCATED = "allocated";
3233
public static final String ALLOCATED_DATE = "allocateddate";
3334
public static final String ALLOCATED_ONLY = "allocatedonly";
3435
public static final String ALLOCATED_TIME = "allocated";
@@ -60,6 +61,7 @@ public class ApiConstants {
6061
public static final String BACKUP_STORAGE_AVAILABLE = "backupstorageavailable";
6162
public static final String BACKUP_STORAGE_LIMIT = "backupstoragelimit";
6263
public static final String BACKUP_STORAGE_TOTAL = "backupstoragetotal";
64+
public static final String BACKUP_VM_OFFERING_REMOVED = "vmbackupofferingremoved";
6365
public static final String BACKUP_TOTAL = "backuptotal";
6466
public static final String BASE64_IMAGE = "base64image";
6567
public static final String BGP_PEERS = "bgppeers";
@@ -160,6 +162,7 @@ public class ApiConstants {
160162
public static final String MAX_IOPS = "maxiops";
161163
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";
162164
public static final String DATACENTER_NAME = "datacentername";
165+
public static final String DATADISKS_DETAILS = "datadisksdetails";
163166
public static final String DATADISK_OFFERING_LIST = "datadiskofferinglist";
164167
public static final String DEFAULT_VALUE = "defaultvalue";
165168
public static final String DELETE_PROTECTION = "deleteprotection";
@@ -168,6 +171,7 @@ public class ApiConstants {
168171
public static final String DESTINATION_ZONE_ID = "destzoneid";
169172
public static final String DETAILS = "details";
170173
public static final String DEVICE_ID = "deviceid";
174+
public static final String DEVICE_IDS = "deviceids";
171175
public static final String DEVICE_NAME = "devicename";
172176
public static final String DIRECT_DOWNLOAD = "directdownload";
173177
public static final String DISK = "disk";
@@ -311,6 +315,7 @@ public class ApiConstants {
311315
public static final String IP_ADDRESS = "ipaddress";
312316
public static final String IP_ADDRESSES = "ipaddresses";
313317
public static final String IP6_ADDRESS = "ip6address";
318+
public static final String IP6_ADDRESSES = "ip6addresses";
314319
public static final String IP_ADDRESS_ID = "ipaddressid";
315320
public static final String IS_2FA_ENABLED = "is2faenabled";
316321
public static final String IS_2FA_VERIFIED = "is2faverified";
@@ -363,6 +368,7 @@ public class ApiConstants {
363368
public static final String LBID = "lbruleid";
364369
public static final String LB_PROVIDER = "lbprovider";
365370
public static final String MAC_ADDRESS = "macaddress";
371+
public static final String MAC_ADDRESSES = "macaddresses";
366372
public static final String MANUAL_UPGRADE = "manualupgrade";
367373
public static final String MAX = "max";
368374
public static final String MAX_SNAPS = "maxsnaps";
@@ -390,6 +396,7 @@ public class ApiConstants {
390396
public static final String NETMASK = "netmask";
391397
public static final String NEW_NAME = "newname";
392398
public static final String NIC = "nic";
399+
public static final String NICS = "nics";
393400
public static final String NIC_NETWORK_LIST = "nicnetworklist";
394401
public static final String NIC_IP_ADDRESS_LIST = "nicipaddresslist";
395402
public static final String NIC_MULTIQUEUE_NUMBER = "nicmultiqueuenumber";
@@ -466,6 +473,7 @@ public class ApiConstants {
466473
public static final String POWER_STATE = "powerstate";
467474
public static final String PRECEDENCE = "precedence";
468475
public static final String PREPARE_VM = "preparevm";
476+
public static final String PRESERVE_IP = "preserveip";
469477
public static final String PRIVATE_INTERFACE = "privateinterface";
470478
public static final String PRIVATE_IP = "privateip";
471479
public static final String PRIVATE_PORT = "privateport";
@@ -501,6 +509,7 @@ public class ApiConstants {
501509
public static final String REGISTERED = "registered";
502510
public static final String QUALIFIERS = "qualifiers";
503511
public static final String QUERY_FILTER = "queryfilter";
512+
public static final String QUIESCE_VM = "quiescevm";
504513
public static final String SCHEDULE = "schedule";
505514
public static final String SCHEDULE_ID = "scheduleid";
506515
public static final String SCOPE = "scope";
@@ -516,6 +525,7 @@ public class ApiConstants {
516525
public static final String SERIAL = "serial";
517526
public static final String SERVICE_IP = "serviceip";
518527
public static final String SERVICE_OFFERING_ID = "serviceofferingid";
528+
public static final String SERVICE_OFFERING_NAME = "serviceofferingname";
519529
public static final String SESSIONKEY = "sessionkey";
520530
public static final String SHOW_CAPACITIES = "showcapacities";
521531
public static final String SHOW_REMOVED = "showremoved";
@@ -583,6 +593,7 @@ public class ApiConstants {
583593
public static final String TRUST_STORE_PASSWORD = "truststorepass";
584594
public static final String URL = "url";
585595
public static final String USAGE_INTERFACE = "usageinterface";
596+
public static final String USED = "used";
586597
public static final String USED_SUBNETS = "usedsubnets";
587598
public static final String USED_IOPS = "usediops";
588599
public static final String USER_DATA = "userdata";
@@ -641,8 +652,10 @@ public class ApiConstants {
641652
public static final String IS_DEDICATED = "isdedicated";
642653
public static final String TAKEN = "taken";
643654
public static final String VM_AVAILABLE = "vmavailable";
655+
public static final String VM_DETAILS = "vmdetails";
644656
public static final String VM_LIMIT = "vmlimit";
645657
public static final String VM_TOTAL = "vmtotal";
658+
public static final String VM_SETTINGS = "vmsettings";
646659
public static final String VM_TYPE = "vmtype";
647660
public static final String VNET = "vnet";
648661
public static final String IS_VOLATILE = "isvolatile";
@@ -824,6 +837,7 @@ public class ApiConstants {
824837
public static final String LIST_ALL = "listall";
825838
public static final String LIST_ONLY_REMOVED = "listonlyremoved";
826839
public static final String LIST_SYSTEM_VMS = "listsystemvms";
840+
public static final String LIST_VM_DETAILS = "listvmdetails";
827841
public static final String IP_RANGES = "ipranges";
828842
public static final String IPV4_ROUTING = "ip4routing";
829843
public static final String IPV4_ROUTES = "ip4routes";

0 commit comments

Comments
 (0)