本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.VirtualMachine类的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachine类的具体用法?Golang VirtualMachine怎么用?Golang VirtualMachine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualMachine类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestConsistencyStaleVM
func TestConsistencyStaleVM(t *testing.T) {
env := new(TestFramework)
env.SetUp("192.0.2.0/24")
client := env.client
netnsProject := new(types.Project)
netnsProject.SetFQName("domain", []string{"default-domain", "testns"})
client.Create(netnsProject)
env.Start()
installPods(env, "testns", 3)
env.SyncBarrier()
env.Shutdown()
assert.True(t, env.checker.Check())
p2 := new(types.Project)
p2.SetFQName("domain", []string{"default-domain", "p2"})
assert.NoError(t, client.Create(p2))
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "p2", "x"})
assert.NoError(t, client.Create(vm))
assert.False(t, env.checker.Check())
assert.NoError(t, client.Delete(vm))
assert.True(t, env.checker.Check())
vm = new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "testns", "pod03"})
assert.NoError(t, client.Create(vm))
assert.False(t, env.checker.Check())
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:33,代码来源:consistency_test.go
示例2: LocateInterface
func (m *InstanceManager) LocateInterface(
network *types.VirtualNetwork, instance *types.VirtualMachine) *types.VirtualMachineInterface {
tenant := network.GetFQName()[len(network.GetFQName())-2]
fqn := interfaceFQName(m.config.DefaultDomain, tenant, instance.GetName())
obj, err := m.client.FindByName(
"virtual-machine-interface", strings.Join(fqn, ":"))
if err == nil {
nic := obj.(*types.VirtualMachineInterface)
// TODO(prm): ensure network is as expected, else update.
return nic
}
nic := new(types.VirtualMachineInterface)
nic.SetFQName("project", fqn)
nic.AddVirtualMachine(instance)
if network != nil {
nic.AddVirtualNetwork(network)
}
err = m.client.Create(nic)
if err != nil {
glog.Errorf("Create interface %s: %v", instance.GetName(), err)
return nil
}
obj, err = m.client.FindByUuid(nic.GetType(), nic.GetUuid())
if err != nil {
glog.Errorf("Get vmi %s: %v", nic.GetUuid(), err)
return nil
}
return obj.(*types.VirtualMachineInterface)
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:32,代码来源:instance.go
示例3: TestListByParent
func TestListByParent(t *testing.T) {
client := new(ApiClient)
client.Init()
projectNames := []string{"p1", "p2", "p3"}
vmNames := []string{"a", "b", "c", "d"}
for _, projectName := range projectNames {
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", projectName})
assert.NoError(t, client.Create(project))
for _, vmName := range vmNames {
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", projectName, vmName})
assert.NoError(t, client.Create(vm))
}
}
elements, err := client.ListByParent("virtual-machine", "default-domain:p2")
assert.NoError(t, err)
for _, element := range elements {
assert.Equal(t, "p2", element.Fq_name[1])
}
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:25,代码来源:client_test.go
示例4: 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
示例5: LocateInstance
func (m *InstanceManager) LocateInstance(tenant, podName, uid string) *types.VirtualMachine {
obj, err := m.client.FindByUuid("virtual-machine", string(uid))
if err == nil {
return obj.(*types.VirtualMachine)
}
instance := new(types.VirtualMachine)
instance.SetName(podName)
instance.SetUuid(uid)
err = m.client.Create(instance)
if err != nil {
glog.Errorf("Create %s: %v", podName, err)
return nil
}
return instance
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:16,代码来源:instance.go
示例6: TestConsistencyStaleVM
func TestConsistencyStaleVM(t *testing.T) {
client := createTestClient()
podStore := new(mocks.Store)
serviceStore := new(mocks.Store)
checker := NewConsistencyChecker(client, NewConfig(), podStore, serviceStore, nil)
kube := mocks.NewKubeClient()
controller := NewTestController(kube, client, nil, nil)
netnsProject := new(types.Project)
netnsProject.SetFQName("domain", []string{"default-domain", "testns"})
client.Create(netnsProject)
serviceStore.On("List").Return([]interface{}{})
installPods(controller, &kube.PodInterface.Mock, &podStore.Mock, "testns", 3)
shutdown := make(chan struct{})
go controller.Run(shutdown)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
time.Sleep(100 * time.Millisecond)
assert.True(t, checker.Check())
p2 := new(types.Project)
p2.SetFQName("domain", []string{"default-domain", "p2"})
assert.NoError(t, client.Create(p2))
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "p2", "x"})
assert.NoError(t, client.Create(vm))
assert.False(t, checker.Check())
assert.NoError(t, client.Delete(vm))
assert.True(t, checker.Check())
vm = new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "testns", "pod03"})
assert.NoError(t, client.Create(vm))
assert.False(t, checker.Check())
}
开发者ID:michaelkuty,项目名称:contrail-kubernetes,代码行数:44,代码来源:consistency_test.go
示例7: TestUpdateClearVM
func TestUpdateClearVM(t *testing.T) {
client := new(ApiClient)
client.Init()
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", "tenant"})
assert.NoError(t, client.Create(project))
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "tenant", "instance"})
assert.NoError(t, client.Create(vm))
vmi := new(types.VirtualMachineInterface)
vmi.SetFQName("project", []string{"default-domain", "tenant", "instance"})
vmi.AddVirtualMachine(vm)
assert.NoError(t, client.Create(vmi))
vmi.ClearVirtualMachine()
assert.NoError(t, client.Update(vmi))
assert.NoError(t, client.Delete(vm))
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:22,代码来源:client_test.go
示例8: 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
示例9: TestPodDelete
func TestPodDelete(t *testing.T) {
client := new(contrail_mocks.ApiClient)
client.Init()
allocator := new(mocks.AddressAllocator)
networkMgr := new(mocks.NetworkManager)
controller := NewTestController(nil, client, allocator, networkMgr)
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "test",
Namespace: "testns",
UID: kubetypes.UID(uuid.New()),
Labels: map[string]string{
"name": "testnet",
},
},
}
netnsProject := new(types.Project)
netnsProject.SetUuid(uuid.New())
netnsProject.SetFQName("", []string{"default-domain", "testns"})
assert.NoError(t, client.Create(netnsProject))
instance := new(types.VirtualMachine)
fqn := []string{"default-domain", "testns", "test"}
instance.SetFQName("project", fqn)
instance.SetUuid(string(pod.ObjectMeta.UID))
assert.NoError(t, client.Create(instance))
vmi := new(types.VirtualMachineInterface)
vmi.SetFQName("project", fqn)
vmi.AddVirtualMachine(instance)
assert.NoError(t, client.Create(vmi))
ipObj := new(types.InstanceIp)
ipObj.SetName("testns_test")
assert.NoError(t, client.Create(ipObj))
allocator.On("ReleaseIpAddress", string(pod.ObjectMeta.UID)).Return()
networkMgr.On("ReleaseNetworkIfEmpty", "testns", "testnet").Return(true, nil)
shutdown := make(chan struct{})
go controller.Run(shutdown)
controller.DeletePod(pod)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
if obj, err := client.FindByName("virtual-machine", strings.Join(fqn, ":")); err == nil {
t.Errorf("virtual-machine object still present %s", obj.GetUuid())
}
if obj, err := client.FindByUuid("virtual-machine-interface", vmi.GetUuid()); err == nil {
t.Errorf("virtual-machine-interface object still present %s", obj.GetUuid())
}
if obj, err := client.FindByUuid("instance-ip", ipObj.GetUuid()); err == nil {
t.Errorf("instance-ip object still present %s", obj.GetUuid())
}
allocator.AssertExpectations(t)
}
开发者ID:WIZARD-CXY,项目名称:contrail-kubernetes,代码行数:63,代码来源:controller_test.go
注:本文中的github.com/Juniper/contrail-go-api/types.VirtualMachine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论