@@ -1177,6 +1177,84 @@ func (ac *APIController) PolicyCreate(policy *contivModel.Policy) error {
1177
1177
return nil
1178
1178
}
1179
1179
1180
+ // PolicyGetOper inspects policy
1181
+ func (ac * APIController ) PolicyGetOper (policy * contivModel.PolicyInspect ) error {
1182
+ log .Infof ("Received PolicyInspect: %+v" , policy )
1183
+
1184
+ // Get the state driver
1185
+ stateDriver , err := utils .GetStateDriver ()
1186
+ if err != nil {
1187
+ return err
1188
+ }
1189
+
1190
+ // To hold total number of Endpoint count
1191
+ var policyEPCount int
1192
+
1193
+ policyCfg := & mastercfg.EpgPolicy {}
1194
+ policyCfg .StateDriver = stateDriver
1195
+
1196
+ // Policy is attached to EPG. So we need to fetch EPGs as well.
1197
+ epgCfg := & mastercfg.EndpointGroupState {}
1198
+ epgCfg .StateDriver = stateDriver
1199
+
1200
+ // Get all the Endpoints
1201
+ readEp := & mastercfg.CfgEndpointState {}
1202
+ readEp .StateDriver = stateDriver
1203
+ epCfgs , epErr := readEp .ReadAll ()
1204
+
1205
+ // Get all the EPGs on which this policy is applied
1206
+ epgs := policy .Config .LinkSets .EndpointGroups
1207
+
1208
+ // Scan all the EPGs which are under this policy
1209
+ for _ , epg := range epgs {
1210
+ log .Infof ("EPG Object : %+v" , epg )
1211
+
1212
+ // Reversing key from TenantName:EPGName to EPGName:TenantName
1213
+ sList := strings .Split (epg .ObjKey , ":" )
1214
+ if sList == nil {
1215
+ log .Errorf ("EPG key %+v is not in valid format" , epg .ObjKey )
1216
+ return err
1217
+ }
1218
+ epgID := sList [1 ] + ":" + sList [0 ]
1219
+
1220
+ log .Infof ("EPG ID : %s" , epgID )
1221
+
1222
+ if err := epgCfg .Read (epgID ); err != nil {
1223
+ log .Errorf ("Error fetching endpointGroup from mastercfg: %s" , epgID )
1224
+ return err
1225
+ }
1226
+
1227
+ policyEPCount = policyEPCount + epgCfg .EpCount
1228
+
1229
+ if epErr == nil {
1230
+ for _ , epCfg := range epCfgs {
1231
+ ep := epCfg .(* mastercfg.CfgEndpointState )
1232
+ if ep .EndpointGroupKey == epgID {
1233
+ epOper := contivModel.EndpointOper {}
1234
+ epOper .Network = ep .NetID
1235
+ epOper .EndpointID = ep .EndpointID
1236
+ epOper .ServiceName = ep .ServiceName
1237
+ epOper .EndpointGroupID = ep .EndpointGroupID
1238
+ epOper .EndpointGroupKey = ep .EndpointGroupKey
1239
+ epOper .IpAddress = []string {ep .IPAddress , ep .IPv6Address }
1240
+ epOper .MacAddress = ep .MacAddress
1241
+ epOper .HomingHost = ep .HomingHost
1242
+ epOper .IntfName = ep .IntfName
1243
+ epOper .VtepIP = ep .VtepIP
1244
+ epOper .Labels = fmt .Sprintf ("%s" , ep .Labels )
1245
+ epOper .ContainerID = ep .ContainerID
1246
+ epOper .ContainerName = ep .ContainerName
1247
+ policy .Oper .Endpoints = append (policy .Oper .Endpoints , epOper )
1248
+ }
1249
+ }
1250
+ }
1251
+ } // End of main for loop
1252
+
1253
+ policy .Oper .NumEndpoints = policyEPCount
1254
+
1255
+ return nil
1256
+ }
1257
+
1180
1258
// PolicyUpdate updates policy
1181
1259
func (ac * APIController ) PolicyUpdate (policy , params * contivModel.Policy ) error {
1182
1260
log .Infof ("Received PolicyUpdate: %+v, params: %+v" , policy , params )
@@ -1412,6 +1490,156 @@ func (ac *APIController) TenantCreate(tenant *contivModel.Tenant) error {
1412
1490
return nil
1413
1491
}
1414
1492
1493
+ // Get all the networks inside tenant
1494
+ func getTenantNetworks (tenant * contivModel.TenantInspect ) error {
1495
+
1496
+ // Get the state driver
1497
+ stateDriver , err := utils .GetStateDriver ()
1498
+ if err != nil {
1499
+ return err
1500
+ }
1501
+
1502
+ tenantID := tenant .Config .TenantName
1503
+ numEPs := 0
1504
+ s := []string {}
1505
+ networkID := ""
1506
+ for _ , net := range tenant .Config .LinkSets .Networks {
1507
+ networkID = net .ObjKey
1508
+ log .Infof ("network has ID %s" , networkID )
1509
+ s = strings .Split (networkID , ":" )
1510
+ if s [0 ] == tenantID {
1511
+ networkID = s [1 ] + "." + s [0 ]
1512
+ nwCfg := & mastercfg.CfgNetworkState {}
1513
+ nwCfg .StateDriver = stateDriver
1514
+ if err := nwCfg .Read (networkID ); err != nil {
1515
+ log .Errorf ("Error fetching network from mastercfg: %s" , networkID )
1516
+ return err
1517
+ }
1518
+ numEPs = numEPs + nwCfg .EpCount
1519
+ netOper := contivModel.NetworkOper {}
1520
+ netOper .AllocatedAddressesCount = nwCfg .EpAddrCount
1521
+ netOper .AvailableIPAddresses = master .ListAvailableIPs (nwCfg )
1522
+ netOper .AllocatedIPAddresses = master .ListAllocatedIPs (nwCfg )
1523
+ netOper .DnsServerIP = nwCfg .DNSServer
1524
+ netOper .ExternalPktTag = nwCfg .ExtPktTag
1525
+ netOper .PktTag = nwCfg .PktTag
1526
+ netOper .NumEndpoints = nwCfg .EpCount
1527
+ readEp := & mastercfg.CfgEndpointState {}
1528
+ readEp .StateDriver = stateDriver
1529
+ epCfgs , err := readEp .ReadAll ()
1530
+ if err == nil {
1531
+ for _ , epCfg := range epCfgs {
1532
+ ep := epCfg .(* mastercfg.CfgEndpointState )
1533
+ if ep .NetID == networkID {
1534
+ epOper := contivModel.EndpointOper {}
1535
+ epOper .Network = ep .NetID
1536
+ epOper .EndpointID = ep .EndpointID
1537
+ epOper .ServiceName = ep .ServiceName
1538
+ epOper .EndpointGroupID = ep .EndpointGroupID
1539
+ epOper .EndpointGroupKey = ep .EndpointGroupKey
1540
+ epOper .IpAddress = []string {ep .IPAddress , ep .IPv6Address }
1541
+ epOper .MacAddress = ep .MacAddress
1542
+ epOper .HomingHost = ep .HomingHost
1543
+ epOper .IntfName = ep .IntfName
1544
+ epOper .VtepIP = ep .VtepIP
1545
+ epOper .Labels = fmt .Sprintf ("%s" , ep .Labels )
1546
+ epOper .ContainerID = ep .ContainerID
1547
+ epOper .ContainerName = ep .ContainerName
1548
+ netOper .Endpoints = append (netOper .Endpoints , epOper )
1549
+ }
1550
+ }
1551
+ }
1552
+ tenant .Oper .Networks = append (tenant .Oper .Networks , netOper )
1553
+ }
1554
+ }
1555
+
1556
+ tenant .Oper .TotalEndpoints = numEPs
1557
+ return nil
1558
+ }
1559
+
1560
+ // Get all the EPGs inside tenant
1561
+ func getTenantEPGs (tenant * contivModel.TenantInspect ) error {
1562
+
1563
+ // Get the state driver
1564
+ stateDriver , err := utils .GetStateDriver ()
1565
+ if err != nil {
1566
+ return err
1567
+ }
1568
+
1569
+ tenantID := tenant .Config .TenantName
1570
+ s := []string {}
1571
+ epgID := ""
1572
+ for _ , epg := range tenant .Config .LinkSets .EndpointGroups {
1573
+ epgID = epg .ObjKey
1574
+ log .Infof ("EPG ID is %s" , epgID )
1575
+ s = strings .Split (epgID , ":" )
1576
+ if s [0 ] == tenantID {
1577
+ epgID = s [1 ] + ":" + s [0 ]
1578
+ epgCfg := & mastercfg.EndpointGroupState {}
1579
+ epgCfg .StateDriver = stateDriver
1580
+ if err := epgCfg .Read (epgID ); err != nil {
1581
+ log .Errorf ("Error fetching epg from mastercfg: %s" , epgID )
1582
+ return err
1583
+ }
1584
+ epgOper := contivModel.EndpointGroupOper {}
1585
+ epgOper .ExternalPktTag = epgCfg .ExtPktTag
1586
+ epgOper .PktTag = epgCfg .PktTag
1587
+ epgOper .NumEndpoints = epgCfg .EpCount
1588
+
1589
+ readEp := & mastercfg.CfgEndpointState {}
1590
+ readEp .StateDriver = stateDriver
1591
+ epCfgs , err := readEp .ReadAll ()
1592
+ if err == nil {
1593
+ for _ , epCfg := range epCfgs {
1594
+ ep := epCfg .(* mastercfg.CfgEndpointState )
1595
+ log .Infof ("EndpointGroupKey is %s" , ep .EndpointGroupKey )
1596
+ if ep .EndpointGroupKey == epgID {
1597
+ epOper := contivModel.EndpointOper {}
1598
+ epOper .Network = ep .NetID
1599
+ epOper .EndpointID = ep .EndpointID
1600
+ epOper .ServiceName = ep .ServiceName
1601
+ epOper .EndpointGroupID = ep .EndpointGroupID
1602
+ epOper .EndpointGroupKey = ep .EndpointGroupKey
1603
+ epOper .IpAddress = []string {ep .IPAddress , ep .IPv6Address }
1604
+ epOper .MacAddress = ep .MacAddress
1605
+ epOper .HomingHost = ep .HomingHost
1606
+ epOper .IntfName = ep .IntfName
1607
+ epOper .VtepIP = ep .VtepIP
1608
+ epOper .Labels = fmt .Sprintf ("%s" , ep .Labels )
1609
+ epOper .ContainerID = ep .ContainerID
1610
+ epOper .ContainerName = ep .ContainerName
1611
+ epgOper .Endpoints = append (epgOper .Endpoints , epOper )
1612
+ }
1613
+ }
1614
+ }
1615
+ tenant .Oper .EndpointGroups = append (tenant .Oper .EndpointGroups , epgOper )
1616
+ }
1617
+ }
1618
+
1619
+ return nil
1620
+ }
1621
+
1622
+ // TenantGetOper inspects tenant
1623
+ func (ac * APIController ) TenantGetOper (tenant * contivModel.TenantInspect ) error {
1624
+ log .Infof ("Received TenantInspect: %+v" , tenant )
1625
+
1626
+ tenant .Oper .TotalNetworks = len (tenant .Config .LinkSets .Networks )
1627
+ tenant .Oper .TotalEPGs = len (tenant .Config .LinkSets .EndpointGroups )
1628
+ tenant .Oper .TotalNetprofiles = len (tenant .Config .LinkSets .NetProfiles )
1629
+ tenant .Oper .TotalPolicies = len (tenant .Config .LinkSets .Policies )
1630
+ tenant .Oper .TotalAppProfiles = len (tenant .Config .LinkSets .AppProfiles )
1631
+ tenant .Oper .TotalServicelbs = len (tenant .Config .LinkSets .Servicelbs )
1632
+
1633
+ //Get all the networks config and oper parmeters under this tenant
1634
+ getTenantNetworks (tenant )
1635
+
1636
+ //Get all the EPGs config and oper parmeters under this tenant
1637
+ getTenantEPGs (tenant )
1638
+
1639
+ return nil
1640
+
1641
+ }
1642
+
1415
1643
// TenantUpdate updates a tenant
1416
1644
func (ac * APIController ) TenantUpdate (tenant , params * contivModel.Tenant ) error {
1417
1645
log .Infof ("Received TenantUpdate: %+v, params: %+v" , tenant , params )
0 commit comments