@@ -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
@@ -1868,6 +1874,20 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
1868
1874
return core .Errorf ("Invalid Port maping . Port format is - Port:TargetPort:Protocol" )
1869
1875
}
1870
1876
1877
+ if serviceCfg .TenantName == "" {
1878
+ return core .Errorf ("Invalid tenant name" )
1879
+ }
1880
+
1881
+ tenant := contivModel .FindTenant (serviceCfg .TenantName )
1882
+ if tenant == nil {
1883
+ return core .Errorf ("Tenant %s not found" , serviceCfg .TenantName )
1884
+ }
1885
+
1886
+ network := contivModel .FindNetwork (serviceCfg .TenantName + ":" + serviceCfg .NetworkName )
1887
+ if network == nil {
1888
+ return core .Errorf ("Network %s not found" , serviceCfg .NetworkName )
1889
+ }
1890
+
1871
1891
// Get the state driver
1872
1892
stateDriver , err := utils .GetStateDriver ()
1873
1893
if err != nil {
@@ -1900,6 +1920,19 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
1900
1920
log .Errorf ("Error creating service {%+v}. Err: %v" , serviceIntentCfg .ServiceName , err )
1901
1921
return err
1902
1922
}
1923
+ // Setup links
1924
+ if tenant != nil {
1925
+ modeldb .AddLink (& serviceCfg .Links .Tenant , tenant )
1926
+ modeldb .AddLinkSet (& tenant .LinkSets .Servicelbs , serviceCfg )
1927
+ tenant .Write ()
1928
+ }
1929
+
1930
+ // Setup links
1931
+ if network != nil {
1932
+ modeldb .AddLink (& serviceCfg .Links .Network , network )
1933
+ modeldb .AddLinkSet (& network .LinkSets .Servicelbs , serviceCfg )
1934
+ network .Write ()
1935
+ }
1903
1936
return nil
1904
1937
1905
1938
}
@@ -1943,6 +1976,23 @@ func (ac *APIController) ServiceLBDelete(serviceCfg *contivModel.ServiceLB) erro
1943
1976
log .Errorf ("Error deleting Service Load Balancer object {%+v}. Err: %v" , serviceCfg .ServiceName , err )
1944
1977
return err
1945
1978
}
1979
+ // Find the tenant
1980
+ tenant := contivModel .FindTenant (serviceCfg .TenantName )
1981
+ if tenant == nil {
1982
+ return core .Errorf ("Tenant %s not found" , serviceCfg .TenantName )
1983
+ }
1984
+
1985
+ modeldb .RemoveLinkSet (& tenant .LinkSets .Servicelbs , serviceCfg )
1986
+ tenant .Write ()
1987
+
1988
+ nwKey := serviceCfg .TenantName + ":" + serviceCfg .NetworkName
1989
+ network := contivModel .FindNetwork (nwKey )
1990
+ if network == nil {
1991
+ return core .Errorf ("Network %s not found in tenant %s" , serviceCfg .NetworkName , serviceCfg .TenantName )
1992
+ }
1993
+ modeldb .RemoveLinkSet (& network .LinkSets .Servicelbs , serviceCfg )
1994
+ network .Write ()
1995
+
1946
1996
return nil
1947
1997
1948
1998
}
0 commit comments