// EndpointGroupCreate creates end point group func (ac *APIController) EndpointGroupCreate(endpointGroup *contivModel.EndpointGroup) error { log.Infof("Received EndpointGroupCreate: %+v", endpointGroup) // assign unique endpoint group ids endpointGroup.EndpointGroupID = globalEpgID globalEpgID = globalEpgID + 1 // Find the tenant tenant := contivModel.FindTenant(endpointGroup.TenantName) if tenant == nil { return core.Errorf("Tenant not found") } // Setup links modeldb.AddLink(&endpointGroup.Links.Tenant, tenant) modeldb.AddLinkSet(&tenant.LinkSets.EndpointGroups, endpointGroup) // Save the tenant too since we added the links err := tenant.Write() if err != nil { return err } // for each policy create an epg policy Instance for _, policyName := range endpointGroup.Policies { policyKey := endpointGroup.TenantName + ":" + policyName // find the policy policy := contivModel.FindPolicy(policyKey) if policy == nil { log.Errorf("Could not find policy %s", policyName) return core.Errorf("Policy not found") } // attach policy to epg err = master.PolicyAttach(endpointGroup, policy) if err != nil { log.Errorf("Error attaching policy %s to epg %s", policyName, endpointGroup.Key) return err } // establish Links modeldb.AddLinkSet(&policy.LinkSets.EndpointGroups, endpointGroup) modeldb.AddLinkSet(&endpointGroup.LinkSets.Policies, policy) // Write the policy err = policy.Write() if err != nil { return err } } return nil }