本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.VirtualNetwork.AddNetworkPolicy方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualNetwork.AddNetworkPolicy方法的具体用法?Golang VirtualNetwork.AddNetworkPolicy怎么用?Golang VirtualNetwork.AddNetworkPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Juniper/contrail-go-api/types.VirtualNetwork
的用法示例。
在下文中一共展示了VirtualNetwork.AddNetworkPolicy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: 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
}
示例3: 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
}