本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.InstanceIp.AddVirtualNetwork方法的典型用法代码示例。如果您正苦于以下问题:Golang InstanceIp.AddVirtualNetwork方法的具体用法?Golang InstanceIp.AddVirtualNetwork怎么用?Golang InstanceIp.AddVirtualNetwork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Juniper/contrail-go-api/types.InstanceIp
的用法示例。
在下文中一共展示了InstanceIp.AddVirtualNetwork方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LocateInstanceIp
func (m *InstanceManager) LocateInstanceIp(
network *types.VirtualNetwork, instanceUID string, nic *types.VirtualMachineInterface) *types.InstanceIp {
tenant := nic.GetFQName()[len(nic.GetFQName())-2]
name := makeInstanceIpName(tenant, nic.GetName())
obj, err := m.client.FindByName("instance-ip", name)
if err == nil {
// TODO(prm): ensure that attributes are as expected
return obj.(*types.InstanceIp)
}
address, err := m.allocator.LocateIpAddress(instanceUID)
if err != nil {
return nil
}
// Create InstanceIp
ipObj := new(types.InstanceIp)
ipObj.SetName(name)
ipObj.AddVirtualNetwork(network)
ipObj.AddVirtualMachineInterface(nic)
ipObj.SetInstanceIpAddress(address)
ipObj.SetInstanceIpMode("active-active")
err = m.client.Create(ipObj)
if err != nil {
glog.Errorf("Create instance-ip %s for %s: %v", address, nic.GetName(), err)
return nil
}
obj, err = m.client.FindByUuid(ipObj.GetType(), ipObj.GetUuid())
if err != nil {
glog.Errorf("Get instance-ip %s for %s: %v", address, ipObj.GetUuid(), err)
return nil
}
return ipObj
}
示例2: allocateIpAddress
func (a *AddressAllocatorImpl) allocateIpAddress(uid string) (contrail.IObject, error) {
ipObj := new(types.InstanceIp)
ipObj.SetName(uid)
ipObj.AddVirtualNetwork(a.network)
err := a.client.Create(ipObj)
if err != nil {
glog.Errorf("Create InstanceIp %s: %v", uid, err)
return nil, err
}
obj, err := a.client.FindByUuid("instance-ip", ipObj.GetUuid())
if err != nil {
glog.Errorf("Get InstanceIp %s: %v", uid, err)
return nil, err
}
return obj, err
}