// Copyright 2012 Citrix Systems, Inc. Licensed under the // Apache License, Version 2.0 (the "License"); you may not use this // file except in compliance with the License. Citrix Systems, Inc. // reserves all rights not expressly granted by the License. // You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.api.commands; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; import com.cloud.api.BaseListCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.ServiceOfferingResponse; import com.cloud.offering.ServiceOffering; @Implementation(description="Lists all available service offerings.", responseObject=ServiceOfferingResponse.class) public class ListServiceOfferingsCmd extends BaseListCmd { public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName()); private static final String s_name = "listserviceofferingsresponse"; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// @IdentityMapper(entityTableName="disk_offering") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="ID of the service offering") private Long id; @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="name of the service offering") private String serviceOfferingName; @IdentityMapper(entityTableName="vm_instance") @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; @IdentityMapper(entityTableName="domain") @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain associated with the service offering") private Long domainId; @Parameter(name=ApiConstants.IS_SYSTEM_OFFERING, type=CommandType.BOOLEAN, description="is this a system vm offering") private Boolean isSystem; @Parameter(name=ApiConstants.SYSTEM_VM_TYPE, type=CommandType.STRING, description="the system VM type. Possible types are \"consoleproxy\", \"secondarystoragevm\" or \"domainrouter\".") private String systemVmType; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// public Long getId() { return id; } public String getServiceOfferingName() { return serviceOfferingName; } public Long getVirtualMachineId() { return virtualMachineId; } public Long getDomainId(){ return domainId; } public Boolean getIsSystem() { return isSystem == null ? false : isSystem; } public String getSystemVmType(){ return systemVmType; } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @Override public String getCommandName() { return s_name; } @Override public void execute(){ List<? extends ServiceOffering> offerings = _mgr.searchForServiceOfferings(this); ListResponse<ServiceOfferingResponse> response = new ListResponse<ServiceOfferingResponse>(); List<ServiceOfferingResponse> offeringResponses = new ArrayList<ServiceOfferingResponse>(); for (ServiceOffering offering : offerings) { ServiceOfferingResponse offeringResponse = _responseGenerator.createServiceOfferingResponse(offering); offeringResponse.setObjectName("serviceoffering"); offeringResponses.add(offeringResponse); } response.setResponses(offeringResponses); response.setResponseName(getCommandName()); this.setResponseObject(response); } }