当前位置: 首页>>代码示例>>Golang>>正文


Golang NetworkPolicy.SetNetworkPolicyEntries方法代码示例

本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.NetworkPolicy.SetNetworkPolicyEntries方法的典型用法代码示例。如果您正苦于以下问题:Golang NetworkPolicy.SetNetworkPolicyEntries方法的具体用法?Golang NetworkPolicy.SetNetworkPolicyEntries怎么用?Golang NetworkPolicy.SetNetworkPolicyEntries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Juniper/contrail-go-api/types.NetworkPolicy的用法示例。


在下文中一共展示了NetworkPolicy.SetNetworkPolicyEntries方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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.SetNetworkPolicyEntries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。