Skip to content

Commit deccea2

Browse files
authored
iso: Added upload iso from local (#33)
Upload ISO from local backport from 4.13
1 parent e8aa476 commit deccea2

File tree

16 files changed

+809
-38
lines changed

16 files changed

+809
-38
lines changed

api/src/com/cloud/template/TemplateApiService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd;
2525
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
2626
import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd;
27+
import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd;
2728
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
2829
import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
2930
import org.apache.cloudstack.api.command.user.template.CopyTemplateCmd;
@@ -45,10 +46,12 @@ public interface TemplateApiService {
4546

4647
VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException;
4748

48-
public GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException;
49+
GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException;
4950

5051
VirtualMachineTemplate registerIso(RegisterIsoCmd cmd) throws IllegalArgumentException, ResourceAllocationException;
5152

53+
GetUploadParamsResponse registerIsoForPostUpload(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException, MalformedURLException;
54+
5255
VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException;
5356

5457
VirtualMachineTemplate prepareTemplate(long templateId, long zoneId, Long storageId);
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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.user.iso;
18+
19+
import com.cloud.exception.ConcurrentOperationException;
20+
import com.cloud.exception.InsufficientCapacityException;
21+
import com.cloud.exception.NetworkRuleConflictException;
22+
import com.cloud.exception.ResourceAllocationException;
23+
import com.cloud.exception.ResourceUnavailableException;
24+
import org.apache.cloudstack.api.APICommand;
25+
import org.apache.cloudstack.api.AbstractGetUploadParamsCmd;
26+
import org.apache.cloudstack.api.ApiConstants;
27+
import org.apache.cloudstack.api.ApiErrorCode;
28+
import org.apache.cloudstack.api.BaseCmd;
29+
import org.apache.cloudstack.api.Parameter;
30+
import org.apache.cloudstack.api.ServerApiException;
31+
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
32+
import org.apache.cloudstack.api.response.GuestOSResponse;
33+
import org.apache.cloudstack.api.response.ZoneResponse;
34+
import org.apache.cloudstack.context.CallContext;
35+
36+
import java.net.MalformedURLException;
37+
38+
@APICommand(name = GetUploadParamsForIsoCmd.APINAME,
39+
description = "upload an existing ISO into the CloudStack cloud.",
40+
responseObject = GetUploadParamsResponse.class, since = "4.11",
41+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
42+
public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
43+
44+
public static final String APINAME = "getUploadParamsForIso";
45+
46+
private static final String s_name = "postuploadisoresponse";
47+
48+
/////////////////////////////////////////////////////
49+
//////////////// API parameters /////////////////////
50+
/////////////////////////////////////////////////////
51+
52+
@Parameter(name = ApiConstants.BOOTABLE, type = BaseCmd.CommandType.BOOLEAN, description = "true if this ISO is bootable. If not passed explicitly its assumed to be true")
53+
private Boolean bootable;
54+
55+
@Parameter(name = ApiConstants.DISPLAY_TEXT,
56+
type = BaseCmd.CommandType.STRING,
57+
required = true,
58+
description = "the display text of the ISO. This is usually used for display purposes.",
59+
length = 4096)
60+
private String displayText;
61+
62+
@Parameter(name = ApiConstants.IS_FEATURED, type = BaseCmd.CommandType.BOOLEAN, description = "true if you want this ISO to be featured")
63+
private Boolean featured;
64+
65+
@Parameter(name = ApiConstants.IS_PUBLIC,
66+
type = BaseCmd.CommandType.BOOLEAN,
67+
description = "true if you want to register the ISO to be publicly available to all users, false otherwise.")
68+
private Boolean publicIso;
69+
70+
@Parameter(name = ApiConstants.IS_EXTRACTABLE, type = BaseCmd.CommandType.BOOLEAN, description = "true if the ISO or its derivatives are extractable; default is false")
71+
private Boolean extractable;
72+
73+
@Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, required = true, description = "the name of the ISO")
74+
private String isoName;
75+
76+
@Parameter(name = ApiConstants.OS_TYPE_ID,
77+
type = BaseCmd.CommandType.UUID,
78+
entityType = GuestOSResponse.class,
79+
description = "the ID of the OS type that best represents the OS of this ISO. If the ISO is bootable this parameter needs to be passed")
80+
private Long osTypeId;
81+
82+
@Parameter(name=ApiConstants.ZONE_ID, type= BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
83+
required=true, description="the ID of the zone you wish to register the ISO to.")
84+
protected Long zoneId;
85+
86+
/////////////////////////////////////////////////////
87+
/////////////////// Accessors ///////////////////////
88+
/////////////////////////////////////////////////////
89+
90+
public Boolean isBootable() {
91+
return bootable;
92+
}
93+
94+
public String getDisplayText() {
95+
return displayText;
96+
}
97+
98+
public Boolean isFeatured() {
99+
return featured;
100+
}
101+
102+
public Boolean isPublic() {
103+
return publicIso;
104+
}
105+
106+
public Boolean isExtractable() {
107+
return extractable;
108+
}
109+
110+
public String getIsoName() {
111+
return isoName;
112+
}
113+
114+
public Long getOsTypeId() {
115+
return osTypeId;
116+
}
117+
118+
public Long getZoneId() {
119+
return zoneId;
120+
}
121+
122+
/////////////////////////////////////////////////////
123+
/////////////// API Implementation///////////////////
124+
/////////////////////////////////////////////////////
125+
126+
@Override
127+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
128+
validateRequest();
129+
try {
130+
GetUploadParamsResponse response = _templateService.registerIsoForPostUpload(this);
131+
response.setResponseName(getCommandName());
132+
setResponseObject(response);
133+
} catch (ResourceAllocationException | MalformedURLException e) {
134+
s_logger.error("Exception while registering ISO", e);
135+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Exception while registering ISO: " + e.getMessage());
136+
}
137+
}
138+
139+
private void validateRequest() {
140+
if (getZoneId() <= 0) {
141+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid zoneid");
142+
}
143+
}
144+
145+
@Override
146+
public String getCommandName() {
147+
return s_name;
148+
}
149+
150+
@Override
151+
public long getEntityOwnerId() {
152+
Long accountId = _accountService.finalyzeAccountId(getAccountName(), getDomainId(), getProjectId(), true);
153+
if (accountId == null) {
154+
return CallContext.current().getCallingAccount().getId();
155+
}
156+
return accountId;
157+
}
158+
}

plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.cloud.utils.db.DB;
4141
import com.cloud.utils.exception.CloudRuntimeException;
4242
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
43+
import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd;
4344
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
4445
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
4546
import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
@@ -72,6 +73,11 @@ public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationExce
7273
throw new CloudRuntimeException("Baremetal doesn't support ISO template");
7374
}
7475

76+
@Override
77+
public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException {
78+
throw new CloudRuntimeException("Baremetal doesn't support ISO template");
79+
}
80+
7581
private void templateCreateUsage(VMTemplateVO template, long dcId) {
7682
if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
7783
UsageEventVO usageEvent =

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
337337
import org.apache.cloudstack.api.command.user.iso.DetachIsoCmd;
338338
import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd;
339+
import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd;
339340
import org.apache.cloudstack.api.command.user.iso.ListIsoPermissionsCmd;
340341
import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
341342
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
@@ -3052,6 +3053,7 @@ public List<Class<?>> getCommands() {
30523053
cmdList.add(CreateManagementNetworkIpRangeCmd.class);
30533054
cmdList.add(DeleteManagementNetworkIpRangeCmd.class);
30543055
cmdList.add(UploadTemplateDirectDownloadCertificateCmd.class);
3056+
cmdList.add(GetUploadParamsForIsoCmd.class);
30553057

30563058
// Out-of-band management APIs for admins
30573059
cmdList.add(EnableOutOfBandManagementForHostCmd.class);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 com.cloud.storage.upload.params;
18+
19+
import com.cloud.hypervisor.Hypervisor;
20+
import com.cloud.storage.Storage;
21+
22+
public class IsoUploadParams extends UploadParamsBase {
23+
24+
public IsoUploadParams(long userId, String name, String displayText, Boolean isPublic, Boolean isFeatured,
25+
Boolean isExtractable, Long osTypeId, Long zoneId, Boolean bootable, long ownerId) {
26+
super(userId, name, displayText, isPublic, isFeatured, isExtractable, osTypeId, zoneId, bootable, ownerId);
27+
setIso(true);
28+
setBits(64);
29+
setFormat(Storage.ImageFormat.ISO.toString());
30+
setHypervisorType(Hypervisor.HypervisorType.None);
31+
setRequiresHVM(true);
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 com.cloud.storage.upload.params;
18+
19+
import com.cloud.hypervisor.Hypervisor;
20+
21+
import java.util.Map;
22+
23+
public class TemplateUploadParams extends UploadParamsBase {
24+
25+
public TemplateUploadParams(long userId, String name, String displayText,
26+
Integer bits, Boolean passwordEnabled, Boolean requiresHVM,
27+
Boolean isPublic, Boolean featured,
28+
Boolean isExtractable, String format, Long guestOSId,
29+
Long zoneId, Hypervisor.HypervisorType hypervisorType, String chksum,
30+
String templateTag, long templateOwnerId,
31+
Map details, Boolean sshkeyEnabled,
32+
Boolean isDynamicallyScalable, Boolean isRoutingType) {
33+
super(userId, name, displayText, bits, passwordEnabled, requiresHVM, isPublic, featured, isExtractable,
34+
format, guestOSId, zoneId, hypervisorType, chksum, templateTag, templateOwnerId, details,
35+
sshkeyEnabled, isDynamicallyScalable, isRoutingType);
36+
setBootable(true);
37+
}
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 com.cloud.storage.upload.params;
18+
19+
import com.cloud.hypervisor.Hypervisor;
20+
21+
import java.util.Map;
22+
23+
public interface UploadParams {
24+
boolean isIso();
25+
long getUserId();
26+
String getName();
27+
String getDisplayText();
28+
Integer getBits();
29+
boolean isPasswordEnabled();
30+
boolean requiresHVM();
31+
String getUrl();
32+
boolean isPublic();
33+
boolean isFeatured();
34+
boolean isExtractable();
35+
String getFormat();
36+
Long getGuestOSId();
37+
Long getZoneId();
38+
Hypervisor.HypervisorType getHypervisorType();
39+
String getChecksum();
40+
boolean isBootable();
41+
String getTemplateTag();
42+
long getTemplateOwnerId();
43+
Map getDetails();
44+
boolean isSshKeyEnabled();
45+
String getImageStoreUuid();
46+
boolean isDynamicallyScalable();
47+
boolean isRoutingType();
48+
boolean isDirectDownload();
49+
}

0 commit comments

Comments
 (0)