Skip to content

Commit c8d8432

Browse files
author
Likitha Shetty
committed
Dedicate guest vlan range to account
1 parent b33b316 commit c8d8432

32 files changed

Lines changed: 1790 additions & 13 deletions

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public enum Type {
5050
AutoScaleVmProfile,
5151
AutoScaleVmGroup,
5252
GlobalLoadBalancerRule,
53-
AffinityGroup
53+
AffinityGroup,
54+
DedicatedGuestVlanRange
5455
}
5556

5657
long getUserId();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ public class EventTypes {
390390
public static final String EVENT_AFFINITY_GROUP_REMOVE = "AG.REMOVE";
391391
public static final String EVENT_VM_AFFINITY_GROUP_UPDATE = "VM.AG.UPDATE";
392392

393+
// Dedicated guest vlan range
394+
public static final String EVENT_GUEST_VLAN_RANGE_DEDICATE = "GUESTVLANRANGE.DEDICATE";
395+
public static final String EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE = "GUESTVLANRANGE.RELEASE";
396+
393397
static {
394398

395399
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -690,6 +694,9 @@ public class EventTypes {
690694
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_UPDATE, AutoScaleVmGroup.class.getName());
691695
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_ENABLE, AutoScaleVmGroup.class.getName());
692696
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_DISABLE, AutoScaleVmGroup.class.getName());
697+
698+
entityEventDetails.put(EVENT_GUEST_VLAN_RANGE_DEDICATE, GuestVlan.class.getName());
699+
entityEventDetails.put(EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, GuestVlan.class.getName());
693700
}
694701

695702
public static String getEntityForEvent (String eventName) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 com.cloud.network;
18+
19+
import org.apache.cloudstack.api.Identity;
20+
import org.apache.cloudstack.api.InternalIdentity;
21+
22+
public interface GuestVlan extends InternalIdentity, Identity {
23+
24+
public long getId();
25+
26+
public long getAccountId();
27+
28+
public String getGuestVlanRange();
29+
30+
public long getPhysicalNetworkId();
31+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.List;
2020

21+
import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
22+
import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
2123
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
2224
import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
2325
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
@@ -29,6 +31,7 @@
2931
import com.cloud.exception.InsufficientCapacityException;
3032
import com.cloud.exception.ResourceAllocationException;
3133
import com.cloud.exception.ResourceUnavailableException;
34+
import com.cloud.network.GuestVlan;
3235
import com.cloud.network.Network.Service;
3336
import com.cloud.network.Networks.TrafficType;
3437
import com.cloud.user.Account;
@@ -114,6 +117,12 @@ PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkI
114117

115118
boolean deletePhysicalNetworkTrafficType(Long id);
116119

120+
GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd);
121+
122+
Pair<List<? extends GuestVlan>, Integer> listDedicatedGuestVlanRanges(ListDedicatedGuestVlanRangesCmd cmd);
123+
124+
boolean releaseDedicatedGuestVlanRange(Long dedicatedGuestVlanRangeId);
125+
117126
Pair<List<? extends PhysicalNetworkTrafficType>, Integer> listTrafficTypes(Long physicalNetworkId);
118127

119128

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public class ApiConstants {
8585
public static final String GSLB_SERVICE_TYPE = "gslbservicetype";
8686
public static final String GSLB_STICKY_SESSION_METHOD = "gslbstickysessionmethodname";
8787
public static final String GUEST_CIDR_ADDRESS = "guestcidraddress";
88+
public static final String GUEST_VLAN_RANGE = "guestvlanrange";
8889
public static final String HA_ENABLE = "haenable";
8990
public static final String HOST_ID = "hostid";
9091
public static final String HOST_NAME = "hostname";
@@ -221,6 +222,7 @@ public class ApiConstants {
221222
public static final String VIRTUAL_MACHINE_ID = "virtualmachineid";
222223
public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids";
223224
public static final String VLAN = "vlan";
225+
public static final String VLAN_RANGE = "vlanrange";
224226
public static final String REMOVE_VLAN="removevlan";
225227
public static final String VLAN_ID = "vlanid";
226228
public static final String VM_AVAILABLE = "vmavailable";

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public interface ResponseGenerator {
198198

199199
IPAddressResponse createIPAddressResponse(IpAddress ipAddress);
200200

201+
GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan result);
202+
201203
GlobalLoadBalancerResponse createGlobalLoadBalancerResponse(GlobalLoadBalancerRule globalLoadBalancerRule);
202204

203205
LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
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.network;
18+
19+
import com.cloud.exception.ResourceAllocationException;
20+
import com.cloud.exception.ResourceUnavailableException;
21+
import com.cloud.network.GuestVlan;
22+
import com.cloud.user.Account;
23+
import org.apache.cloudstack.api.*;
24+
import org.apache.cloudstack.api.response.*;
25+
import org.apache.log4j.Logger;
26+
27+
@APICommand(name = "dedicateGuestVlanRange", description="Dedicates a guest vlan range to an account", responseObject=GuestVlanRangeResponse.class)
28+
public class DedicateGuestVlanRangeCmd extends BaseCmd {
29+
public static final Logger s_logger = Logger.getLogger(DedicateGuestVlanRangeCmd.class.getName());
30+
31+
private static final String s_name = "dedicateguestvlanrangeresponse";
32+
33+
/////////////////////////////////////////////////////
34+
//////////////// API parameters /////////////////////
35+
/////////////////////////////////////////////////////
36+
37+
@Parameter(name=ApiConstants.VLAN_RANGE, type=CommandType.STRING, required=true,
38+
description="guest vlan range to be dedicated")
39+
private String vlan;
40+
41+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true,
42+
description="account who will own the VLAN")
43+
private String accountName;
44+
45+
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
46+
description="project who will own the VLAN")
47+
private Long projectId;
48+
49+
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class,
50+
required=true, description="domain ID of the account owning a VLAN")
51+
private Long domainId;
52+
53+
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.UUID, entityType = PhysicalNetworkResponse.class,
54+
required=true, description="physical network ID of the vlan")
55+
private Long physicalNetworkId;
56+
57+
/////////////////////////////////////////////////////
58+
/////////////////// Accessors ///////////////////////
59+
/////////////////////////////////////////////////////
60+
61+
public String getVlan() {
62+
return vlan;
63+
}
64+
65+
public String getAccountName() {
66+
return accountName;
67+
}
68+
69+
public Long getDomainId() {
70+
return domainId;
71+
}
72+
73+
public Long getPhysicalNetworkId() {
74+
return physicalNetworkId;
75+
}
76+
77+
public Long getProjectId() {
78+
return projectId;
79+
}
80+
81+
/////////////////////////////////////////////////////
82+
/////////////// API Implementation///////////////////
83+
/////////////////////////////////////////////////////
84+
85+
@Override
86+
public String getCommandName() {
87+
return s_name;
88+
}
89+
90+
@Override
91+
public long getEntityOwnerId() {
92+
return Account.ACCOUNT_ID_SYSTEM;
93+
}
94+
95+
@Override
96+
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
97+
GuestVlan result = _networkService.dedicateGuestVlanRange(this);
98+
if (result != null) {
99+
GuestVlanRangeResponse response = _responseGenerator.createDedicatedGuestVlanRangeResponse(result);
100+
response.setResponseName(getCommandName());
101+
response.setObjectName("dedicatedguestvlanrange");
102+
this.setResponseObject(response);
103+
} else {
104+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate guest vlan range");
105+
}
106+
}
107+
108+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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.network;
18+
19+
import com.cloud.network.GuestVlan;
20+
import com.cloud.user.Account;
21+
import com.cloud.utils.Pair;
22+
import org.apache.cloudstack.api.*;
23+
import org.apache.cloudstack.api.response.*;
24+
import org.apache.log4j.Logger;
25+
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
29+
30+
@APICommand(name = "listDedicatedGuestVlanRanges", description="Lists dedicated guest vlan ranges", responseObject=GuestVlanRangeResponse.class)
31+
public class ListDedicatedGuestVlanRangesCmd extends BaseListCmd {
32+
public static final Logger s_logger = Logger.getLogger(ListDedicatedGuestVlanRangesCmd.class.getName());
33+
34+
private static final String s_name = "listdedicatedguestvlanrangesresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=GuestVlanRangeResponse.class,
41+
description="list dedicated guest vlan ranges by id")
42+
private Long id;
43+
44+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account with which the guest VLAN range is associated. Must be used with the domainId parameter.")
45+
private String accountName;
46+
47+
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
48+
description="project who will own the guest VLAN range")
49+
private Long projectId;
50+
51+
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class,
52+
description="the domain ID with which the guest VLAN range is associated. If used with the account parameter, returns all guest VLAN ranges for that account in the specified domain.")
53+
private Long domainId;
54+
55+
@Parameter(name=ApiConstants.GUEST_VLAN_RANGE, type=CommandType.STRING, description="the dedicated guest vlan range")
56+
private String guestVlanRange;
57+
58+
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.UUID, entityType = PhysicalNetworkResponse.class,
59+
description="physical network id of the guest VLAN range")
60+
private Long physicalNetworkId;
61+
62+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
63+
description="zone of the guest VLAN 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 String getGuestVlanRange() {
87+
return guestVlanRange;
88+
}
89+
90+
public Long getPhysicalNetworkId() {
91+
return physicalNetworkId;
92+
}
93+
94+
public Long getZoneId() {
95+
return zoneId;
96+
}
97+
98+
99+
/////////////////////////////////////////////////////
100+
/////////////// API Implementation///////////////////
101+
/////////////////////////////////////////////////////
102+
103+
@Override
104+
public String getCommandName() {
105+
return s_name;
106+
}
107+
108+
@Override
109+
public long getEntityOwnerId() {
110+
return Account.ACCOUNT_ID_SYSTEM;
111+
}
112+
113+
@Override
114+
public void execute(){
115+
Pair<List<? extends GuestVlan>, Integer> vlans = _networkService.listDedicatedGuestVlanRanges(this);
116+
ListResponse<GuestVlanRangeResponse> response = new ListResponse<GuestVlanRangeResponse>();
117+
List<GuestVlanRangeResponse> guestVlanResponses = new ArrayList<GuestVlanRangeResponse>();
118+
for (GuestVlan vlan : vlans.first()) {
119+
GuestVlanRangeResponse guestVlanResponse = _responseGenerator.createDedicatedGuestVlanRangeResponse(vlan);
120+
guestVlanResponse.setObjectName("dedicatedguestvlanrange");
121+
guestVlanResponses.add(guestVlanResponse);
122+
}
123+
124+
response.setResponses(guestVlanResponses, vlans.second());
125+
response.setResponseName(getCommandName());
126+
this.setResponseObject(response);
127+
}
128+
129+
}

0 commit comments

Comments
 (0)