Skip to content

Commit d9dd2f2

Browse files
authored
Update netris VPC and tier name (apache#56)
* Update netris VPC and tier name * add support to update vpc tier name * add license * support editing names of dual stack VPCs
1 parent 0565ab9 commit d9dd2f2

File tree

18 files changed

+405
-5
lines changed

18 files changed

+405
-5
lines changed

api/src/main/java/com/cloud/network/element/VpcProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context
5555
boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException;
5656

5757
boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address);
58+
59+
boolean updateVpc(Vpc vpc, String previousVpcName);
5860
}

api/src/main/java/com/cloud/network/guru/NetworkGuru.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,8 @@ void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDe
215215
default boolean isSlaacV6Only() {
216216
return true;
217217
}
218+
219+
default boolean update(Network network, String prevNetworkName) {
220+
return true;
221+
}
218222
}

api/src/main/java/com/cloud/network/netris/NetrisService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ public interface NetrisService {
2828

2929
boolean createVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled, String cidr, boolean isVpcNetwork);
3030

31+
boolean updateVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, String previousVpcName);
32+
3133
boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc vpc);
3234

3335
boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr, Boolean globalRouting);
3436

37+
boolean updateVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String prevNetworkName);
38+
3539
boolean deleteVnetResource(long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr);
3640

3741
boolean createSnatRule(long zoneId, long accountId, long domainId, String vpcName, long vpcId, String networkName, long networkId, boolean isForVpc, String vpcCidr, String sourceNatIp);

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,8 @@ private NicVO checkForRaceAndAllocateNic(final NicProfile requested, final Netwo
10991099
nsxGuru.allocate(network, profile, vm);
11001100
} else if (isNicAllocatedForProviderPublicNetworkOnVR(network, profile, vm, Provider.Netris)) {
11011101
String guruName = "NetrisPublicNetworkGuru";
1102-
NetworkGuru nsxGuru = AdapterBase.getAdapterByName(networkGurus, guruName);
1103-
nsxGuru.allocate(network, profile, vm);
1102+
NetworkGuru netrisGuru = AdapterBase.getAdapterByName(networkGurus, guruName);
1103+
netrisGuru.allocate(network, profile, vm);
11041104
}
11051105

11061106
if (isDefaultNic != null) {

plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailVpcElementImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,9 @@ public boolean applyACLItemsToPrivateGw(PrivateGateway privateGateway,
201201
public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) {
202202
return true;
203203
}
204+
205+
@Override
206+
public boolean updateVpc(Vpc vpc, String previousVpcName) {
207+
return true;
208+
}
204209
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.agent.api;
18+
19+
public class UpdateNetrisVnetCommand extends NetrisCommand{
20+
private String prevNetworkName;
21+
private String vpcName;
22+
private Long vpcId;
23+
24+
public UpdateNetrisVnetCommand(long zoneId, Long accountId, Long domainId, String name, Long id, boolean isVpc) {
25+
super(zoneId, accountId, domainId, name, id, isVpc);
26+
}
27+
28+
public String getPrevNetworkName() {
29+
return prevNetworkName;
30+
}
31+
32+
public void setPrevNetworkName(String prevNetworkName) {
33+
this.prevNetworkName = prevNetworkName;
34+
}
35+
36+
public String getVpcName() {
37+
return vpcName;
38+
}
39+
40+
public void setVpcName(String vpcName) {
41+
this.vpcName = vpcName;
42+
}
43+
44+
public Long getVpcId() {
45+
return vpcId;
46+
}
47+
48+
public void setVpcId(Long vpcId) {
49+
this.vpcId = vpcId;
50+
}
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.agent.api;
18+
19+
public class UpdateNetrisVpcCommand extends NetrisCommand {
20+
private String previousVpcName;
21+
public UpdateNetrisVpcCommand(long zoneId, Long accountId, Long domainId, String name, Long id, boolean isVpc) {
22+
super(zoneId, accountId, domainId, name, id, isVpc);
23+
}
24+
25+
public String getPreviousVpcName() {
26+
return previousVpcName;
27+
}
28+
29+
public void setPreviousVpcName(String previousVpcName) {
30+
this.previousVpcName = previousVpcName;
31+
}
32+
}

plugins/network-elements/netris/src/main/java/org/apache/cloudstack/resource/NetrisResource.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import org.apache.cloudstack.StartupNetrisCommand;
4545
import org.apache.cloudstack.agent.api.ReleaseNatIpCommand;
4646
import org.apache.cloudstack.agent.api.SetupNetrisPublicRangeCommand;
47+
import org.apache.cloudstack.agent.api.UpdateNetrisVnetCommand;
48+
import org.apache.cloudstack.agent.api.UpdateNetrisVpcCommand;
4749
import org.apache.cloudstack.service.NetrisApiClient;
4850
import org.apache.cloudstack.service.NetrisApiClientImpl;
4951
import org.apache.logging.log4j.LogManager;
@@ -98,10 +100,14 @@ public Answer executeRequest(Command cmd) {
98100
return executeRequest((CheckHealthCommand) cmd);
99101
} else if (cmd instanceof CreateNetrisVpcCommand) {
100102
return executeRequest((CreateNetrisVpcCommand) cmd);
103+
} else if (cmd instanceof UpdateNetrisVpcCommand) {
104+
return executeRequest((UpdateNetrisVpcCommand) cmd);
101105
} else if (cmd instanceof DeleteNetrisVpcCommand) {
102106
return executeRequest((DeleteNetrisVpcCommand) cmd);
103107
} else if (cmd instanceof CreateNetrisVnetCommand) {
104108
return executeRequest((CreateNetrisVnetCommand) cmd);
109+
} else if (cmd instanceof UpdateNetrisVnetCommand) {
110+
return executeRequest((UpdateNetrisVnetCommand) cmd);
105111
} else if (cmd instanceof DeleteNetrisVnetCommand) {
106112
return executeRequest((DeleteNetrisVnetCommand) cmd);
107113
} else if (cmd instanceof SetupNetrisPublicRangeCommand) {
@@ -242,6 +248,20 @@ private Answer executeRequest(CreateNetrisVpcCommand cmd) {
242248
}
243249
}
244250

251+
private Answer executeRequest(UpdateNetrisVpcCommand cmd) {
252+
try {
253+
boolean result = netrisApiClient.updateVpc(cmd);
254+
if (!result) {
255+
return new NetrisAnswer(cmd, false, String.format("Netris VPC %s creation failed", cmd.getName()));
256+
}
257+
return new NetrisAnswer(cmd, true, "OK");
258+
} catch (CloudRuntimeException e) {
259+
String msg = String.format("Error creating Netris VPC: %s", e.getMessage());
260+
logger.error(msg, e);
261+
return new NetrisAnswer(cmd, new CloudRuntimeException(msg));
262+
}
263+
}
264+
245265
private Answer executeRequest(CreateNetrisVnetCommand cmd) {
246266
try {
247267
String vpcName = cmd.getVpcName();
@@ -257,6 +277,22 @@ private Answer executeRequest(CreateNetrisVnetCommand cmd) {
257277
}
258278
}
259279

280+
private Answer executeRequest(UpdateNetrisVnetCommand cmd) {
281+
try {
282+
String networkName = cmd.getName();
283+
String prevNetworkName = cmd.getPrevNetworkName();
284+
boolean result = netrisApiClient.updateVnet(cmd);
285+
if (!result) {
286+
return new NetrisAnswer(cmd, false, String.format("Failed to update network name from %s to %s", prevNetworkName, networkName));
287+
}
288+
return new NetrisAnswer(cmd, true, "OK");
289+
} catch (CloudRuntimeException e) {
290+
String msg = String.format("Error updating Netris vNet: %s", e.getMessage());
291+
logger.error(msg, e);
292+
return new NetrisAnswer(cmd, new CloudRuntimeException(msg));
293+
}
294+
}
295+
260296
private Answer executeRequest(DeleteNetrisVnetCommand cmd) {
261297
try {
262298
String networkName = cmd.getName();

plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.apache.cloudstack.agent.api.DeleteNetrisVpcCommand;
3535
import org.apache.cloudstack.agent.api.ReleaseNatIpCommand;
3636
import org.apache.cloudstack.agent.api.SetupNetrisPublicRangeCommand;
37+
import org.apache.cloudstack.agent.api.UpdateNetrisVnetCommand;
38+
import org.apache.cloudstack.agent.api.UpdateNetrisVpcCommand;
3739

3840
import java.util.List;
3941

@@ -50,6 +52,8 @@ public interface NetrisApiClient {
5052
*/
5153
boolean createVpc(CreateNetrisVpcCommand cmd);
5254

55+
boolean updateVpc(UpdateNetrisVpcCommand cmd);
56+
5357
/**
5458
* Delete a VPC on CloudStack removes the following Netris resources:
5559
* - Delete the IPAM Allocation for the VPC using the Prefix = VPC CIDR
@@ -64,6 +68,8 @@ public interface NetrisApiClient {
6468
*/
6569
boolean createVnet(CreateNetrisVnetCommand cmd);
6670

71+
boolean updateVnet(UpdateNetrisVnetCommand cmd);
72+
6773
/**
6874
* Deletion of a VPC network tier deletes the following Netris resources:
6975
* - Deletes the Netris IPAM Subnet for the specified network tier's CIDR

0 commit comments

Comments
 (0)