Skip to content

Commit 9ae1d06

Browse files
committed
adding link from service to network
1 parent 6c9c51a commit 9ae1d06

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

netmaster/master/servicelb.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ limitations under the License.
1616
package master
1717

1818
import (
19+
"reflect"
20+
"strings"
21+
1922
log "github.com/Sirupsen/logrus"
2023
"github.com/contiv/netplugin/core"
2124
"github.com/contiv/netplugin/netmaster/intent"
2225
"github.com/contiv/netplugin/netmaster/mastercfg"
2326
"github.com/contiv/netplugin/utils"
24-
"reflect"
25-
"strings"
2627
)
2728

2829
//CreateServiceLB adds to the etcd state

netmaster/objApi/apiController.go

+50
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@ func (ac *APIController) NetworkDelete(network *contivModel.Network) error {
10471047
network.NetworkName, epgCount)
10481048
}
10491049

1050+
svcCount := len(network.LinkSets.Servicelbs)
1051+
if svcCount != 0 {
1052+
return core.Errorf("cannot delete %s has %d services ",
1053+
network.NetworkName, svcCount)
1054+
}
1055+
10501056
// Remove link
10511057
modeldb.RemoveLinkSet(&tenant.LinkSets.Networks, network)
10521058

@@ -1635,6 +1641,20 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
16351641
return core.Errorf("Invalid Port maping . Port format is - Port:TargetPort:Protocol")
16361642
}
16371643

1644+
if serviceCfg.TenantName == "" {
1645+
return core.Errorf("Invalid tenant name")
1646+
}
1647+
1648+
tenant := contivModel.FindTenant(serviceCfg.TenantName)
1649+
if tenant == nil {
1650+
return core.Errorf("Tenant %s not found", serviceCfg.TenantName)
1651+
}
1652+
1653+
network := contivModel.FindNetwork(serviceCfg.TenantName + ":" + serviceCfg.NetworkName)
1654+
if network == nil {
1655+
return core.Errorf("Network %s not found", serviceCfg.NetworkName)
1656+
}
1657+
16381658
// Get the state driver
16391659
stateDriver, err := utils.GetStateDriver()
16401660
if err != nil {
@@ -1667,6 +1687,19 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
16671687
log.Errorf("Error creating service {%+v}. Err: %v", serviceIntentCfg.ServiceName, err)
16681688
return err
16691689
}
1690+
// Setup links
1691+
if tenant != nil {
1692+
modeldb.AddLink(&serviceCfg.Links.Tenant, tenant)
1693+
modeldb.AddLinkSet(&tenant.LinkSets.Servicelbs, serviceCfg)
1694+
tenant.Write()
1695+
}
1696+
1697+
// Setup links
1698+
if network != nil {
1699+
modeldb.AddLink(&serviceCfg.Links.Network, network)
1700+
modeldb.AddLinkSet(&network.LinkSets.Servicelbs, serviceCfg)
1701+
network.Write()
1702+
}
16701703
return nil
16711704

16721705
}
@@ -1710,6 +1743,23 @@ func (ac *APIController) ServiceLBDelete(serviceCfg *contivModel.ServiceLB) erro
17101743
log.Errorf("Error deleting Service Load Balancer object {%+v}. Err: %v", serviceCfg.ServiceName, err)
17111744
return err
17121745
}
1746+
// Find the tenant
1747+
tenant := contivModel.FindTenant(serviceCfg.TenantName)
1748+
if tenant == nil {
1749+
return core.Errorf("Tenant %s not found", serviceCfg.TenantName)
1750+
}
1751+
1752+
modeldb.RemoveLinkSet(&tenant.LinkSets.Servicelbs, serviceCfg)
1753+
tenant.Write()
1754+
1755+
nwKey := serviceCfg.TenantName + ":" + serviceCfg.NetworkName
1756+
network := contivModel.FindNetwork(nwKey)
1757+
if network == nil {
1758+
return core.Errorf("Network %s not found in tenant %s", serviceCfg.NetworkName, serviceCfg.TenantName)
1759+
}
1760+
modeldb.RemoveLinkSet(&network.LinkSets.Servicelbs, serviceCfg)
1761+
network.Write()
1762+
17131763
return nil
17141764

17151765
}

0 commit comments

Comments
 (0)