diff --git a/api/src/com/cloud/acl/SecurityChecker.java b/api/src/com/cloud/acl/SecurityChecker.java index e835d9d2241..53b8438b8f0 100644 --- a/api/src/com/cloud/acl/SecurityChecker.java +++ b/api/src/com/cloud/acl/SecurityChecker.java @@ -6,6 +6,8 @@ package com.cloud.acl; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; import com.cloud.exception.PermissionDeniedException; +import com.cloud.offering.DiskOffering; +import com.cloud.offering.ServiceOffering; import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.utils.component.Adapter; @@ -57,6 +59,10 @@ public interface SecurityChecker extends Adapter { boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException; + public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException; + + boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException; + // We should be able to use this method to check against commands. For example, we can // annotate the command with access annotations and this method can use it to extract // OwnedBy and PartOf interfaces on the object and use it to verify against a user. diff --git a/api/src/com/cloud/api/commands/AttachVolumeCmd.java b/api/src/com/cloud/api/commands/AttachVolumeCmd.java index 51507aad251..3639e33cdad 100755 --- a/api/src/com/cloud/api/commands/AttachVolumeCmd.java +++ b/api/src/com/cloud/api/commands/AttachVolumeCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.VolumeResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.storage.Volume; import com.cloud.user.Account; @@ -85,6 +86,14 @@ public class AttachVolumeCmd extends BaseAsyncCmd { public String getName() { return s_name; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Volume; + } + + public Long getInstanceId() { + return getId(); + } @Override public long getAccountId() { @@ -107,6 +116,11 @@ public class AttachVolumeCmd extends BaseAsyncCmd { @Override public void execute(){ + try { + Thread.sleep(2000); + } catch (Exception e) { + + } Volume result = _userVmService.attachVolumeToVM(this); if (result != null) { VolumeResponse response = _responseGenerator.createVolumeResponse(result); diff --git a/api/src/com/cloud/api/commands/CancelMaintenanceCmd.java b/api/src/com/cloud/api/commands/CancelMaintenanceCmd.java index 76368a114c3..7603756d331 100644 --- a/api/src/com/cloud/api/commands/CancelMaintenanceCmd.java +++ b/api/src/com/cloud/api/commands/CancelMaintenanceCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.HostResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.host.Host; import com.cloud.user.Account; @@ -87,6 +88,14 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd { public String getEventDescription() { return "canceling maintenance for host: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CopyIsoCmd.java b/api/src/com/cloud/api/commands/CopyIsoCmd.java index 712a7a65083..3b5f3b747e7 100644 --- a/api/src/com/cloud/api/commands/CopyIsoCmd.java +++ b/api/src/com/cloud/api/commands/CopyIsoCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.TemplateResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.StorageUnavailableException; import com.cloud.template.VirtualMachineTemplate; @@ -99,6 +100,14 @@ public class CopyIsoCmd extends BaseAsyncCmd { public String getEventDescription() { return "copying ISO: " + getId() + " from zone: " + getSourceZoneId() + " to zone: " + getDestinationZoneId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Iso; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CopyTemplateCmd.java b/api/src/com/cloud/api/commands/CopyTemplateCmd.java index d66fafb2b3c..451a2e0a9c2 100644 --- a/api/src/com/cloud/api/commands/CopyTemplateCmd.java +++ b/api/src/com/cloud/api/commands/CopyTemplateCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.TemplateResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.StorageUnavailableException; import com.cloud.template.VirtualMachineTemplate; @@ -100,6 +101,14 @@ public class CopyTemplateCmd extends BaseAsyncCmd { public String getEventDescription() { return "copying template: " + getId() + " from zone: " + getSourceZoneId() + " to zone: " + getDestinationZoneId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Template; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java index 0ab12647b60..99bd1955d1b 100644 --- a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java @@ -25,6 +25,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.ServiceOfferingResponse; import com.cloud.offering.ServiceOffering; @@ -64,6 +65,9 @@ public class CreateServiceOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.USE_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="if true, the VM created will use default virtual networking. If false, the VM created will use a direct attached networking model. The default value is true.") private Boolean useVirtualNetwork; + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings") + private Long domainId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -100,7 +104,11 @@ public class CreateServiceOfferingCmd extends BaseCmd { return tags; } - public Boolean getUseVirtualNetwork() { + public Long getDomainId() { + return domainId; + } + + public Boolean getUseVirtualNetwork() { return useVirtualNetwork; } diff --git a/api/src/com/cloud/api/commands/CreateSnapshotCmd.java b/api/src/com/cloud/api/commands/CreateSnapshotCmd.java index 53cc4ac549e..94fddf93d17 100644 --- a/api/src/com/cloud/api/commands/CreateSnapshotCmd.java +++ b/api/src/com/cloud/api/commands/CreateSnapshotCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SnapshotResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; import com.cloud.storage.Snapshot; @@ -100,7 +101,11 @@ public class CreateSnapshotCmd extends BaseAsyncCmd { public String getEventDescription() { return "creating snapshot for volume: " + getVolumeId(); } - + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Snapshot; + } + @Override public void execute(){ try { diff --git a/api/src/com/cloud/api/commands/CreateTemplateCmd.java b/api/src/com/cloud/api/commands/CreateTemplateCmd.java index 79e37d92b9f..f4d5ad76448 100644 --- 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.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.StoragePoolResponse; import com.cloud.api.response.TemplateResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.storage.Snapshot; import com.cloud.storage.Volume; @@ -161,6 +162,10 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd { public String getEventDescription() { return "creating template: " + getTemplateName(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Template; + } @Override public void callCreate(){ diff --git a/api/src/com/cloud/api/commands/CreateVolumeCmd.java b/api/src/com/cloud/api/commands/CreateVolumeCmd.java index 4c72088f734..fd921467060 100644 --- a/api/src/com/cloud/api/commands/CreateVolumeCmd.java +++ b/api/src/com/cloud/api/commands/CreateVolumeCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.VolumeResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; import com.cloud.storage.Volume; @@ -108,7 +109,11 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { public static String getResultObjectName() { return "volume"; } - + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Volume; + } + @Override public long getAccountId() { Account account = UserContext.current().getAccount(); diff --git a/api/src/com/cloud/api/commands/DeleteIsoCmd.java b/api/src/com/cloud/api/commands/DeleteIsoCmd.java index c90bd942ae5..d73c1c0aa8d 100644 --- a/api/src/com/cloud/api/commands/DeleteIsoCmd.java +++ b/api/src/com/cloud/api/commands/DeleteIsoCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; @@ -91,6 +92,14 @@ public class DeleteIsoCmd extends BaseAsyncCmd { return "Deleting iso " + getId(); } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Iso; + } + + public Long getInstanceId() { + return getId(); + } + @Override public void execute(){ boolean result = _templateService.deleteIso(this); diff --git a/api/src/com/cloud/api/commands/DeleteSnapshotCmd.java b/api/src/com/cloud/api/commands/DeleteSnapshotCmd.java index bdec3f6e881..ad1b9d0f7aa 100644 --- a/api/src/com/cloud/api/commands/DeleteSnapshotCmd.java +++ b/api/src/com/cloud/api/commands/DeleteSnapshotCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.storage.Snapshot; import com.cloud.user.Account; @@ -80,6 +81,14 @@ public class DeleteSnapshotCmd extends BaseAsyncCmd { public String getEventDescription() { return "deleting snapshot: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Snapshot; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DeleteTemplateCmd.java b/api/src/com/cloud/api/commands/DeleteTemplateCmd.java index ff90c4633c8..7b9c25e565c 100644 --- a/api/src/com/cloud/api/commands/DeleteTemplateCmd.java +++ b/api/src/com/cloud/api/commands/DeleteTemplateCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; @@ -93,6 +94,14 @@ public class DeleteTemplateCmd extends BaseAsyncCmd { return "Deleting template " + getId(); } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Template; + } + + public Long getInstanceId() { + return getId(); + } + @Override public void execute(){ boolean result = _templateService.deleteTemplate(this); diff --git a/api/src/com/cloud/api/commands/DetachVolumeCmd.java b/api/src/com/cloud/api/commands/DetachVolumeCmd.java index 66ebd6988cb..2509bc5ad27 100755 --- a/api/src/com/cloud/api/commands/DetachVolumeCmd.java +++ b/api/src/com/cloud/api/commands/DetachVolumeCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.VolumeResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.storage.Volume; import com.cloud.user.Account; @@ -77,6 +78,14 @@ public class DetachVolumeCmd extends BaseAsyncCmd { public static String getResultObjectName() { return "volume"; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Volume; + } + + public Long getInstanceId() { + return getId(); + } @Override public long getAccountId() { diff --git a/api/src/com/cloud/api/commands/ExtractIsoCmd.java b/api/src/com/cloud/api/commands/ExtractIsoCmd.java index aaafd7d3ac7..7e335357002 100755 --- a/api/src/com/cloud/api/commands/ExtractIsoCmd.java +++ b/api/src/com/cloud/api/commands/ExtractIsoCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ExtractResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.InternalErrorException; import com.cloud.template.VirtualMachineTemplate; @@ -106,6 +107,14 @@ public class ExtractIsoCmd extends BaseAsyncCmd { return s_name; } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Iso; + } + + public Long getInstanceId() { + return getId(); + } + @Override public void execute(){ try { diff --git a/api/src/com/cloud/api/commands/ExtractTemplateCmd.java b/api/src/com/cloud/api/commands/ExtractTemplateCmd.java index e103b81c4cc..0c3f14ae143 100755 --- a/api/src/com/cloud/api/commands/ExtractTemplateCmd.java +++ b/api/src/com/cloud/api/commands/ExtractTemplateCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ExtractResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.InternalErrorException; import com.cloud.template.VirtualMachineTemplate; @@ -106,6 +107,14 @@ public class ExtractTemplateCmd extends BaseAsyncCmd { public String getEventDescription() { return "Extraction job"; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Template; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/ExtractVolumeCmd.java b/api/src/com/cloud/api/commands/ExtractVolumeCmd.java index 0e9386d27f7..7d116f6964a 100755 --- a/api/src/com/cloud/api/commands/ExtractVolumeCmd.java +++ b/api/src/com/cloud/api/commands/ExtractVolumeCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ExtractResponse; +import com.cloud.async.AsyncJob; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; import com.cloud.storage.Upload; @@ -91,6 +92,14 @@ public class ExtractVolumeCmd extends BaseAsyncCmd { public static String getStaticName() { return s_name; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Volume; + } + + public Long getInstanceId() { + return getId(); + } @Override public long getAccountId() { diff --git a/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java b/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java index 61645d06597..46cc202d0ee 100644 --- a/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java +++ b/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java @@ -40,7 +40,7 @@ public class ListDiskOfferingsCmd extends BaseListCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain of the disk offering. This information is not currently applicable, and should not be used as a parameter.") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain of the disk offering.") private Long domainId; @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="ID of the disk offering") diff --git a/api/src/com/cloud/api/commands/ListHostsCmd.java b/api/src/com/cloud/api/commands/ListHostsCmd.java index 4ea9640eaee..1cb214564ea 100644 --- a/api/src/com/cloud/api/commands/ListHostsCmd.java +++ b/api/src/com/cloud/api/commands/ListHostsCmd.java @@ -29,6 +29,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.HostResponse; import com.cloud.api.response.ListResponse; +import com.cloud.async.AsyncJob; import com.cloud.host.Host; @Implementation(description="Lists hosts.", responseObject=HostResponse.class) @@ -103,6 +104,10 @@ public class ListHostsCmd extends BaseListCmd { @Override public String getName() { return s_name; + } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; } @Override diff --git a/api/src/com/cloud/api/commands/ListIsosCmd.java b/api/src/com/cloud/api/commands/ListIsosCmd.java index 2e042cdc3fe..ae42cd95310 100755 --- a/api/src/com/cloud/api/commands/ListIsosCmd.java +++ b/api/src/com/cloud/api/commands/ListIsosCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.TemplateResponse; +import com.cloud.async.AsyncJob; import com.cloud.template.VirtualMachineTemplate; import com.cloud.template.VirtualMachineTemplate.TemplateFilter; import com.cloud.user.Account; @@ -130,6 +131,10 @@ public class ListIsosCmd extends BaseListCmd { return s_name; } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Iso; + } + @Override public void execute(){ List isos = _mgr.listIsos(this); diff --git a/api/src/com/cloud/api/commands/ListRoutersCmd.java b/api/src/com/cloud/api/commands/ListRoutersCmd.java index 9da699faa8b..35e3550a5c5 100644 --- a/api/src/com/cloud/api/commands/ListRoutersCmd.java +++ b/api/src/com/cloud/api/commands/ListRoutersCmd.java @@ -29,6 +29,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.DomainRouterResponse; import com.cloud.api.response.ListResponse; +import com.cloud.async.AsyncJob; import com.cloud.network.router.VirtualRouter; @Implementation(description="List routers.", responseObject=DomainRouterResponse.class) @@ -102,6 +103,10 @@ public class ListRoutersCmd extends BaseListCmd { public String getName() { return s_name; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.DomainRouter; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java b/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java index 37aa4b01276..1c81a02c9f2 100644 --- a/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java +++ b/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.ApiConstants; import com.cloud.api.BaseListCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; +import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.ListResponse; import com.cloud.api.response.ServiceOfferingResponse; import com.cloud.offering.ServiceOffering; @@ -48,6 +49,9 @@ public class ListServiceOfferingsCmd extends BaseListCmd { @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="the ID of the virtual machine. Pass this in if you want to see the available service offering that a virtual machine can be changed to.") private Long virtualMachineId; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain associated with the service offering") + private Long domainId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -65,6 +69,9 @@ public class ListServiceOfferingsCmd extends BaseListCmd { return virtualMachineId; } + public Long getDomainId(){ + return domainId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/ListSnapshotsCmd.java b/api/src/com/cloud/api/commands/ListSnapshotsCmd.java index 79d1e0a9451..0469c706094 100644 --- a/api/src/com/cloud/api/commands/ListSnapshotsCmd.java +++ b/api/src/com/cloud/api/commands/ListSnapshotsCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.SnapshotResponse; +import com.cloud.async.AsyncJob; import com.cloud.storage.Snapshot; @Implementation(description="Lists all available snapshots for the account.", responseObject=SnapshotResponse.class) @@ -101,6 +102,10 @@ public class ListSnapshotsCmd extends BaseListCmd { public String getName() { return s_name; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Snapshot; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/ListSystemVMsCmd.java b/api/src/com/cloud/api/commands/ListSystemVMsCmd.java index 4c76c846881..d2f60282aa4 100644 --- a/api/src/com/cloud/api/commands/ListSystemVMsCmd.java +++ b/api/src/com/cloud/api/commands/ListSystemVMsCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.SystemVmResponse; +import com.cloud.async.AsyncJob; import com.cloud.vm.VirtualMachine; @Implementation(description="List system virtual machines.", responseObject=SystemVmResponse.class) @@ -102,6 +103,10 @@ public class ListSystemVMsCmd extends BaseListCmd { return s_name; } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.SystemVm; + } + @Override public void execute(){ List systemVMs = _mgr.searchForSystemVm(this); diff --git a/api/src/com/cloud/api/commands/ListTemplatesCmd.java b/api/src/com/cloud/api/commands/ListTemplatesCmd.java index dd0d314d65a..b9776370728 100644 --- a/api/src/com/cloud/api/commands/ListTemplatesCmd.java +++ b/api/src/com/cloud/api/commands/ListTemplatesCmd.java @@ -29,6 +29,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.TemplateResponse; +import com.cloud.async.AsyncJob; import com.cloud.storage.Storage; import com.cloud.template.VirtualMachineTemplate; import com.cloud.template.VirtualMachineTemplate.TemplateFilter; @@ -111,6 +112,10 @@ public class ListTemplatesCmd extends BaseListCmd { return s_name; } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Template; + } + @Override public void execute(){ List templates = _mgr.listTemplates(this); diff --git a/api/src/com/cloud/api/commands/ListVolumesCmd.java b/api/src/com/cloud/api/commands/ListVolumesCmd.java index 43d9f4c7871..1f30ddbd9d1 100755 --- a/api/src/com/cloud/api/commands/ListVolumesCmd.java +++ b/api/src/com/cloud/api/commands/ListVolumesCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.VolumeResponse; +import com.cloud.async.AsyncJob; import com.cloud.storage.Volume; @Implementation(description="Lists all volumes.", responseObject=VolumeResponse.class) @@ -116,6 +117,10 @@ public class ListVolumesCmd extends BaseListCmd { return s_name; } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Volume; + } + @Override public void execute(){ List volumes = _mgr.searchForVolumes(this); diff --git a/api/src/com/cloud/api/commands/PrepareForMaintenanceCmd.java b/api/src/com/cloud/api/commands/PrepareForMaintenanceCmd.java index acd4941802d..01a3d472b5c 100644 --- a/api/src/com/cloud/api/commands/PrepareForMaintenanceCmd.java +++ b/api/src/com/cloud/api/commands/PrepareForMaintenanceCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.HostResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.host.Host; import com.cloud.user.Account; @@ -85,6 +86,14 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd { return "preparing host: " + getId() + " for maintenance"; } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; + } + + public Long getInstanceId() { + return getId(); + } + @Override public void execute(){ Host result = _resourceService.maintain(this); diff --git a/api/src/com/cloud/api/commands/RebootRouterCmd.java b/api/src/com/cloud/api/commands/RebootRouterCmd.java index 76a75b942ad..ba74ae086a7 100644 --- a/api/src/com/cloud/api/commands/RebootRouterCmd.java +++ b/api/src/com/cloud/api/commands/RebootRouterCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DomainRouterResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.network.router.VirtualRouter; import com.cloud.user.Account; @@ -79,6 +80,14 @@ public class RebootRouterCmd extends BaseAsyncCmd { public String getEventDescription() { return "rebooting router: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.DomainRouter; + } + + public Long getInstanceId() { + return getId(); + } @Override diff --git a/api/src/com/cloud/api/commands/RebootSystemVmCmd.java b/api/src/com/cloud/api/commands/RebootSystemVmCmd.java index f3c6656f94e..815fdd024bf 100644 --- a/api/src/com/cloud/api/commands/RebootSystemVmCmd.java +++ b/api/src/com/cloud/api/commands/RebootSystemVmCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SystemVmResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -82,6 +83,14 @@ public class RebootSystemVmCmd extends BaseAsyncCmd { return "rebooting system vm: " + getId(); } + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.SystemVm; + } + + public Long getInstanceId() { + return getId(); + } + @Override public void execute(){ VirtualMachine result = _mgr.rebootSystemVM(this); diff --git a/api/src/com/cloud/api/commands/ReconnectHostCmd.java b/api/src/com/cloud/api/commands/ReconnectHostCmd.java index 61aa64194e2..b6189d7286d 100644 --- a/api/src/com/cloud/api/commands/ReconnectHostCmd.java +++ b/api/src/com/cloud/api/commands/ReconnectHostCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.HostResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.AgentUnavailableException; import com.cloud.host.Host; @@ -86,6 +87,14 @@ public class ReconnectHostCmd extends BaseAsyncCmd { public String getEventDescription() { return "reconnecting host: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/RegisterTemplateCmd.java b/api/src/com/cloud/api/commands/RegisterTemplateCmd.java index 4a7075e3073..f8e528513f2 100755 --- a/api/src/com/cloud/api/commands/RegisterTemplateCmd.java +++ b/api/src/com/cloud/api/commands/RegisterTemplateCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ListResponse; import com.cloud.api.response.TemplateResponse; +import com.cloud.async.AsyncJob; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; @@ -158,6 +159,10 @@ public class RegisterTemplateCmd extends BaseCmd { public String getName() { return s_name; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Template; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/StartRouterCmd.java b/api/src/com/cloud/api/commands/StartRouterCmd.java index db2b83c3a87..e30d6d16a2a 100644 --- a/api/src/com/cloud/api/commands/StartRouterCmd.java +++ b/api/src/com/cloud/api/commands/StartRouterCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DomainRouterResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -89,6 +90,14 @@ public class StartRouterCmd extends BaseAsyncCmd { public String getEventDescription() { return "starting router: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.DomainRouter; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{ diff --git a/api/src/com/cloud/api/commands/StartSystemVMCmd.java b/api/src/com/cloud/api/commands/StartSystemVMCmd.java index 3250935bb86..11b5fb5f8f7 100644 --- a/api/src/com/cloud/api/commands/StartSystemVMCmd.java +++ b/api/src/com/cloud/api/commands/StartSystemVMCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SystemVmResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -85,6 +86,14 @@ public class StartSystemVMCmd extends BaseAsyncCmd { public String getEventDescription() { return "starting system vm: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.SystemVm; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/StopRouterCmd.java b/api/src/com/cloud/api/commands/StopRouterCmd.java index 3d60300afd7..cba1afa0166 100644 --- a/api/src/com/cloud/api/commands/StopRouterCmd.java +++ b/api/src/com/cloud/api/commands/StopRouterCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DomainRouterResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ResourceUnavailableException; @@ -83,6 +84,14 @@ public class StopRouterCmd extends BaseAsyncCmd { public String getEventDescription() { return "stopping router: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.DomainRouter; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException{ diff --git a/api/src/com/cloud/api/commands/StopSystemVmCmd.java b/api/src/com/cloud/api/commands/StopSystemVmCmd.java index 7b3bdb7ad67..d7544a9e847 100644 --- a/api/src/com/cloud/api/commands/StopSystemVmCmd.java +++ b/api/src/com/cloud/api/commands/StopSystemVmCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SystemVmResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -81,6 +82,14 @@ public class StopSystemVmCmd extends BaseAsyncCmd { public String getEventDescription() { return "stopping system vm: " + getId(); } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.SystemVm; + } + + public Long getInstanceId() { + return getId(); + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java index 211b6082e7f..41a3c67d481 100644 --- a/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java @@ -24,6 +24,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.DiskOfferingResponse; import com.cloud.offering.DiskOffering; @@ -48,6 +49,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd{ // @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="update tags of the disk offering with this value") // private String tags; + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings") + private Long domainId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -67,6 +71,10 @@ public class UpdateDiskOfferingCmd extends BaseCmd{ // public String getTags() { // return tags; // } + + public Long getDomainId() { + return domainId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java index cd765e6276f..96db774da5e 100644 --- a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java @@ -24,6 +24,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.ServiceOfferingResponse; import com.cloud.offering.ServiceOffering; @@ -53,6 +54,9 @@ public class UpdateServiceOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.USE_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="if true, the VM created from the offering will use default virtual networking. If false, the VM created will use a direct attached networking model. The default value is true.") private Boolean useVirtualNetwork; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings") + private Long domainId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -82,17 +86,25 @@ public class UpdateServiceOfferingCmd extends BaseCmd { return useVirtualNetwork; } + + public Long getDomainId() { + return domainId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// - - @Override + + + @Override public String getName() { return s_name; } @Override public void execute(){ + //Note + //Once an offering is created, we cannot update the domainId field (keeping consistent with zones logic) ServiceOffering result = _configService.updateServiceOffering(this); if (result != null){ ServiceOfferingResponse response = _responseGenerator.createServiceOfferingResponse(result); diff --git a/api/src/com/cloud/api/response/DomainRouterResponse.java b/api/src/com/cloud/api/response/DomainRouterResponse.java index 6ef83fe6af6..54af0bed0ea 100644 --- a/api/src/com/cloud/api/response/DomainRouterResponse.java +++ b/api/src/com/cloud/api/response/DomainRouterResponse.java @@ -102,6 +102,10 @@ public class DomainRouterResponse extends BaseResponse { @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain associated with the router") private String domainName; + + public Long getObjectId() { + return getId(); + } public Long getId() { return id; diff --git a/api/src/com/cloud/api/response/HostResponse.java b/api/src/com/cloud/api/response/HostResponse.java index f5208252a2f..572e2aac402 100755 --- a/api/src/com/cloud/api/response/HostResponse.java +++ b/api/src/com/cloud/api/response/HostResponse.java @@ -131,6 +131,10 @@ public class HostResponse extends BaseResponse { @SerializedName("events") @Param(description="events available for the host") private String events; + + public Long getObjectId() { + return getId(); + } public Long getId() { return id; diff --git a/api/src/com/cloud/api/response/ServiceOfferingResponse.java b/api/src/com/cloud/api/response/ServiceOfferingResponse.java index 16cd432f1a9..5eb505f6708 100644 --- a/api/src/com/cloud/api/response/ServiceOfferingResponse.java +++ b/api/src/com/cloud/api/response/ServiceOfferingResponse.java @@ -19,6 +19,7 @@ package com.cloud.api.response; import java.util.Date; +import com.cloud.api.ApiConstants; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -56,6 +57,12 @@ public class ServiceOfferingResponse extends BaseResponse { @SerializedName("tags") @Param(description="the tags for the service offering") private String tags; + @SerializedName("domainId") @Param(description="the domain id of the service offering") + private Long domainId; + + @SerializedName(ApiConstants.DOMAIN) @Param(description="Domain name for the offering") + private String domain; + public Long getId() { return id; } @@ -143,4 +150,23 @@ public class ServiceOfferingResponse extends BaseResponse { public void setTags(String tags) { this.tags = tags; } + + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + + } diff --git a/api/src/com/cloud/api/response/SnapshotResponse.java b/api/src/com/cloud/api/response/SnapshotResponse.java index db8e733e3c1..6e993c43523 100644 --- a/api/src/com/cloud/api/response/SnapshotResponse.java +++ b/api/src/com/cloud/api/response/SnapshotResponse.java @@ -61,6 +61,10 @@ public class SnapshotResponse extends BaseResponse { @SerializedName("intervaltype") @Param(description="valid types are hourly, daily, weekly, monthy, template, and none.") private String intervalType; + + public Long getObjectId() { + return getId(); + } public Long getId() { return id; diff --git a/api/src/com/cloud/api/response/SystemVmResponse.java b/api/src/com/cloud/api/response/SystemVmResponse.java index bc5e0020fb1..a24fd0b5bab 100644 --- a/api/src/com/cloud/api/response/SystemVmResponse.java +++ b/api/src/com/cloud/api/response/SystemVmResponse.java @@ -94,6 +94,10 @@ public class SystemVmResponse extends BaseResponse { @SerializedName("activeviewersessions") @Param(description="the number of active console sessions for the console proxy system vm") private Integer activeViewerSessions; + + public Long getObjectId() { + return getId(); + } public Long getId() { return id; diff --git a/api/src/com/cloud/api/response/TemplateResponse.java b/api/src/com/cloud/api/response/TemplateResponse.java index d66756eefc1..45d7bd307fc 100755 --- a/api/src/com/cloud/api/response/TemplateResponse.java +++ b/api/src/com/cloud/api/response/TemplateResponse.java @@ -107,6 +107,10 @@ public class TemplateResponse extends BaseResponse { @SerializedName("isextractable") @Param(description="true if the template is extractable, false otherwise") private Boolean extractable; + public Long getObjectId() { + return getId(); + } + public Long getZoneId() { return zoneId; } diff --git a/api/src/com/cloud/api/response/VolumeResponse.java b/api/src/com/cloud/api/response/VolumeResponse.java index c7338eea2c7..481b0a640f3 100644 --- a/api/src/com/cloud/api/response/VolumeResponse.java +++ b/api/src/com/cloud/api/response/VolumeResponse.java @@ -119,6 +119,10 @@ public class VolumeResponse extends BaseResponse { @SerializedName("serviceofferingdisplaytext") @Param(description="the display text of the service offering for root disk") private String serviceOfferingDisplayText; + + public Long getObjectId() { + return getId(); + } public Boolean getDestroyed() { return destroyed; diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java index d9eca636556..51f2994a1b9 100644 --- a/api/src/com/cloud/async/AsyncJob.java +++ b/api/src/com/cloud/async/AsyncJob.java @@ -23,10 +23,14 @@ public interface AsyncJob { public enum Type { None, VirtualMachine, - Router, + DomainRouter, Volume, ConsoleProxy, - Snapshot + Snapshot, + Template, + Iso, + SystemVm, + Host } Long getId(); diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index 357715f59cc..aa9c97c1b8c 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -77,4 +77,6 @@ public interface ServiceOffering { */ boolean getUseLocalStorage(); + Long getDomainId(); + } diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index cf5ffd04223..44f6c4d50e3 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -810,7 +810,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) { if (vmSpec.getBootloader() == BootloaderType.CD) { vm.setPVBootloader(conn, "eliloader"); - vm.addToOtherConfig(conn, "install-repository", "cdrom"); + Map otherConfig = vm.getOtherConfig(conn); + otherConfig.put( "install-repository", "cdrom"); + vm.setOtherConfig(conn, otherConfig); } else if (vmSpec.getBootloader() == BootloaderType.PyGrub ){ vm.setPVBootloader(conn, "pygrub"); } else { @@ -5527,7 +5529,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR if (!result) { throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI); } - + installPath = installPath + "/" + tmpltFilename; return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUUID, ImageFormat.VHD); } catch (XenAPIException e) { details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.getMessage(); @@ -6197,103 +6199,4 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected String getGuestOsType(String stdType) { return stdType; } - -/* - protected boolean patchSystemVm(VDI vdi, String vmName, VirtualMachine.Type type) { - if (type == VirtualMachine.Type.DomainRouter) { - return patchSpecialVM(vdi, vmName, "router"); - } else if (type == VirtualMachine.Type.ConsoleProxy) { - return patchSpecialVM(vdi, vmName, "consoleproxy"); - } else if (type == VirtualMachine.Type.SecondaryStorageVm) { - return patchSpecialVM(vdi, vmName, "secstorage"); - } else { - throw new CloudRuntimeException("Tried to patch unknown type of system vm"); - } - } - - protected boolean patchSystemVm(VDI vdi, String vmName) { - if (vmName.startsWith("r-")) { - return patchSpecialVM(vdi, vmName, "router"); - } else if (vmName.startsWith("v-")) { - return patchSpecialVM(vdi, vmName, "consoleproxy"); - } else if (vmName.startsWith("s-")) { - return patchSpecialVM(vdi, vmName, "secstorage"); - } else { - throw new CloudRuntimeException("Tried to patch unknown type of system vm"); - } - } - - protected boolean patchSpecialVM(VDI vdi, String vmname, String vmtype) { - // patch special vm here, domr, domp - VBD vbd = null; - Connection conn = getConnection(); - try { - Host host = Host.getByUuid(conn, _host.uuid); - - Set vms = host.getResidentVMs(conn); - - for (VM vm : vms) { - VM.Record vmrec = null; - try { - vmrec = vm.getRecord(conn); - } catch (Exception e) { - String msg = "VM.getRecord failed due to " + e.toString() + " " + e.getMessage(); - s_logger.warn(msg); - continue; - } - if (vmrec.isControlDomain) { - - VBD.Record vbdr = new VBD.Record(); - vbdr.VM = vm; - vbdr.VDI = vdi; - vbdr.bootable = false; - vbdr.userdevice = getUnusedDeviceNum(vm); - vbdr.unpluggable = true; - vbdr.mode = Types.VbdMode.RW; - vbdr.type = Types.VbdType.DISK; - - vbd = VBD.create(conn, vbdr); - - vbd.plug(conn); - - String device = vbd.getDevice(conn); - - return patchspecialvm(vmname, device, vmtype); - } - } - - } catch (XenAPIException e) { - String msg = "patchSpecialVM faile on " + _host.uuid + " due to " + e.toString(); - s_logger.warn(msg, e); - } catch (Exception e) { - String msg = "patchSpecialVM faile on " + _host.uuid + " due to " + e.getMessage(); - s_logger.warn(msg, e); - } finally { - if (vbd != null) { - try { - if (vbd.getCurrentlyAttached(conn)) { - vbd.unplug(conn); - } - vbd.destroy(conn); - } catch (XmlRpcException e) { - String msg = "Catch XmlRpcException due to " + e.getMessage(); - s_logger.warn(msg, e); - } catch (XenAPIException e) { - String msg = "Catch XenAPIException due to " + e.toString(); - s_logger.warn(msg, e); - } - - } - } - return false; - } - - protected boolean patchspecialvm(String vmname, String device, String vmtype) { - String result = callHostPlugin("vmops", "patchdomr", "vmname", vmname, "vmtype", vmtype, "device", "/dev/" + device); - if (result == null || result.isEmpty()) - return false; - return true; - } -*/ - } diff --git a/core/src/com/cloud/storage/DiskOfferingVO.java b/core/src/com/cloud/storage/DiskOfferingVO.java index 591f609fd67..4c52e1bc9d3 100644 --- a/core/src/com/cloud/storage/DiskOfferingVO.java +++ b/core/src/com/cloud/storage/DiskOfferingVO.java @@ -120,6 +120,21 @@ public class DiskOfferingVO implements DiskOffering { this.systemUse = systemUse; this.customized = customized; } + + //domain specific offerings constructor (null domainId implies public offering) + public DiskOfferingVO(String name, String displayText, boolean mirrored, String tags, boolean recreatable, boolean useLocalStorage, boolean systemUse, boolean customized, Long domainId) { + this.domainId = null; + this.type = Type.Service; + this.name = name; + this.displayText = displayText; + this.mirrored = mirrored; + this.tags = tags; + this.recreatable = recreatable; + this.useLocalStorage = useLocalStorage; + this.systemUse = systemUse; + this.customized = customized; + this.domainId = domainId; + } @Override public long getId() { diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java index df1683b11b1..f18c81f0372 100755 --- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java +++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java @@ -224,7 +224,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S protected Answer execute(final DeleteTemplateCommand cmd) { String relativeTemplatePath = cmd.getTemplatePath(); String parent = _parent; - + if (relativeTemplatePath.startsWith(File.separator)) { relativeTemplatePath = relativeTemplatePath.substring(1); } @@ -234,24 +234,37 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } String absoluteTemplatePath = parent + relativeTemplatePath; File tmpltParent = new File(absoluteTemplatePath).getParentFile(); - - boolean result = true; - if (tmpltParent.exists()) { - File [] tmpltFiles = tmpltParent.listFiles(); - if (tmpltFiles != null) { - for (File f : tmpltFiles) { - f.delete(); - } - } - - result = _storage.delete(tmpltParent.getAbsolutePath()); - } - - if (result) { - return new Answer(cmd, true, null); - } else { - return new Answer(cmd, false, "Failed to delete file"); - } + if (!tmpltParent.exists()) { + return new Answer(cmd, false, "template parent directory " + tmpltParent.getName() + + " doesn't exist, Template path ( " + relativeTemplatePath + " ) is wrong"); + } + File[] tmpltFiles = tmpltParent.listFiles(); + if (tmpltFiles == null || tmpltFiles.length == 0) { + return new Answer(cmd, false, "No files under template parent directory " + tmpltParent.getName() + + " Template path ( " + relativeTemplatePath + " ) is wrong"); + } + boolean found = false; + for (File f : tmpltFiles) { + if (f.getName().equals("template.properties")) { + found = true; + break; + } + } + if (!found) { + return new Answer(cmd, false, "Can not find template.properties, Template path ( " + relativeTemplatePath + + " ) is wrong"); + } + for (File f : tmpltFiles) { + if( !f.delete() ) { + return new Answer(cmd, false, "Unable to delete file " + f.getName() + + " Template path ( " + relativeTemplatePath + " ) is wrong"); + } + } + if ( !tmpltParent.delete() ) { + return new Answer(cmd, false, "Unable to delete directory " + tmpltParent.getName() + + " Template path ( " + relativeTemplatePath + " ) is wrong"); + } + return new Answer(cmd, true, null); } protected long getUsedSize() { diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index 6586e7a5ce0..9a21cc4f108 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -63,9 +63,6 @@ def setup_iscsi(session, args): txt = '' return txt -@echo -def execute_script(session, args): - return "" @echo def getvncport(session, args): @@ -130,21 +127,6 @@ def setIptables(session, args): return txt -@echo -def patchdomr(session, args): - vmname = args['vmname'] - vmtype = args['vmtype'] - device = args['device'] - try: - cmd = ["/bin/bash", "/opt/xensource/bin/prepsystemvm.sh", "-l", vmname, "-t", vmtype, "-d", device] - txt = util.pread2(cmd) - txt = 'success' - except: - util.SMlog(" patch domr failed " ) - txt = '' - - return txt - @echo def pingdomr(session, args): host = args['host'] @@ -1077,5 +1059,5 @@ def network_rules(session, args): if __name__ == "__main__": - XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats, "getvncport": getvncport, "getgateway": getgateway, "getnetwork": getnetwork, "preparemigration": preparemigration, "setIptables": setIptables, "patchdomr": patchdomr, "pingdomr": pingdomr, "pingxenserver": pingxenserver, "ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword, "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile, "networkUsage": networkUsage, "network_rules":network_rules, "can_bridge_firewall":can_bridge_firewall, "default_network_rules":default_network_rules, "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn}) + XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats, "getvncport": getvncport, "getgateway": getgateway, "getnetwork": getnetwork, "preparemigration": preparemigration, "setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver, "ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword, "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile, "networkUsage": networkUsage, "network_rules":network_rules, "can_bridge_firewall":can_bridge_firewall, "default_network_rules":default_network_rules, "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn}) diff --git a/server/src/com/cloud/acl/DomainChecker.java b/server/src/com/cloud/acl/DomainChecker.java index 95dca17171b..7af3f8b42d8 100644 --- a/server/src/com/cloud/acl/DomainChecker.java +++ b/server/src/com/cloud/acl/DomainChecker.java @@ -25,6 +25,8 @@ import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.exception.PermissionDeniedException; +import com.cloud.offering.DiskOffering; +import com.cloud.offering.ServiceOffering; import com.cloud.storage.LaunchPermissionVO; import com.cloud.storage.dao.LaunchPermissionDao; import com.cloud.template.VirtualMachineTemplate; @@ -100,6 +102,100 @@ public class DomainChecker extends AdapterBase implements SecurityChecker { return checkAccess(account, entity); } + @Override + public boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException + { + if(account == null || dof.getDomainId() == null) + {//public offering + return true; + } + else + { + //admin has all permissions + if(account.getType() == Account.ACCOUNT_TYPE_ADMIN) + { + return true; + } + //if account is normal user or domain admin + //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for disk offering) + else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) + { + if(account.getDomainId() == dof.getDomainId()) + { + return true; //disk offering and account at exact node + } + else + { + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + if(domainRecord != null) + { + while(true) + { + if(domainRecord.getId() == dof.getDomainId()) + { + //found as a child + return true; + } + if(domainRecord.getParent() != null) + domainRecord = _domainDao.findById(domainRecord.getParent()); + else + break; + } + } + } + } + } + //not found + return false; + } + + @Override + public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException + { + if(account == null || so.getDomainId() == null) + {//public offering + return true; + } + else + { + //admin has all permissions + if(account.getType() == Account.ACCOUNT_TYPE_ADMIN) + { + return true; + } + //if account is normal user or domain admin + //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for service offering) + else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) + { + if(account.getDomainId() == so.getDomainId()) + { + return true; //service offering and account at exact node + } + else + { + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + if(domainRecord != null) + { + while(true) + { + if(domainRecord.getId() == so.getDomainId()) + { + //found as a child + return true; + } + if(domainRecord.getParent() != null) + domainRecord = _domainDao.findById(domainRecord.getParent()); + else + break; + } + } + } + } + } + //not found + return false; + } + @Override public boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException { if(account == null || zone.getDomainId() == null){//public zone diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 71767e63c32..0261d12a9a9 100644 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -382,9 +382,16 @@ public class AlertManagerImpl implements AlertManager { Map> capacityDcTypeMap = new HashMap>(); for (CapacityVO capacity : capacityList) { - long dataCenterId = capacity.getDataCenterId(); + long dataCenterId = capacity.getDataCenterId(); + Long podId = capacity.getPodId(); short type = capacity.getCapacityType(); - String key = "dc" + dataCenterId + "t" + type; + String key = null; + if((type == CapacityVO.CAPACITY_TYPE_PUBLIC_IP) || (type == CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE)){ + key = "dc" + dataCenterId + "t" + type; + } else { + key = "pod" + podId + "t" + type; + } + List list = capacityDcTypeMap.get(key); if (list == null) { list = new ArrayList(); @@ -399,7 +406,8 @@ public class AlertManagerImpl implements AlertManager { double usedCapacity = 0d; CapacityVO cap = capacities.get(0); short capacityType = cap.getCapacityType(); - long dataCenterId = cap.getDataCenterId(); + long dataCenterId = cap.getDataCenterId(); + Long podId = cap.getPodId(); for (CapacityVO capacity : capacities) { totalCapacity += capacity.getTotalCapacity(); @@ -409,7 +417,12 @@ public class AlertManagerImpl implements AlertManager { double capacityPct = (usedCapacity / totalCapacity); double thresholdLimit = 1.0; DataCenterVO dcVO = _dcDao.findById(dataCenterId); - String dcName = ((dcVO == null) ? "unknown" : dcVO.getName()); + String dcName = ((dcVO == null) ? "unknown" : dcVO.getName()); + String podName = ""; + if( podId != null){ + HostPodVO pod = _podDao.findById(podId); + podName = ((pod == null) ? "unknown" : pod.getName()); + } String msgSubject = ""; String msgContent = ""; String totalStr = ""; @@ -420,28 +433,28 @@ public class AlertManagerImpl implements AlertManager { switch (capacityType) { case CapacityVO.CAPACITY_TYPE_MEMORY: thresholdLimit = _memoryCapacityThreshold; - msgSubject = "System Alert: Low Available Memory in availablity zone " + dcName; + msgSubject = "System Alert: Low Available Memory in pod "+podName+" of availablity zone " + dcName; totalStr = formatBytesToMegabytes(totalCapacity); usedStr = formatBytesToMegabytes(usedCapacity); msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)"; break; case CapacityVO.CAPACITY_TYPE_CPU: thresholdLimit = _cpuCapacityThreshold; - msgSubject = "System Alert: Low Unallocated CPU in availablity zone " + dcName; + msgSubject = "System Alert: Low Unallocated CPU in pod "+podName+" of availablity zone " + dcName; totalStr = _dfWhole.format(totalCapacity); usedStr = _dfWhole.format(usedCapacity); msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)"; break; case CapacityVO.CAPACITY_TYPE_STORAGE: thresholdLimit = _storageCapacityThreshold; - msgSubject = "System Alert: Low Available Storage in availablity zone " + dcName; + msgSubject = "System Alert: Low Available Storage in pod "+podName+" of availablity zone " + dcName; totalStr = formatBytesToMegabytes(totalCapacity); usedStr = formatBytesToMegabytes(usedCapacity); msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)"; break; case CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED: thresholdLimit = _storageAllocCapacityThreshold; - msgSubject = "System Alert: Remaining unallocated Storage is low in availablity zone " + dcName; + msgSubject = "System Alert: Remaining unallocated Storage is low in pod "+podName+" of availablity zone " + dcName; totalStr = formatBytesToMegabytes(totalCapacity); usedStr = formatBytesToMegabytes(usedCapacity); msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)"; @@ -455,7 +468,7 @@ public class AlertManagerImpl implements AlertManager { break; case CapacityVO.CAPACITY_TYPE_PRIVATE_IP: thresholdLimit = _privateIPCapacityThreshold; - msgSubject = "System Alert: Number of unallocated private IPs is low in availablity zone " + dcName; + msgSubject = "System Alert: Number of unallocated private IPs is low in pod "+podName+" of availablity zone " + dcName; totalStr = Double.toString(totalCapacity); usedStr = Double.toString(usedCapacity); msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)"; diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 73a9df94469..b2a2be27dd9 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -420,7 +420,7 @@ public class ApiDBUtils { } public static VolumeVO findVolumeById(Long volumeId) { - return _volumeDao.findById(volumeId); + return _volumeDao.findByIdIncludingRemoved(volumeId); } public static DataCenterVO findZoneById(Long zoneId) { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 4c8252be2d9..edeb70b087d 100644 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -345,6 +345,10 @@ public class ApiResponseHelper implements ResponseGenerator { offeringResponse.setOfferHa(offering.getOfferHA()); offeringResponse.setUseVirtualNetwork(offering.getGuestIpType().equals(GuestIpType.Virtualized)); offeringResponse.setTags(offering.getTags()); + if(offering.getDomainId() != null){ + offeringResponse.setDomain(ApiDBUtils.findDomainById(offering.getDomainId()).getName()); + offeringResponse.setDomainId(offering.getDomainId()); + } offeringResponse.setObjectName("serviceoffering"); return offeringResponse; @@ -374,20 +378,17 @@ public class ApiResponseHelper implements ResponseGenerator { snapshotResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); } - VolumeVO volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId()); + VolumeVO volume = findVolumeById(snapshot.getVolumeId()); String snapshotTypeStr = Type.values()[snapshot.getSnapshotType()].name(); snapshotResponse.setSnapshotType(snapshotTypeStr); snapshotResponse.setVolumeId(snapshot.getVolumeId()); - snapshotResponse.setVolumeName(volume.getName()); - snapshotResponse.setVolumeType(volume.getVolumeType().name()); + if( volume != null ) { + snapshotResponse.setVolumeName(volume.getName()); + snapshotResponse.setVolumeType(volume.getVolumeType().name()); + } snapshotResponse.setCreated(snapshot.getCreated()); snapshotResponse.setName(snapshot.getName()); snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId())); - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("snapshot", snapshot.getId()); - if (asyncJob != null) { - snapshotResponse.setJobId(asyncJob.getId()); - snapshotResponse.setJobStatus(asyncJob.getStatus()); - } snapshotResponse.setObjectName("snapshot"); return snapshotResponse; } @@ -427,12 +428,6 @@ public class ApiResponseHelper implements ResponseGenerator { } userVmResponse.setId(userVm.getId()); - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_instance", userVm.getId()); - if (asyncJob != null) { - userVmResponse.setJobId(asyncJob.getId()); - userVmResponse.setJobStatus(asyncJob.getStatus()); - } - userVmResponse.setName(userVm.getHostName()); userVmResponse.setCreated(userVm.getCreated()); userVmResponse.setIpAddress(userVm.getPrivateIpAddress()); @@ -558,12 +553,6 @@ public class ApiResponseHelper implements ResponseGenerator { // the moment } - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob(instanceType, vm.getId()); - if (asyncJob != null) { - vmResponse.setJobId(asyncJob.getId()); - vmResponse.setJobStatus(asyncJob.getStatus()); - } - vmResponse.setZoneId(vm.getDataCenterId()); vmResponse.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName()); vmResponse.setDns1(vm.getDns1()); @@ -882,12 +871,6 @@ public class ApiResponseHelper implements ResponseGenerator { VolumeResponse volResponse = new VolumeResponse(); volResponse.setId(volume.getId()); - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("volume", volume.getId()); - if (asyncJob != null) { - volResponse.setJobId(asyncJob.getId()); - volResponse.setJobStatus(asyncJob.getStatus()); - } - if (volume.getName() != null) { volResponse.setName(volume.getName()); } else { @@ -1119,12 +1102,6 @@ public class ApiResponseHelper implements ResponseGenerator { } userVmResponse.setId(userVm.getId()); - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_instance", userVm.getId()); - if (asyncJob != null) { - userVmResponse.setJobId(asyncJob.getId()); - userVmResponse.setJobStatus(asyncJob.getStatus()); - } - userVmResponse.setName(userVm.getHostName()); userVmResponse.setCreated(userVm.getCreated()); @@ -1332,12 +1309,6 @@ public class ApiResponseHelper implements ResponseGenerator { // the moment } - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob(instanceType, vm.getId()); - if (asyncJob != null) { - vmResponse.setJobId(asyncJob.getId()); - vmResponse.setJobStatus(asyncJob.getStatus()); - } - // for console proxies, add the active sessions if (systemVM instanceof ConsoleProxyVO) { ConsoleProxyVO proxy = (ConsoleProxyVO) systemVM; @@ -1392,7 +1363,7 @@ public class ApiResponseHelper implements ResponseGenerator { } @Override - public Volume findVolumeById(Long volumeId) { + public VolumeVO findVolumeById(Long volumeId) { return ApiDBUtils.findVolumeById(volumeId); } @@ -1535,12 +1506,6 @@ public class ApiResponseHelper implements ResponseGenerator { templateResponse.setSize(templateSize); } - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_template", template.getId()); - if (asyncJob != null) { - templateResponse.setJobId(asyncJob.getId()); - templateResponse.setJobStatus(asyncJob.getStatus()); - } - templateResponse.setObjectName("template"); responses.add(templateResponse); } @@ -1921,12 +1886,12 @@ public class ApiResponseHelper implements ResponseGenerator { response.setPasswordEnabled(template.getEnablePassword()); response.setCrossZones(template.isCrossZones()); - Volume volume = null; + VolumeVO volume = null; if (snapshotId != null) { Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId); - volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId()); + volume = findVolumeById(snapshot.getVolumeId()); } else { - volume = ApiDBUtils.findVolumeById(volumeId); + volume = findVolumeById(volumeId); } VMTemplateHostVO templateHostRef = ApiDBUtils.findTemplateHostRef(template.getId(), volume.getDataCenterId()); @@ -2077,12 +2042,6 @@ public class ApiResponseHelper implements ResponseGenerator { isoResponse.setSize(isoSize); } - AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_template", iso.getId()); - if(asyncJob != null) { - isoResponse.setJobId(asyncJob.getId()); - isoResponse.setJobStatus(asyncJob.getStatus()); - } - isoResponse.setObjectName("iso"); isoResponses.add(isoResponse); } diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index dba8252ea3b..4a307839a64 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -380,9 +380,6 @@ public class ApiServer implements HttpRequestHandler { } BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmdObj; - if (objectId != null) { - objectId = asyncCmd.getInstanceId(); - } if (userId != null) { params.put("ctxUserId", userId.toString()); @@ -400,7 +397,7 @@ public class ApiServer implements HttpRequestHandler { } AsyncJobVO job = new AsyncJobVO(); - job.setInstanceId(asyncCmd.getInstanceId()); + job.setInstanceId((objectId == null) ? asyncCmd.getInstanceId() : objectId); job.setInstanceType(asyncCmd.getInstanceType()); job.setUserId(userId); if (account != null) { @@ -439,7 +436,7 @@ public class ApiServer implements HttpRequestHandler { return; } - // Using maps might possibly be more efficient if the set is large enough but for now, we'll just n squared + // Using maps might possibly be more efficient if the set is large enough but for now, we'll just do a // comparison of two lists. Either way, there shouldn't be too many async jobs active for the account. for (AsyncJob job : jobs) { if (job.getInstanceId() == null) continue; diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index cad2d478858..f05e478226a 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -26,6 +26,8 @@ import com.cloud.dc.HostPodVO; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.offering.DiskOffering; +import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.user.Account; @@ -56,9 +58,10 @@ public interface ConfigurationManager extends Manager { * @param localStorageRequired * @param offerHA * @param useVirtualNetwork + * @param domainId * @return ID */ - ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags); + ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, Long domainId); @@ -152,5 +155,10 @@ public interface ConfigurationManager extends Manager { void checkAccess(Account caller, DataCenter zone) throws PermissionDeniedException; - + + void checkServiceOfferingAccess(Account caller, ServiceOffering so) + throws PermissionDeniedException; + + void checkDiskOfferingAccess(Account caller, DiskOffering dof) + throws PermissionDeniedException; } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 35949b11b41..20f418602df 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1115,6 +1115,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to create service offering " + name + ": specify the memory value between 1 and 2147483647"); } + //check if valid domain + if(cmd.getDomainId() != null){ + DomainVO domain = _domainDao.findById(cmd.getDomainId()); + if(domain == null) + throw new InvalidParameterValueException("Please specify a valid domain id"); + } + boolean localStorageRequired = false; String storageType = cmd.getStorageType(); if (storageType == null) { @@ -1138,18 +1145,18 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } return createServiceOffering(userId, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), - localStorageRequired, offerHA, useVirtualNetwork, cmd.getTags()); + localStorageRequired, offerHA, useVirtualNetwork, cmd.getTags(),cmd.getDomainId()); } @Override - public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags) { + public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, Long domainId) { String networkRateStr = _configDao.getValue("network.throttling.rate"); String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtualized : NetworkOffering.GuestIpType.DirectSingle; tags = cleanupTags(tags); - ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, false); + ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, false,domainId); if ((offering = _serviceOfferingDao.persist(offering)) != null) { saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_CREATE, "Successfully created new service offering with name: " + name + ".", "soId=" + offering.getId(), "name=" + name, "numCPUs=" + cpu, "ram=" + ramSize, "cpuSpeed=" + speed, @@ -1159,7 +1166,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return null; } } - + @Override public ServiceOffering updateServiceOffering(UpdateServiceOfferingCmd cmd) { String displayText = cmd.getDisplayText(); @@ -1169,7 +1176,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura // String tags = cmd.getTags(); Boolean useVirtualNetwork = cmd.getUseVirtualNetwork(); Long userId = UserContext.current().getUserId(); - + Long domainId = cmd.getDomainId(); + if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); } @@ -1179,8 +1187,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (offeringHandle == null) { throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + id); } - - boolean updateNeeded = (name != null || displayText != null || ha != null || useVirtualNetwork != null); + + boolean updateNeeded = (name != null || displayText != null || ha != null || useVirtualNetwork != null || domainId != null); if (!updateNeeded) { return _serviceOfferingDao.findById(id); } @@ -1204,6 +1212,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura offering.setGuestIpType(guestIpType); } + if (domainId != null){ + offering.setDomainId(domainId); + } // if (tags != null) // { // if (tags.trim().isEmpty() && offeringHandle.getTags() == null) @@ -1229,7 +1240,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (_serviceOfferingDao.update(id, offering)) { offering = _serviceOfferingDao.findById(id); saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully updated service offering with name: " + offering.getName() + ".", "soId=" + offering.getId(), "name=" + offering.getName(), - "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags()); + "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags(), "domainId=" + offering.getDomainId()); return offering; } else { return null; @@ -1280,6 +1291,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String name = cmd.getDiskOfferingName(); String displayText = cmd.getDisplayText(); // String tags = cmd.getTags(); + Long domainId = cmd.getDomainId(); //Check if diskOffering exists DiskOfferingVO diskOfferingHandle = _diskOfferingDao.findById(diskOfferingId); @@ -1303,6 +1315,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura diskOffering.setDisplayText(displayText); } + if (domainId != null){ + diskOffering.setDomainId(domainId); + } + // if (tags != null) // { // if (tags.trim().isEmpty() && diskOfferingHandle.getTags() == null) @@ -1327,7 +1343,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (_diskOfferingDao.update(diskOfferingId, diskOffering)) { saveConfigurationEvent(UserContext.current().getUserId(), null, EventTypes.EVENT_DISK_OFFERING_EDIT, "Successfully updated disk offering with name: " + diskOffering.getName() + ".", "doId=" + diskOffering.getId(), "name=" + diskOffering.getName(), - "displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags()); + "displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags(),"domainId="+cmd.getDomainId()); return _diskOfferingDao.findById(diskOfferingId); } else { return null; @@ -2311,7 +2327,41 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return deleteVlanAndPublicIpRange(userId, vlanDbId); } + + @Override + public void checkDiskOfferingAccess(Account caller, DiskOffering dof) throws PermissionDeniedException { + for (SecurityChecker checker : _secChecker) { + if (checker.checkAccess(caller, dof)) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Access granted to " + caller + " to disk offering:" + dof.getId() + " by " + checker.getName()); + } + return; + }else{ + throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName()); + } + } + + assert false : "How can all of the security checkers pass on checking this caller?"; + throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to disk offering:" + dof.getId()); + } + @Override + public void checkServiceOfferingAccess(Account caller, ServiceOffering so) throws PermissionDeniedException { + for (SecurityChecker checker : _secChecker) { + if (checker.checkAccess(caller, so)) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Access granted to " + caller + " to service offering:" + so.getId() + " by " + checker.getName()); + } + return; + }else{ + throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName()); + } + } + + assert false : "How can all of the security checkers pass on checking this caller?"; + throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to service offering:" + so.getId()); + } + @Override public void checkAccess(Account caller, DataCenter zone) throws PermissionDeniedException { for (SecurityChecker checker : _secChecker) { diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 53685efad9a..47e5b75ed7f 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1196,6 +1196,16 @@ public class ManagementServerImpl implements ManagementServer { throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId); } + if(offering.getDomainId() == null){ + //do nothing as offering is public + }else{ + if(userAccount != null){ + _configMgr.checkServiceOfferingAccess(userAccount, offering);//user deploying his own vm + }else{ + _configMgr.checkServiceOfferingAccess(ctxAccount, offering); + } + } + VMTemplateVO template = _templateDao.findById(templateId); // Make sure a valid template ID was specified if (template == null) { @@ -1220,6 +1230,18 @@ public class ManagementServerImpl implements ManagementServer { throw new InvalidParameterValueException("Please specify a valid disk offering ID."); } + if(diskOffering != null){ + if(diskOffering.getDomainId() == null){ + //do nothing as offering is public + }else{ + if(userAccount != null){ + _configMgr.checkDiskOfferingAccess(userAccount, diskOffering);//user deploying his own vm + }else{ + _configMgr.checkDiskOfferingAccess(ctxAccount, diskOffering); + } + } + } + if (isIso) { /*iso template doesn;t have hypervisor type, temporarily set it's type as user specified, pass it to storage allocator */ template.setHypervisorType(HypervisorType.getType(cmd.getHypervisor())); @@ -1592,17 +1614,71 @@ public class ManagementServerImpl implements ManagementServer { return _userAccountDao.search(sc, searchFilter); } + + //This method is used for permissions check for both disk and service offerings + private boolean isPermissible(Long accountDomainId, Long offeringDomainId){ + + if(accountDomainId == offeringDomainId) + return true; // account and service offering in same domain + + DomainVO domainRecord = _domainDao.findById(accountDomainId); + + if(domainRecord != null){ + while(true){ + if(domainRecord.getId() == offeringDomainId) + return true; + + //try and move on to the next domain + if(domainRecord.getParent() != null) + domainRecord = _domainDao.findById(domainRecord.getParent()); + else + break; + } + } + + return false; + } @Override public List searchForServiceOfferings(ListServiceOfferingsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException { - Filter searchFilter = new Filter(ServiceOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + + //Note + //The list method for offerings is being modified in accordance with discussion with Will/Kevin + //For now, we will be listing the following based on the usertype + //1. For root, we will list all offerings + //2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way till root + Filter searchFilter = new Filter(ServiceOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _offeringsDao.createSearchCriteria(); + Account account = UserContext.current().getAccount(); Object name = cmd.getServiceOfferingName(); Object id = cmd.getId(); Object keyword = cmd.getKeyword(); Long vmId = cmd.getVirtualMachineId(); - + Long domainId = cmd.getDomainId(); + + //Keeping this logic consistent with domain specific zones + //if a domainId is provided, we just return the so associated with this domain + if(domainId != null){ + if(account.getType() == Account.ACCOUNT_TYPE_ADMIN){ + return _offeringsDao.findServiceOfferingByDomainId(domainId);//no perm check + }else{ + //check if the user's domain == so's domain || user's domain is a child of so's domain + if(isPermissible(account.getDomainId(), domainId)){ + //perm check succeeded + return _offeringsDao.findServiceOfferingByDomainId(domainId); + }else{ + throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account:"+account.getAccountName()+" does not fall in the same domain hierarchy as the service offering"); + } + } + } + + //For non-root users + if((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)){ + return searchServiceOfferingsInternal(account, name, id, vmId, keyword, searchFilter); + } + + //for root users, the existing flow if (keyword != null) { SearchCriteria ssc = _offeringsDao.createSearchCriteria(); ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -1610,8 +1686,6 @@ public class ManagementServerImpl implements ManagementServer { sc.addAnd("name", SearchCriteria.Op.SC, ssc); } else if (vmId != null) { - Account account = UserContext.current().getAccount(); - UserVmVO vmInstance = _userVmDao.findById(vmId); if ((vmInstance == null) || (vmInstance.getRemoved() != null)) { throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); @@ -1642,6 +1716,80 @@ public class ManagementServerImpl implements ManagementServer { return _offeringsDao.search(sc, searchFilter); } + private List searchServiceOfferingsInternal(Account account, Object name, Object id, Long vmId, Object keyword, Filter searchFilter){ + + //it was decided to return all offerings for the user's domain, and everything above till root (for normal user or domain admin) + //list all offerings belonging to this domain, and all of its parents + //check the parent, if not null, add offerings for that parent to list + List sol = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + boolean includePublicOfferings = true; + if(domainRecord != null) + { + while(true){ + SearchCriteria sc = _offeringsDao.createSearchCriteria(); + + if (keyword != null) { + includePublicOfferings = false; + SearchCriteria ssc = _offeringsDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } else if (vmId != null) { + includePublicOfferings = false; + UserVmVO vmInstance = _userVmDao.findById(vmId); + if ((vmInstance == null) || (vmInstance.getRemoved() != null)) { + throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); + } + if ((account != null) && !isAdmin(account.getType())) { + if (account.getId() != vmInstance.getAccountId()) { + throw new PermissionDeniedException("unable to find a virtual machine with id " + vmId + " for this account"); + } + } + + ServiceOfferingVO offering = _offeringsDao.findById(vmInstance.getServiceOfferingId()); + sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId()); + + // Only return offerings with the same Guest IP type and storage pool preference + sc.addAnd("guestIpType", SearchCriteria.Op.EQ, offering.getGuestIpType()); + sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage()); + } + + if (id != null) { + includePublicOfferings = false; + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + if (name != null) { + includePublicOfferings = false; + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + } + sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); + + //for this domain + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId()); + + //search and add for this domain + sol.addAll(_offeringsDao.search(sc, searchFilter)); + + //try and move on to the next domain + if(domainRecord.getParent() != null) + domainRecord = _domainDao.findById(domainRecord.getParent()); + else + break;//now we got all the offerings for this user/dom adm + } + }else{ + s_logger.error("Could not find the domainId for account:"+account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:"+account.getAccountName()); + } + + //add all the public offerings to the sol list before returning + if(includePublicOfferings) + sol.addAll(_offeringsDao.findPublicServiceOfferings()); + + return sol; + } @Override public List searchForClusters(ListClustersCmd cmd) { Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); @@ -4202,17 +4350,106 @@ public class ManagementServerImpl implements ManagementServer { return accountNames; } + private List searchDiskOfferingsInternal(Account account, Object name, Object id, Object keyword, Filter searchFilter){ + //it was decided to return all offerings for the user's domain, and everything above till root (for normal user or domain admin) + //list all offerings belonging to this domain, and all of its parents + //check the parent, if not null, add offerings for that parent to list + List dol = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + boolean includePublicOfferings = true; + if(domainRecord != null) + { + while(true){ + SearchBuilder sb = _diskOfferingDao.createSearchBuilder(); + + sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + + SearchCriteria sc = sb.create(); + if (keyword != null) { + includePublicOfferings = false; + SearchCriteria ssc = _diskOfferingDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (name != null) { + includePublicOfferings = false; + sc.setParameters("name", "%" + name + "%"); + } + + if (id != null) { + includePublicOfferings = false; + sc.setParameters("id", id); + } + + //for this domain + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId()); + + //search and add for this domain + dol.addAll(_diskOfferingDao.search(sc, searchFilter)); + + //try and move on to the next domain + if(domainRecord.getParent() != null) + domainRecord = _domainDao.findById(domainRecord.getParent()); + else + break;//now we got all the offerings for this user/dom adm + } + }else{ + s_logger.error("Could not find the domainId for account:"+account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:"+account.getAccountName()); + } + + //add all the public offerings to the sol list before returning + if(includePublicOfferings) + dol.addAll(_diskOfferingDao.findPublicDiskOfferings()); + + return dol; + + } + @Override public List searchForDiskOfferings(ListDiskOfferingsCmd cmd) { + //Note + //The list method for offerings is being modified in accordance with discussion with Will/Kevin + //For now, we will be listing the following based on the usertype + //1. For root, we will list all offerings + //2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way till root + Filter searchFilter = new Filter(DiskOfferingVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchBuilder sb = _diskOfferingDao.createSearchBuilder(); // SearchBuilder and SearchCriteria are now flexible so that the search builder can be built with all possible // search terms and only those with criteria can be set. The proper SQL should be generated as a result. + Account account = UserContext.current().getAccount(); Object name = cmd.getDiskOfferingName(); Object id = cmd.getId(); Object keyword = cmd.getKeyword(); - + Long domainId = cmd.getDomainId(); + //Keeping this logic consistent with domain specific zones + //if a domainId is provided, we just return the disk offering associated with this domain + if(domainId != null){ + if(account.getType() == Account.ACCOUNT_TYPE_ADMIN){ + return _diskOfferingDao.listByDomainId(domainId);//no perm check + }else{ + //check if the user's domain == do's domain || user's domain is a child of so's domain + if(isPermissible(account.getDomainId(), domainId)){ + //perm check succeeded + return _diskOfferingDao.listByDomainId(domainId); + }else{ + throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account:"+account.getAccountName()+" does not fall in the same domain hierarchy as the disk offering"); + } + } + } + + //For non-root users + if((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)){ + return searchDiskOfferingsInternal(account, name, id, keyword, searchFilter); + } + + //For root users, preserving existing flow sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java index d4e48cfbe51..9591f6c8b57 100644 --- a/server/src/com/cloud/service/ServiceOfferingVO.java +++ b/server/src/com/cloud/service/ServiceOfferingVO.java @@ -72,6 +72,17 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.offerHA = offerHA; this.guestIpType = guestIpType; } + + public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId) { + super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse,false,domainId); + this.cpu = cpu; + this.ramSize = ramSize; + this.speed = speed; + this.rateMbps = rateMbps; + this.multicastRateMbps = multicastRateMbps; + this.offerHA = offerHA; + this.guestIpType = guestIpType; + } @Override public boolean getOfferHA() { @@ -145,5 +156,6 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering @Override public NetworkOffering.GuestIpType getGuestIpType() { return guestIpType; - } + } + } diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDao.java b/server/src/com/cloud/service/dao/ServiceOfferingDao.java index 3eee286fadb..9e823c2a01c 100644 --- a/server/src/com/cloud/service/dao/ServiceOfferingDao.java +++ b/server/src/com/cloud/service/dao/ServiceOfferingDao.java @@ -18,6 +18,8 @@ package com.cloud.service.dao; +import java.util.List; + import com.cloud.service.ServiceOfferingVO; import com.cloud.utils.db.GenericDao; @@ -26,5 +28,7 @@ import com.cloud.utils.db.GenericDao; */ public interface ServiceOfferingDao extends GenericDao { ServiceOfferingVO findByName(String name); - ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo); + ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo); + List findPublicServiceOfferings(); + List findServiceOfferingByDomainId(Long domainId); } diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java index 7d73f09161c..710c2c18520 100644 --- a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java +++ b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java @@ -25,6 +25,7 @@ import javax.persistence.EntityExistsException; import org.apache.log4j.Logger; +import com.cloud.dc.DataCenterVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; @@ -35,7 +36,11 @@ import com.cloud.utils.db.SearchCriteria; public class ServiceOfferingDaoImpl extends GenericDaoBase implements ServiceOfferingDao { protected static final Logger s_logger = Logger.getLogger(ServiceOfferingDaoImpl.class); - protected final SearchBuilder UniqueNameSearch; + protected final SearchBuilder UniqueNameSearch; + protected final SearchBuilder ServiceOfferingsByDomainIdSearch; + protected final SearchBuilder ServiceOfferingsByKeywordSearch; + protected final SearchBuilder PublicServiceOfferingSearch; + protected ServiceOfferingDaoImpl() { super(); @@ -43,6 +48,20 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase findServiceOfferingByDomainId(Long domainId){ + SearchCriteria sc = ServiceOfferingsByDomainIdSearch.create(); + sc.setParameters("domainId", domainId); + return listBy(sc); + } + + @Override + public List findPublicServiceOfferings(){ + SearchCriteria sc = PublicServiceOfferingSearch.create(); + sc.setParameters("system", false); + return listBy(sc); } } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 767327d85c6..5a840d2b551 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -1742,6 +1742,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag throw new InvalidParameterValueException("Please specify a valid disk offering."); } + if(diskOffering.getDomainId() == null){ + //do nothing as offering is public + }else{ + _configMgr.checkDiskOfferingAccess(account, diskOffering); + } + if(!validateVolumeSizeRange(diskOffering.getDiskSize()/1024)){//convert size from mb to gb for validation throw new InvalidParameterValueException("Invalid size for custom volume creation: " + size+" ,max volume size is:"+_maxVolumeSizeInGb); } diff --git a/server/src/com/cloud/storage/dao/DiskOfferingDao.java b/server/src/com/cloud/storage/dao/DiskOfferingDao.java index 0cfe20e3aea..70646ec7337 100644 --- a/server/src/com/cloud/storage/dao/DiskOfferingDao.java +++ b/server/src/com/cloud/storage/dao/DiskOfferingDao.java @@ -26,5 +26,6 @@ import com.cloud.utils.db.GenericDao; public interface DiskOfferingDao extends GenericDao { List listByDomainId(long domainId); List findPrivateDiskOffering(); + List findPublicDiskOfferings(); } diff --git a/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java b/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java index ae6f587d5fa..2e9c4591413 100644 --- a/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java +++ b/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java @@ -24,6 +24,7 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO.Type; import com.cloud.utils.db.Attribute; @@ -39,6 +40,7 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im private final SearchBuilder DomainIdSearch; private final SearchBuilder PrivateDiskOfferingSearch; + private final SearchBuilder PublicDiskOfferingSearch; private final Attribute _typeAttr; protected DiskOfferingDaoImpl() { @@ -50,6 +52,11 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im PrivateDiskOfferingSearch.and("diskSize", PrivateDiskOfferingSearch.entity().getDiskSize(), SearchCriteria.Op.EQ); PrivateDiskOfferingSearch.done(); + PublicDiskOfferingSearch = createSearchBuilder(); + PublicDiskOfferingSearch.and("domainId", PublicDiskOfferingSearch.entity().getDomainId(), SearchCriteria.Op.NULL); + PublicDiskOfferingSearch.and("system", PublicDiskOfferingSearch.entity().isSystemUse(), SearchCriteria.Op.EQ); + PublicDiskOfferingSearch.done(); + _typeAttr = _allAttributes.get("type"); } @@ -91,5 +98,12 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im } return super.executeList(sql, Type.Disk, params); + } + + @Override + public List findPublicDiskOfferings(){ + SearchCriteria sc = PublicDiskOfferingSearch.create(); + sc.setParameters("system", false); + return listBy(sc); } } diff --git a/ui/css/main.css b/ui/css/main.css index 724c8a097ff..74ae674d9df 100644 --- a/ui/css/main.css +++ b/ui/css/main.css @@ -1320,6 +1320,95 @@ a:hover { text-decoration:underline; } +.language_dropdownpanel { + width:103px; + height:19px; + float:left; + position:relative; + background:url(../images/language_bg.gif) no-repeat top left; + margin:-3px 0 0 8px; + display:inline; + padding:0; + cursor:pointer; + cursor:hand; +} + +.language_dropdownpanel:hover { + background:url(../images/language_bg_hover.gif) no-repeat top left; +} + +.language_dropdownpanel p { + width:auto; + height:auto; + float:left; + color:#FFF; + font-size:11px; + font-weight:normal; + text-align:left; + margin:4px 0 0 4px; + padding:0; +} + +.language_icon { + width: 12px; + height:11px; + float:left; + background:url(../images/language_icon.gif) no-repeat top left; + margin:4px 0 0 5px; + display:inline; + padding:0; +} + +.language_ddarrow { + width: 9px; + height:5px; + float:left; + background:url(../images/language_ddarrow.png) no-repeat top left; + margin:8px 0 0 5px; + display:inline; + padding:0; +} + +.language_dropdownbox { + width:105px; + height:auto; + position:absolute; + background:#FFF repeat top left; + border:1px solid #999; + margin:0; + padding:0 0 15px 0; + top:16px; + z-index:1010; +} + +.language_dropdownbox ul { + width:85px; + height:auto; + float:left; + list-style:none; + margin:5px 0 0 10px; + display:inline; + padding:0; +} + +.language_dropdownbox li { + width:80px; + height:auto; + float:left; + list-style:none; + margin:0px 0 0 0; + border-bottom:1px dashed #999; + color:#333; + font-size:11px; + font-weight:normal; + display:inline; + padding:6px 0 6px 3px; +} + +.language_dropdownbox li:hover { + background:#e9e9e9 repeat top left; +} + #main_contentpanel { min-width:960px; width:100%; diff --git a/ui/images/language_bg.gif b/ui/images/language_bg.gif new file mode 100644 index 00000000000..931feacb718 Binary files /dev/null and b/ui/images/language_bg.gif differ diff --git a/ui/images/language_bg_hover.gif b/ui/images/language_bg_hover.gif new file mode 100644 index 00000000000..54890508515 Binary files /dev/null and b/ui/images/language_bg_hover.gif differ diff --git a/ui/images/language_ddarrow.png b/ui/images/language_ddarrow.png new file mode 100644 index 00000000000..1c2519f8368 Binary files /dev/null and b/ui/images/language_ddarrow.png differ diff --git a/ui/images/language_icon.gif b/ui/images/language_icon.gif new file mode 100644 index 00000000000..5c5a74f232d Binary files /dev/null and b/ui/images/language_icon.gif differ diff --git a/ui/index.jsp b/ui/index.jsp index de626da15e2..81f7e91999b 100644 --- a/ui/index.jsp +++ b/ui/index.jsp @@ -126,6 +126,19 @@

,

+
+
+

International

+
+ +
+ @@ -138,57 +151,17 @@
  1. -
    - +
- + - - - - + + +
+
+ +
diff --git a/ui/jsp/event.jsp b/ui/jsp/event.jsp index ebfaeca3f12..a7da929c79f 100644 --- a/ui/jsp/event.jsp +++ b/ui/jsp/event.jsp @@ -120,4 +120,132 @@
- \ No newline at end of file + + + + + \ No newline at end of file diff --git a/ui/jsp/instance.jsp b/ui/jsp/instance.jsp index d67dca52091..fd38119e372 100644 --- a/ui/jsp/instance.jsp +++ b/ui/jsp/instance.jsp @@ -1353,3 +1353,60 @@ + + + + \ No newline at end of file diff --git a/ui/jsp/volume.jsp b/ui/jsp/volume.jsp index a095a0239e0..f1ee93b1c9e 100644 --- a/ui/jsp/volume.jsp +++ b/ui/jsp/volume.jsp @@ -717,3 +717,49 @@ + + + + \ No newline at end of file diff --git a/ui/scripts/cloud.core.account.js b/ui/scripts/cloud.core.account.js index da84d45740f..7c46cf50a69 100644 --- a/ui/scripts/cloud.core.account.js +++ b/ui/scripts/cloud.core.account.js @@ -19,6 +19,10 @@ var systemAccountId = 1; var adminAccountId = 2; +function accountGetSearchParams() { + return ""; +} + function afterLoadAccountJSP() { initDialog("dialog_resource_limits"); initDialog("dialog_disable_account"); @@ -60,15 +64,15 @@ function accountJsonToDetailsTab() { var $detailsTab = $("#right_panel_content").find("#tab_content_details"); $detailsTab.find("#grid_header_title").text(fromdb(jsonObj.name)); - $detailsTab.find("#id").text(noNull(jsonObj.id)); + $detailsTab.find("#id").text(fromdb(jsonObj.id)); $detailsTab.find("#role").text(toRole(jsonObj.accounttype)); $detailsTab.find("#account").text(fromdb(jsonObj.name)); $detailsTab.find("#domain").text(fromdb(jsonObj.domain)); - $detailsTab.find("#vm_total").text(noNull(jsonObj.vmtotal)); - $detailsTab.find("#ip_total").text(noNull(jsonObj.iptotal)); + $detailsTab.find("#vm_total").text(fromdb(jsonObj.vmtotal)); + $detailsTab.find("#ip_total").text(fromdb(jsonObj.iptotal)); $detailsTab.find("#bytes_received").text(convertBytes(jsonObj.receivedbytes)); $detailsTab.find("#bytes_sent").text(convertBytes(jsonObj.sentbytes)); - $detailsTab.find("#state").text(noNull(jsonObj.state)); + $detailsTab.find("#state").text(fromdb(jsonObj.state)); //actions *** var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); diff --git a/ui/scripts/cloud.core.alert.js b/ui/scripts/cloud.core.alert.js index 2355e7a5b86..4fc02e17f77 100644 --- a/ui/scripts/cloud.core.alert.js +++ b/ui/scripts/cloud.core.alert.js @@ -16,6 +16,10 @@ * */ +function alertGetSearchParams() { + return ""; +} + function afterLoadAlertJSP() { } diff --git a/ui/scripts/cloud.core.diskoffering.js b/ui/scripts/cloud.core.diskoffering.js index 588336c7adb..2e736973b19 100644 --- a/ui/scripts/cloud.core.diskoffering.js +++ b/ui/scripts/cloud.core.diskoffering.js @@ -16,6 +16,10 @@ * */ +function diskOfferingGetSearchParams() { + return ""; +} + function afterLoadDiskOfferingJSP() { var $detailsTab = $("#right_panel_content #tab_content_details"); initAddDiskOfferingButton($("#midmenu_add_link")); @@ -84,7 +88,7 @@ function initAddDiskOfferingButton($midmenuAddLink1) { var tags = trim(thisDialog.find("#add_disk_tags").val()); if(tags != null && tags.length > 0) - array1.push("&tags="+encodeURIComponent(tags)); + array1.push("&tags="+todb(tags)); $.ajax({ data: createURL("command=createDiskOffering&isMirrored=false" + array1.join("")), @@ -149,7 +153,7 @@ function doEditDiskOffering2($actionLink, $detailsTab, $midmenuItem1, $readonlyF array1.push("&displayText="+todb(displaytext)); var tags = $detailsTab.find("#tags_edit").val(); - array1.push("&tags="+encodeURIComponent(tags)); + array1.push("&tags="+todb(tags)); $.ajax({ data: createURL("command=updateDiskOffering&id="+id+array1.join("")), @@ -212,7 +216,7 @@ function diskOfferingJsonToDetailsTab() { } }); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); $thisTab.find("#name").text(fromdb(jsonObj.name)); diff --git a/ui/scripts/cloud.core.domain.js b/ui/scripts/cloud.core.domain.js index 3378bb8fe59..e87906a0eca 100644 --- a/ui/scripts/cloud.core.domain.js +++ b/ui/scripts/cloud.core.domain.js @@ -60,12 +60,12 @@ function drawNode(json, level, container) { var $treeNode = $("#domain_tree_node_template").clone(true); $treeNode.find("#domain_indent").css("marginLeft", (30*(level+1))); - $treeNode.attr("id", "domain_"+noNull(json.id)); + $treeNode.attr("id", "domain_"+fromdb(json.id)); $treeNode.data("jsonObj", json).data("domainLevel", level); - $treeNode.find("#domain_title_container").attr("id", "domain_title_container_"+noNull(json.id)); - $treeNode.find("#domain_expand_icon").attr("id", "domain_expand_icon_"+noNull(json.id)); - $treeNode.find("#domain_name").attr("id", "domain_name_"+noNull(json.id)).text(fromdb(json.name)); - $treeNode.find("#domain_children_container").attr("id", "domain_children_container_"+noNull(json.id)); + $treeNode.find("#domain_title_container").attr("id", "domain_title_container_"+fromdb(json.id)); + $treeNode.find("#domain_expand_icon").attr("id", "domain_expand_icon_"+fromdb(json.id)); + $treeNode.find("#domain_name").attr("id", "domain_name_"+fromdb(json.id)).text(fromdb(json.name)); + $treeNode.find("#domain_children_container").attr("id", "domain_children_container_"+fromdb(json.id)); container.append($treeNode.show()); return $treeNode; } diff --git a/ui/scripts/cloud.core.event.js b/ui/scripts/cloud.core.event.js index 1522d25d050..7a9b40daaac 100644 --- a/ui/scripts/cloud.core.event.js +++ b/ui/scripts/cloud.core.event.js @@ -16,6 +16,49 @@ * */ +function eventGetSearchParams() { + var moreCriteria = []; + + var $advancedSearchPopup = $("#advanced_search_popup"); + if (lastSearchType == "advanced_search" && $advancedSearchPopup.length > 0) { + var type = $advancedSearchPopup.find("#adv_search_type").val(); + if (type!=null && trim(type).length > 0) + moreCriteria.push("&type="+todb(type)); + + var level = $advancedSearchPopup.find("#adv_search_level").val(); + if (level!=null && level.length > 0) + moreCriteria.push("&level="+todb(level)); + + if ($advancedSearchPopup.find("#adv_search_domain_li").css("display") != "none") { + var domainId = $advancedSearchPopup.find("#adv_search_domain").val(); + if (domainId!=null && domainId.length > 0) + moreCriteria.push("&domainid="+todb(domainId)); + } + + if ($advancedSearchPopup.find("#adv_search_account_li").css("display") != "none") { + var account = $advancedSearchPopup.find("#adv_search_account").val(); + if (account!=null && account.length > 0) + moreCriteria.push("&account="+todb(account)); + } + + var startdate = $advancedSearchPopup.find("#adv_search_startdate").val(); + if (startdate!=null && startdate.length > 0) + moreCriteria.push("&startdate="+todb(startdate)); + + var enddate = $advancedSearchPopup.find("#adv_search_enddate").val(); + if (enddate!=null && enddate.length > 0) + moreCriteria.push("&enddate="+todb(enddate)); + } + else { + var searchInput = $("#basic_search").find("#search_input").val(); + if (lastSearchType == "basic_search" && searchInput != null && searchInput.length > 0) { + moreCriteria.push("&type="+todb(searchInput)); + } + } + + return moreCriteria.join(""); +} + function afterLoadEventJSP() { } @@ -55,7 +98,7 @@ function eventJsonToDetailsTab() { $thisTab.find("#tab_container").hide(); $thisTab.find("#tab_spinning_wheel").show(); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#username").text(fromdb(jsonObj.username)); $thisTab.find("#account").text(fromdb(jsonObj.account)); $thisTab.find("#type").text(fromdb(jsonObj.type)); diff --git a/ui/scripts/cloud.core.host.js b/ui/scripts/cloud.core.host.js index 4a8a8aef46c..56d93db2104 100644 --- a/ui/scripts/cloud.core.host.js +++ b/ui/scripts/cloud.core.host.js @@ -86,7 +86,7 @@ function hostJsonToDetailsTab() { $thisTab.find("#tab_container").hide(); $thisTab.find("#tab_spinning_wheel").show(); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); $thisTab.find("#name").text(fromdb(jsonObj.name)); diff --git a/ui/scripts/cloud.core.init.js b/ui/scripts/cloud.core.init.js index 0afa5e57d8f..c77ecaf172e 100644 --- a/ui/scripts/cloud.core.init.js +++ b/ui/scripts/cloud.core.init.js @@ -60,7 +60,7 @@ $(document).ready(function() { }); $("#leftmenu_account").bind("click", function(event) { selectLeftMenu($(this), false); - listMidMenuItems("listAccounts", "listaccountsresponse", "account", "jsp/account.jsp", afterLoadAccountJSP, accountToMidmenu, accountToRightPanel, getMidmenuId, false, "leftmenu_account"); + listMidMenuItems("listAccounts", accountGetSearchParams, "listaccountsresponse", "account", "jsp/account.jsp", afterLoadAccountJSP, accountToMidmenu, accountToRightPanel, getMidmenuId, false, "leftmenu_account"); return false; }); @@ -109,31 +109,31 @@ $(document).ready(function() { function buildSecondLevelNavigation() { // Instance sub menus - bindAndListMidMenuItems($("#leftmenu_instances_my_instances"), "listVirtualMachines&domainid="+g_domainid+"&account="+g_account, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); - bindAndListMidMenuItems($("#leftmenu_instances_all_instances"), "listVirtualMachines", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); - bindAndListMidMenuItems($("#leftmenu_instances_running_instances"), "listVirtualMachines&state=Running", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); - bindAndListMidMenuItems($("#leftmenu_instances_stopped_instances"), "listVirtualMachines&state=Stopped", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); - bindAndListMidMenuItems($("#leftmenu_instances_destroyed_instances"), "listVirtualMachines&state=Destroyed", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); + bindAndListMidMenuItems($("#leftmenu_instances_my_instances"), "listVirtualMachines&domainid="+g_domainid+"&account="+g_account, vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); + bindAndListMidMenuItems($("#leftmenu_instances_all_instances"), "listVirtualMachines", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); + bindAndListMidMenuItems($("#leftmenu_instances_running_instances"), "listVirtualMachines&state=Running", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); + bindAndListMidMenuItems($("#leftmenu_instances_stopped_instances"), "listVirtualMachines&state=Stopped", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); + bindAndListMidMenuItems($("#leftmenu_instances_destroyed_instances"), "listVirtualMachines&state=Destroyed", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); - bindAndListMidMenuItems($("#leftmenu_event"), "listEvents", "listeventsresponse", "event", "jsp/event.jsp", afterLoadEventJSP, eventToMidmenu, eventToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_alert"), "listAlerts", "listalertsresponse", "alert", "jsp/alert.jsp", afterLoadAlertJSP, alertToMidmenu, alertToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_volume"), "listVolumes", "listvolumesresponse", "volume", "jsp/volume.jsp", afterLoadVolumeJSP, volumeToMidmenu, volumeToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_snapshot"), "listSnapshots", "listsnapshotsresponse", "snapshot", "jsp/snapshot.jsp", afterLoadSnapshotJSP, snapshotToMidmenu, snapshotToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_ip"), "listPublicIpAddresses", "listpublicipaddressesresponse", "publicipaddress", "jsp/ipaddress.jsp", afterLoadIpJSP, ipToMidmenu, ipToRightPanel, ipGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_event"), "listEvents", eventGetSearchParams, "listeventsresponse", "event", "jsp/event.jsp", afterLoadEventJSP, eventToMidmenu, eventToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_alert"), "listAlerts", alertGetSearchParams, "listalertsresponse", "alert", "jsp/alert.jsp", afterLoadAlertJSP, alertToMidmenu, alertToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_volume"), "listVolumes", volumeGetSearchParams, "listvolumesresponse", "volume", "jsp/volume.jsp", afterLoadVolumeJSP, volumeToMidmenu, volumeToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_snapshot"), "listSnapshots", snapshotGetSearchParams, "listsnapshotsresponse", "snapshot", "jsp/snapshot.jsp", afterLoadSnapshotJSP, snapshotToMidmenu, snapshotToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_ip"), "listPublicIpAddresses", ipGetSearchParams, "listpublicipaddressesresponse", "publicipaddress", "jsp/ipaddress.jsp", afterLoadIpJSP, ipToMidmenu, ipToRightPanel, ipGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_my_template"), "listTemplates&templatefilter=self", "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_featured_template"), "listTemplates&templatefilter=featured", "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_community_template"), "listTemplates&templatefilter=community", "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_my_template"), "listTemplates&templatefilter=self", templateGetSearchParams, "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_featured_template"), "listTemplates&templatefilter=featured", templateGetSearchParams, "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_community_template"), "listTemplates&templatefilter=community", templateGetSearchParams, "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_my_iso"), "listIsos&isofilter=self", "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_featured_iso"), "listIsos&isofilter=featured", "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_community_iso"), "listIsos&isofilter=community", "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_my_iso"), "listIsos&isofilter=self", isoGetSearchParams, "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_featured_iso"), "listIsos&isofilter=featured", isoGetSearchParams, "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_community_iso"), "listIsos&isofilter=community", isoGetSearchParams, "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_service_offering"), "listServiceOfferings", "listserviceofferingsresponse", "serviceoffering", "jsp/serviceoffering.jsp", afterLoadServiceOfferingJSP, serviceOfferingToMidmenu, serviceOfferingToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_disk_offering"), "listDiskOfferings", "listdiskofferingsresponse", "diskoffering", "jsp/diskoffering.jsp", afterLoadDiskOfferingJSP, diskOfferingToMidmenu, diskOfferingToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_service_offering"), "listServiceOfferings", serviceOfferingGetSearchParams, "listserviceofferingsresponse", "serviceoffering", "jsp/serviceoffering.jsp", afterLoadServiceOfferingJSP, serviceOfferingToMidmenu, serviceOfferingToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_disk_offering"), "listDiskOfferings", diskOfferingGetSearchParams, "listdiskofferingsresponse", "diskoffering", "jsp/diskoffering.jsp", afterLoadDiskOfferingJSP, diskOfferingToMidmenu, diskOfferingToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_virtual_router"), "listRouters", "listroutersresponse", "router", "jsp/router.jsp", afterLoadRouterJSP, routerToMidmenu, routerToRightPanel, getMidmenuId, false); - bindAndListMidMenuItems($("#leftmenu_submenu_systemvm"), "listSystemVms", "listsystemvmsresponse", "systemvm", "jsp/systemvm.jsp", afterLoadSystemVmJSP, systemvmToMidmenu, systemvmToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_virtual_router"), "listRouters", routerGetSearchParams, "listroutersresponse", "router", "jsp/router.jsp", afterLoadRouterJSP, routerToMidmenu, routerToRightPanel, getMidmenuId, false); + bindAndListMidMenuItems($("#leftmenu_submenu_systemvm"), "listSystemVms", systemVmGetSearchParams, "listsystemvmsresponse", "systemvm", "jsp/systemvm.jsp", afterLoadSystemVmJSP, systemvmToMidmenu, systemvmToRightPanel, getMidmenuId, false); $("#leftmenu_global_setting").bind("click", function(event) { selectLeftSubMenu($(this)); @@ -210,6 +210,147 @@ $(document).ready(function() { return; } + //basic search + $("#basic_search").find("#search_input").unbind("keypress").bind("keypress", function(event) { + event.stopPropagation(); + if(event.keyCode == keycode_Enter) { + event.preventDefault(); + var params = $("#middle_menu_pagination").data("params"); + if(params == null) + return; + lastSearchType = "basic_search"; + listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, 1); + } + }); + + //advanced search + $("#advanced_search_icon").unbind("click").bind("click", function(event) { + var $advancedSearch = $("#advanced_search_template").clone().attr("id", "advanced_search_popup"); + + $advancedSearch.unbind("click").bind("click", function(event) { + var $target = $(event.target); + var targetId = $target.attr("id"); + if(targetId == "advanced_search_close") { + $(this).hide(); + return false; + } + else if(targetId == "adv_search_button") { + var params = $("#middle_menu_pagination").data("params"); + if(params == null) + return; + lastSearchType = "advanced_search"; + $("#basic_search").find("#search_input").val(""); + listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, 1); + $(this).hide(); + return false; + } + return true; + }); + + $advancedSearch.unbind("keypress").bind("keypress", function(event) { + event.stopPropagation(); + if(event.keyCode == keycode_Enter) { + event.preventDefault(); + $(this).find("#adv_search_button").click(); + } + }); + + if(isAdmin()) + $advancedSearch.find("#adv_search_domain_li, #adv_search_account_li, #adv_search_pod_li").show(); + else + $advancedSearch.find("#adv_search_domain_li, #adv_search_account_li, #adv_search_pod_li").hide(); + + var zoneSelect = $advancedSearch.find("#adv_search_zone"); + if(zoneSelect.length>0) { //if zone dropdown is found on Advanced Search dialog + $.ajax({ + data: createURL("command=listZones&available=true"), + dataType: "json", + success: function(json) { + var zones = json.listzonesresponse.zone; + zoneSelect.empty(); + zoneSelect.append(""); + if (zones != null && zones.length > 0) { + for (var i = 0; i < zones.length; i++) { + zoneSelect.append(""); + } + } + } + }); + + var podSelect = $advancedSearch.find("#adv_search_pod").empty(); + var podLabel = $advancedSearch.find("#adv_search_pod_label"); + if(podSelect.length>0 && $advancedSearch.find("#adv_search_pod_li").css("display")!="none") { + zoneSelect.bind("change", function(event) { + var zoneId = $(this).val(); + if (zoneId == null || zoneId.length == 0) { + podLabel.css("color", "gray"); + podSelect.attr("disabled", "disabled"); + podSelect.empty(); + } else { + podLabel.css("color", "black"); + podSelect.removeAttr("disabled"); + $.ajax({ + data: createURL("command=listPods&zoneId="+zoneId+""), + dataType: "json", + async: false, + success: function(json) { + var pods = json.listpodsresponse.pod; + podSelect.empty(); + if (pods != null && pods.length > 0) { + for (var i = 0; i < pods.length; i++) { + podSelect.append(""); + } + } + } + }); + } + return false; + }); + + zoneSelect.change(); + } + } + + var domainSelect = $advancedSearch.find("#adv_search_domain"); + if(domainSelect.length>0 && $advancedSearch.find("#adv_search_domain_li").css("display")!="none") { + var domainSelect = domainSelect.empty(); + $.ajax({ + data: createURL("command=listDomains&available=true"), + dataType: "json", + success: function(json) { + var domains = json.listdomainsresponse.domain; + if (domains != null && domains.length > 0) { + for (var i = 0; i < domains.length; i++) { + domainSelect.append(""); + } + } + } + }); + } + + var vmSelect = $advancedSearch.find("#adv_search_vm"); + if(vmSelect.length>0) { + vmSelect.empty(); + vmSelect.append(""); + $.ajax({ + data: createURL("command=listVirtualMachines"), + dataType: "json", + success: function(json) { + var items = json.listvirtualmachinesresponse.virtualmachine; + if (items != null && items.length > 0) { + for (var i = 0; i < items.length; i++) { + vmSelect.append(""); + } + } + } + }); + } + + $("#advanced_search_container").empty().append($advancedSearch.show()); + + return false; + }); + //pagination $("#middle_menu_pagination").unbind("clik").bind("click", function(event) { var params = $(this).data("params"); @@ -220,10 +361,10 @@ $(document).ready(function() { var targetId = $target.attr("id"); if(targetId == "midmenu_prevbutton") { - listMidMenuItems2(params.commandString, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page-1)); + listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page-1)); } else if(targetId == "midmenu_nextbutton") { - listMidMenuItems2(params.commandString, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page+1)); + listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page+1)); } return false; diff --git a/ui/scripts/cloud.core.instance.js b/ui/scripts/cloud.core.instance.js index c418aa4ad93..143fe719ecd 100644 --- a/ui/scripts/cloud.core.instance.js +++ b/ui/scripts/cloud.core.instance.js @@ -16,7 +16,44 @@ * */ -var $instanceSubMenuContainer; +function vmGetSearchParams() { + var moreCriteria = []; + + var $advancedSearchPopup = $("#advanced_search_popup"); + if (lastSearchType == "advanced_search" && $advancedSearchPopup.length > 0) { + var name = $advancedSearchPopup.find("#adv_search_name").val(); + if (name!=null && trim(name).length > 0) + moreCriteria.push("&name="+todb(name)); + + var state = $advancedSearchPopup.find("#adv_search_state").val(); + if (state!=null && state.length > 0) + moreCriteria.push("&state="+todb(state)); + + var zone = $advancedSearchPopup.find("#adv_search_zone").val(); + if (zone!=null && zone.length > 0) + moreCriteria.push("&zoneid="+todb(zone)); + + if ($advancedSearchPopup.find("#adv_search_domain_li").css("display") != "none") { + var domainId = $advancedSearchPopup.find("#adv_search_domain").val(); + if(domainId!=null && domainId.length > 0) + moreCriteria.push("&domainid="+todb(domainId)); + } + + if ($advancedSearchPopup.find("#adv_search_account_li").css("display") != "none") { + var account = $advancedSearchPopup.find("#adv_search_account").val(); + if(account!=null && account.length > 0) + moreCriteria.push("&account="+todb(account)); + } + } + else { + var searchInput = $("#basic_search").find("#search_input").val(); + if (lastSearchType == "basic_search" && searchInput != null && searchInput.length > 0) { + moreCriteria.push("&name="+todb(searchInput)); + } + } + + return moreCriteria.join(""); +} function instanceBuildSubMenu() { if (isAdmin() || isDomainAdmin()) { $("#leftmenu_instance_expandedbox").find("#leftmenu_instances_my_instances_container, #leftmenu_instances_all_instances_container, #leftmenu_instances_running_instances_container, #leftmenu_instances_stopped_instances_container, #leftmenu_instances_destroyed_instances_container ").show(); @@ -27,7 +64,8 @@ function instanceBuildSubMenu() { cache: false, data: createURL("command=listInstanceGroups"), dataType: "json", - success: function(json) { + success: function(json) { + $("#leftmenu_instance_group_container").empty(); var instancegroups = json.listinstancegroupsresponse.instancegroup; if(instancegroups!=null && instancegroups.length>0) { for(var i=0; i < instancegroups.length; i++) { @@ -42,8 +80,8 @@ function instanceBuildSubMenu() { function instanceBuildSubMenu2(label, commandString) { var $newSubMenu = $("#leftmenu_secondindent_template").clone(); $newSubMenu.find("#label").text(label); - bindAndListMidMenuItems($newSubMenu, commandString, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); - $instanceSubMenuContainer.append($newSubMenu.show()); + bindAndListMidMenuItems($newSubMenu, commandString, vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true); + $("#leftmenu_instance_group_container").append($newSubMenu.show()); } var $doTemplateNo, $doTemplateCustom,$doTemplateExisting; @@ -1327,9 +1365,9 @@ function vmJsonToDetailsTab(){ resetViewConsoleAction(jsonObj, $thisTab); setVmStateInRightPanel(jsonObj.state, $thisTab.find("#state")); - $thisTab.find("#ipAddress").text(noNull(jsonObj.ipaddress)); + $thisTab.find("#ipAddress").text(fromdb(jsonObj.ipaddress)); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#zoneName").text(fromdb(jsonObj.zonename)); var vmName = getVmName(jsonObj.name, jsonObj.displayname); @@ -1549,10 +1587,10 @@ var vmVolumeActionMap = { } function vmVolumeJSONToTemplate(json, $template) { - $template.attr("id","vm_volume_"+noNull(json.id)); + $template.attr("id","vm_volume_"+fromdb(json.id)); $template.data("jsonObj", json); $template.find("#title").text(fromdb(json.name)); - $template.find("#id").text(noNull(json.id)); + $template.find("#id").text(fromdb(json.id)); $template.find("#name").text(fromdb(json.name)); if (json.storagetype == "shared") $template.find("#type").text(fromdb(json.type) + " (shared storage)"); @@ -1608,7 +1646,7 @@ function vmRouterJSONToTemplate(jsonObj, $template) { resetViewConsoleAction(jsonObj, $template); setVmStateInRightPanel(fromdb(jsonObj.state), $template.find("#state")); - $template.find("#ipAddress").text(noNull(jsonObj.publicip)); + $template.find("#ipAddress").text(fromdb(jsonObj.publicip)); $template.find("#zonename").text(fromdb(jsonObj.zonename)); $template.find("#name").text(fromdb(jsonObj.name)); diff --git a/ui/scripts/cloud.core.ipaddress.js b/ui/scripts/cloud.core.ipaddress.js index 77d88766ac5..a68008d246c 100644 --- a/ui/scripts/cloud.core.ipaddress.js +++ b/ui/scripts/cloud.core.ipaddress.js @@ -16,6 +16,10 @@ * */ +function ipGetSearchParams() { + return ""; +} + function afterLoadIpJSP() { //***** switch between different tabs (begin) ******************************************************************** var tabArray = [$("#tab_details"), $("#tab_port_forwarding"), $("#tab_load_balancer"), $("#tab_vpn")]; @@ -755,8 +759,8 @@ function ipJsonToDetailsTab() { } }); - $thisTab.find("#grid_header_title").text(noNull(ipObj.ipaddress)); - $thisTab.find("#ipaddress").text(noNull(ipObj.ipaddress)); + $thisTab.find("#grid_header_title").text(fromdb(ipObj.ipaddress)); + $thisTab.find("#ipaddress").text(fromdb(ipObj.ipaddress)); $thisTab.find("#zonename").text(fromdb(ipObj.zonename)); $thisTab.find("#vlanname").text(fromdb(ipObj.vlanname)); setBooleanReadField(ipObj.issourcenat, $thisTab.find("#source_nat")); @@ -991,20 +995,20 @@ function ipClearPortForwardingTab() { } function portForwardingJsonToTemplate(jsonObj, $template) { - $template.attr("id", "portForwarding_" + noNull(jsonObj.id)).data("portForwardingId", noNull(jsonObj.id)); + $template.attr("id", "portForwarding_" + fromdb(jsonObj.id)).data("portForwardingId", fromdb(jsonObj.id)); - $template.find("#row_container #public_port").text(noNull(jsonObj.publicport)); - $template.find("#row_container_edit #public_port").text(noNull(jsonObj.publicport)); + $template.find("#row_container #public_port").text(fromdb(jsonObj.publicport)); + $template.find("#row_container_edit #public_port").text(fromdb(jsonObj.publicport)); - $template.find("#row_container #private_port").text(noNull(jsonObj.privateport)); - $template.find("#row_container_edit #private_port").val(noNull(jsonObj.privateport)); + $template.find("#row_container #private_port").text(fromdb(jsonObj.privateport)); + $template.find("#row_container_edit #private_port").val(fromdb(jsonObj.privateport)); $template.find("#row_container #protocol").text(fromdb(jsonObj.protocol)); $template.find("#row_container_edit #protocol").text(fromdb(jsonObj.protocol)); var vmName = getVmName(jsonObj.virtualmachinename, jsonObj.virtualmachinedisplayname); $template.find("#row_container #vm_name").text(vmName); - var virtualMachineId = noNull(jsonObj.virtualmachineid); + var virtualMachineId = fromdb(jsonObj.virtualmachineid); var $midmenuItem1 = $("#right_panel_content").data("$midmenuItem1"); if($midmenuItem1 == null) @@ -1012,8 +1016,8 @@ function portForwardingJsonToTemplate(jsonObj, $template) { var ipObj = $midmenuItem1.data("jsonObj"); if(ipObj == null) return; - var ipAddress = noNull(ipObj.ipaddress); - var IpDomainid = noNull(ipObj.domainid); + var ipAddress = fromdb(ipObj.ipaddress); + var IpDomainid = fromdb(ipObj.domainid); var IpAccount = fromdb(ipObj.account); var $vmSelect = $template.find("#row_container_edit #vm").empty(); @@ -1028,7 +1032,7 @@ function portForwardingJsonToTemplate(jsonObj, $template) { $spinningWheel.find("#description").text("Deleting...."); $spinningWheel.show(); $.ajax({ - data: createURL("command=deletePortForwardingRule&id="+noNull(jsonObj.id)), + data: createURL("command=deletePortForwardingRule&id="+fromdb(jsonObj.id)), dataType: "json", success: function(json) { $template.slideUp("slow", function(){ @@ -1148,7 +1152,7 @@ function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) { var instances = json.listvirtualmachinesresponse.virtualmachine; if (instances != null && instances.length > 0) { for (var i = 0; i < instances.length; i++) { - var html = $(""); + var html = $(""); $vmSelect.append(html); } } @@ -1163,7 +1167,7 @@ function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) { var instances = json.listvirtualmachinesresponse.virtualmachine; if (instances != null && instances.length > 0) { for (var i = 0; i < instances.length; i++) { - var html = $(""); + var html = $(""); $vmSelect.append(html); } } @@ -1180,17 +1184,17 @@ function ipClearLoadBalancerTab() { } function loadBalancerJsonToTemplate(jsonObj, $template) { - var loadBalancerId = noNull(jsonObj.id); + var loadBalancerId = fromdb(jsonObj.id); $template.attr("id", "loadBalancer_" + loadBalancerId).data("loadBalancerId", loadBalancerId); $template.find("#row_container #name").text(fromdb(jsonObj.name)); $template.find("#row_container_edit #name").val(fromdb(jsonObj.name)); - $template.find("#row_container #public_port").text(noNull(jsonObj.publicport)); - $template.find("#row_container_edit #public_port").text(noNull(jsonObj.publicport)); + $template.find("#row_container #public_port").text(fromdb(jsonObj.publicport)); + $template.find("#row_container_edit #public_port").text(fromdb(jsonObj.publicport)); - $template.find("#row_container #private_port").text(noNull(jsonObj.privateport)); - $template.find("#row_container_edit #private_port").val(noNull(jsonObj.privateport)); + $template.find("#row_container #private_port").text(fromdb(jsonObj.privateport)); + $template.find("#row_container_edit #private_port").val(fromdb(jsonObj.privateport)); $template.find("#row_container #algorithm").text(fromdb(jsonObj.algorithm)); $template.find("#row_container_edit #algorithm").val(fromdb(jsonObj.algorithm)); @@ -1440,13 +1444,13 @@ function refreshCreateLoadBalancerRow() { function lbVmObjToTemplate(obj, $template) { $template.find("#vm_name").text(obj.vmName); - $template.find("#vm_private_ip").text(noNull(obj.vmPrivateIp)); + $template.find("#vm_private_ip").text(fromdb(obj.vmPrivateIp)); $template.find("#remove_link").bind("click", function(event){ var $spinningWheel = $template.find("#spinning_wheel"); $spinningWheel.show(); $.ajax({ - data: createURL("command=removeFromLoadBalancerRule&id="+noNull(obj.loadBalancerId)+"&virtualmachineid="+noNull(obj.vmId)), + data: createURL("command=removeFromLoadBalancerRule&id="+fromdb(obj.loadBalancerId)+"&virtualmachineid="+fromdb(obj.vmId)), dataType: "json", success: function(json) { var lbJSON = json.removefromloadbalancerruleresponse; diff --git a/ui/scripts/cloud.core.iso.js b/ui/scripts/cloud.core.iso.js index 37c9cb5e5ca..de4bdc96b08 100644 --- a/ui/scripts/cloud.core.iso.js +++ b/ui/scripts/cloud.core.iso.js @@ -21,6 +21,10 @@ var xsToolsIsoId = 200; var g_zoneIds = []; var g_zoneNames = []; +function isoGetSearchParams() { + return ""; +} + function afterLoadIsoJSP() { var $detailsTab = $("#right_panel_content #tab_content_details"); @@ -52,7 +56,7 @@ function afterLoadIsoJSP() { array1.push("&displayText="+todb(desc)); var url = trim(thisDialog.find("#add_iso_url").val()); - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); var zoneId = thisDialog.find("#add_iso_zone").val(); array1.push("&zoneId="+zoneId); @@ -225,7 +229,7 @@ function isoJsonToDetailsTab() { $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#zonename").text(fromdb(jsonObj.zonename)); $thisTab.find("#name").text(fromdb(jsonObj.name)); @@ -234,7 +238,7 @@ function isoJsonToDetailsTab() { $thisTab.find("#displaytext").text(fromdb(jsonObj.displaytext)); $thisTab.find("#displaytext_edit").val(fromdb(jsonObj.displaytext)); $thisTab.find("#ostypename").text(fromdb(jsonObj.ostypename)); - $thisTab.find("#ostypename_edit").val(noNull(jsonObj.ostypeid)); + $thisTab.find("#ostypename_edit").val(fromdb(jsonObj.ostypeid)); $thisTab.find("#account").text(fromdb(jsonObj.account)); $thisTab.find("#domain").text(fromdb(jsonObj.domain)); diff --git a/ui/scripts/cloud.core.js b/ui/scripts/cloud.core.js index d5f3ab8f158..a150b1fcc32 100644 --- a/ui/scripts/cloud.core.js +++ b/ui/scripts/cloud.core.js @@ -474,20 +474,6 @@ function hideDetailsTabActionSpinningWheel(id, inProcessText) { } } -/* -function handleAsyncJobFailInMidMenu(errorMsg, $midmenuItem1) { - $midmenuItem1.find("#content").removeClass("inaction"); - $midmenuItem1.find("#spinning_wheel").hide(); - $midmenuItem1.find("#info_icon").addClass("error").show(); - $midmenuItem1.find("#first_row").text("Adding failed"); - - if(errorMsg.length > 0) - $midmenuItem1.find("#second_row").text(fromdb(errorMsg)); - else - $midmenuItem1.find("#second_row").html(" "); -} -*/ - /* If Cancel button in dialog is clicked, action won't preceed. i.e. doActionToMidMenu() won't get called => highlight won't be removd from middle menu. @@ -568,6 +554,9 @@ function clearMiddleMenu() { $("#midmenu_container").empty(); $("#midmenu_action_link").hide(); clearAddButtonsOnTop(); + lastSearchType = null; + $("#basic_search").find("#search_input").val(""); + $("#advanced_search_container").empty(); $("#midmenu_prevbutton, #midmenu_nextbutton").hide(); $("#middle_menu_pagination").data("params", null); } @@ -926,9 +915,11 @@ function getMidmenuId(jsonObj) { return "midmenuItem_" + jsonObj.id; } -function listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, page) { +var lastSearchType; +function listMidMenuItems2(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, page) { var params = { "commandString": commandString, + "getSearchParamsFn": getSearchParamsFn, "jsonResponse1": jsonResponse1, "jsonResponse2": jsonResponse2, "toMidmenuFn": toMidmenuFn, @@ -949,7 +940,7 @@ function listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmen var count = 0; $.ajax({ cache: false, - data: createURL("command="+commandString+"&pagesize="+midmenuItemCount+"&page="+page), + data: createURL("command="+commandString+getSearchParamsFn()+"&pagesize="+midmenuItemCount+"&page="+page), dataType: "json", async: false, success: function(json) { @@ -986,7 +977,7 @@ function listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmen return count; } -function listMidMenuItems(commandString, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, leftmenuId) { +function listMidMenuItems(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, leftmenuId) { clearMiddleMenu(); showMiddleMenu(); $("#midmenu_container").hide(); @@ -1008,15 +999,15 @@ function listMidMenuItems(commandString, jsonResponse1, jsonResponse2, rightPane }); removeDialogs(); afterLoadRightPanelJSPFn(); - listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, 1); + listMidMenuItems2(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, 1); }); return false; } -function bindAndListMidMenuItems($leftmenu, commandString, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu) { +function bindAndListMidMenuItems($leftmenu, commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu) { $leftmenu.bind("click", function(event) { selectLeftSubMenu($(this)); - listMidMenuItems(commandString, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, $(this).attr("id")); + listMidMenuItems(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, $(this).attr("id")); return false; }); } @@ -1342,215 +1333,6 @@ function convertMilliseconds(string) { } } -/* -function drawGrid(items, submenuContent, template, fnJSONToTemplate) { - var grid = submenuContent.find("#grid_content").empty(); - if (items != null && items.length > 0) { - for (var i = 0; i < items.length; i++) { - var newTemplate = template.clone(true); - fnJSONToTemplate(items[i], newTemplate); - grid.append(newTemplate.show()); - } - setGridRowsTotal(submenuContent.find("#grid_rows_total"), items.length); - if(items.length < pageSize) - submenuContent.find("#nextPage_div").hide(); - else - submenuContent.find("#nextPage_div").show(); - } else { - setGridRowsTotal(submenuContent.find("#grid_rows_total"), null); - submenuContent.find("#nextPage_div").hide(); - } -} - -//listItems() function takes care of loading image, pagination -var items = []; -function listItems(submenuContent, commandString, jsonResponse1, jsonResponse2, template, fnJSONToTemplate ) { - if(currentPage==1) - submenuContent.find("#prevPage_div").hide(); - else - submenuContent.find("#prevPage_div").show(); - - submenuContent.find("#loading_gridtable").show(); - submenuContent.find("#pagination_panel").hide(); - - index = 0; - $.ajax({ - data: createURL(commandString), - dataType: "json", - async: false, - success: function(json) { - //IF jsonResponse1=="listaccountsresponse", jsonResponse2=="account", THEN json[jsonResponse1][jsonResponse2] == json.listaccountsresponse.account - items = json[jsonResponse1][jsonResponse2]; - drawGrid(items, submenuContent, template, fnJSONToTemplate); - submenuContent.find("#loading_gridtable").hide(); - submenuContent.find("#pagination_panel").show(); - }, - error: function(XMLHttpResponse) { - submenuContent.find("#loading_gridtable").hide(); - handleError(XMLHttpResponse, function() { - if(XMLHttpResponse.status == ERROR_VMOPS_ACCOUNT_ERROR) { - submenuContent.find("#grid_content").empty(); - setGridRowsTotal(submenuContent.find("#grid_rows_total"), null); - submenuContent.find("#nextPage_div").hide(); - } - submenuContent.find("#loading_gridtable").hide(); - submenuContent.find("#pagination_panel").show(); - }); - } - }); -} - - -//event binder -var currentPage = 1; -var pageSize = 50; //consistent with server-side -function submenuContentEventBinder(submenuContent, listFunction) { - submenuContent.find("#nextPage").bind("click", function(event){ - event.preventDefault(); - currentPage++; - listFunction(); - }); - - submenuContent.find("#prevPage").bind("click", function(event){ - event.preventDefault(); - currentPage--; - listFunction(); - }); - - submenuContent.find("#refresh").bind("click", function(event){ - event.preventDefault(); - currentPage=1; - listFunction(); - }); - - submenuContent.find("#search_button").bind("click", function(event) { - event.preventDefault(); - currentPage = 1; - listFunction(); - }); - - submenuContent.find("#adv_search_button").bind("click", function(event) { - event.preventDefault(); - currentPage = 1; - listFunction(); - submenuContent.find("#search_button").data("advanced", false); - submenuContent.find("#advanced_search").hide(); - }); - - submenuContent.find("#search_input").bind("keypress", function(event) { - if(event.keyCode == keycode_Enter) { - event.preventDefault(); - submenuContent.find("#search_button").click(); - } - }); - - submenuContent.find("#advanced_search").bind("keypress", function(event) { - if(event.keyCode == keycode_Enter) { - event.preventDefault(); - submenuContent.find("#adv_search_button").click(); - } - }); - - submenuContent.find("#advanced_search_close").bind("click", function(event) { - event.preventDefault(); - submenuContent.find("#search_button").data("advanced", false); - submenuContent.find("#advanced_search").hide(); - }); - - submenuContent.find("#advanced_search_link").bind("click", function(event) { - event.preventDefault(); - submenuContent.find("#search_button").data("advanced", true); - submenuContent.find("#advanced_search").show(); - }); - - var zoneSelect = submenuContent.find("#advanced_search #adv_search_zone"); - if(zoneSelect.length>0) { //if zone dropdown is found on Advanced Search dialog - $.ajax({ - data: createURL("command=listZones&available=true&response=json"), - dataType: "json", - success: function(json) { - var zones = json.listzonesresponse.zone; - zoneSelect.empty(); - zoneSelect.append(""); - if (zones != null && zones.length > 0) { - for (var i = 0; i < zones.length; i++) { - zoneSelect.append(""); - } - } - } - }); - - var podSelect = submenuContent.find("#advanced_search #adv_search_pod").empty(); - var podLabel = submenuContent.find("#advanced_search #adv_search_pod_label"); - if(podSelect.length>0 && isAdmin()) { //if pod dropdown is found on Advanced Search dialog and if its role is admin - zoneSelect.bind("change", function(event) { - var zoneId = $(this).val(); - if (zoneId == null || zoneId.length == 0) { - podLabel.css("color", "gray"); - podSelect.attr("disabled", "disabled"); - podSelect.empty(); - } else { - podLabel.css("color", "black"); - podSelect.removeAttr("disabled"); - $.ajax({ - data: createURL("command=listPods&zoneId="+zoneId+"&response=json"), - dataType: "json", - async: false, - success: function(json) { - var pods = json.listpodsresponse.pod; - podSelect.empty(); - if (pods != null && pods.length > 0) { - for (var i = 0; i < pods.length; i++) { - podSelect.append(""); - } - } - } - }); - } - return false; - }); - - zoneSelect.change(); - } - } - - var domainSelect = submenuContent.find("#advanced_search #adv_search_domain"); - if(domainSelect.length>0 && isAdmin()) { - var domainSelect = domainSelect.empty(); - $.ajax({ - data: createURL("command=listDomains&available=true&response=json"), - dataType: "json", - success: function(json) { - var domains = json.listdomainsresponse.domain; - if (domains != null && domains.length > 0) { - for (var i = 0; i < domains.length; i++) { - domainSelect.append(""); - } - } - } - }); - } - - var vmSelect = submenuContent.find("#advanced_search").find("#adv_search_vm"); - if(vmSelect.length>0) { - vmSelect.empty(); - vmSelect.append(""); - $.ajax({ - data: createURL("command=listVirtualMachines&response=json"), - dataType: "json", - success: function(json) { - var items = json.listvirtualmachinesresponse.virtualmachine; - if (items != null && items.length > 0) { - for (var i = 0; i < items.length; i++) { - vmSelect.append(""); - } - } - } - }); - } -} -*/ - // Validation functions function showError(isValid, field, errMsgField, errMsg) { if(isValid) { diff --git a/ui/scripts/cloud.core.pod.js b/ui/scripts/cloud.core.pod.js index 02b08e41960..424e7fa39a0 100644 --- a/ui/scripts/cloud.core.pod.js +++ b/ui/scripts/cloud.core.pod.js @@ -70,7 +70,7 @@ function podJsonToDetailsTab() { $thisTab.find("#tab_container").hide(); $thisTab.find("#tab_spinning_wheel").show(); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); $thisTab.find("#name").text(fromdb(jsonObj.name)); @@ -90,7 +90,7 @@ function podJsonToDetailsTab() { // hide network tab upon zone vlan var networkType; $.ajax({ - data: createURL("command=listZones&id="+noNull(jsonObj.zoneid)), + data: createURL("command=listZones&id="+fromdb(jsonObj.zoneid)), dataType: "json", async: false, success: function(json) { @@ -143,7 +143,7 @@ function podJsonToNetworkTab() { $thisTab.find("#tab_spinning_wheel").show(); $.ajax({ - data: createURL("command=listVlanIpRanges&zoneid="+noNull(jsonObj.zoneid)+"&podid="+noNull(jsonObj.id)), + data: createURL("command=listVlanIpRanges&zoneid="+fromdb(jsonObj.zoneid)+"&podid="+fromdb(jsonObj.id)), dataType: "json", success: function(json) { var items = json.listvlaniprangesresponse.vlaniprange; @@ -164,12 +164,12 @@ function podJsonToNetworkTab() { function podNetworkJsonToTemplate(jsonObj, template) { template.data("jsonObj", jsonObj); - template.attr("id", "pod_VLAN_"+noNull(jsonObj.id)).data("podVLANId", noNull(jsonObj.id)); + template.attr("id", "pod_VLAN_"+fromdb(jsonObj.id)).data("podVLANId", fromdb(jsonObj.id)); template.find("#grid_header_title").text(fromdb(jsonObj.description)); - template.find("#id").text(noNull(jsonObj.id)); + template.find("#id").text(fromdb(jsonObj.id)); template.find("#iprange").text(fromdb(jsonObj.description)); - template.find("#netmask").text(noNull(jsonObj.netmask)); - template.find("#gateway").text(noNull(jsonObj.gateway)); + template.find("#netmask").text(fromdb(jsonObj.netmask)); + template.find("#gateway").text(fromdb(jsonObj.gateway)); template.find("#podname").text(fromdb(jsonObj.podname)); var $actionLink = template.find("#network_action_link"); @@ -247,9 +247,9 @@ function refreshClsuterFieldInAddHostDialog(dialogAddHost, podId, clusterId) { if(items != null && items.length > 0) { for(var i=0; i" + fromdb(items[i].name) + ""); + clusterSelect.append(""); else - clusterSelect.append(""); + clusterSelect.append(""); } dialogAddHost.find("input[value=existing_cluster_radio]").attr("checked", true); } @@ -328,10 +328,10 @@ function initAddHostButton($button, currentPageInRightPanel, $leftmenuItem1) { array1.push("&podId="+podId); var username = trim($thisDialog.find("#host_username").val()); - array1.push("&username="+encodeURIComponent(username)); + array1.push("&username="+todb(username)); var password = trim($thisDialog.find("#host_password").val()); - array1.push("&password="+encodeURIComponent(password)); + array1.push("&password="+todb(password)); var newClusterName, existingClusterId; if(clusterRadio == "new_cluster_radio") { @@ -352,7 +352,7 @@ function initAddHostButton($button, currentPageInRightPanel, $leftmenuItem1) { url = "http://" + todb(hostname); else url = hostname; - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); //var $midmenuItem1 = beforeAddingMidMenuItem() ; @@ -521,11 +521,11 @@ function initAddPrimaryStorageButton($button, currentPageInRightPanel, $leftmenu var lun = trim($thisDialog.find("#add_pool_lun").val()); url = iscsiURL(server, iqn, lun); } - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); var tags = trim($thisDialog.find("#add_pool_tags").val()); if(tags != null && tags.length > 0) - array1.push("&tags="+encodeURIComponent(tags)); + array1.push("&tags="+todb(tags)); $.ajax({ data: createURL("command=createStoragePool" + array1.join("")), @@ -615,11 +615,11 @@ function initAddPodVLANButton($button, $leftmenuItem1) { array1.push("&zoneid=" + zoneId); array1.push("&podId=" + podId); array1.push("&forVirtualNetwork=false"); //direct VLAN - array1.push("&gateway="+encodeURIComponent(guestgateway)); - array1.push("&netmask="+encodeURIComponent(netmask)); - array1.push("&startip="+encodeURIComponent(startip)); + array1.push("&gateway="+todb(guestgateway)); + array1.push("&netmask="+todb(netmask)); + array1.push("&startip="+todb(startip)); if(endip != null && endip.length > 0) - array1.push("&endip="+encodeURIComponent(endip)); + array1.push("&endip="+todb(endip)); $.ajax({ data: createURL("command=createVlanIpRange" + array1.join("")), @@ -751,17 +751,17 @@ function doEditPod2($actionLink, $detailsTab, $midmenuItem1, $readonlyFields, $e if(newName != oldName) array1.push("&name="+todb(newName)); if(newCidr != oldCidr) - array1.push("&cidr="+encodeURIComponent(newCidr)); + array1.push("&cidr="+todb(newCidr)); if(newStartip != oldStartip) - array1.push("&startIp="+encodeURIComponent(newStartip)); + array1.push("&startIp="+todb(newStartip)); if(newEndip != oldEndip && newEndip != null && newEndip.length > 0) { if(newStartip == oldStartip) { - array1.push("&startIp="+encodeURIComponent(newStartip)); //startIp needs to be passed to updatePod API when endIp is passed to updatePod API. + array1.push("&startIp="+todb(newStartip)); //startIp needs to be passed to updatePod API when endIp is passed to updatePod API. } - array1.push("&endIp="+encodeURIComponent(newEndip)); + array1.push("&endIp="+todb(newEndip)); } if(newGateway != oldGateway && newGateway != null && newGateway.length > 0) - array1.push("&gateway="+encodeURIComponent(newGateway)); + array1.push("&gateway="+todb(newGateway)); if(array1.length > 0) { $.ajax({ diff --git a/ui/scripts/cloud.core.primarystorage.js b/ui/scripts/cloud.core.primarystorage.js index 2a2001e9056..a3b1dcee3aa 100644 --- a/ui/scripts/cloud.core.primarystorage.js +++ b/ui/scripts/cloud.core.primarystorage.js @@ -77,7 +77,7 @@ function primarystorageJsonToDetailsTab() { $thisTab.find("#tab_container").hide(); $thisTab.find("#tab_spinning_wheel").show(); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); $thisTab.find("#name").text(fromdb(jsonObj.name)); @@ -90,7 +90,7 @@ function primarystorageJsonToDetailsTab() { if (jsonObj.type == 'NetworkFilesystem') storageType = "NFS Share"; $thisTab.find("#type").text(fromdb(storageType)); - $thisTab.find("#ipaddress").text(noNull(jsonObj.ipaddress)); + $thisTab.find("#ipaddress").text(fromdb(jsonObj.ipaddress)); $thisTab.find("#path").text(fromdb(jsonObj.path)); $thisTab.find("#disksizetotal").text(convertBytes(jsonObj.disksizetotal)); $thisTab.find("#disksizeallocated").text(convertBytes(jsonObj.disksizeallocated)); @@ -240,7 +240,7 @@ function doEditPrimaryStorage2($actionLink, $detailsTab, $midmenuItem1, $readonl var array1 = []; var tags = $detailsTab.find("#tags_edit").val(); - array1.push("&tags="+encodeURIComponent(tags)); + array1.push("&tags="+todb(tags)); if(array1.length == 0) return; diff --git a/ui/scripts/cloud.core.resource.js b/ui/scripts/cloud.core.resource.js index 7430f799eb3..367a332ee29 100644 --- a/ui/scripts/cloud.core.resource.js +++ b/ui/scripts/cloud.core.resource.js @@ -320,11 +320,11 @@ function initAddPodShortcut() { var array1 = []; array1.push("&zoneId="+zoneId); array1.push("&name="+todb(name)); - array1.push("&cidr="+encodeURIComponent(cidr)); - array1.push("&startIp="+encodeURIComponent(startip)); + array1.push("&cidr="+todb(cidr)); + array1.push("&startIp="+todb(startip)); if (endip != null && endip.length > 0) - array1.push("&endIp="+encodeURIComponent(endip)); - array1.push("&gateway="+encodeURIComponent(gateway)); + array1.push("&endIp="+todb(endip)); + array1.push("&gateway="+todb(gateway)); $.ajax({ data: createURL("command=createPod"+array1.join("")), @@ -458,10 +458,10 @@ function initAddHostShortcut() { array1.push("&podid="+podId); var username = trim($thisDialog.find("#host_username").val()); - array1.push("&username="+encodeURIComponent(username)); + array1.push("&username="+todb(username)); var password = trim($thisDialog.find("#host_password").val()); - array1.push("&password="+encodeURIComponent(password)); + array1.push("&password="+todb(password)); var newClusterName, existingClusterId; if(clusterRadio == "new_cluster_radio") { @@ -482,7 +482,7 @@ function initAddHostShortcut() { url = "http://" + todb(hostname); else url = hostname; - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); //var $midmenuItem1 = beforeAddingMidMenuItem() ; @@ -751,32 +751,32 @@ function addZoneWizardSubmit($thisWizard) { moreCriteria.push("&name="+todb(name)); var dns1 = trim($thisWizard.find("#add_zone_dns1").val()); - moreCriteria.push("&dns1="+encodeURIComponent(dns1)); + moreCriteria.push("&dns1="+todb(dns1)); var dns2 = trim($thisWizard.find("#add_zone_dns2").val()); if (dns2 != null && dns2.length > 0) - moreCriteria.push("&dns2="+encodeURIComponent(dns2)); + moreCriteria.push("&dns2="+todb(dns2)); var internaldns1 = trim($thisWizard.find("#add_zone_internaldns1").val()); - moreCriteria.push("&internaldns1="+encodeURIComponent(internaldns1)); + moreCriteria.push("&internaldns1="+todb(internaldns1)); var internaldns2 = trim($thisWizard.find("#add_zone_internaldns2").val()); if (internaldns2 != null && internaldns2.length > 0) - moreCriteria.push("&internaldns2="+encodeURIComponent(internaldns2)); + moreCriteria.push("&internaldns2="+todb(internaldns2)); if($thisWizard.find("#step2").find("#add_zone_vlan_container").css("display") != "none") { var vlanStart = $thisWizard.find("#add_zone_startvlan").val(); if(vlanStart != null && vlanStart.length > 0) { var vlanEnd = $thisWizard.find("#add_zone_endvlan").val(); if (vlanEnd != null && vlanEnd.length > 0) - moreCriteria.push("&vlan=" + encodeURIComponent(vlanStart + "-" + vlanEnd)); + moreCriteria.push("&vlan=" + todb(vlanStart + "-" + vlanEnd)); else - moreCriteria.push("&vlan=" + encodeURIComponent(vlanStart)); + moreCriteria.push("&vlan=" + todb(vlanStart)); } } var guestcidraddress = trim($thisWizard.find("#add_zone_guestcidraddress").val()); - moreCriteria.push("&guestcidraddress="+encodeURIComponent(guestcidraddress)); + moreCriteria.push("&guestcidraddress="+todb(guestcidraddress)); if($thisWizard.find("#domain_dropdown_container").css("display") != "none") { var domainId = trim($thisWizard.find("#domain_dropdown").val()); @@ -825,11 +825,11 @@ function addZoneWizardSubmit($thisWizard) { var array1 = []; array1.push("&zoneId="+zoneId); array1.push("&name="+todb(name)); - array1.push("&cidr="+encodeURIComponent(cidr)); - array1.push("&startIp="+encodeURIComponent(startip)); + array1.push("&cidr="+todb(cidr)); + array1.push("&startIp="+todb(startip)); if (endip != null && endip.length > 0) - array1.push("&endIp="+encodeURIComponent(endip)); - array1.push("&gateway="+encodeURIComponent(gateway)); + array1.push("&endIp="+todb(endip)); + array1.push("&gateway="+todb(gateway)); $.ajax({ data: createURL("command=createPod"+array1.join("")), @@ -885,11 +885,11 @@ function addZoneWizardSubmit($thisWizard) { array1.push("&zoneid=" + zoneId); array1.push("&podId=" + podId); array1.push("&forVirtualNetwork=false"); //direct VLAN - array1.push("&gateway="+encodeURIComponent(guestgateway)); - array1.push("&netmask="+encodeURIComponent(netmask)); - array1.push("&startip="+encodeURIComponent(startip)); + array1.push("&gateway="+todb(guestgateway)); + array1.push("&netmask="+todb(netmask)); + array1.push("&startip="+todb(startip)); if(endip != null && endip.length > 0) - array1.push("&endip="+encodeURIComponent(endip)); + array1.push("&endip="+todb(endip)); $.ajax({ data: createURL("command=createVlanIpRange" + array1.join("")), @@ -936,7 +936,7 @@ function initUpdateConsoleCertButton($midMenuAddLink2) { var cert = trim($thisDialog.find("#update_cert").val()); $.ajax({ - data: createURL("command=uploadCustomCertificate&certificate="+encodeURIComponent(cert)), + data: createURL("command=uploadCustomCertificate&certificate="+todb(cert)), dataType: "json", success: function(json) { var jobId = json.uploadcustomcertificateresponse.jobid; @@ -1123,7 +1123,7 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel var lun = trim($thisDialog.find("#add_pool_lun").val()); url = iscsiURL(server, iqn, lun); } - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); var tags = trim($thisDialog.find("#add_pool_tags").val()); if(tags != null && tags.length > 0) diff --git a/ui/scripts/cloud.core.router.js b/ui/scripts/cloud.core.router.js index 346710e2db8..02024663f64 100644 --- a/ui/scripts/cloud.core.router.js +++ b/ui/scripts/cloud.core.router.js @@ -16,6 +16,10 @@ * */ +function routerGetSearchParams() { + return ""; +} + function afterLoadRouterJSP() { } diff --git a/ui/scripts/cloud.core.serviceoffering.js b/ui/scripts/cloud.core.serviceoffering.js index a7a8f72bd5e..3ff69220fc7 100644 --- a/ui/scripts/cloud.core.serviceoffering.js +++ b/ui/scripts/cloud.core.serviceoffering.js @@ -16,6 +16,10 @@ * */ +function serviceOfferingGetSearchParams() { + return ""; +} + function afterLoadServiceOfferingJSP() { var $detailsTab = $("#right_panel_content #tab_content_details"); @@ -84,7 +88,7 @@ function afterLoadServiceOfferingJSP() { var tags = trim(thisDialog.find("#add_service_tags").val()); if(tags != null && tags.length > 0) - array1.push("&tags="+encodeURIComponent(tags)); + array1.push("&tags="+todb(tags)); $.ajax({ data: createURL("command=createServiceOffering"+array1.join("")+"&response=json"), @@ -159,7 +163,7 @@ function doEditServiceOffering2($actionLink, $detailsTab, $midmenuItem1, $readon */ var tags = $detailsTab.find("#tags_edit").val(); - array1.push("&tags="+encodeURIComponent(tags)); + array1.push("&tags="+todb(tags)); $.ajax({ data: createURL("command=updateServiceOffering&id="+id+array1.join("")), @@ -221,7 +225,7 @@ function serviceOfferingJsonToDetailsTab() { } }); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); $thisTab.find("#name").text(fromdb(jsonObj.name)); diff --git a/ui/scripts/cloud.core.snapshot.js b/ui/scripts/cloud.core.snapshot.js index 67112a0bc61..1d214c11bdc 100644 --- a/ui/scripts/cloud.core.snapshot.js +++ b/ui/scripts/cloud.core.snapshot.js @@ -16,6 +16,10 @@ * */ +function snapshotGetSearchParams() { + return ""; +} + function afterLoadSnapshotJSP() { //initialize dialog initDialog("dialog_add_volume_from_snapshot"); @@ -85,7 +89,7 @@ function snapshotJsonToDetailsTab() { } }); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#name").text(fromdb(jsonObj.name)); $thisTab.find("#volume_name").text(fromdb(jsonObj.volumename)); $thisTab.find("#interval_type").text(fromdb(jsonObj.intervaltype)); diff --git a/ui/scripts/cloud.core.systemvm.js b/ui/scripts/cloud.core.systemvm.js index 4f26778298f..298687e9118 100644 --- a/ui/scripts/cloud.core.systemvm.js +++ b/ui/scripts/cloud.core.systemvm.js @@ -16,6 +16,10 @@ * */ + function systemVmGetSearchParams() { + return ""; + } + function afterLoadSystemVmJSP($midmenuItem1) { //hideMiddleMenu(); //systemvmToRightPanel($midmenuItem1); @@ -61,7 +65,7 @@ function systemvmJsonToDetailsTab() { resetViewConsoleAction(jsonObj, $thisTab); setVmStateInRightPanel(fromdb(jsonObj.state), $thisTab.find("#state")); - $thisTab.find("#ipAddress").text(noNull(jsonObj.publicip)); + $thisTab.find("#ipAddress").text(fromdb(jsonObj.publicip)); $thisTab.find("#state").text(fromdb(jsonObj.state)); $thisTab.find("#systemvmtype").text(toSystemVMTypeText(jsonObj.systemvmtype)); diff --git a/ui/scripts/cloud.core.template.js b/ui/scripts/cloud.core.template.js index 10c3287d983..5de25803486 100644 --- a/ui/scripts/cloud.core.template.js +++ b/ui/scripts/cloud.core.template.js @@ -21,6 +21,10 @@ var g_zoneIds = []; var g_zoneNames = []; +function templateGetSearchParams() { + return ""; +} + function afterLoadTemplateJSP() { var $detailsTab = $("#right_panel_content #tab_content_details"); @@ -84,7 +88,7 @@ function afterLoadTemplateJSP() { var $midmenuItem1 = beforeAddingMidMenuItem() ; $.ajax({ - data: createURL("command=registerTemplate&name="+todb(name)+"&displayText="+todb(desc)+"&url="+encodeURIComponent(url)+"&zoneid="+zoneId+"&ispublic="+isPublic+moreCriteria.join("")+"&format="+format+"&passwordEnabled="+password+"&osTypeId="+osType+"&hypervisor="+hypervisor+"&response=json"), + data: createURL("command=registerTemplate&name="+todb(name)+"&displayText="+todb(desc)+"&url="+todb(url)+"&zoneid="+zoneId+"&ispublic="+isPublic+moreCriteria.join("")+"&format="+format+"&passwordEnabled="+password+"&osTypeId="+osType+"&hypervisor="+hypervisor+"&response=json"), dataType: "json", success: function(json) { var items = json.registertemplateresponse.template; @@ -242,7 +246,7 @@ function templateJsonToDetailsTab() { $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#zonename").text(fromdb(jsonObj.zonename)); $thisTab.find("#name").text(fromdb(jsonObj.name)); diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js index 437b27ac8f6..0966c7cd7b2 100644 --- a/ui/scripts/cloud.core.volume.js +++ b/ui/scripts/cloud.core.volume.js @@ -16,6 +16,47 @@ * */ +function volumeGetSearchParams() { + var moreCriteria = []; + + var $advancedSearchPopup = $("#advanced_search_popup"); + if (lastSearchType == "advanced_search" && $advancedSearchPopup.length > 0) { + var name = $advancedSearchPopup.find("#adv_search_name").val(); + if (name!=null && trim(name).length > 0) + moreCriteria.push("&name="+todb(name)); + + var zone = $advancedSearchPopup.find("#adv_search_zone").val(); + if (zone!=null && zone.length > 0) + moreCriteria.push("&zoneId="+zone); + + if ($advancedSearchPopup.find("#adv_search_pod_li").css("display") != "none") { + var pod = $advancedSearchPopup.find("#adv_search_pod").val(); + if (pod!=null && pod.length > 0) + moreCriteria.push("&podId="+pod); + } + + if ($advancedSearchPopup.find("#adv_search_domain_li").css("display") != "none") { + var domainId = $advancedSearchPopup.find("#adv_search_domain").val(); + if (domainId!=null && domainId.length > 0) + moreCriteria.push("&domainid="+domainId); + } + + if ($advancedSearchPopup.find("#adv_search_account_li").css("display") != "none") { + var account = $advancedSearchPopup.find("#adv_search_account").val(); + if (account!=null && account.length > 0) + moreCriteria.push("&account="+account); + } + } + else { + var searchInput = $("#basic_search").find("#search_input").val(); + if (lastSearchType == "basic_search" && searchInput != null && searchInput.length > 0) { + moreCriteria.push("&name="+todb(searchInput)); + } + } + + return moreCriteria.join(""); +} + function afterLoadVolumeJSP() { initDialog("dialog_create_template", 400); initDialog("dialog_create_snapshot"); @@ -329,7 +370,7 @@ function volumeJsonToDetailsTab(){ } }); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#name").text(fromdb(jsonObj.name)); $thisTab.find("#zonename").text(fromdb(jsonObj.zonename)); $thisTab.find("#device_id").text(fromdb(jsonObj.deviceid)); @@ -394,7 +435,7 @@ function volumeJsonToSnapshotTab() { $.ajax({ cache: false, - data: createURL("command=listSnapshots&volumeid="+noNull(jsonObj.id)), + data: createURL("command=listSnapshots&volumeid="+fromdb(jsonObj.id)), dataType: "json", success: function(json) { var items = json.listsnapshotsresponse.snapshot; @@ -415,9 +456,9 @@ function volumeJsonToSnapshotTab() { function volumeSnapshotJSONToTemplate(jsonObj, template) { template.data("jsonObj", jsonObj); - template.attr("id", "volume_snapshot_"+noNull(jsonObj.id)).data("volumeSnapshotId", noNull(jsonObj.id)); + template.attr("id", "volume_snapshot_"+fromdb(jsonObj.id)).data("volumeSnapshotId", fromdb(jsonObj.id)); template.find("#grid_header_title").text(fromdb(jsonObj.name)); - template.find("#id").text(noNull(jsonObj.id)); + template.find("#id").text(fromdb(jsonObj.id)); template.find("#name").text(fromdb(jsonObj.name)); template.find("#volumename").text(fromdb(jsonObj.volumename)); template.find("#intervaltype").text(fromdb(jsonObj.intervaltype)); @@ -732,7 +773,7 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { } var thisLink; $.ajax({ - data: createURL("command=createSnapshotPolicy&intervaltype="+intervalType+"&schedule="+schedule+"&volumeid="+volumeId+"&maxsnaps="+max+"&timezone="+encodeURIComponent(timezone)), + data: createURL("command=createSnapshotPolicy&intervaltype="+intervalType+"&schedule="+schedule+"&volumeid="+volumeId+"&maxsnaps="+max+"&timezone="+todb(timezone)), dataType: "json", success: function(json) { thisDialog.dialog("close"); diff --git a/ui/scripts/cloud.core.zone.js b/ui/scripts/cloud.core.zone.js index 70f9bcb4ceb..8e3016000e0 100644 --- a/ui/scripts/cloud.core.zone.js +++ b/ui/scripts/cloud.core.zone.js @@ -96,7 +96,7 @@ function zoneJsonToDetailsTab() { $thisTab.find("#tab_container").hide(); $thisTab.find("#tab_spinning_wheel").show(); - $thisTab.find("#id").text(noNull(jsonObj.id)); + $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); $thisTab.find("#name").text(fromdb(jsonObj.name)); @@ -479,7 +479,7 @@ function initAddVLANButton($button, $leftmenuItem1) { var endip = trim($thisDialog.find("#add_publicip_vlan_endip").val()); $.ajax({ - data: createURL("command=createVlanIpRange&forVirtualNetwork="+type+"&zoneId="+zoneObj.id+vlan+scopeParams+"&gateway="+encodeURIComponent(gateway)+"&netmask="+encodeURIComponent(netmask)+"&startip="+encodeURIComponent(startip)+"&endip="+encodeURIComponent(endip)), + data: createURL("command=createVlanIpRange&forVirtualNetwork="+type+"&zoneId="+zoneObj.id+vlan+scopeParams+"&gateway="+todb(gateway)+"&netmask="+todb(netmask)+"&startip="+todb(startip)+"&endip="+todb(endip)), dataType: "json", success: function(json) { $thisDialog.find("#spinning_wheel").hide(); @@ -543,7 +543,7 @@ function initAddSecondaryStorageButton($button, $leftmenuItem1) { var url = nfsURL(nfs_server, path); $.ajax({ - data: createURL("command=addSecondaryStorage&zoneId="+zoneId+"&url="+encodeURIComponent(url)), + data: createURL("command=addSecondaryStorage&zoneId="+zoneId+"&url="+todb(url)), dataType: "json", success: function(json) { $thisDialog.find("#spinning_wheel").hide(); @@ -604,11 +604,11 @@ function initAddPodButton($button, $leftmenuItem1) { var array1 = []; array1.push("&zoneId="+zoneObj.id); array1.push("&name="+todb(name)); - array1.push("&cidr="+encodeURIComponent(cidr)); - array1.push("&startIp="+encodeURIComponent(startip)); + array1.push("&cidr="+todb(cidr)); + array1.push("&startIp="+todb(startip)); if (endip != null && endip.length > 0) - array1.push("&endIp="+encodeURIComponent(endip)); - array1.push("&gateway="+encodeURIComponent(gateway)); + array1.push("&endIp="+todb(endip)); + array1.push("&gateway="+todb(gateway)); $.ajax({ data: createURL("command=createPod"+array1.join("")), @@ -855,19 +855,19 @@ function doEditZone2($actionLink, $detailsTab, $leftmenuItem1, $readonlyFields, var dns1 = $detailsTab.find("#dns1_edit").val(); if(dns1 != jsonObj.dns1) - moreCriteria.push("&dns1="+encodeURIComponent(dns1)); + moreCriteria.push("&dns1="+todb(dns1)); var dns2 = $detailsTab.find("#dns2_edit").val(); if (dns2 != null && dns2.length > 0 && dns2 != jsonObj.dns2) - moreCriteria.push("&dns2="+encodeURIComponent(dns2)); + moreCriteria.push("&dns2="+todb(dns2)); var internaldns1 = $detailsTab.find("#internaldns1_edit").val(); if(internaldns1 != jsonObj.internaldns1) - moreCriteria.push("&internaldns1="+encodeURIComponent(internaldns1)); + moreCriteria.push("&internaldns1="+todb(internaldns1)); var internaldns2 = $detailsTab.find("#internaldns2_edit").val(); if (internaldns2 != null && internaldns2.length > 0 && internaldns2 != jsonObj.internaldns2) - moreCriteria.push("&internaldns2="+encodeURIComponent(internaldns2)); + moreCriteria.push("&internaldns2="+todb(internaldns2)); var vlan; if ($("#tab_content_details #vlan_container").css("display") != "none") { @@ -880,13 +880,13 @@ function doEditZone2($actionLink, $detailsTab, $leftmenuItem1, $readonlyFields, vlan = vlanStart; if(vlan != jsonObj.vlan) - moreCriteria.push("&vlan=" + encodeURIComponent(vlan)); + moreCriteria.push("&vlan=" + todb(vlan)); } } var guestcidraddress = $detailsTab.find("#guestcidraddress_edit").val(); if(guestcidraddress != jsonObj.guestcidraddress) - moreCriteria.push("&guestcidraddress="+encodeURIComponent(guestcidraddress)); + moreCriteria.push("&guestcidraddress="+todb(guestcidraddress)); if(moreCriteria.length > 0) { $.ajax({ @@ -986,10 +986,10 @@ function initAddHostButtonOnZonePage($button, zoneId, zoneName) { array1.push("&podid="+podId); var username = trim($thisDialog.find("#host_username").val()); - array1.push("&username="+encodeURIComponent(username)); + array1.push("&username="+todb(username)); var password = trim($thisDialog.find("#host_password").val()); - array1.push("&password="+encodeURIComponent(password)); + array1.push("&password="+todb(password)); var newClusterName, existingClusterId; if(clusterRadio == "new_cluster_radio") { @@ -1010,7 +1010,7 @@ function initAddHostButtonOnZonePage($button, zoneId, zoneName) { url = "http://" + todb(hostname); else url = hostname; - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); //var $midmenuItem1 = beforeAddingMidMenuItem() ; @@ -1176,7 +1176,7 @@ function initAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) { var lun = trim($thisDialog.find("#add_pool_lun").val()); url = iscsiURL(server, iqn, lun); } - array1.push("&url="+encodeURIComponent(url)); + array1.push("&url="+todb(url)); var tags = trim($thisDialog.find("#add_pool_tags").val()); if(tags != null && tags.length > 0)