2222
2323import javax .inject .Inject ;
2424
25+ import org .apache .cloudstack .acl .SecurityChecker ;
2526import org .apache .cloudstack .api .ApiCommandResourceType ;
2627import org .apache .cloudstack .api .ApiConstants ;
2728import org .apache .cloudstack .api .command .admin .kubernetes .version .AddKubernetesSupportedVersionCmd ;
@@ -312,6 +313,7 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
312313 final String semanticVersion = cmd .getSemanticVersion ();
313314 final Long zoneId = cmd .getZoneId ();
314315 final String isoUrl = cmd .getUrl ();
316+ final Long isoId = cmd .getIsoId ();
315317 final String isoChecksum = cmd .getChecksum ();
316318 final Integer minimumCpu = cmd .getMinimumCpu ();
317319 final Integer minimumRamSize = cmd .getMinimumRamSize ();
@@ -334,8 +336,8 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
334336 throw new InvalidParameterValueException (String .format ("Zone: %s supports only direct download Kubernetes versions" , zone .getName ()));
335337 }
336338 }
337- if (StringUtils .isEmpty (isoUrl )) {
338- throw new InvalidParameterValueException (String .format ("Invalid URL for ISO specified, %s " , isoUrl ));
339+ if (StringUtils .isEmpty (isoUrl ) && isoId == null ) {
340+ throw new InvalidParameterValueException (String .format ("Either %s or %s parameter is required " , ApiConstants . URL , ApiConstants . ISO_ID ));
339341 }
340342 if (StringUtils .isEmpty (name )) {
341343 name = String .format ("v%s" , semanticVersion );
@@ -345,12 +347,23 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
345347 }
346348
347349 VMTemplateVO template = null ;
348- try {
349- VirtualMachineTemplate vmTemplate = registerKubernetesVersionIso (zoneId , name , isoUrl , isoChecksum , isDirectDownload );
350- template = templateDao .findById (vmTemplate .getId ());
351- } catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException | ResourceAllocationException ex ) {
352- logger .error (String .format ("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s" , name , isoUrl ), ex );
353- throw new CloudRuntimeException (String .format ("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s" , name , isoUrl ));
350+
351+ if (isoId != null ) {
352+ template = templateDao .findById (isoId );
353+ if (template == null ) {
354+ throw new InvalidParameterValueException (String .format ("Invalid ISO ID specified, %s" , isoId ));
355+ }
356+ accountManager .checkAccess (CallContext .current ().getCallingAccount (), SecurityChecker .AccessType .UseEntry , true , template );
357+ }
358+ if (template == null ) {
359+ try {
360+ VirtualMachineTemplate vmTemplate = registerKubernetesVersionIso (zoneId , name , isoUrl , isoChecksum , isDirectDownload );
361+ template = templateDao .findById (vmTemplate .getId ());
362+ } catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException |
363+ ResourceAllocationException ex ) {
364+ logger .error (String .format ("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s" , name , isoUrl ), ex );
365+ throw new CloudRuntimeException (String .format ("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s" , name , isoUrl ));
366+ }
354367 }
355368
356369 KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO (name , semanticVersion , template .getId (), zoneId , minimumCpu , minimumRamSize );
0 commit comments