當前位置: 首頁>>代碼示例>>Golang>>正文


Golang NetworkPolicy.GetNetworkPolicyEntries方法代碼示例

本文整理匯總了Golang中github.com/Juniper/contrail-go-api/types.NetworkPolicy.GetNetworkPolicyEntries方法的典型用法代碼示例。如果您正苦於以下問題:Golang NetworkPolicy.GetNetworkPolicyEntries方法的具體用法?Golang NetworkPolicy.GetNetworkPolicyEntries怎麽用?Golang NetworkPolicy.GetNetworkPolicyEntries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/Juniper/contrail-go-api/types.NetworkPolicy的用法示例。


在下文中一共展示了NetworkPolicy.GetNetworkPolicyEntries方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: policyLocateRuleByFQN

func policyLocateRuleByFQN(client contrail.ApiClient, policy *types.NetworkPolicy, lhsFQN, rhsFQN []string) error {
	lhsName := strings.Join(lhsFQN, ":")
	rhsName := strings.Join(rhsFQN, ":")
	entries := policy.GetNetworkPolicyEntries()
	for _, rule := range entries.PolicyRule {
		if rule.SrcAddresses[0].VirtualNetwork == lhsName &&
			rule.DstAddresses[0].VirtualNetwork == rhsName {
			return nil
		}
	}
	rule := new(types.PolicyRuleType)
	rule.Protocol = "any"
	rule.Direction = "<>"
	rule.SrcAddresses = []types.AddressType{types.AddressType{
		VirtualNetwork: lhsName,
	}}
	rule.DstAddresses = []types.AddressType{types.AddressType{
		VirtualNetwork: rhsName,
	}}
	rule.SrcPorts = []types.PortType{types.PortType{StartPort: -1, EndPort: -1}}
	rule.DstPorts = []types.PortType{types.PortType{StartPort: -1, EndPort: -1}}
	rule.ActionList = &types.ActionListType{
		SimpleAction: "pass",
	}

	entries.AddPolicyRule(rule)
	policy.SetNetworkPolicyEntries(&entries)
	err := client.Update(policy)
	if err != nil {
		glog.Errorf("policy-rule: %v", err)
		return err
	}
	return nil
}
開發者ID:pupapaik,項目名稱:contrail-kubernetes,代碼行數:34,代碼來源:policy.go

示例2: locatePolicyRule

func (m *ServiceManagerImpl) locatePolicyRule(policy *types.NetworkPolicy, lhs, rhs *types.VirtualNetwork) error {
	lhsName := strings.Join(lhs.GetFQName(), ":")
	rhsName := strings.Join(rhs.GetFQName(), ":")

	entries := policy.GetNetworkPolicyEntries()
	for _, rule := range entries.PolicyRule {
		if rule.SrcAddresses[0].VirtualNetwork == lhsName &&
			rule.DstAddresses[0].VirtualNetwork == rhsName {
			return nil
		}
	}
	rule := new(types.PolicyRuleType)
	rule.Protocol = "any"
	rule.Direction = "<>"
	rule.SrcAddresses = []types.AddressType{types.AddressType{
		VirtualNetwork: lhsName,
	}}
	rule.DstAddresses = []types.AddressType{types.AddressType{
		VirtualNetwork: rhsName,
	}}
	rule.SrcPorts = []types.PortType{types.PortType{-1, -1}}
	rule.DstPorts = []types.PortType{types.PortType{-1, -1}}
	rule.ActionList = &types.ActionListType{
		SimpleAction: "pass",
	}

	entries.AddPolicyRule(rule)
	policy.SetNetworkPolicyEntries(&entries)
	err := m.client.Update(policy)
	if err != nil {
		glog.Errorf("policy-rule: %v", err)
		return err
	}
	return nil
}
開發者ID:ZJU-SEL,項目名稱:contrail-kubernetes,代碼行數:35,代碼來源:service.go

示例3: getRulesNetworks

// Retrieves the virtual-network references from the policy rules
// for display purposes.
func getRulesNetworks(policy *types.NetworkPolicy) (string, string) {
	displayValue := func(m map[string]bool) string {
		if len(m) > 1 {
			return "<multiple>"
		}
		for key, _ := range m {
			fqn := strings.Split(key, ":")
			return fqn[len(fqn)-1]
		}
		return "none"
	}

	sourceMap := make(map[string]bool, 0)
	destMap := make(map[string]bool, 0)
	for _, rule := range policy.GetNetworkPolicyEntries().PolicyRule {
		if len(rule.SrcAddresses) > 0 &&
			len(rule.SrcAddresses[0].VirtualNetwork) > 0 {
			sourceMap[rule.SrcAddresses[0].VirtualNetwork] = true
		}
		if len(rule.DstAddresses) > 0 &&
			len(rule.DstAddresses[0].VirtualNetwork) > 0 {
			destMap[rule.DstAddresses[0].VirtualNetwork] = true
		}
	}

	source := displayValue(sourceMap)
	destination := displayValue(destMap)
	return source, destination
}
開發者ID:netturpin,項目名稱:contrail-go-api,代碼行數:31,代碼來源:policy.go

示例4: policyHasRule

func policyHasRule(policy *types.NetworkPolicy, lhsName, rhsName string) bool {
	entries := policy.GetNetworkPolicyEntries()
	for _, rule := range entries.PolicyRule {
		if rule.SrcAddresses[0].VirtualNetwork == lhsName &&
			rule.DstAddresses[0].VirtualNetwork == rhsName {
			return true
		}
	}
	return false
}
開發者ID:WIZARD-CXY,項目名稱:contrail-kubernetes,代碼行數:10,代碼來源:controller_test.go

示例5: policyDeleteRule

func policyDeleteRule(client contrail.ApiClient, policy *types.NetworkPolicy, lhsName, rhsName string) error {
	entries := policy.GetNetworkPolicyEntries()
	var index int = -1
	for i, rule := range entries.PolicyRule {
		if rule.SrcAddresses[0].VirtualNetwork == lhsName &&
			rule.DstAddresses[0].VirtualNetwork == rhsName {
			index = i
			break
		}
	}
	if index < 0 {
		return nil
	}
	entries.PolicyRule = removeRulesIndex(entries.PolicyRule, index)
	policy.SetNetworkPolicyEntries(&entries)
	err := client.Update(policy)
	if err != nil {
		glog.Errorf("policy-rule: %v", err)
	}
	return err
}
開發者ID:pupapaik,項目名稱:contrail-kubernetes,代碼行數:21,代碼來源:policy.go


注:本文中的github.com/Juniper/contrail-go-api/types.NetworkPolicy.GetNetworkPolicyEntries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。