Skip to content

Commit 81565c2

Browse files
authored
Merge pull request #499 from jeongda-young/ablestack-diplo
Glue이미지(Root Volume)을 이용한 가상머신 생성 기능
2 parents d42e5c5 + 71ea894 commit 81565c2

File tree

19 files changed

+1519
-94
lines changed

19 files changed

+1519
-94
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.cloudstack.api.command.user.vm.CloneVMCmd;
3030
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
3131
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
32+
import org.apache.cloudstack.api.command.user.vm.DeployVMVolumeCmd;
3233
import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
3334
import org.apache.cloudstack.api.command.user.vm.RemoveNicFromVMCmd;
3435
import org.apache.cloudstack.api.command.user.vm.RemoveVbmcToVMCmd;
@@ -402,6 +403,7 @@ UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffe
402403
* if the resources required the deploy the VM is not currently available.
403404
*/
404405
UserVm startVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException;
406+
UserVm startVirtualMachineVolume(DeployVMVolumeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException;
405407

406408
/**
407409
* Creates a vm group.
@@ -431,6 +433,9 @@ UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffe
431433
UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException,
432434
StorageUnavailableException, ResourceAllocationException;
433435

436+
UserVm createVirtualMachineVolume(DeployVMVolumeCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException,
437+
StorageUnavailableException, ResourceAllocationException;
438+
434439
UserVm recordVirtualMachineToDB(CloneVMCmd cmd, long templateId) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException,
435440
StorageUnavailableException, ResourceAllocationException;
436441
/**
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.api.ApiConstants;
20+
import org.apache.cloudstack.api.Parameter;
21+
import org.apache.cloudstack.api.response.ClusterResponse;
22+
import org.apache.cloudstack.api.response.PodResponse;
23+
24+
import org.apache.cloudstack.api.APICommand;
25+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
26+
import org.apache.cloudstack.api.command.admin.AdminCmd;
27+
import org.apache.cloudstack.api.command.user.vm.DeployVMVolumeCmd;
28+
import org.apache.cloudstack.api.response.UserVmResponse;
29+
30+
import com.cloud.vm.VirtualMachine;
31+
32+
33+
@APICommand(name = "deployVirtualMachineForVolume", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
34+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
35+
public class DeployVMVolumeCmdByAdmin extends DeployVMVolumeCmd implements AdminCmd {
36+
37+
38+
@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.13")
39+
private Long podId;
40+
41+
@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.13")
42+
private Long clusterId;
43+
44+
public Long getPodId() {
45+
return podId;
46+
}
47+
48+
public Long getClusterId() {
49+
return clusterId;
50+
}
51+
}

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMVolumeCmd.java

Lines changed: 865 additions & 0 deletions
Large diffs are not rendered by default.

engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ interface Topics {
112112
*/
113113
void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, DiskOfferingInfo rootDiskOfferingInfo,
114114
List<DiskOfferingInfo> dataDiskOfferings, LinkedHashMap<? extends Network, List<? extends NicProfile>> auxiliaryNetworks, DeploymentPlan plan,
115-
HypervisorType hyperType, Map<String, Map<Integer, String>> extraDhcpOptions, Map<Long, DiskOffering> datadiskTemplateToDiskOfferingMap) throws InsufficientCapacityException;
115+
HypervisorType hyperType, Map<String, Map<Integer, String>> extraDhcpOptions, Map<Long, DiskOffering> datadiskTemplateToDiskOfferingMap, Map<String, String> customParameters) throws InsufficientCapacityException;
116116

117117
void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering,
118118
LinkedHashMap<? extends Network, List<? extends NicProfile>> networkProfiles, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException;

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId,
109109
DiskProfile allocateRawVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
110110
Account owner, Long deviceId);
111111

112+
DiskProfile allocateRawVolumes(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
113+
Account owner, Long deviceId, Map<String, String> customParameters);
114+
112115
VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm, VolumeInfo volume, HypervisorType rootDiskHyperType, StoragePool storagePool) throws NoTransitionException;
113116

114117
void release(VirtualMachineProfile profile);
@@ -179,4 +182,4 @@ DiskProfile updateImportedVolume(Type type, DiskOffering offering, VirtualMachin
179182
* Unmanage VM volumes
180183
*/
181184
void unmanageVolumes(long vmId);
182-
}
185+
}

engine/api/src/main/java/org/apache/cloudstack/engine/service/api/OrchestrationService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public interface OrchestrationService {
6363
@Path("/createvm")
6464
VirtualMachineEntity createVirtualMachine(@QueryParam("id") String id, @QueryParam("owner") String owner, @QueryParam("template-id") String templateId,
6565
@QueryParam("host-name") String hostName, @QueryParam("display-name") String displayName, @QueryParam("hypervisor") String hypervisor,
66-
@QueryParam("cpu") int cpu, @QueryParam("speed") int speed, @QueryParam("ram") long memory, @QueryParam("disk-size") Long diskSize,
66+
@QueryParam("cpu") int cpu, @QueryParam("speed") int speed, @QueryParam("ram") long memory, @QueryParam("customParameters") Map<String, String> customParameters,
67+
@QueryParam("disk-size") Long diskSize,
6768
@QueryParam("compute-tags") List<String> computeTags, @QueryParam("root-disk-tags") List<String> rootDiskTags,
6869
@QueryParam("network-nic-map") Map<String, List<NicProfile>> networkNicMap, @QueryParam("deploymentplan") DeploymentPlan plan,
6970
@QueryParam("root-disk-size") Long rootDiskSize, @QueryParam("extra-dhcp-option-map") Map<String, Map<Integer, String>> extraDhcpOptionMap,
@@ -72,7 +73,7 @@ VirtualMachineEntity createVirtualMachine(@QueryParam("id") String id, @QueryPar
7273
@POST
7374
VirtualMachineEntity createVirtualMachineFromScratch(@QueryParam("id") String id, @QueryParam("owner") String owner, @QueryParam("iso-id") String isoId,
7475
@QueryParam("host-name") String hostName, @QueryParam("display-name") String displayName, @QueryParam("hypervisor") String hypervisor,
75-
@QueryParam("os") String os, @QueryParam("cpu") int cpu, @QueryParam("speed") int speed, @QueryParam("ram") long memory, @QueryParam("disk-size") Long diskSize,
76+
@QueryParam("os") String os, @QueryParam("cpu") int cpu, @QueryParam("speed") int speed, @QueryParam("ram") long memory, @QueryParam("customParameters") Map<String, String> customParameters, @QueryParam("disk-size") Long diskSize,
7677
@QueryParam("compute-tags") List<String> computeTags, @QueryParam("root-disk-tags") List<String> rootDiskTags,
7778
@QueryParam("network-nic-map") Map<String, List<NicProfile>> networkNicMap, @QueryParam("deploymentplan") DeploymentPlan plan,
7879
@QueryParam("extra-dhcp-option-map") Map<String, Map<Integer, String>> extraDhcpOptionMap, @QueryParam("disk-offering-id") Long diskOfferingId) throws InsufficientCapacityException;

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ public void registerGuru(final VirtualMachine.Type type, final VirtualMachineGur
473473
@DB
474474
public void allocate(final String vmInstanceName, final VirtualMachineTemplate template, final ServiceOffering serviceOffering,
475475
final DiskOfferingInfo rootDiskOfferingInfo, final List<DiskOfferingInfo> dataDiskOfferings,
476-
final LinkedHashMap<? extends Network, List<? extends NicProfile>> auxiliaryNetworks, final DeploymentPlan plan, final HypervisorType hyperType, final Map<String, Map<Integer, String>> extraDhcpOptions, final Map<Long, DiskOffering> datadiskTemplateToDiskOfferingMap)
476+
final LinkedHashMap<? extends Network, List<? extends NicProfile>> auxiliaryNetworks, final DeploymentPlan plan, final HypervisorType hyperType, final Map<String, Map<Integer, String>> extraDhcpOptions,
477+
final Map<Long, DiskOffering> datadiskTemplateToDiskOfferingMap, final Map<String, String> customParameters)
477478
throws InsufficientCapacityException {
478479

479-
logger.info("allocating virtual machine from template:{} with hostname:{} and {} networks", template.getUuid(), vmInstanceName, auxiliaryNetworks.size());
480480
VMInstanceVO persistedVm = null;
481481
try {
482482
final VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName);
@@ -511,7 +511,13 @@ public void allocate(final String vmInstanceName, final VirtualMachineTemplate t
511511

512512
logger.debug("Allocating disks for {}", persistedVm);
513513

514-
allocateRootVolume(persistedVm, template, rootDiskOfferingInfo, owner, rootDiskSizeFinal);
514+
if (customParameters.get("volumeId") != null){
515+
VolumeVO volVO =_volsDao.findById(Long.parseLong(customParameters.get("volumeId")));
516+
volVO.setInstanceId(vm.getId());
517+
_volsDao.update(volVO.getId(), volVO);
518+
} else {
519+
allocateRootVolume(persistedVm, template, rootDiskOfferingInfo, owner, rootDiskSizeFinal);
520+
}
515521

516522
// Create new Volume context and inject event resource type, id and details to generate VOLUME.CREATE event for the ROOT disk.
517523
CallContext volumeContext = CallContext.register(CallContext.current(), ApiCommandResourceType.Volume);
@@ -576,7 +582,7 @@ private void allocateRootVolume(VMInstanceVO vm, VirtualMachineTemplate template
576582
public void allocate(final String vmInstanceName, final VirtualMachineTemplate template, final ServiceOffering serviceOffering,
577583
final LinkedHashMap<? extends Network, List<? extends NicProfile>> networks, final DeploymentPlan plan, final HypervisorType hyperType) throws InsufficientCapacityException {
578584
DiskOffering diskOffering = _diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
579-
allocate(vmInstanceName, template, serviceOffering, new DiskOfferingInfo(diskOffering), new ArrayList<>(), networks, plan, hyperType, null, null);
585+
allocate(vmInstanceName, template, serviceOffering, new DiskOfferingInfo(diskOffering), new ArrayList<>(), networks, plan, hyperType, null, null, null );
580586
}
581587

582588
VirtualMachineGuru getVmGuru(final VirtualMachine vm) {

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void destroyVolume(String volumeEntity) {
158158

159159
@Override
160160
public VirtualMachineEntity createVirtualMachine(String id, String owner, String templateId, String hostName, String displayName, String hypervisor, int cpu,
161-
int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan,
161+
int speed, long memory, Map<String, String> customParameters, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan,
162162
Long rootDiskSize, Map<String, Map<Integer, String>> extraDhcpOptionMap, Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, Long dataDiskOfferingId, Long rootDiskOfferingId) throws InsufficientCapacityException {
163163

164164
// VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks,
@@ -254,16 +254,15 @@ public VirtualMachineEntity createVirtualMachine(String id, String owner, String
254254
}
255255
}
256256
}
257-
258-
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(templateId)), computeOffering, rootDiskOfferingInfo, dataDiskOfferings, networkIpMap, plan,
259-
hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap);
257+
_itMgr.allocate(vm.getInstanceName(), _templateDao.findByIdIncludingRemoved(new Long(templateId)), computeOffering, rootDiskOfferingInfo, dataDiskOfferings, networkIpMap, plan,
258+
hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap, customParameters);
260259

261260
return vmEntity;
262261
}
263262

264263
@Override
265264
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os,
266-
int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan,
265+
int cpu, int speed, long memory, Map<String, String> customParameters, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan,
267266
Map<String, Map<Integer, String>> extraDhcpOptionMap, Long diskOfferingId)
268267
throws InsufficientCapacityException {
269268

@@ -281,6 +280,7 @@ public VirtualMachineEntity createVirtualMachineFromScratch(String id, String ow
281280
if (diskOfferingId == null) {
282281
throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
283282
}
283+
284284
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
285285
if (diskOffering == null) {
286286
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
@@ -321,8 +321,7 @@ public VirtualMachineEntity createVirtualMachineFromScratch(String id, String ow
321321

322322
HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
323323

324-
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType, extraDhcpOptionMap, null);
325-
324+
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType, extraDhcpOptionMap, null, customParameters);
326325
return vmEntity;
327326
}
328327

0 commit comments

Comments
 (0)