Skip to content

Commit 8f865c5

Browse files
author
Likitha Shetty
committed
Dedicate Public IP address range to an account
1 parent 95cbb79 commit 8f865c5

15 files changed

Lines changed: 1017 additions & 49 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ public class EventTypes {
226226
// VLANs/IP ranges
227227
public static final String EVENT_VLAN_IP_RANGE_CREATE = "VLAN.IP.RANGE.CREATE";
228228
public static final String EVENT_VLAN_IP_RANGE_DELETE = "VLAN.IP.RANGE.DELETE";
229+
public static final String EVENT_VLAN_IP_RANGE_DEDICATE = "VLAN.IP.RANGE.DEDICATE";
230+
public static final String EVENT_VLAN_IP_RANGE_RELEASE = "VLAN.IP.RANGE.RELEASE";
229231

230232
public static final String EVENT_STORAGE_IP_RANGE_CREATE = "STORAGE.IP.RANGE.CREATE";
231233
public static final String EVENT_STORAGE_IP_RANGE_DELETE = "STORAGE.IP.RANGE.DELETE";
@@ -545,6 +547,8 @@ public class EventTypes {
545547
// VLANs/IP ranges
546548
entityEventDetails.put(EVENT_VLAN_IP_RANGE_CREATE, Vlan.class.getName());
547549
entityEventDetails.put(EVENT_VLAN_IP_RANGE_DELETE,Vlan.class.getName());
550+
entityEventDetails.put(EVENT_VLAN_IP_RANGE_DEDICATE, Vlan.class.getName());
551+
entityEventDetails.put(EVENT_VLAN_IP_RANGE_RELEASE,Vlan.class.getName());
548552

549553
entityEventDetails.put(EVENT_STORAGE_IP_RANGE_CREATE, StorageNetworkIpRange.class.getName());
550554
entityEventDetails.put(EVENT_STORAGE_IP_RANGE_DELETE, StorageNetworkIpRange.class.getName());
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
/////////////////////////////////////////////////////
63+
/////////////////// Accessors ///////////////////////
64+
/////////////////////////////////////////////////////
65+
66+
public Long getId() {
67+
return id;
68+
}
69+
70+
public String getAccountName() {
71+
return accountName;
72+
}
73+
74+
public Long getDomainId() {
75+
return domainId;
76+
}
77+
78+
public Long getProjectId() {
79+
return projectId;
80+
}
81+
82+
/////////////////////////////////////////////////////
83+
/////////////// API Implementation///////////////////
84+
/////////////////////////////////////////////////////
85+
86+
@Override
87+
public String getCommandName() {
88+
return s_name;
89+
}
90+
91+
@Override
92+
public long getEntityOwnerId() {
93+
return Account.ACCOUNT_ID_SYSTEM;
94+
}
95+
96+
@Override
97+
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
98+
Vlan result = _configService.dedicatePublicIpRange(this);
99+
if (result != null) {
100+
VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
101+
response.setResponseName(getCommandName());
102+
this.setResponseObject(response);
103+
} else {
104+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate vlan ip range");
105+
}
106+
}
107+
108+
}
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

100644100755
Lines changed: 4 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;
@@ -150,6 +151,8 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
150151
*/
151152
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
152153

154+
boolean releasePublicIpRange(long userId, long vlanDbId, Account caller);
155+
153156
/**
154157
* Converts a comma separated list of tags to a List
155158
*
@@ -211,7 +214,7 @@ NetworkOfferingVO createNetworkOffering(String name, String displayText, Traffic
211214

212215
ClusterVO getCluster(long id);
213216

214-
boolean deleteAccountSpecificVirtualRanges(long accountId);
217+
boolean releaseAccountSpecificVirtualRanges(long accountId);
215218

216219
/**
217220
* 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)