Skip to content

Commit d6ed8d7

Browse files
Likitha ShettyJessica Wang
authored andcommitted
Dedicate Public IP range
1 parent 68a30d4 commit d6ed8d7

15 files changed

Lines changed: 997 additions & 48 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
3636
import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
3737
import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
38+
import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
3839
import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
40+
import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
3941
import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
4042
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
4143
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
@@ -234,6 +236,10 @@ public interface ConfigurationService {
234236

235237
boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd);
236238

239+
Vlan dedicatePublicIpRange(DedicatePublicIpRangeCmd cmd) throws ResourceAllocationException;
240+
241+
boolean releasePublicIpRange(ReleasePublicIpRangeCmd cmd);
242+
237243
NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd);
238244

239245
NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public class EventTypes {
223223
// VLANs/IP ranges
224224
public static final String EVENT_VLAN_IP_RANGE_CREATE = "VLAN.IP.RANGE.CREATE";
225225
public static final String EVENT_VLAN_IP_RANGE_DELETE = "VLAN.IP.RANGE.DELETE";
226+
public static final String EVENT_VLAN_IP_RANGE_DEDICATE = "VLAN.IP.RANGE.DEDICATE";
227+
public static final String EVENT_VLAN_IP_RANGE_RELEASE = "VLAN.IP.RANGE.RELEASE";
226228

227229
public static final String EVENT_STORAGE_IP_RANGE_CREATE = "STORAGE.IP.RANGE.CREATE";
228230
public static final String EVENT_STORAGE_IP_RANGE_DELETE = "STORAGE.IP.RANGE.DELETE";
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
package org.apache.cloudstack.api.command.admin.vlan;
18+
19+
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.ApiErrorCode;
22+
import org.apache.cloudstack.api.BaseCmd;
23+
import org.apache.cloudstack.api.Parameter;
24+
import org.apache.cloudstack.api.ServerApiException;
25+
import org.apache.cloudstack.api.response.DomainResponse;
26+
import org.apache.cloudstack.api.response.ProjectResponse;
27+
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
28+
import org.apache.cloudstack.api.response.ZoneResponse;
29+
import org.apache.log4j.Logger;
30+
31+
import com.cloud.dc.Vlan;
32+
import com.cloud.exception.ResourceAllocationException;
33+
import com.cloud.exception.ResourceUnavailableException;
34+
import com.cloud.user.Account;
35+
36+
@APICommand(name = "dedicatePublicIpRange", description="Dedicates a Public IP range to an account", responseObject=VlanIpRangeResponse.class)
37+
public class DedicatePublicIpRangeCmd extends BaseCmd {
38+
public static final Logger s_logger = Logger.getLogger(DedicatePublicIpRangeCmd.class.getName());
39+
40+
private static final String s_name = "dedicatepubliciprangeresponse";
41+
42+
/////////////////////////////////////////////////////
43+
//////////////// API parameters /////////////////////
44+
/////////////////////////////////////////////////////
45+
46+
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = VlanIpRangeResponse.class,
47+
required=true, description="the id of the VLAN IP range")
48+
private Long id;
49+
50+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true,
51+
description="account who will own the VLAN")
52+
private String accountName;
53+
54+
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
55+
description="project who will own the VLAN")
56+
private Long projectId;
57+
58+
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class,
59+
required=true, description="domain ID of the account owning a VLAN")
60+
private Long domainId;
61+
62+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
63+
required=true, description="the Zone ID of the VLAN IP range")
64+
private Long zoneId;
65+
66+
/////////////////////////////////////////////////////
67+
/////////////////// Accessors ///////////////////////
68+
/////////////////////////////////////////////////////
69+
70+
public Long getId() {
71+
return id;
72+
}
73+
74+
public String getAccountName() {
75+
return accountName;
76+
}
77+
78+
public Long getDomainId() {
79+
return domainId;
80+
}
81+
82+
public Long getProjectId() {
83+
return projectId;
84+
}
85+
86+
public Long getZoneId() {
87+
return zoneId;
88+
}
89+
90+
/////////////////////////////////////////////////////
91+
/////////////// API Implementation///////////////////
92+
/////////////////////////////////////////////////////
93+
94+
@Override
95+
public String getCommandName() {
96+
return s_name;
97+
}
98+
99+
@Override
100+
public long getEntityOwnerId() {
101+
return Account.ACCOUNT_ID_SYSTEM;
102+
}
103+
104+
@Override
105+
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
106+
Vlan result = _configService.dedicatePublicIpRange(this);
107+
if (result != null) {
108+
VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
109+
response.setResponseName(getCommandName());
110+
this.setResponseObject(response);
111+
} else {
112+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate vlan ip range");
113+
}
114+
}
115+
116+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
package org.apache.cloudstack.api.command.admin.vlan;
18+
19+
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.ApiErrorCode;
22+
import org.apache.cloudstack.api.BaseCmd;
23+
import org.apache.cloudstack.api.Parameter;
24+
import org.apache.cloudstack.api.ServerApiException;
25+
import org.apache.cloudstack.api.response.SuccessResponse;
26+
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
27+
import org.apache.log4j.Logger;
28+
29+
import com.cloud.user.Account;
30+
31+
@APICommand(name = "releasePublicIpRange", description="Releases a Public IP range back to the system pool", responseObject=SuccessResponse.class)
32+
public class ReleasePublicIpRangeCmd extends BaseCmd {
33+
public static final Logger s_logger = Logger.getLogger(ReleasePublicIpRangeCmd.class.getName());
34+
35+
private static final String s_name = "releasepubliciprangeresponse";
36+
37+
/////////////////////////////////////////////////////
38+
//////////////// API parameters /////////////////////
39+
/////////////////////////////////////////////////////
40+
41+
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = VlanIpRangeResponse.class,
42+
required=true, description="the id of the Public IP range")
43+
private Long id;
44+
45+
/////////////////////////////////////////////////////
46+
/////////////////// Accessors ///////////////////////
47+
/////////////////////////////////////////////////////
48+
49+
public Long getId() {
50+
return id;
51+
}
52+
53+
/////////////////////////////////////////////////////
54+
/////////////// API Implementation///////////////////
55+
/////////////////////////////////////////////////////
56+
57+
@Override
58+
public String getCommandName() {
59+
return s_name;
60+
}
61+
62+
@Override
63+
public long getEntityOwnerId() {
64+
return Account.ACCOUNT_ID_SYSTEM;
65+
}
66+
67+
@Override
68+
public void execute(){
69+
boolean result = _configService.releasePublicIpRange(this);
70+
if (result) {
71+
SuccessResponse response = new SuccessResponse(getCommandName());
72+
this.setResponseObject(response);
73+
} else {
74+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to release public ip range");
75+
}
76+
}
77+
}

client/tomcatconf/commands.properties.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ listDiskOfferings=15
124124
createVlanIpRange=1
125125
deleteVlanIpRange=1
126126
listVlanIpRanges=1
127+
dedicatePublicIpRange=1
128+
releasePublicIpRange=1
127129

128130
#### address commands
129131
associateIpAddress=15

server/src/com/cloud/configuration/ConfigurationManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.exception.ConcurrentOperationException;
3131
import com.cloud.exception.InsufficientCapacityException;
3232
import com.cloud.exception.InvalidParameterValueException;
33+
import com.cloud.exception.ResourceAllocationException;
3334
import com.cloud.network.Network;
3435
import com.cloud.network.Network.Capability;
3536
import com.cloud.network.Network.Provider;
@@ -149,6 +150,10 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
149150
*/
150151
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
151152

153+
boolean releasePublicIpRange(long userId, long vlanDbId, Account caller);
154+
155+
Vlan dedicatePublicIpRange(Long vlanDbId, String accountName, Long domainId, Long zoneId, Long projectId) throws ResourceAllocationException;
156+
152157
/**
153158
* Converts a comma separated list of tags to a List
154159
*
@@ -210,7 +215,7 @@ NetworkOfferingVO createNetworkOffering(String name, String displayText, Traffic
210215

211216
ClusterVO getCluster(long id);
212217

213-
boolean deleteAccountSpecificVirtualRanges(long accountId);
218+
boolean releaseAccountSpecificVirtualRanges(long accountId);
214219

215220
/**
216221
* Edits a pod in the database. Will not allow you to edit pods that are being used anywhere in the system.

0 commit comments

Comments
 (0)