From 95535f926608f6222694c07901b4f5ba83acf59f Mon Sep 17 00:00:00 2001 From: frank Date: Tue, 26 Jul 2011 18:04:41 -0700 Subject: [PATCH] Bug 9887 - baremetal: support for image operation (create template from guest disk) (edit) Use createTemplate API instead a new one --- .../cloud/api/commands/CreateTemplateCmd.java | 23 ++++++++++++++++++- api/src/com/cloud/vm/BareMetalVmService.java | 1 - 2 files changed, 22 insertions(+), 2 deletions(-) mode change 100644 => 100755 api/src/com/cloud/vm/BareMetalVmService.java diff --git a/api/src/com/cloud/api/commands/CreateTemplateCmd.java b/api/src/com/cloud/api/commands/CreateTemplateCmd.java index 23c0f485ffe..d0a5dcf18c6 100755 --- a/api/src/com/cloud/api/commands/CreateTemplateCmd.java +++ b/api/src/com/cloud/api/commands/CreateTemplateCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; +import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.StoragePoolResponse; import com.cloud.api.response.TemplateResponse; import com.cloud.async.AsyncJob; @@ -78,6 +79,14 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.LONG, description = "the ID of the disk volume the template is being created from. Either this parameter, or snapshotId has to be passed in") private Long volumeId; + + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="Optional, VM ID. If this presents, it is going to create a baremetal template for VM this ID refers to. This is only for VM whose hypervisor type is BareMetal") + private Long vmId; + + @Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="Optional, only for baremetal hypervisor. The directory name where template stored on CIFS server") + private String url; + + // /////////////////////////////////////////////////// // ///////////////// Accessors /////////////////////// @@ -122,7 +131,14 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd { public Long getVolumeId() { return volumeId; } + + public Long getVmId() { + return vmId; + } + public String getUrl() { + return url; + } // /////////////////////////////////////////////////// // ///////////// API Implementation/////////////////// // /////////////////////////////////////////////////// @@ -186,7 +202,12 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd { @Override public void execute() { UserContext.current().setEventDetails("Template Id: "+getEntityId()+((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId())); - VirtualMachineTemplate template = _userVmService.createPrivateTemplate(this); + VirtualMachineTemplate template = null; + if (vmId != null && url != null) { + template = _bareMetalVmService.createPrivateTemplate(this); + } else { + template = _userVmService.createPrivateTemplate(this); + } if (template != null){ List templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false); TemplateResponse response = new TemplateResponse(); diff --git a/api/src/com/cloud/vm/BareMetalVmService.java b/api/src/com/cloud/vm/BareMetalVmService.java old mode 100644 new mode 100755 index 6958b98e24a..fd9c3a738f4 --- a/api/src/com/cloud/vm/BareMetalVmService.java +++ b/api/src/com/cloud/vm/BareMetalVmService.java @@ -21,5 +21,4 @@ package com.cloud.vm; import com.cloud.exception.ResourceAllocationException; public interface BareMetalVmService extends UserVmService { - public Long createTemplate(Long hostId, Integer bits, String displayText, String url, Boolean featured, Boolean publicTemplate, String templateName, Long osTypeId) throws ResourceAllocationException; }