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


Golang NetworkPolicy.SetFQName方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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.SetFQName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。