mirror of https://github.com/apache/cloudstack.git
Separate IpAddress related cmds to use two different views.
This commit is contained in:
parent
add277a4aa
commit
a6d03cd826
|
|
@ -234,7 +234,7 @@ public interface ResponseGenerator {
|
|||
|
||||
VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan);
|
||||
|
||||
IPAddressResponse createIPAddressResponse(IpAddress ipAddress);
|
||||
IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddress);
|
||||
|
||||
GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan result);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with 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.
|
||||
package org.apache.cloudstack.api.command.admin.address;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
|
||||
import org.apache.cloudstack.api.response.IPAddressResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
|
||||
@APICommand(name = "associateIpAddress", description = "Acquires and associates a public IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Full)
|
||||
public class AssociateIPAddrCmdByAdmin extends AssociateIPAddrCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmdByAdmin.class.getName());
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, ResourceAllocationException,
|
||||
ConcurrentOperationException, InsufficientCapacityException {
|
||||
CallContext.current().setEventDetails("Ip Id: " + getEntityId());
|
||||
|
||||
IpAddress result = null;
|
||||
|
||||
if (getVpcId() != null) {
|
||||
result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
|
||||
} else if (getNetworkId() != null) {
|
||||
result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, result);
|
||||
ipResponse.setResponseName(getCommandName());
|
||||
setResponseObject(ipResponse);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign ip address");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with 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.
|
||||
package org.apache.cloudstack.api.command.admin.address;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
|
||||
import org.apache.cloudstack.api.response.IPAddressResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listPublicIpAddresses", description = "Lists all public ip addresses", responseObject = IPAddressResponse.class, responseView = ResponseView.Full)
|
||||
public class ListPublicIpAddressesCmdByAdmin extends ListPublicIpAddressesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmdByAdmin.class.getName());
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
|
||||
ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
|
||||
List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
|
||||
for (IpAddress ipAddress : result.first()) {
|
||||
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, ipAddress);
|
||||
ipResponse.setObjectName("publicipaddress");
|
||||
ipAddrResponses.add(ipResponse);
|
||||
}
|
||||
|
||||
response.setResponses(ipAddrResponses, result.second());
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
|
|||
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.IPAddressResponse;
|
||||
|
|
@ -55,7 +56,7 @@ import com.cloud.offering.NetworkOffering;
|
|||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "associateIpAddress", description="Acquires and associates a public IP to an account.", responseObject=IPAddressResponse.class)
|
||||
@APICommand(name = "associateIpAddress", description = "Acquires and associates a public IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted)
|
||||
public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName());
|
||||
private static final String s_name = "associateipaddressresponse";
|
||||
|
|
@ -307,7 +308,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
|
|||
}
|
||||
|
||||
if (result != null) {
|
||||
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
|
||||
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, result);
|
||||
ipResponse.setResponseName(getCommandName());
|
||||
setResponseObject(ipResponse);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -19,11 +19,14 @@ package org.apache.cloudstack.api.command.user.address;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.response.IPAddressResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.NetworkResponse;
|
||||
|
|
@ -31,12 +34,11 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
|
|||
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
|
||||
import org.apache.cloudstack.api.response.VpcResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listPublicIpAddresses", description="Lists all public ip addresses", responseObject=IPAddressResponse.class)
|
||||
@APICommand(name = "listPublicIpAddresses", description = "Lists all public ip addresses", responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted)
|
||||
public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
|
||||
|
||||
|
|
@ -149,16 +151,17 @@ public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
|
|||
ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
|
||||
List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
|
||||
for (IpAddress ipAddress : result.first()) {
|
||||
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ipAddress);
|
||||
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, ipAddress);
|
||||
ipResponse.setObjectName("publicipaddress");
|
||||
ipAddrResponses.add(ipResponse);
|
||||
}
|
||||
|
||||
response.setResponses(ipAddrResponses, result.second());
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.IpAddress;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IPAddressResponse createIPAddressResponse(IpAddress ipAddr) {
|
||||
public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr) {
|
||||
VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
|
||||
boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
|
||||
long zoneId = ipAddr.getDataCenterId();
|
||||
|
|
@ -705,9 +705,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
// show this info to admin only
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if (_accountMgr.isRootAdmin(account.getId())) {
|
||||
// show this info to full view only
|
||||
if (view == ResponseView.Full) {
|
||||
VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
|
||||
if (vl != null) {
|
||||
ipResponse.setVlanId(vl.getUuid());
|
||||
|
|
|
|||
Loading…
Reference in New Issue