本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.NetworkPolicy类的典型用法代码示例。如果您正苦于以下问题:Golang NetworkPolicy类的具体用法?Golang NetworkPolicy怎么用?Golang NetworkPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetworkPolicy类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: disconnectNetworkFromPolicy
func (m *NetworkManagerImpl) disconnectNetworkFromPolicy(policy *types.NetworkPolicy, targetCSN string) error {
target, err := types.VirtualNetworkByName(m.client, targetCSN)
if err != nil {
return err
}
err = target.DeleteNetworkPolicy(policy.GetUuid())
if err != nil {
return err
}
return m.client.Update(target)
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:11,代码来源:network.go
示例6: locatePolicy
func (m *ServiceManagerImpl) locatePolicy(tenant, serviceName string) (*types.NetworkPolicy, error) {
var policy *types.NetworkPolicy = nil
policyName := makeServicePolicyName(m.config, tenant, serviceName)
obj, err := m.client.FindByName("network-policy", strings.Join(policyName, ":"))
if err != nil {
policy = new(types.NetworkPolicy)
policy.SetFQName("project", policyName)
err = m.client.Create(policy)
if err != nil {
glog.Errorf("Create policy %s: %v", strings.Join(policyName, ":"), err)
return nil, err
}
} else {
policy = obj.(*types.NetworkPolicy)
}
return policy, nil
}
开发者ID:sanabby,项目名称:contrail-kubernetes,代码行数:18,代码来源:service.go
示例7: locatePolicy
func (m *ServiceManagerImpl) locatePolicy(tenant, serviceName string) (*types.NetworkPolicy, error) {
var policy *types.NetworkPolicy = nil
fqn := []string{DefaultDomain, tenant, serviceName}
obj, err := m.client.FindByName("network-policy", strings.Join(fqn, ":"))
if err != nil {
policy = new(types.NetworkPolicy)
policy.SetFQName("project", fqn)
err = m.client.Create(policy)
if err != nil {
glog.Errorf("Create policy %s: %v", strings.Join(fqn, ":"), err)
return nil, err
}
} else {
policy = obj.(*types.NetworkPolicy)
}
return policy, nil
}
开发者ID:ZJU-SEL,项目名称:contrail-kubernetes,代码行数:18,代码来源:service.go
示例8: 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
示例9: policyAttach
func policyAttach(client contrail.ApiClient, network *types.VirtualNetwork, policy *types.NetworkPolicy) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("get network policy-refs %s: %v", network.GetName(), err)
return err
}
for _, ref := range refs {
if ref.Uuid == policy.GetUuid() {
return nil
}
}
network.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{Major: 10, Minor: 0},
})
err = client.Update(network)
if err != nil {
glog.Errorf("Update network %s policies: %v", network.GetName(), err)
return err
}
return nil
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:22,代码来源:policy.go
示例10: attachPolicy
func (m *ServiceManagerImpl) attachPolicy(network *types.VirtualNetwork, policy *types.NetworkPolicy) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("get network policy-refs %s: %v", network.GetName(), err)
return err
}
for _, ref := range refs {
if ref.Uuid == policy.GetUuid() {
return nil
}
}
network.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{10, 0},
})
err = m.client.Update(network)
if err != nil {
glog.Errorf("Update network %s policies: %v", network.GetName(), err)
return err
}
return nil
}
开发者ID:ZJU-SEL,项目名称:contrail-kubernetes,代码行数:22,代码来源:service.go
示例11: TestReadModifiedPolicy
func TestReadModifiedPolicy(t *testing.T) {
client := new(ApiClient)
client.Init()
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", "p1"})
assert.NoError(t, client.Create(project))
policy := new(types.NetworkPolicy)
policy.SetFQName("project", []string{"default-domain", "p1", "x"})
assert.NoError(t, client.Create(policy))
net1 := new(types.VirtualNetwork)
net1.SetFQName("project", []string{"default-domain", "p1", "n1"})
net1.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{10, 0},
})
assert.NoError(t, client.Create(net1))
net2 := new(types.VirtualNetwork)
net2.SetFQName("project", []string{"default-domain", "p1", "n2"})
net2.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{10, 0},
})
assert.NoError(t, client.Create(net2))
refs, err := policy.GetVirtualNetworkBackRefs()
assert.NoError(t, err)
assert.Len(t, refs, 2)
assert.NoError(t, client.Delete(net1))
refs, err = policy.GetVirtualNetworkBackRefs()
assert.NoError(t, err)
assert.Len(t, refs, 1)
assert.NoError(t, client.Delete(net2))
refs, err = policy.GetVirtualNetworkBackRefs()
assert.NoError(t, err)
assert.Len(t, refs, 0)
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:43,代码来源:updater_test.go
示例12: policyCreate
// Create (an empty) network-policy.
func policyCreate(client *contrail.Client, flagSet *flag.FlagSet) {
if flagSet.NArg() < 1 {
flagSet.Usage()
os.Exit(2)
}
name := flagSet.Args()[0]
projectFQN, err := config.GetProjectFQN(client,
policyCommonOpts.project, policyCommonOpts.projectId)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
policy := new(types.NetworkPolicy)
policy.SetFQName("project", append(projectFQN, name))
err = client.Create(policy)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
开发者ID:netturpin,项目名称:contrail-go-api,代码行数:24,代码来源:policy.go
注:本文中的github.com/Juniper/contrail-go-api/types.NetworkPolicy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论