mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-7068: addIpToNicCmd changed to BaseAsyncCreate
(cherry picked from commit 252e58381a)
Conflicts:
api/src/com/cloud/event/EventTypes.java
This commit is contained in:
parent
6d0e43d36b
commit
865cdc08e5
|
|
@ -68,6 +68,7 @@ import com.cloud.template.VirtualMachineTemplate;
|
|||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.vm.ConsoleProxy;
|
||||
import com.cloud.vm.NicSecondaryIp;
|
||||
import com.cloud.vm.SecondaryStorageVm;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
|
|
@ -507,6 +508,11 @@ public class EventTypes {
|
|||
public static final String EVENT_GUEST_OS_MAPPING_REMOVE = "GUEST.OS.MAPPING.REMOVE";
|
||||
public static final String EVENT_GUEST_OS_MAPPING_UPDATE = "GUEST.OS.MAPPING.UPDATE";
|
||||
|
||||
public static final String EVENT_NIC_SECONDARY_IP_ASSIGN = "NIC.SECONDARY.IP.ASSIGN";
|
||||
public static final String EVENT_NIC_SECONDARY_IP_UNASSIGN = "NIC.SECONDARY.IP.UNASSIGN";
|
||||
public static final String EVENT_NIC_SECONDARY_IP_CONFIGURE = "NIC.SECONDARY.IP.CONFIGURE";
|
||||
|
||||
|
||||
static {
|
||||
|
||||
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
|
||||
|
|
@ -848,6 +854,10 @@ public class EventTypes {
|
|||
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_ADD, GuestOSHypervisor.class);
|
||||
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_REMOVE, GuestOSHypervisor.class);
|
||||
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_UPDATE, GuestOSHypervisor.class);
|
||||
entityEventDetails.put(EVENT_NIC_SECONDARY_IP_ASSIGN, NicSecondaryIp.class);
|
||||
entityEventDetails.put(EVENT_NIC_SECONDARY_IP_UNASSIGN, NicSecondaryIp.class);
|
||||
entityEventDetails.put(EVENT_NIC_SECONDARY_IP_CONFIGURE, NicSecondaryIp.class);
|
||||
|
||||
}
|
||||
|
||||
public static String getEntityForEvent(String eventName) {
|
||||
|
|
|
|||
|
|
@ -178,4 +178,6 @@ public interface NetworkService {
|
|||
Map<Network.Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service);
|
||||
|
||||
IpAddress updateIP(Long id, String customId, Boolean displayIp);
|
||||
|
||||
boolean configureNicSecondaryIp(NicSecondaryIp secIp, boolean isZoneSgEnabled);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import org.apache.cloudstack.api.APICommand;
|
|||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.NicResponse;
|
||||
|
|
@ -45,7 +45,7 @@ import com.cloud.vm.VirtualMachine;
|
|||
|
||||
@APICommand(name = "addIpToNic", description = "Assigns secondary IP to NIC", responseObject = NicSecondaryIpResponse.class,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
||||
public class AddIpToVmNicCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AddIpToVmNicCmd.class.getName());
|
||||
private static final String s_name = "addiptovmnicresponse";
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_NET_IP_ASSIGN;
|
||||
return EventTypes.EVENT_NIC_SECONDARY_IP_ASSIGN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -125,35 +125,18 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
|
||||
|
||||
CallContext.current().setEventDetails("Nic Id: " + getNicId());
|
||||
String ip;
|
||||
NicSecondaryIp result;
|
||||
String secondaryIp = null;
|
||||
if ((ip = getIpaddress()) != null) {
|
||||
if (!NetUtils.isValidIp(ip)) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid ip address " + ip);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
result = _networkService.allocateSecondaryGuestIP(getNicId(), getIpaddress());
|
||||
} catch (InsufficientAddressCapacityException e) {
|
||||
throw new InvalidParameterValueException("Allocating guest ip for nic failed : " + e.getMessage());
|
||||
}
|
||||
NicSecondaryIp result = _entityMgr.findById(NicSecondaryIp.class, getEntityId());
|
||||
|
||||
if (result != null) {
|
||||
secondaryIp = result.getIp4Address();
|
||||
if (isZoneSGEnabled()) {
|
||||
// add security group rules for the secondary ip addresses
|
||||
boolean success = false;
|
||||
success = _securityGroupService.securityGroupRulesForVmSecIp(getNicId(), secondaryIp, true);
|
||||
if (success == false) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set security group rules for the secondary ip");
|
||||
}
|
||||
CallContext.current().setEventDetails("secondary Ip Id: " + getEntityId());
|
||||
boolean success = false;
|
||||
success = _networkService.configureNicSecondaryIp(result, isZoneSGEnabled());
|
||||
|
||||
if (success == false) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set security group rules for the secondary ip");
|
||||
}
|
||||
|
||||
s_logger.info("Associated ip address to NIC : " + secondaryIp);
|
||||
NicSecondaryIpResponse response = new NicSecondaryIpResponse();
|
||||
response = _responseGenerator.createSecondaryIPToNicResponse(result);
|
||||
NicSecondaryIpResponse response = _responseGenerator.createSecondaryIPToNicResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
|
|
@ -161,10 +144,6 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyncObjType() {
|
||||
return BaseAsyncCmd.networkSyncObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSyncObjId() {
|
||||
|
|
@ -188,4 +167,29 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
return vm.getAccountId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException {
|
||||
String ip;
|
||||
NicSecondaryIp result;
|
||||
String secondaryIp = null;
|
||||
if ((ip = getIpaddress()) != null) {
|
||||
if (!NetUtils.isValidIp(ip)) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid ip address " + ip);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
result = _networkService.allocateSecondaryGuestIP(getNicId(), getIpaddress());
|
||||
if (result != null) {
|
||||
setEntityId(result.getId());
|
||||
setEntityUuid(result.getUuid());
|
||||
}
|
||||
} catch (InsufficientAddressCapacityException e) {
|
||||
throw new InvalidParameterValueException("Allocating guest ip for nic failed : " + e.getMessage());
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign secondary ip to nic");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class RemoveIpFromVmNicCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_NET_IP_ASSIGN;
|
||||
return EventTypes.EVENT_NIC_SECONDARY_IP_UNASSIGN;
|
||||
}
|
||||
|
||||
public NicSecondaryIp getIpEntry() {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import javax.ejb.Local;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.network.security.SecurityGroupService;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
|
|
@ -315,6 +316,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
@Inject
|
||||
LoadBalancingRulesService _lbService;
|
||||
|
||||
@Inject
|
||||
public SecurityGroupService _securityGroupService;
|
||||
|
||||
int _cidrLimit;
|
||||
boolean _allowSubdomainNetworkAccess;
|
||||
|
||||
|
|
@ -648,6 +652,22 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NIC_SECONDARY_IP_CONFIGURE, eventDescription = "Configuring secondary ip " +
|
||||
"rules", async = true)
|
||||
public boolean configureNicSecondaryIp(NicSecondaryIp secIp, boolean isZoneSgEnabled) {
|
||||
boolean success = false;
|
||||
|
||||
if (isZoneSgEnabled) {
|
||||
success = _securityGroupService.securityGroupRulesForVmSecIp(secIp.getNicId(), secIp.getIp4Address(), true);
|
||||
s_logger.info("Associated ip address to NIC : " + secIp.getIp4Address());
|
||||
} else {
|
||||
success = true;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NIC_SECONDARY_IP_ASSIGN, eventDescription = "assigning secondary ip to nic", create = true)
|
||||
public NicSecondaryIp allocateSecondaryGuestIP(final long nicId, String requestedIp) throws InsufficientAddressCapacityException {
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
|
|
@ -752,6 +772,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NIC_SECONDARY_IP_UNASSIGN, eventDescription = "Removing secondary ip " +
|
||||
"from nic", async = true)
|
||||
public boolean releaseSecondaryIpFromNic(long ipAddressId) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
boolean success = false;
|
||||
|
|
|
|||
|
|
@ -862,4 +862,9 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureNicSecondaryIp(NicSecondaryIp secIp, boolean isZoneSgEnabled) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue