Esempio n. 1
0
// PolicyAttach attaches a policy to an endpoint and adds associated rules to policyDB
func PolicyAttach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
	epgpKey := epg.Key + ":" + policy.Key

	// See if it already exists
	gp := mastercfg.FindEpgPolicy(epgpKey)
	if gp != nil {
		log.Errorf("EPG policy %s already exists", epgpKey)
		return EpgPolicyExists
	}

	// Create the epg policy
	gp, err := mastercfg.NewEpgPolicy(epgpKey, epg.EndpointGroupID, policy)
	if err != nil {
		log.Errorf("Error creating EPG policy. Err: %v", err)
		return err
	}

	return nil
}
Esempio n. 2
0
// PolicyAttach attaches a policy to an endpoint and adds associated rules to policyDB
func PolicyAttach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
	// Dont install policies in ACI mode
	if !isPolicyEnabled() {
		return nil
	}

	epgpKey := epg.Key + ":" + policy.Key

	// See if it already exists
	gp := mastercfg.FindEpgPolicy(epgpKey)
	if gp != nil {
		log.Errorf("EPG policy %s already exists", epgpKey)
		return EpgPolicyExists
	}

	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		log.Errorf("Could not get StateDriver while attaching policy %+v", policy)
		return err
	}

	epgID, err := mastercfg.GetEndpointGroupID(stateDriver, epg.GroupName, epg.TenantName)
	if err != nil {
		log.Errorf("Error getting epgID for %s. Err: %v", epgpKey, err)
		return err
	}

	// Create the epg policy
	gp, err = mastercfg.NewEpgPolicy(epgpKey, epgID, policy)
	if err != nil {
		log.Errorf("Error creating EPG policy. Err: %v", err)
		return err
	}

	return nil
}