Skip to content

Commit d6452be

Browse files
committed
CLOUDSTACK-652: meging 'portable public ip' feature
Squashed commit of the following: commit f244f9ce7982db16984dd87c31545f1c0240c704 Merge: 993cbb0 f5c8e38 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Mon May 20 18:54:05 2013 +0530 Merge branch 'master' into portablepublicip Conflicts: server/src/com/cloud/server/ManagementServerImpl.java server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java commit 993cbb0df9fa6e64b96b18ed775b73cdf4a8f5d7 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Mon May 20 18:49:54 2013 +0530 introduce 'transferPortableIP' interface method in network manger. This method will transfer association of portable ip from one network to another network. commit 0c1c2652c1b39e9a81ca35464360e11ed9ef23f1 Merge: a718d35 a29e393 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Fri May 17 02:48:54 2013 +0530 Merge branch 'master' into portablepublicip Conflicts: utils/src/com/cloud/utils/net/NetUtils.java commit a718d35 Merge: ecca117 c211818 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Mon May 13 21:22:19 2013 +0530 Merge branch 'master' into portablepublicip Conflicts: api/src/org/apache/cloudstack/api/ResponseGenerator.java server/src/com/cloud/api/ApiResponseHelper.java server/src/com/cloud/network/NetworkServiceImpl.java server/src/com/cloud/network/addr/PublicIp.java server/src/com/cloud/server/ManagementServerImpl.java server/test/com/cloud/network/MockNetworkManagerImpl.java server/test/com/cloud/vpc/MockConfigurationManagerImpl.java server/test/com/cloud/vpc/MockNetworkManagerImpl.java setup/db/db/schema-410to420.sql commit ecca117 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Mon May 13 20:05:29 2013 +0530 added integration tests for testing portable ip ranges commit 895a27c Author: Murali Reddy <muralimmreddy@gmail.com> Date: Mon May 13 15:12:19 2013 +0530 - establish model for transferring portable IP association from a network with which it is associated to another network. - enabling static nat api, extended to transfer potrtable IP across the networks if the VM/network is different from the current associate network of the portable ip commit 5150975 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Mon May 13 12:05:33 2013 +0530 seperate out associate/disassociate with guest network operations from alloc and release of portable ip commit bd058f5 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Sun May 12 21:14:48 2013 +0530 enhance disasociateIPAddr API to release protable IP associated with a guest network or VPC commit 27504d9 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Sun May 12 16:53:45 2013 +0530 enhance asociateIPAddr API to acquire a protable IP and associate with a guest network or VPC commit f82c6a8 Merge: 3dbfb44 0749013 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Sat May 11 23:32:13 2013 +0530 Merge branch 'master' into portablepublicip Conflicts: api/src/com/cloud/network/IpAddress.java api/src/org/apache/cloudstack/api/ResponseGenerator.java client/tomcatconf/commands.properties.in server/src/com/cloud/api/ApiResponseHelper.java server/src/com/cloud/configuration/ConfigurationManagerImpl.java server/src/com/cloud/server/ManagementServerImpl.java server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java setup/db/db/schema-410to420.sql commit 3dbfb44 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Sat May 11 20:33:19 2013 +0530 - add 'portable' boolean as property of IpAddress, persist the property in IPAddressVO, return the property in IpAddressResponse - add ability to request portable IP in associateIpAddress api commit bf3cb27 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Sat May 11 16:08:40 2013 +0530 add the status of each portable IP (its state, details of associated data center/VPC/guest network etc) in the PortableIpRangeResponse returned by listPortableIpRanges API commit e7b2fb2 Author: Murali Reddy <muralimmreddy@gmail.com> Date: Sat May 11 14:36:01 2013 +0530 Introdcues notion of 'portable IP' pool at region level. Introduces root admin only API's to provision portable ip to a region - createPortableIpRange - deletePortableIpRange - listPortableIpRanges
1 parent f5c8e38 commit d6452be

43 files changed

Lines changed: 2542 additions & 64 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/async/AsyncJob.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum Type {
3535
Host,
3636
StoragePool,
3737
IpAddress,
38+
PortableIpAddress,
3839
SecurityGroup,
3940
PhysicalNetwork,
4041
TrafficType,

api/src/com/cloud/configuration/ConfigurationService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
4040
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
4141
import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
42+
import org.apache.cloudstack.api.command.admin.region.CreatePortableIpRangeCmd;
43+
import org.apache.cloudstack.api.command.admin.region.DeletePortableIpRangeCmd;
44+
import org.apache.cloudstack.api.command.admin.region.ListPortableIpRangesCmd;
4245
import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
4346
import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
4447
import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
@@ -56,6 +59,8 @@
5659
import com.cloud.offering.NetworkOffering;
5760
import com.cloud.offering.ServiceOffering;
5861
import com.cloud.user.Account;
62+
import org.apache.cloudstack.region.PortableIp;
63+
import org.apache.cloudstack.region.PortableIpRange;
5964

6065
public interface ConfigurationService {
6166

@@ -278,4 +283,12 @@ public interface ConfigurationService {
278283
* @return
279284
*/
280285
boolean isOfferingForVpc(NetworkOffering offering);
286+
287+
PortableIpRange createPortableIpRange(CreatePortableIpRangeCmd cmd) throws ConcurrentOperationException;
288+
289+
boolean deletePortableIpRange(DeletePortableIpRangeCmd cmd);
290+
291+
List<? extends PortableIpRange> listPortableIpRanges(ListPortableIpRangesCmd cmd);
292+
293+
List<? extends PortableIp> listPortableIps(long id);
281294
}

api/src/com/cloud/event/EventTypes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public class EventTypes {
102102
// Network Events
103103
public static final String EVENT_NET_IP_ASSIGN = "NET.IPASSIGN";
104104
public static final String EVENT_NET_IP_RELEASE = "NET.IPRELEASE";
105+
public static final String EVENT_PORTABLE_IP_ASSIGN = "PORTABLE.IPASSIGN";
106+
public static final String EVENT_PORTABLE_IP_RELEASE = "PORTABLEIPRELEASE";
105107
public static final String EVENT_NET_RULE_ADD = "NET.RULEADD";
106108
public static final String EVENT_NET_RULE_DELETE = "NET.RULEDELETE";
107109
public static final String EVENT_NET_RULE_MODIFY = "NET.RULEMODIFY";
@@ -432,6 +434,9 @@ public class EventTypes {
432434
public static final String EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE = "GUESTVLANRANGE.RELEASE";
433435

434436

437+
public static final String EVENT_PORTABLE_IP_RANGE_CREATE = "PORTABLE.IP.RANGE.CREATE";
438+
public static final String EVENT_PORTABLE_IP_RANGE_DELETE = "PORTABLE.IP.RANGE.DELETE";
439+
435440
static {
436441

437442
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ enum Purpose {
8181
Long getVpcId();
8282

8383
String getVmIp();
84-
84+
85+
boolean isPortable();
86+
8587
Long getNetworkId();
8688

8789
}

api/src/com/cloud/network/NetworkService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws Resour
5252

5353
boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException;
5454

55+
IpAddress allocatePortableIP(Account ipOwner, int regionId, Long zoneId, Long networkId, Long vpcId) throws ResourceAllocationException,
56+
InsufficientAddressCapacityException, ConcurrentOperationException;
57+
58+
boolean releasePortableIpAddress(long ipAddressId) throws InsufficientAddressCapacityException;
59+
5560
Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException,
5661
ResourceAllocationException;
5762

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class ApiConstants {
114114
public static final String IS_CLEANUP_REQUIRED = "iscleanuprequired";
115115
public static final String IS_EXTRACTABLE = "isextractable";
116116
public static final String IS_FEATURED = "isfeatured";
117+
public static final String IS_PORTABLE = "isportable";
117118
public static final String IS_PUBLIC = "ispublic";
118119
public static final String IS_PERSISTENT = "ispersistent";
119120
public static final String IS_READY = "isready";
@@ -158,6 +159,7 @@ public class ApiConstants {
158159
public static final String POLICY_ID = "policyid";
159160
public static final String PORT = "port";
160161
public static final String PORTAL = "portal";
162+
public static final String PORTABLE_IP_ADDRESS = "portableipaddress";
161163
public static final String PORT_FORWARDING_SERVICE_ID = "portforwardingserviceid";
162164
public static final String PRIVATE_INTERFACE = "privateinterface";
163165
public static final String PRIVATE_IP = "privateip";

api/src/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
import org.apache.cloudstack.api.response.*;
120120
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
121121
import org.apache.cloudstack.region.Region;
122+
import org.apache.cloudstack.region.PortableIp;
123+
import org.apache.cloudstack.region.PortableIpRange;
122124
import org.apache.cloudstack.usage.Usage;
123125

124126
import com.cloud.async.AsyncJob;
@@ -441,7 +443,12 @@ LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthChe
441443

442444
Long getAffinityGroupId(String name, long entityOwnerId);
443445

446+
PortableIpRangeResponse createPortableIPRangeResponse(PortableIpRange range);
447+
448+
PortableIpResponse createPortableIPResponse(PortableIp portableIp);
449+
444450
InternalLoadBalancerElementResponse createInternalLbElementResponse(VirtualRouterProvider result);
445-
451+
446452
IsolationMethodResponse createIsolationMethodResponse(IsolationType method);
453+
447454
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.api.command.admin.region;
19+
20+
import javax.inject.Inject;
21+
22+
import com.cloud.async.AsyncJob;
23+
import com.cloud.dc.Vlan;
24+
import com.cloud.event.EventTypes;
25+
import com.cloud.exception.ConcurrentOperationException;
26+
import com.cloud.exception.InsufficientCapacityException;
27+
import com.cloud.exception.ResourceAllocationException;
28+
import org.apache.cloudstack.api.APICommand;
29+
import org.apache.cloudstack.api.ApiConstants;
30+
import org.apache.cloudstack.api.ApiErrorCode;
31+
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
32+
import org.apache.cloudstack.api.Parameter;
33+
import org.apache.cloudstack.api.ServerApiException;
34+
import org.apache.cloudstack.api.response.PortableIpRangeResponse;
35+
import org.apache.cloudstack.api.response.RegionResponse;
36+
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
37+
import org.apache.cloudstack.region.PortableIpRange;
38+
import org.apache.cloudstack.region.Region;
39+
import org.apache.cloudstack.region.RegionService;
40+
import org.apache.log4j.Logger;
41+
42+
import com.cloud.user.Account;
43+
44+
@APICommand(name = "createPortableIpRange", responseObject=PortableIpRangeResponse.class, description="adds a range of portable public IP's to a region", since="4.2.0")
45+
public class CreatePortableIpRangeCmd extends BaseAsyncCreateCmd {
46+
47+
public static final Logger s_logger = Logger.getLogger(CreatePortableIpRangeCmd.class.getName());
48+
49+
private static final String s_name = "createportableiprangeresponse";
50+
51+
/////////////////////////////////////////////////////
52+
//////////////// API parameters /////////////////////
53+
/////////////////////////////////////////////////////
54+
55+
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.INTEGER, entityType = RegionResponse.class, required=true, description="Id of the Region")
56+
private Integer regionId;
57+
58+
@Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the beginning IP address in the portable IP range")
59+
private String startIp;
60+
61+
@Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, required=true, description="the ending IP address in the portable IP range")
62+
private String endIp;
63+
64+
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway for the portable IP range")
65+
private String gateway;
66+
67+
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the portable IP range")
68+
private String netmask;
69+
70+
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="VLAN id, if not specified defaulted to untagged")
71+
private String vlan;
72+
73+
/////////////////////////////////////////////////////
74+
/////////////////// Accessors ///////////////////////
75+
/////////////////////////////////////////////////////
76+
77+
public Integer getRegionId() {
78+
return regionId;
79+
}
80+
81+
public String getStartIp() {
82+
return startIp;
83+
}
84+
85+
public String getEndIp() {
86+
return endIp;
87+
}
88+
89+
public String getVlan() {
90+
return vlan;
91+
}
92+
93+
public String getGateway() {
94+
return gateway;
95+
}
96+
97+
public String getNetmask() {
98+
return netmask;
99+
}
100+
101+
/////////////////////////////////////////////////////
102+
/////////////// API Implementation///////////////////
103+
/////////////////////////////////////////////////////
104+
105+
@Override
106+
public String getCommandName() {
107+
return s_name;
108+
}
109+
110+
@Override
111+
public long getEntityOwnerId() {
112+
return Account.ACCOUNT_ID_SYSTEM;
113+
}
114+
115+
@Override
116+
public void execute(){
117+
PortableIpRange portableIpRange = _entityMgr.findById(PortableIpRange.class, getEntityId());
118+
PortableIpRangeResponse response = null;
119+
if (portableIpRange != null) {
120+
response = _responseGenerator.createPortableIPRangeResponse(portableIpRange);
121+
}
122+
response.setResponseName(getCommandName());
123+
this.setResponseObject(response);
124+
}
125+
126+
@Override
127+
public void create() throws ResourceAllocationException {
128+
try {
129+
PortableIpRange portableIpRange = _configService.createPortableIpRange(this);
130+
if (portableIpRange != null) {
131+
this.setEntityId(portableIpRange.getId());
132+
this.setEntityUuid(portableIpRange.getUuid());
133+
} else {
134+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create portable public IP range");
135+
}
136+
} catch (ConcurrentOperationException ex) {
137+
s_logger.warn("Exception: ", ex);
138+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
139+
}
140+
}
141+
142+
@Override
143+
public String getEventType() {
144+
return EventTypes.EVENT_PORTABLE_IP_RANGE_CREATE;
145+
}
146+
147+
@Override
148+
public String getEventDescription() {
149+
return "creating a portable public ip range in region: " + getRegionId();
150+
}
151+
152+
@Override
153+
public AsyncJob.Type getInstanceType() {
154+
return AsyncJob.Type.PortableIpAddress;
155+
}
156+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.api.command.admin.region;
19+
20+
import javax.inject.Inject;
21+
22+
import com.cloud.async.AsyncJob;
23+
import com.cloud.event.EventTypes;
24+
import org.apache.cloudstack.api.*;
25+
import org.apache.cloudstack.api.response.PortableIpRangeResponse;
26+
import org.apache.cloudstack.api.response.RegionResponse;
27+
import org.apache.cloudstack.api.response.SuccessResponse;
28+
import org.apache.cloudstack.region.Region;
29+
import org.apache.cloudstack.region.RegionService;
30+
import org.apache.log4j.Logger;
31+
32+
import com.cloud.user.Account;
33+
34+
@APICommand(name = "deletePortableIpRange", description="deletes a range of portable public IP's associated with a region", responseObject=SuccessResponse.class)
35+
public class DeletePortableIpRangeCmd extends BaseAsyncCmd {
36+
public static final Logger s_logger = Logger.getLogger(DeletePortableIpRangeCmd.class.getName());
37+
38+
private static final String s_name = "deleteportablepublicipresponse";
39+
40+
/////////////////////////////////////////////////////
41+
//////////////// API parameters /////////////////////
42+
/////////////////////////////////////////////////////
43+
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, required=true, entityType = PortableIpRangeResponse.class, description="Id of the portable ip range")
44+
private Long id;
45+
46+
/////////////////////////////////////////////////////
47+
/////////////////// Accessors ///////////////////////
48+
/////////////////////////////////////////////////////
49+
50+
public Long getId() {
51+
return id;
52+
}
53+
54+
/////////////////////////////////////////////////////
55+
/////////////// API Implementation///////////////////
56+
/////////////////////////////////////////////////////
57+
58+
@Override
59+
public String getCommandName() {
60+
return s_name;
61+
}
62+
63+
@Override
64+
public long getEntityOwnerId() {
65+
return Account.ACCOUNT_ID_SYSTEM;
66+
}
67+
68+
@Override
69+
public void execute(){
70+
boolean result = _configService.deletePortableIpRange(this);
71+
if (result) {
72+
SuccessResponse response = new SuccessResponse(getCommandName());
73+
this.setResponseObject(response);
74+
} else {
75+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete portable ip range");
76+
}
77+
}
78+
79+
@Override
80+
public String getEventType() {
81+
return EventTypes.EVENT_PORTABLE_IP_RANGE_DELETE;
82+
}
83+
84+
@Override
85+
public String getEventDescription() {
86+
return "deleting a portable public ip range";
87+
}
88+
89+
@Override
90+
public AsyncJob.Type getInstanceType() {
91+
return AsyncJob.Type.PortableIpAddress;
92+
}
93+
}

0 commit comments

Comments
 (0)