Exemplo n.º 1
0
func (m *NetworkManagerImpl) DeleteConnections(network *types.VirtualNetwork, policies map[string]string) error {
	for policyID, _ := range policies {
		network.DeleteNetworkPolicy(policyID)
	}
	err := m.client.Update(network)

	for policyID, targetName := range policies {
		policy, policyErr := types.NetworkPolicyByUuid(m.client, policyID)
		if policyErr != nil {
			glog.Error(policyErr)
			continue
		}
		networkRefs, policyErr := policy.GetVirtualNetworkBackRefs()
		if len(networkRefs) > 1 {
			continue
		}
		if len(networkRefs) == 1 {
			if strings.Join(networkRefs[0].To, ":") == targetName {
				policyErr = m.disconnectNetworkFromPolicy(policy, targetName)
				if policyErr != nil {
					glog.Error(policyErr)
					continue
				}
			} else {
				continue
			}
		}
		policyErr = m.client.Delete(policy)
		if policyErr != nil {
			glog.Error(policyErr)
		}
	}

	return err
}
Exemplo n.º 2
0
func (m *ServiceManagerImpl) DeleteConnections(network *types.VirtualNetwork, purgeList []string) error {
	if len(purgeList) == 0 {
		return nil
	}
	for _, policyId := range purgeList {
		network.DeleteNetworkPolicy(policyId)
	}
	err := m.client.Update(network)
	if err != nil {
		return err
	}
	for _, policyId := range purgeList {
		policy, err := types.NetworkPolicyByUuid(m.client, policyId)
		if err != nil {
			glog.Error(err)
			continue
		}
		refs, err := policy.GetVirtualNetworkBackRefs()
		if err != nil {
			glog.Error(err)
			continue
		}
		if len(refs) == 0 {
			err = m.client.Delete(policy)
			if err != nil {
				glog.Error(err)
			}
		}
	}
	return nil
}
Exemplo n.º 3
0
func (m *ServiceManagerImpl) PurgeStalePolicyRefs(network *types.VirtualNetwork, services ServiceIdList,
	doDelete func(string, string) bool) error {
	purgeList := make([]string, 0)
	refs, err := network.GetNetworkPolicyRefs()
	if err != nil {
		return err
	}
	for _, ref := range refs {
		if len(ref.To) < 3 {
			glog.Errorf("unexpected policy id %+v", ref.To)
			continue
		}
		namespace := ref.To[1]
		serviceName := ref.To[len(ref.To)-1]
		if !services.Contains(namespace, serviceName) && doDelete(namespace, serviceName) {
			purgeList = append(purgeList, ref.Uuid)
		}
	}
	if len(purgeList) == 0 {
		return nil
	}
	for _, policyId := range purgeList {
		network.DeleteNetworkPolicy(policyId)
	}
	err = m.client.Update(network)
	if err != nil {
		return err
	}
	for _, policyId := range purgeList {
		policy, err := types.NetworkPolicyByUuid(m.client, policyId)
		if err != nil {
			glog.Error(err)
			continue
		}
		refs, err := policy.GetVirtualNetworkBackRefs()
		if err != nil {
			glog.Error(err)
		}
		if len(refs) == 0 {
			err = m.client.Delete(policy)
			if err != nil {
				glog.Error(err)
			}
		}
	}
	return nil
}