Skip to content

Commit 4af5fa6

Browse files
author
SadiJr
committed
Merge branch 'backport-create-vm-from-backup' into '4.20.0.0-scclouds'
Criação de VM a partir de _backup_ Closes #3045 See merge request scclouds/scclouds!1308
2 parents cf65a29 + 22713b4 commit 4af5fa6

97 files changed

Lines changed: 8024 additions & 1424 deletions

File tree

Some content is hidden

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ public class EventTypes {
613613
public static final String EVENT_VM_BACKUP_SCHEDULE_DELETE = "BACKUP.SCHEDULE.DELETE";
614614
public static final String EVENT_VM_BACKUP_USAGE_METRIC = "BACKUP.USAGE.METRIC";
615615
public static final String EVENT_VM_BACKUP_EDIT = "BACKUP.OFFERING.EDIT";
616+
public static final String EVENT_VM_CREATE_FROM_BACKUP = "VM.CREATE.FROM.BACKUP";
616617

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,9 @@ Network createPrivateNetwork(String networkName, String displayText, long physic
268268
InternalLoadBalancerElementService getInternalLoadBalancerElementByNetworkServiceProviderId(long networkProviderId);
269269
InternalLoadBalancerElementService getInternalLoadBalancerElementById(long providerId);
270270
List<InternalLoadBalancerElementService> getInternalLoadBalancerElements();
271+
272+
/**
273+
* Validate given addresses and return a Network.IpAddresses object.
274+
* */
275+
IpAddresses getIpAddressesFromIps(String ipAddress, String ip6Address, String macAddress);
271276
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public class DiskOfferingInfo {
2727
public DiskOfferingInfo() {
2828
}
2929

30+
31+
public DiskOfferingInfo(DiskOffering diskOffering, Long size, Long minIops, Long maxIops) {
32+
_diskOffering = diskOffering;
33+
_size = size;
34+
_minIops = minIops;
35+
_maxIops = maxIops;
36+
}
37+
3038
public DiskOfferingInfo(DiskOffering diskOffering) {
3139
_diskOffering = diskOffering;
3240
}

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

Lines changed: 123 additions & 117 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public static StateMachine2<State, VirtualMachine.Event, VirtualMachine> getStat
131131
s_fsm.addTransition(new Transition<State, Event>(State.Error, VirtualMachine.Event.DestroyRequested, State.Expunging, null));
132132
s_fsm.addTransition(new Transition<State, Event>(State.Error, VirtualMachine.Event.ExpungeOperation, State.Expunging, null));
133133
s_fsm.addTransition(new Transition<State, Event>(State.Stopped, Event.RestoringRequested, State.Restoring, null));
134-
s_fsm.addTransition(new Transition<State, Event>(State.Expunging, Event.RestoringRequested, State.Restoring, null));
135134
s_fsm.addTransition(new Transition<State, Event>(State.Destroyed, Event.RestoringRequested, State.Restoring, null));
136135
s_fsm.addTransition(new Transition<State, Event>(State.Restoring, Event.RestoringSuccess, State.Stopped, null));
137136
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+
this.deviceId = deviceId;
34+
}
35+
36+
public Long getDeviceId() {
37+
return deviceId;
38+
}
39+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ApiConstants {
3030
public static final String ACTIVITY = "activity";
3131
public static final String ADAPTER_TYPE = "adaptertype";
3232
public static final String ADDRESS = "address";
33+
public static final String ALLOCATED = "allocated";
3334
public static final String ALGORITHM = "algorithm";
3435
public static final String ALIAS = "alias";
3536
public static final String ALLOCATED_DATE = "allocateddate";
@@ -307,6 +308,7 @@ public class ApiConstants {
307308
public static final String EGRESS_DEFAULT_POLICY = "egressdefaultpolicy";
308309
public static final String IS_READY = "isready";
309310
public static final String IS_RECURSIVE = "isrecursive";
311+
public static final String IS_ISO = "isiso";
310312
public static final String ISO_FILTER = "isofilter";
311313
public static final String ISO_ID = "isoid";
312314
public static final String ISO_GUEST_OS_NONE = "None";
@@ -1287,6 +1289,17 @@ public class ApiConstants {
12871289
public static final String ALLOW_QUICK_RESTORE = "allowquickrestore";
12881290

12891291
public static final String ALLOW_EXTRACT_FILE = "allowextractfile";
1292+
public static final String BACKUP_VM_OFFERING_REMOVED = "vmbackupofferingremoved";
1293+
public static final String DATADISKS_DETAILS = "datadisksdetails";
1294+
public static final String DEVICE_IDS = "deviceids";
1295+
public static final String IP6_ADDRESSES = "ip6addresses";
1296+
public static final String MAC_ADDRESSES = "macaddresses";
1297+
public static final String NICS = "nics";
1298+
public static final String PRESERVE_IP = "preserveip";
1299+
public static final String USED = "used";
1300+
public static final String VM_DETAILS = "vmdetails";
1301+
public static final String VM_SETTINGS = "vmsettings";
1302+
public static final String LIST_VM_DETAILS = "listvmdetails";
12901303

12911304
public static final String BACKUP_CHAIN_SIZE = "backupchainsize";
12921305

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
4949
import org.apache.cloudstack.api.response.BackupOfferingResponse;
5050
import org.apache.cloudstack.api.response.BackupRepositoryResponse;
51-
import org.apache.cloudstack.api.response.BackupResponse;
5251
import org.apache.cloudstack.api.response.BackupScheduleResponse;
5352
import org.apache.cloudstack.api.response.BaseRolePermissionResponse;
5453
import org.apache.cloudstack.api.response.BucketResponse;
@@ -153,7 +152,6 @@
153152
import org.apache.cloudstack.api.response.VpcResponse;
154153
import org.apache.cloudstack.api.response.VpnUsersResponse;
155154
import org.apache.cloudstack.api.response.ZoneResponse;
156-
import org.apache.cloudstack.backup.Backup;
157155
import org.apache.cloudstack.backup.BackupOffering;
158156
import org.apache.cloudstack.backup.BackupRepository;
159157
import org.apache.cloudstack.backup.BackupSchedule;
@@ -535,8 +533,6 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
535533

536534
UserDataResponse createUserDataResponse(UserData userData);
537535

538-
BackupResponse createBackupResponse(Backup backup);
539-
540536
BackupScheduleResponse createBackupScheduleResponse(BackupSchedule backup);
541537

542538
BackupOfferingResponse createBackupOfferingResponse(BackupOffering policy);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.vm;
18+
19+
import org.apache.cloudstack.acl.RoleType;
20+
import org.apache.cloudstack.api.APICommand;
21+
import org.apache.cloudstack.api.ApiConstants;
22+
import org.apache.cloudstack.api.Parameter;
23+
import org.apache.cloudstack.api.ResponseObject;
24+
import org.apache.cloudstack.api.command.admin.AdminCmd;
25+
import org.apache.cloudstack.api.command.user.vm.CreateVMFromBackupCmd;
26+
import org.apache.cloudstack.api.response.ClusterResponse;
27+
import org.apache.cloudstack.api.response.PodResponse;
28+
import org.apache.cloudstack.api.response.UserVmResponse;
29+
30+
import com.cloud.vm.VirtualMachine;
31+
32+
@APICommand(name = "createVMFromBackup",
33+
description = "Creates and automatically starts a VM from a backup.",
34+
responseObject = UserVmResponse.class,
35+
responseView = ResponseObject.ResponseView.Full,
36+
entityType = {VirtualMachine.class},
37+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true,
38+
since = "4.20.0.6-scclouds",
39+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
40+
public class CreateVMFromBackupCmdByAdmin extends CreateVMFromBackupCmd implements AdminCmd {
41+
42+
@Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, description = "destination Pod ID to deploy the VM to - parameter available for root admin only", since = "4.20.0.6-scclouds")
43+
private Long podId;
44+
45+
@Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class, description = "destination Cluster ID to deploy the VM to - parameter available for root admin only", since = "4.20.0.6-scclouds")
46+
private Long clusterId;
47+
48+
public Long getPodId() {
49+
return podId;
50+
}
51+
52+
public Long getClusterId() {
53+
return clusterId;
54+
}
55+
}

api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupCmd.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public class CreateBackupCmd extends BaseAsyncCreateCmd {
6161
description = "ID of the VM")
6262
private Long vmId;
6363

64+
@Parameter(name = ApiConstants.NAME,
65+
type = CommandType.STRING,
66+
description = "the name of the backup")
67+
private String name;
68+
69+
@Parameter(name = ApiConstants.DESCRIPTION,
70+
type = CommandType.STRING,
71+
description = "the description for the backup")
72+
private String description;
73+
6474
@Parameter(name = ApiConstants.VM_SNAPSHOT_QUIESCEVM,
6575
type = CommandType.BOOLEAN,
6676
required = false,
@@ -81,18 +91,30 @@ public Long getVmId() {
8191
return vmId;
8292
}
8393

94+
public String getName() {
95+
return name;
96+
}
97+
98+
public String getDescription() {
99+
return description;
100+
}
101+
84102
public boolean isQuiesceVm() {
85103
return quiesceVm;
86104
}
87105

106+
public boolean isIsolated() {
107+
return isolated;
108+
}
109+
88110
/////////////////////////////////////////////////////
89111
/////////////// API Implementation///////////////////
90112
/////////////////////////////////////////////////////
91113

92114
@Override
93115
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
94116
try {
95-
boolean result = backupManager.createBackup(getVmId(), quiesceVm, isolated, getJob());
117+
boolean result = backupManager.createBackup(this, getJob());
96118
if (result) {
97119
SuccessResponse response = new SuccessResponse(getCommandName());
98120
response.setResponseName(getCommandName());

0 commit comments

Comments
 (0)