Skip to content

Commit e02ffed

Browse files
committed
Phase5 - Support for LB - create, delete and Update operations (#49)
* Add support for Netris ACLs * acl support * Make acl api call to netris to create the rule * refactor add acl rule to populate the right fields * support icmp type acl rule * acl rule creation - move netrisnetworkRule * Update ACL naming on Netris * Add support for Deletion of netris acls * Add support to delete and re-order ACL rules * support creation of default acl rules and replacing acl rules * fix NSXNetworkRule * Fix naming convention for NAT subnets to follow other resources * Use vpc ID for nat subnets * Phase5 - Support for LB - create, delete and Update operations * Use new nat subnet name for deletion of static nat rule * add support to add netris lb rule * support deletion of LB rule on Netris * add checks when editing unsupported fields of LB rule for Netris and hide columns on the UI * fix test failure * fix imports * add license * address comments
1 parent 62febc2 commit e02ffed

File tree

15 files changed

+617
-37
lines changed

15 files changed

+617
-37
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.netris;
18+
19+
public class NetrisLbBackend {
20+
private long vmId;
21+
private String vmIp;
22+
private int port;
23+
24+
public NetrisLbBackend(long vmId, String vmIp, int port) {
25+
this.vmId = vmId;
26+
this.vmIp = vmIp;
27+
this.port = port;
28+
}
29+
30+
public long getVmId() {
31+
return vmId;
32+
}
33+
34+
public String getVmIp() {
35+
return vmIp;
36+
}
37+
38+
public int getPort() {
39+
return port;
40+
}
41+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,33 @@
1919
import com.cloud.network.SDNProviderNetworkRule;
2020

2121

22+
import java.util.List;
23+
2224
public class NetrisNetworkRule {
2325
public enum NetrisRuleAction {
2426
PERMIT, DENY
2527
}
2628

2729
private SDNProviderNetworkRule baseRule;
2830
private NetrisRuleAction aclAction;
31+
private List<NetrisLbBackend> lbBackends;
2932
private String reason;
3033

3134
public NetrisNetworkRule(Builder builder) {
3235
this.baseRule = builder.baseRule;
3336
this.aclAction = builder.aclAction;
37+
this.lbBackends = builder.lbBackends;
3438
this.reason = builder.reason;
3539
}
3640

3741
public NetrisRuleAction getAclAction() {
3842
return aclAction;
3943
}
4044

45+
public List<NetrisLbBackend> getLbBackends() {
46+
return lbBackends;
47+
}
48+
4149
public String getReason() {
4250
return reason;
4351
}
@@ -50,6 +58,7 @@ public SDNProviderNetworkRule getBaseRule() {
5058
public static class Builder {
5159
private SDNProviderNetworkRule baseRule;
5260
private NetrisRuleAction aclAction;
61+
private List<NetrisLbBackend> lbBackends;
5362
private String reason;
5463

5564
public Builder baseRule(SDNProviderNetworkRule baseRule) {
@@ -62,6 +71,11 @@ public Builder aclAction(NetrisRuleAction aclAction) {
6271
return this;
6372
}
6473

74+
public Builder lbBackends(List<NetrisLbBackend> lbBackends) {
75+
this.lbBackends = lbBackends;
76+
return this;
77+
}
78+
6579
public Builder reason(String reason) {
6680
this.reason = reason;
6781
return this;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ public interface NetrisService {
5454
boolean deleteStaticRoute(long zoneId, long accountId, long domainId, String networkResourceName, Long networkResourceId, boolean isForVpc, String prefix, String nextHop, Long routeId);
5555

5656
boolean releaseNatIp(long zoneId, String publicIp);
57+
58+
boolean createLbRule(NetrisNetworkRule rule);
59+
boolean deleteLbRule(NetrisNetworkRule rule);
5760
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
import com.cloud.network.netris.NetrisLbBackend;
20+
21+
import java.util.List;
22+
23+
public class CreateOrUpdateNetrisLoadBalancerRuleCommand extends NetrisCommand {
24+
private final String publicPort;
25+
private final String privatePort;
26+
private final String algorithm;
27+
private final String protocol;
28+
List<NetrisLbBackend> lbBackends;
29+
private String publicIp;
30+
private final Long lbId;
31+
32+
public CreateOrUpdateNetrisLoadBalancerRuleCommand(long zoneId, Long accountId, Long domainId, String name, Long id, boolean isVpc,
33+
List<NetrisLbBackend> lbBackends, long lbId, String publicIp, String publicPort,
34+
String privatePort, String algorithm, String protocol) {
35+
super(zoneId, accountId, domainId, name, id, isVpc);
36+
this.lbId = lbId;
37+
this.publicIp = publicIp;
38+
this.publicPort = publicPort;
39+
this.privatePort = privatePort;
40+
this.algorithm = algorithm;
41+
this.protocol = protocol;
42+
this.lbBackends = lbBackends;
43+
}
44+
45+
public String getPublicPort() {
46+
return publicPort;
47+
}
48+
49+
public String getPrivatePort() {
50+
return privatePort;
51+
}
52+
53+
public String getAlgorithm() {
54+
return algorithm;
55+
}
56+
57+
public String getProtocol() {
58+
return protocol;
59+
}
60+
61+
public List<NetrisLbBackend> getLbBackends() {
62+
return lbBackends;
63+
}
64+
65+
public Long getLbId() {
66+
return lbId;
67+
}
68+
69+
public String getPublicIp() {
70+
return publicIp;
71+
}
72+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 DeleteNetrisLoadBalancerRuleCommand extends NetrisCommand {
20+
private Long lbId;
21+
22+
public DeleteNetrisLoadBalancerRuleCommand(long zoneId, Long accountId, Long domainId, String name, Long id, boolean isVpc, Long lbId) {
23+
super(zoneId, accountId, domainId, name, id, isVpc);
24+
this.lbId = lbId;
25+
}
26+
27+
public Long getLbId() {
28+
return lbId;
29+
}
30+
31+
public void setLbId(Long lbId) {
32+
this.lbId = lbId;
33+
}
34+
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
import org.apache.cloudstack.agent.api.AddOrUpdateNetrisStaticRouteCommand;
3333
import org.apache.cloudstack.agent.api.CreateNetrisVnetCommand;
3434
import org.apache.cloudstack.agent.api.CreateNetrisVpcCommand;
35+
import org.apache.cloudstack.agent.api.CreateOrUpdateNetrisLoadBalancerRuleCommand;
3536
import org.apache.cloudstack.agent.api.CreateOrUpdateNetrisNatCommand;
3637
import org.apache.cloudstack.agent.api.DeleteNetrisACLCommand;
38+
import org.apache.cloudstack.agent.api.DeleteNetrisLoadBalancerRuleCommand;
3739
import org.apache.cloudstack.agent.api.DeleteNetrisNatRuleCommand;
3840
import org.apache.cloudstack.agent.api.DeleteNetrisStaticRouteCommand;
3941
import org.apache.cloudstack.agent.api.DeleteNetrisVnetCommand;
@@ -118,6 +120,10 @@ public Answer executeRequest(Command cmd) {
118120
return executeRequest((AddOrUpdateNetrisStaticRouteCommand) cmd);
119121
} else if (cmd instanceof ReleaseNatIpCommand) {
120122
return executeRequest((ReleaseNatIpCommand) cmd);
123+
} else if (cmd instanceof CreateOrUpdateNetrisLoadBalancerRuleCommand) {
124+
return executeRequest((CreateOrUpdateNetrisLoadBalancerRuleCommand) cmd);
125+
} else if (cmd instanceof DeleteNetrisLoadBalancerRuleCommand) {
126+
return executeRequest((DeleteNetrisLoadBalancerRuleCommand) cmd);
121127
} else {
122128
return Answer.createUnsupportedCommandAnswer(cmd);
123129
}
@@ -352,6 +358,31 @@ private Answer executeRequest(ReleaseNatIpCommand cmd) {
352358
return new NetrisAnswer(cmd, true, "OK");
353359
}
354360

361+
private Answer executeRequest(CreateOrUpdateNetrisLoadBalancerRuleCommand cmd) {
362+
boolean result = netrisApiClient.createLbRule(cmd);
363+
if (!result) {
364+
return new NetrisAnswer(cmd, false, String.format("Failed to create Netris LB rule for %s: %s, " +
365+
"for private port: %s and public port: %s", getNetworkType(cmd.isVpc()), cmd.getName(), cmd.getPrivatePort(), cmd.getPublicPort(), cmd.getPublicPort()));
366+
}
367+
return new NetrisAnswer(cmd, true, "OK");
368+
}
369+
370+
private Answer executeRequest(DeleteNetrisLoadBalancerRuleCommand cmd) {
371+
boolean result = netrisApiClient.deleteLbRule(cmd);
372+
if (!result) {
373+
return new NetrisAnswer(cmd, false, String.format("Failed to delete Netris LB rule for %s: %s, " +
374+
"for private port: %s and public port: %s", getNetworkType(cmd.isVpc()), cmd.getName()));
375+
}
376+
return new NetrisAnswer(cmd, true, "OK");
377+
}
378+
379+
private String getNetworkType(Boolean isVpc) {
380+
if (isVpc) {
381+
return "VPC";
382+
}
383+
return "Network";
384+
}
385+
355386
@Override
356387
public boolean start() {
357388
return true;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class NetrisResourceObjectUtils {
2525

2626
public enum NetrisObjectType {
27-
VPC, IPAM_ALLOCATION, IPAM_SUBNET, VNET, SNAT, STATICNAT, DNAT, STATICROUTE, ACL
27+
VPC, IPAM_ALLOCATION, IPAM_SUBNET, VNET, SNAT, STATICNAT, DNAT, STATICROUTE, ACL, LB
2828
}
2929

3030
public static String retrieveNetrisResourceObjectName(NetrisCommand cmd, NetrisObjectType netrisObjectType, String... suffixes) {
@@ -59,7 +59,7 @@ public static String retrieveNetrisResourceObjectName(NetrisCommand cmd, NetrisO
5959
break;
6060
case IPAM_SUBNET:
6161
if (!isZoneLevel) {
62-
if (Objects.nonNull(objectId) && Objects.nonNull(objectName)) {
62+
if (Objects.nonNull(objectId) && Objects.nonNull(objectName) && !isVpc) {
6363
stringBuilder.append(String.format("-N%s", objectId));
6464
} else {
6565
stringBuilder.append(String.format("-V%s-%s", suffixes[0], suffixes[1]));
@@ -86,6 +86,9 @@ public static String retrieveNetrisResourceObjectName(NetrisCommand cmd, NetrisO
8686
case VNET:
8787
case ACL:
8888
break;
89+
case LB:
90+
stringBuilder.append(String.format("%s%s", prefix, objectId));
91+
break;
8992
default:
9093
stringBuilder.append(String.format("-%s", objectName));
9194
break;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.apache.cloudstack.agent.api.AddOrUpdateNetrisStaticRouteCommand;
2525
import org.apache.cloudstack.agent.api.CreateNetrisVnetCommand;
2626
import org.apache.cloudstack.agent.api.CreateNetrisVpcCommand;
27+
import org.apache.cloudstack.agent.api.CreateOrUpdateNetrisLoadBalancerRuleCommand;
2728
import org.apache.cloudstack.agent.api.CreateOrUpdateNetrisNatCommand;
2829
import org.apache.cloudstack.agent.api.DeleteNetrisACLCommand;
30+
import org.apache.cloudstack.agent.api.DeleteNetrisLoadBalancerRuleCommand;
2931
import org.apache.cloudstack.agent.api.DeleteNetrisNatRuleCommand;
3032
import org.apache.cloudstack.agent.api.DeleteNetrisStaticRouteCommand;
3133
import org.apache.cloudstack.agent.api.DeleteNetrisVnetCommand;
@@ -84,4 +86,6 @@ public interface NetrisApiClient {
8486
boolean addOrUpdateStaticRoute(AddOrUpdateNetrisStaticRouteCommand cmd);
8587
boolean deleteStaticRoute(DeleteNetrisStaticRouteCommand cmd);
8688
boolean releaseNatIp(ReleaseNatIpCommand cmd);
89+
boolean createLbRule(CreateOrUpdateNetrisLoadBalancerRuleCommand cmd);
90+
boolean deleteLbRule(DeleteNetrisLoadBalancerRuleCommand cmd);
8791
}

0 commit comments

Comments
 (0)