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


Golang VirtualNetwork.SetVirtualNetworkProperties方法代碼示例

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


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

示例1: TestPropertyUpdate

func TestPropertyUpdate(t *testing.T) {
	client := contrail.NewClient("localhost", 8082)
	net := types.VirtualNetwork{}
	net.SetName("test")

	err := client.Create(&net)
	if err != nil {
		t.Error(err)
	}

	defer client.Delete(&net)

	props := net.GetVirtualNetworkProperties()
	if len(props.ForwardingMode) > 0 {
		t.Error(props.ForwardingMode)
	}
	props.ForwardingMode = "l2_l3"
	net.SetVirtualNetworkProperties(&props)
	err = client.Update(&net)
	if err != nil {
		t.Error(err)
	}

	obj, err := client.FindByUuid("virtual-network", net.GetUuid())
	if err != nil {
		t.Fatal(err)
	}
	netPtr := obj.(*types.VirtualNetwork)
	p2 := netPtr.GetVirtualNetworkProperties()
	if p2.ForwardingMode != "l2_l3" {
		t.Errorf("Expected: l2_l3 got: %s", p2.ForwardingMode)
	}
}
開發者ID:hkumarmk,項目名稱:contrail-go-api,代碼行數:33,代碼來源:client_test.go

示例2: TestReadBackRefs

func TestReadBackRefs(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))

	net := new(types.VirtualNetwork)
	net.SetFQName("project", []string{"default-domain", "p1", "n1"})
	props := new(types.VirtualNetworkType)
	props.ForwardingMode = "turbo"
	net.SetVirtualNetworkProperties(props)
	assert.NoError(t, client.Create(net))

	vmi1 := new(types.VirtualMachineInterface)
	vmi1.SetFQName("project", []string{"default-domain", "p1", "port1"})
	vmi1.AddVirtualNetwork(net)
	assert.NoError(t, client.Create(vmi1))

	vmi2 := new(types.VirtualMachineInterface)
	vmi2.SetFQName("project", []string{"default-domain", "p1", "port2"})
	vmi2.AddVirtualNetwork(net)
	assert.NoError(t, client.Create(vmi2))

	refs, err := net.GetVirtualMachineInterfaceBackRefs()
	assert.NoError(t, err)
	assert.Len(t, refs, 2)
	idList := make([]string, len(refs))
	for i, ref := range refs {
		idList[i] = ref.Uuid
	}

	assert.Contains(t, idList, vmi1.GetUuid())
	assert.Contains(t, idList, vmi2.GetUuid())

	rProps := net.GetVirtualNetworkProperties()
	assert.Equal(t, "turbo", rProps.ForwardingMode)
}
開發者ID:hkumarmk,項目名稱:contrail-go-api,代碼行數:39,代碼來源:updater_test.go


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