You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2014/07/10 02:39:43 UTC
git commit: updated refs/heads/4.4-forward to 252e583
Repository: cloudstack
Updated Branches:
refs/heads/4.4-forward a0486aedc -> 252e58381
CLOUDSTACK-7068: addIpToNicCmd changed to BaseAsyncCreate
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/252e5838
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/252e5838
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/252e5838
Branch: refs/heads/4.4-forward
Commit: 252e58381aae6f321c972d00a3bb8dd7c89d97c0
Parents: a0486ae
Author: Jayapal <ja...@apache.org>
Authored: Wed Jul 9 12:43:32 2014 +0530
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Wed Jul 9 17:39:32 2014 -0700
----------------------------------------------------------------------
api/src/com/cloud/event/EventTypes.java | 10 +++
api/src/com/cloud/network/NetworkService.java | 2 +
.../api/command/user/vm/AddIpToVmNicCmd.java | 68 +++++++++++---------
.../command/user/vm/RemoveIpFromVmNicCmd.java | 2 +-
.../com/cloud/network/NetworkServiceImpl.java | 22 +++++++
.../com/cloud/vpc/MockNetworkManagerImpl.java | 5 ++
6 files changed, 76 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/252e5838/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index 5b9ea5c..a5c3f32 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -31,6 +31,7 @@ import com.cloud.network.Site2SiteVpnConnection;
import com.cloud.server.ResourceTag;
import com.cloud.storage.snapshot.SnapshotPolicy;
import com.cloud.vm.ConsoleProxy;
+import com.cloud.vm.NicSecondaryIp;
import com.cloud.vm.SecondaryStorageVm;
import org.apache.cloudstack.config.Configuration;
@@ -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) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/252e5838/api/src/com/cloud/network/NetworkService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java
index 1e126f5..18b59e9 100755
--- a/api/src/com/cloud/network/NetworkService.java
+++ b/api/src/com/cloud/network/NetworkService.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/252e5838/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
index 870bbbf..4b805ac 100644
--- a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
@@ -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");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/252e5838/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
index 70d5b48..19da39a 100644
--- a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
@@ -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() {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/252e5838/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 95d3dec..6c6fd61 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/252e5838/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index 387a710..ae227fc 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -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.
+ }
+
}