@@ -1047,6 +1047,12 @@ func (ac *APIController) NetworkDelete(network *contivModel.Network) error {
1047
1047
network .NetworkName , epgCount )
1048
1048
}
1049
1049
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
+
1050
1056
// Remove link
1051
1057
modeldb .RemoveLinkSet (& tenant .LinkSets .Networks , network )
1052
1058
@@ -1635,6 +1641,20 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
1635
1641
return core .Errorf ("Invalid Port maping . Port format is - Port:TargetPort:Protocol" )
1636
1642
}
1637
1643
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
+
1638
1658
// Get the state driver
1639
1659
stateDriver , err := utils .GetStateDriver ()
1640
1660
if err != nil {
@@ -1667,6 +1687,19 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
1667
1687
log .Errorf ("Error creating service {%+v}. Err: %v" , serviceIntentCfg .ServiceName , err )
1668
1688
return err
1669
1689
}
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
+ }
1670
1703
return nil
1671
1704
1672
1705
}
@@ -1710,6 +1743,23 @@ func (ac *APIController) ServiceLBDelete(serviceCfg *contivModel.ServiceLB) erro
1710
1743
log .Errorf ("Error deleting Service Load Balancer object {%+v}. Err: %v" , serviceCfg .ServiceName , err )
1711
1744
return err
1712
1745
}
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
+
1713
1763
return nil
1714
1764
1715
1765
}
0 commit comments