mirror of https://github.com/apache/cloudstack.git
bug 7489: Added events for network create/delete
status 7489: resolved fixed
This commit is contained in:
parent
dceab9f18a
commit
bb088a2e4c
|
|
@ -54,8 +54,10 @@ public class EventTypes {
|
|||
public static final String EVENT_NET_IP_RELEASE = "NET.IPRELEASE";
|
||||
public static final String EVENT_NET_RULE_ADD = "NET.RULEADD";
|
||||
public static final String EVENT_NET_RULE_DELETE = "NET.RULEDELETE";
|
||||
public static final String EVENT_NET_RULE_MODIFY = "NET.RULEMODIFY";
|
||||
|
||||
public static final String EVENT_NET_RULE_MODIFY = "NET.RULEMODIFY";
|
||||
public static final String EVENT_NETWORK_CREATE = "NETWORK.CREATE";
|
||||
public static final String EVENT_NETWORK_DELETE = "NETWORK.DELETE";
|
||||
|
||||
// Load Balancers
|
||||
public static final String EVENT_ASSIGN_TO_LOAD_BALANCER_RULE = "LB.ASSIGN.TO.RULE";
|
||||
public static final String EVENT_REMOVE_FROM_LOAD_BALANCER_RULE = "LB.REMOVE.FROM.RULE";
|
||||
|
|
|
|||
|
|
@ -185,5 +185,7 @@ public interface ConfigurationManager extends Manager {
|
|||
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
|
||||
|
||||
void createDefaultNetworks(long zoneId) throws ConcurrentOperationException;
|
||||
|
||||
Long saveConfigurationEvent(long userId, Long accountId, String type, String description, String... paramsList);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2438,7 +2438,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
}
|
||||
}
|
||||
|
||||
private Long saveConfigurationEvent(long userId, Long accountId, String type, String description, String... paramsList) {
|
||||
@Override
|
||||
public Long saveConfigurationEvent(long userId, Long accountId, String type, String description, String... paramsList) {
|
||||
UserVO user = _userDao.findById(userId);
|
||||
long accountIdToUse = (accountId != null) ? accountId : user.getAccountId();
|
||||
|
||||
|
|
|
|||
|
|
@ -1632,10 +1632,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
String gateway = cmd.getGateway();
|
||||
String startIP = cmd.getStartIp();
|
||||
String endIP = cmd.getEndIp();
|
||||
String vlanNetmask = cmd.getNetmask();
|
||||
String netmask = cmd.getNetmask();
|
||||
String cidr = null;
|
||||
if (gateway != null && vlanNetmask != null) {
|
||||
cidr = NetUtils.ipAndNetMaskToCidr(gateway, vlanNetmask);
|
||||
if (gateway != null && netmask != null) {
|
||||
cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
|
||||
}
|
||||
String accountName = cmd.getAccountName();
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
|
@ -1644,6 +1644,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
String displayText = cmd.getDisplayText();
|
||||
Boolean isShared = cmd.getIsShared();
|
||||
Account owner = null;
|
||||
Long ownerId = null;
|
||||
|
||||
//if end ip is not specified, default it to startIp
|
||||
if (endIP == null && startIP != null) {
|
||||
|
|
@ -1677,9 +1678,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
owner = ctxAccount;
|
||||
}
|
||||
} else {
|
||||
//regular user can't create networks for anybody else but himself
|
||||
owner = ctxAccount;
|
||||
}
|
||||
|
||||
ownerId = owner.getId();
|
||||
|
||||
//Don't allow to create network with vlan that already exists in the system
|
||||
if (networkOffering.getGuestIpType() == GuestIpType.Direct && vlanId != null) {
|
||||
String uri ="vlan://" + vlanId;
|
||||
|
|
@ -1764,14 +1768,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
//Don't pass owner to create vlan when network offering is of type Direct
|
||||
//Don't pass owner to create vlan when network offering is of type Direct - done to prevent accountVlanMap entry creation when vlan is mapped to network
|
||||
if (networkOffering.getGuestIpType() == GuestIpType.Direct) {
|
||||
owner = null;
|
||||
}
|
||||
|
||||
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_ADMIN && networkOffering.getGuestIpType() == GuestIpType.Direct && startIP != null && endIP != null && gateway != null) {
|
||||
//Create vlan ip range
|
||||
Vlan vlan = _configMgr.createVlanAndPublicIpRange(userId, zoneId, null, startIP, endIP, gateway, vlanNetmask, false, vlanId, owner, networkId);
|
||||
Vlan vlan = _configMgr.createVlanAndPublicIpRange(userId, zoneId, null, startIP, endIP, gateway, netmask, false, vlanId, owner, networkId);
|
||||
if (vlan == null) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Failed to create a vlan");
|
||||
|
|
@ -1779,6 +1783,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
txn.commit();
|
||||
|
||||
String eventMsg = "Successfully created network " + name + " (networkOfferingId=" + networkOfferingId + ", isShared=" + isShared + ", ownerId=" + ownerId + ", netmask=" + netmask + ", startIP=" + startIP + ", endIP=" + endIP + ", gateway=" + gateway + ", vlan=" + vlanId + ")";
|
||||
if (networks != null && !networks.isEmpty()) {
|
||||
_configMgr.saveConfigurationEvent(userId, ownerId, EventTypes.EVENT_NETWORK_CREATE, eventMsg,
|
||||
"dcId=" + zoneId,
|
||||
"networkOfferingId=" + networkOfferingId,
|
||||
"name=" + name,
|
||||
"isShared=" + isShared,
|
||||
"ownerId=" + ownerId,
|
||||
"networkGateway=" + gateway,
|
||||
"networkNetmask=" + netmask,
|
||||
"startIP=" + startIP,
|
||||
"endIP=" + endIP,
|
||||
"vlan=" + vlanId);
|
||||
}
|
||||
|
||||
return networks.get(0);
|
||||
} catch (Exception ex) {
|
||||
s_logger.warn("Unexpected exception while creating network ", ex);
|
||||
|
|
@ -1891,6 +1910,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
throw new InvalidParameterValueException("unable to find network " + networkId);
|
||||
}
|
||||
|
||||
Long ownerId = network.getAccountId();
|
||||
Long zoneId = network.getDataCenterId();
|
||||
String name = network.getName();
|
||||
|
||||
//Perform permission check
|
||||
if (account != null) {
|
||||
if (!isAdmin(account.getType())) {
|
||||
|
|
@ -1929,6 +1952,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
_networksDao.remove(networkId);
|
||||
|
||||
txn.commit();
|
||||
|
||||
String eventMsg = "Successfully deleted network " + name + " (id=" + networkId + ")";
|
||||
_configMgr.saveConfigurationEvent(userId, ownerId, EventTypes.EVENT_NETWORK_DELETE, eventMsg, "id=" + networkId, "dcId=" + zoneId, "accountId=" + ownerId);
|
||||
|
||||
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
|
|
@ -1979,7 +2007,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
txn.start();
|
||||
if (success) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unsuccessfully shutdown the network.");
|
||||
}
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
guru.destroy(network, _networkOfferingDao.findById(network.getNetworkOfferingId()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue