本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.InstanceIp类的典型用法代码示例。如果您正苦于以下问题:Golang InstanceIp类的具体用法?Golang InstanceIp怎么用?Golang InstanceIp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InstanceIp类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
}
开发者ID:michaelkuty,项目名称:contrail-kubernetes,代码行数:16,代码来源:address_allocator.go
示例2: 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
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:34,代码来源:instance.go
示例3: 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.InstanceIp类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论