本文整理匯總了Golang中github.com/Juniper/contrail-go-api/types.VirtualMachineInterface.AddVirtualNetwork方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirtualMachineInterface.AddVirtualNetwork方法的具體用法?Golang VirtualMachineInterface.AddVirtualNetwork怎麽用?Golang VirtualMachineInterface.AddVirtualNetwork使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Juniper/contrail-go-api/types.VirtualMachineInterface
的用法示例。
在下文中一共展示了VirtualMachineInterface.AddVirtualNetwork方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: TestReadChildren
func TestReadChildren(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"})
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 := project.GetVirtualMachineInterfaces()
assert.NoError(t, err)
assert.Len(t, refs, 2)
}
示例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))
}
示例4: TestReadRefs
func TestReadRefs(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"})
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))
refs, err := vmi1.GetVirtualNetworkRefs()
assert.NoError(t, err)
assert.Len(t, refs, 1)
assert.Equal(t, net.GetUuid(), refs[0].Uuid)
}
示例5: 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)
}