Skip to content

Commit ba826dd

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
Fixed listing public IP addresses
1 parent 57ddf63 commit ba826dd

5 files changed

Lines changed: 37 additions & 26 deletions

File tree

‎api/src/com/cloud/acl/SecurityChecker.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public interface SecurityChecker extends Adapter {
3939
public enum AccessType {
4040
ListEntry,
4141
ModifyEntry,
42-
ModifyProject
42+
ModifyProject,
43+
UseNetwork
4344
}
4445
/**
4546
* Checks if the account owns the object.

‎api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java‎

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,41 @@ public Long getNetworkId() {
141141
Long zoneId = getZoneId();
142142

143143
if (zoneId == null) {
144-
throw new InvalidParameterValueException("Either networkId or zoneId has to be specified");
144+
Long ipId = getSourceIpAddressId();
145+
if (ipId == null) {
146+
throw new InvalidParameterValueException("Either networkId or zoneId or publicIpId has to be specified");
147+
}
145148
}
146149

147-
DataCenter zone = _configService.getZone(zoneId);
148-
if (zone.getNetworkType() == NetworkType.Advanced) {
149-
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
150-
if (networks.size() == 0) {
151-
String domain = _domainService.getDomain(getDomainId()).getName();
152-
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
153-
}
154-
155-
if (networks.size() < 1) {
156-
throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
157-
} else if (networks.size() > 1) {
158-
throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
159-
}
160-
161-
return networks.get(0).getId();
162-
} else {
163-
Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
164-
if (defaultGuestNetwork == null) {
165-
throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain id=" + getDomainId());
150+
if (zoneId != null) {
151+
DataCenter zone = _configService.getZone(zoneId);
152+
if (zone.getNetworkType() == NetworkType.Advanced) {
153+
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
154+
if (networks.size() == 0) {
155+
String domain = _domainService.getDomain(getDomainId()).getName();
156+
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
157+
}
158+
159+
if (networks.size() < 1) {
160+
throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
161+
} else if (networks.size() > 1) {
162+
throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
163+
}
164+
165+
return networks.get(0).getId();
166166
} else {
167-
return defaultGuestNetwork.getId();
167+
Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
168+
if (defaultGuestNetwork == null) {
169+
throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain id=" + getDomainId());
170+
} else {
171+
return defaultGuestNetwork.getId();
172+
}
168173
}
174+
} else {
175+
IpAddress ipAddr = _networkService.getIp(publicIpId);
176+
return ipAddr.getAssociatedWithNetworkId();
169177
}
178+
170179
}
171180

172181
public Integer getPublicPort() {

‎server/src/com/cloud/acl/DomainChecker.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
109109
}
110110

111111
return true;
112-
} else if (entity instanceof Network) {
112+
} else if (entity instanceof Network && accessType != null && accessType == AccessType.UseNetwork) {
113113
_networkMgr.checkNetworkPermissions(caller, (Network)entity);
114114
} else {
115115
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.log4j.Logger;
4444

4545
import com.cloud.acl.ControlledEntity.ACLType;
46+
import com.cloud.acl.SecurityChecker.AccessType;
4647
import com.cloud.agent.AgentManager;
4748
import com.cloud.agent.Listener;
4849
import com.cloud.agent.api.AgentControlAnswer;
@@ -931,8 +932,8 @@ public IpAddress allocateIP(long networkId, Account ipOwner, boolean isElastic)
931932
}
932933

933934
//check permissions
934-
_accountMgr.checkAccess(caller, null, false, ipOwner, network);
935-
_accountMgr.checkAccess(ipOwner, null, false, network);
935+
_accountMgr.checkAccess(caller, null, false, ipOwner);
936+
_accountMgr.checkAccess(ipOwner, AccessType.UseNetwork, false, network);
936937

937938
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
938939

‎server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ public LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb, boolea
627627

628628
Network guestNetwork = _networkMgr.getNetwork(lb.getNetworkId());
629629
NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
630-
if (ipAddressVo != null) {
630+
if (ipAddressVo != null && off.getElasticLb()) {
631631
throw new InvalidParameterValueException("Can't specify ipAddressId when create LB in the network with LB capability " + Capability.ElasticLb.getName());
632632
}
633633

0 commit comments

Comments
 (0)