Skip to content

Commit 16caf19

Browse files
author
Alex Huang
committed
New ip address states and mode
1 parent daa9add commit 16caf19

14 files changed

Lines changed: 331 additions & 298 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public String getName() {
7979
public long getEntityOwnerId() {
8080
IpAddress addr = _entityMgr.findById(IpAddress.class, getPublicIp());
8181
if (addr != null) {
82-
return addr.getAccountId();
82+
return addr.getAllocatedToAccountId();
8383
}
8484

8585
// bad address given, parent this command to SYSTEM so ERROR events are tracked

‎api/src/com/cloud/network/IpAddress.java‎

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,48 @@
1919

2020
import java.util.Date;
2121

22-
public interface IpAddress {
22+
import com.cloud.acl.ControlledEntity;
23+
24+
/**
25+
* IpAddress represents the public ip address to be allocated in the CloudStack.
26+
*
27+
* When it is not allocated, it should have
28+
* - State = Free
29+
* - Allocated = null
30+
* - AccountId = null
31+
* - DomainId = null
32+
*
33+
* When it is allocated, it should have
34+
* - State = Allocated
35+
* - AccountId = account owner.
36+
* - DomainId = domain of the account owner.
37+
* - Allocated = time it was allocated.
38+
*/
39+
public interface IpAddress extends ControlledEntity {
40+
enum State {
41+
Allocating, // The IP Address is being propagated to other network elements and is not ready for use yet.
42+
Allocated, // The IP address is in used.
43+
Releasing, // The IP address is being released for other network elements and is not ready for allocation.
44+
Free // The IP address is ready to be allocated.
45+
}
46+
2347
long getDataCenterId();
2448

2549
String getAddress();
26-
Long getAccountId();
27-
Long getDomainId();
28-
Date getAllocated();
29-
boolean isSourceNat();
30-
31-
void setAccountId(Long accountId);
32-
33-
void setDomainId(Long domainId);
34-
35-
void setSourceNat(boolean sourceNat);
3650

37-
boolean getSourceNat();
38-
39-
void setAllocated(Date allocated);
51+
Long getAllocatedToAccountId();
4052

41-
long getVlanDbId();
53+
Long getAllocatedInDomainId();
4254

43-
void setVlanDbId(long vlanDbId);
55+
Date getAllocatedTime();
56+
57+
boolean isSourceNat();
4458

45-
boolean isOneToOneNat();
59+
long getVlanId();
4660

47-
void setOneToOneNat(boolean oneToOneNat);
61+
boolean isOneToOneNat();
62+
63+
State getState();
64+
65+
boolean readyToUse();
4866
}

‎server/src/com/cloud/api/ApiDBUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public static UserVm findUserVmByPublicIpAndGuestIp(String publicIp, String gues
411411
List<UserVmVO> vms = _userVmDao.listVmsUsingGuestIpAddress(addr.getDataCenterId(), guestIp);
412412
if (vms != null) {
413413
for (UserVmVO vm : vms) {
414-
if (vm.getAccountId() == addr.getAccountId()) {
414+
if (vm.getAccountId() == addr.getAllocatedToAccountId()) {
415415
return vm;
416416
}
417417
}

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,20 +767,20 @@ public VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan) {
767767

768768
@Override
769769
public IPAddressResponse createIPAddressResponse(IpAddress ipAddress) {
770-
VlanVO vlan = ApiDBUtils.findVlanById(ipAddress.getVlanDbId());
770+
VlanVO vlan = ApiDBUtils.findVlanById(ipAddress.getVlanId());
771771
boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
772772

773773
IPAddressResponse ipResponse = new IPAddressResponse();
774774
ipResponse.setIpAddress(ipAddress.getAddress());
775-
if (ipAddress.getAllocated() != null) {
776-
ipResponse.setAllocated(ipAddress.getAllocated());
775+
if (ipAddress.getAllocatedTime() != null) {
776+
ipResponse.setAllocated(ipAddress.getAllocatedTime());
777777
}
778778
ipResponse.setZoneId(ipAddress.getDataCenterId());
779779
ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName());
780780
ipResponse.setSourceNat(ipAddress.isSourceNat());
781781

782782
// get account information
783-
Account accountTemp = ApiDBUtils.findAccountById(ipAddress.getAccountId());
783+
Account accountTemp = ApiDBUtils.findAccountById(ipAddress.getAllocatedToAccountId());
784784
if (accountTemp != null) {
785785
ipResponse.setAccountName(accountTemp.getAccountName());
786786
ipResponse.setDomainId(accountTemp.getDomainId());
@@ -793,8 +793,8 @@ public IPAddressResponse createIPAddressResponse(IpAddress ipAddress) {
793793
// show this info to admin only
794794
Account account = UserContext.current().getAccount();
795795
if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
796-
ipResponse.setVlanId(ipAddress.getVlanDbId());
797-
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanDbId()).getVlanId());
796+
ipResponse.setVlanId(ipAddress.getVlanId());
797+
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanId()).getVlanId());
798798
}
799799
ipResponse.setObjectName("ipaddress");
800800
return ipResponse;

‎server/src/com/cloud/async/executor/DisassociateIpAddressExecutor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private DomainRouterVO getRouterSyncSource(DisassociateIpAddressParam param) {
9898
if (ip.isSourceNat()) {
9999
router = routerDao.findByPublicIpAddress(param.getIpAddress());
100100
} else {
101-
router = routerDao.findBy(ip.getAccountId(), ip.getDataCenterId());
101+
router = routerDao.findBy(ip.getAllocatedToAccountId(), ip.getDataCenterId());
102102
}
103103

104104
return router;

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

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@
2929

3030
/**
3131
* A bean representing a public IP Address
32-
*
33-
* @author Will Chan
3432
*
3533
*/
3634
@Entity
3735
@Table(name=("user_ip_address"))
3836
public class IPAddressVO implements IpAddress {
3937
@Column(name="account_id")
40-
private Long accountId = null;
38+
private Long allocatedToAccountId = null;
4139

4240
@Column(name="domain_id")
43-
private Long domainId = null;
41+
private Long allocatedInDomainId = null;
4442

4543
@Id
4644
@Column(name="public_ip_address")
@@ -54,22 +52,34 @@ public class IPAddressVO implements IpAddress {
5452

5553
@Column(name="allocated")
5654
@Temporal(value=TemporalType.TIMESTAMP)
57-
private Date allocated;
55+
private Date allocatedTime;
5856

5957
@Column(name="vlan_db_id")
60-
private long vlanDbId;
58+
private long vlanId;
6159

6260
@Column(name="one_to_one_nat")
6361
private boolean oneToOneNat;
62+
63+
@Column(name="state")
64+
private State state;
6465

6566
protected IPAddressVO() {
67+
}
68+
69+
@Override
70+
public boolean readyToUse() {
71+
return state == State.Allocated;
6672
}
6773

6874
public IPAddressVO(String address, long dataCenterId, long vlanDbId, boolean sourceNat) {
6975
this.address = address;
7076
this.dataCenterId = dataCenterId;
71-
this.vlanDbId = vlanDbId;
72-
this.sourceNat = sourceNat;
77+
this.vlanId = vlanDbId;
78+
this.sourceNat = sourceNat;
79+
this.allocatedInDomainId = null;
80+
this.allocatedToAccountId = null;
81+
this.allocatedTime = null;
82+
this.state = State.Free;
7383
}
7484

7585
@Override
@@ -80,68 +90,80 @@ public long getDataCenterId() {
8090
@Override
8191
public String getAddress() {
8292
return address;
83-
}
93+
}
94+
8495
@Override
85-
public Long getAccountId() {
86-
return accountId;
87-
}
96+
public Long getAllocatedToAccountId() {
97+
return allocatedToAccountId;
98+
}
99+
88100
@Override
89-
public Long getDomainId() {
90-
return domainId;
91-
}
101+
public Long getAllocatedInDomainId() {
102+
return allocatedInDomainId;
103+
}
104+
92105
@Override
93-
public Date getAllocated() {
94-
return allocated;
95-
}
96-
@Override
97-
public boolean isSourceNat() {
98-
return sourceNat;
106+
public Date getAllocatedTime() {
107+
return allocatedTime;
99108
}
100109

101-
@Override
102-
public void setAccountId(Long accountId) {
103-
this.accountId = accountId;
110+
public void setAllocatedToAccountId(Long accountId) {
111+
this.allocatedToAccountId = accountId;
104112
}
105113

106-
@Override
107-
public void setDomainId(Long domainId) {
108-
this.domainId = domainId;
114+
public void setAllocatedInDomainId(Long domainId) {
115+
this.allocatedInDomainId = domainId;
109116
}
110117

111-
@Override
112118
public void setSourceNat(boolean sourceNat) {
113119
this.sourceNat = sourceNat;
114120
}
115121

116122
@Override
117-
public boolean getSourceNat() {
118-
return this.sourceNat;
123+
public boolean isSourceNat() {
124+
return sourceNat;
119125
}
120126

121-
@Override
122-
public void setAllocated(Date allocated) {
123-
this.allocated = allocated;
127+
public void setAllocatedTime(Date allocated) {
128+
this.allocatedTime = allocated;
124129
}
125130

126131
@Override
127-
public long getVlanDbId() {
128-
return this.vlanDbId;
132+
public long getVlanId() {
133+
return this.vlanId;
129134
}
130135

131-
@Override
132-
public void setVlanDbId(long vlanDbId) {
133-
this.vlanDbId = vlanDbId;
136+
public void setVlanId(long vlanDbId) {
137+
this.vlanId = vlanDbId;
134138
}
135139

136140
@Override
137141
public boolean isOneToOneNat() {
138142
return oneToOneNat;
139143
}
140144

141-
@Override
142145
public void setOneToOneNat(boolean oneToOneNat) {
143146
this.oneToOneNat = oneToOneNat;
144147
}
148+
149+
@Override
150+
public long getDomainId() {
151+
return allocatedInDomainId == null ? -1 : allocatedInDomainId;
152+
}
153+
154+
@Override
155+
public long getAccountId() {
156+
return allocatedToAccountId == null ? -1 : allocatedToAccountId;
157+
}
158+
159+
@Override
160+
public State getState() {
161+
return state;
162+
}
163+
164+
public void setState(State state) {
165+
this.state = state;
166+
}
145167

146168
@Override
147169
public String toString() {

0 commit comments

Comments
 (0)