Repository: cloudstack
Updated Branches:
refs/heads/4.4 6d0e43d36 -> 865cdc08e
CLOUDSTACK-7068: addIpToNicCmd changed to BaseAsyncCreate
(cherry picked from commit 252e58381aae6f321c972d00a3bb8dd7c89d97c0)
Conflicts:
api/src/com/cloud/event/EventTypes.java
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/865cdc08
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/865cdc08
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/865cdc08
Branch: refs/heads/4.4
Commit: 865cdc08e547a7b7f93a4d47e26772ec99fd8507
Parents: 6d0e43d
Author: Jayapal <[email protected]>
Authored: Wed Jul 9 12:43:32 2014 +0530
Committer: Daan Hoogland <[email protected]>
Committed: Wed Jul 30 13:36:22 2014 +0200
----------------------------------------------------------------------
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/865cdc08/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 a030d53..5934ee4 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -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) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/865cdc08/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/865cdc08/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/865cdc08/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/865cdc08/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/865cdc08/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.
+ }
+
}