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


Golang VirtualMachineInterface.SetUuid方法代码示例

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


在下文中一共展示了VirtualMachineInterface.SetUuid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestDeleteRefs

// Create floating-ip with 2 vmi references, delete it and verify that
// the back_refs are updated as expected.
func TestDeleteRefs(t *testing.T) {
	db := NewInMemDatabase()

	vmi1 := new(types.VirtualMachineInterface)
	vmi1.SetUuid(uuid.New())
	vmi1.SetName("port1")
	assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))

	vmi2 := new(types.VirtualMachineInterface)
	vmi2.SetUuid(uuid.New())
	vmi2.SetName("port2")
	assert.NoError(t, db.Put(vmi2, nil, GetReferenceList(vmi2)))

	fip := new(types.FloatingIp)
	fip.SetUuid(uuid.New())
	fip.SetName("fip")
	fip.AddVirtualMachineInterface(vmi1)
	fip.AddVirtualMachineInterface(vmi2)
	assert.NoError(t, db.Put(fip, nil, GetReferenceList(fip)))

	assert.Error(t, db.Delete(vmi1))

	result, err := db.GetBackReferences(parseUID(vmi2.GetUuid()), "floating_ip")
	assert.NoError(t, err)
	assert.Len(t, result, 1)

	assert.NoError(t, db.Delete(fip))

	result, err = db.GetBackReferences(parseUID(vmi2.GetUuid()), "floating_ip")
	assert.NoError(t, err)
	assert.Len(t, result, 0)

	assert.NoError(t, db.Delete(vmi1))
	assert.NoError(t, db.Delete(vmi2))
}
开发者ID:netturpin,项目名称:contrail-go-api,代码行数:37,代码来源:database_test.go

示例2: TestUpdateOne

func TestUpdateOne(t *testing.T) {
	db := NewInMemDatabase()

	instance := new(types.VirtualMachine)
	instance.SetUuid(uuid.New())
	instance.SetName("instance")
	assert.NoError(t, db.Put(instance, nil, UIDList{}))

	vmi1 := new(types.VirtualMachineInterface)
	vmi1.SetUuid(uuid.New())
	vmi1.SetName("port1")
	assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))

	vmi1.AddVirtualMachine(instance)
	assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))

	result, err := db.GetBackReferences(parseUID(instance.GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Contains(t, result, parseUID(vmi1.GetUuid()))

	vmi1.ClearVirtualMachine()
	assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))
	result, err = db.GetBackReferences(parseUID(instance.GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, result, 0)
}
开发者ID:netturpin,项目名称:contrail-go-api,代码行数:26,代码来源:database_test.go

示例3: TestChildrenRefs

func TestChildrenRefs(t *testing.T) {
	db := NewInMemDatabase()
	project := new(types.Project)
	project.SetUuid(uuid.New())
	project.SetName("p1")
	assert.NoError(t, db.Put(project, nil, GetReferenceList(project)))

	net := new(types.VirtualNetwork)
	net.SetUuid(uuid.New())
	net.SetFQName("project", []string{"p1", "n1"})
	assert.NoError(t, db.Put(net, project, UIDList{}))

	vmi1 := new(types.VirtualMachineInterface)
	vmi1.SetUuid(uuid.New())
	vmi1.SetName("port1")
	vmi1.AddVirtualNetwork(net)
	assert.NoError(t, db.Put(vmi1, project, GetReferenceList(vmi1)))

	vmi2 := new(types.VirtualMachineInterface)
	vmi2.SetUuid(uuid.New())
	vmi2.SetName("port2")
	vmi2.AddVirtualNetwork(net)
	assert.NoError(t, db.Put(vmi2, project, GetReferenceList(vmi2)))

	result, err := db.GetChildren(parseUID(project.GetUuid()), "virtual_network")
	assert.NoError(t, err)
	assert.Len(t, result, 1)

	result, err = db.GetChildren(parseUID(project.GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, result, 2)
	assert.Contains(t, result, parseUID(vmi1.GetUuid()))
	assert.Contains(t, result, parseUID(vmi2.GetUuid()))

	assert.Error(t, db.Delete(project))

	assert.NoError(t, db.Delete(vmi1))
	assert.Error(t, db.Delete(net))
	assert.NoError(t, db.Delete(vmi2))

	assert.NoError(t, db.Delete(net))
	assert.NoError(t, db.Delete(project))
}
开发者ID:netturpin,项目名称:contrail-go-api,代码行数:43,代码来源:database_test.go

示例4: TestUpdateRefs

func TestUpdateRefs(t *testing.T) {
	db := NewInMemDatabase()

	var instances [8]*types.VirtualMachine
	for i := 0; i < 8; i++ {
		instance := new(types.VirtualMachine)
		instance.SetUuid(uuid.New())
		instance.SetName(fmt.Sprintf("instance-%d", i))
		assert.NoError(t, db.Put(instance, nil, UIDList{}))
		instances[i] = instance
	}

	vmi1 := new(types.VirtualMachineInterface)
	vmi1.SetUuid(uuid.New())
	vmi1.SetName("port1")
	vmi1.AddVirtualMachine(instances[0])
	vmi1.AddVirtualMachine(instances[1])
	vmi1.AddVirtualMachine(instances[2])
	assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))

	vmi2 := new(types.VirtualMachineInterface)
	vmi2.SetUuid(uuid.New())
	vmi2.SetName("port2")
	vmi2.AddVirtualMachine(instances[2])
	vmi2.AddVirtualMachine(instances[4])
	vmi2.AddVirtualMachine(instances[3])
	assert.NoError(t, db.Put(vmi2, nil, GetReferenceList(vmi2)))

	r2, err := db.GetBackReferences(parseUID(instances[2].GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, r2, 2)
	assert.Contains(t, r2, parseUID(vmi1.GetUuid()))
	assert.Contains(t, r2, parseUID(vmi2.GetUuid()))

	r3, err := db.GetBackReferences(parseUID(instances[3].GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, r3, 1)

	vmi2.ClearVirtualMachine()
	vmi2.AddVirtualMachine(instances[4])
	vmi2.AddVirtualMachine(instances[6])
	assert.NoError(t, db.Update(vmi2, GetReferenceList(vmi2)))

	r2, err = db.GetBackReferences(parseUID(instances[2].GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, r2, 1)
	assert.Contains(t, r2, parseUID(vmi1.GetUuid()))

	r3, err = db.GetBackReferences(parseUID(instances[3].GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, r3, 0)

	r4, err := db.GetBackReferences(parseUID(instances[4].GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, r4, 1)
	assert.Contains(t, r4, parseUID(vmi2.GetUuid()))

	vmi1.ClearVirtualMachine()
	vmi1.AddVirtualMachine(instances[0])
	vmi1.AddVirtualMachine(instances[1])
	vmi1.AddVirtualMachine(instances[5])
	vmi1.AddVirtualMachine(instances[4])
	assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))

	r4, err = db.GetBackReferences(parseUID(instances[4].GetUuid()), "virtual_machine_interface")
	assert.NoError(t, err)
	assert.Len(t, r4, 2)
	assert.Contains(t, r4, parseUID(vmi1.GetUuid()))
	assert.Contains(t, r4, parseUID(vmi2.GetUuid()))
}
开发者ID:netturpin,项目名称:contrail-go-api,代码行数:70,代码来源:database_test.go


注:本文中的github.com/Juniper/contrail-go-api/types.VirtualMachineInterface.SetUuid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。