本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.FloatingIp.GetVirtualMachineInterfaceRefs方法的典型用法代码示例。如果您正苦于以下问题:Golang FloatingIp.GetVirtualMachineInterfaceRefs方法的具体用法?Golang FloatingIp.GetVirtualMachineInterfaceRefs怎么用?Golang FloatingIp.GetVirtualMachineInterfaceRefs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Juniper/contrail-go-api/types.FloatingIp
的用法示例。
在下文中一共展示了FloatingIp.GetVirtualMachineInterfaceRefs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AttachFloatingIp
func (m *InstanceManager) AttachFloatingIp(
podName, projectName string, floatingIp *types.FloatingIp) {
fqn := []string{m.config.DefaultDomain, projectName, podName}
obj, err := m.client.FindByName(
"virtual-machine-interface", strings.Join(fqn, ":"))
if err != nil {
glog.Errorf("GET vmi %s: %v", podName, err)
return
}
vmi := obj.(*types.VirtualMachineInterface)
refs, err := floatingIp.GetVirtualMachineInterfaceRefs()
if err != nil {
glog.Errorf("GET floating-ip %s: %v", floatingIp.GetUuid(), err)
return
}
for _, ref := range refs {
if ref.Uuid == vmi.GetUuid() {
return
}
}
floatingIp.AddVirtualMachineInterface(vmi)
err = m.client.Update(floatingIp)
if err != nil {
glog.Errorf("Update floating-ip %s: %v", podName, err)
}
}
示例2: getFloatingIpToInstanceList
func getFloatingIpToInstanceList(client contrail.ApiClient, fip *types.FloatingIp) ([]string, error) {
vmList := make([]string, 0)
refs, err := fip.GetVirtualMachineInterfaceRefs()
if err != nil {
return vmList, err
}
for _, ref := range refs {
vmi, err := types.VirtualMachineInterfaceByUuid(client, ref.Uuid)
if err != nil {
continue
}
instanceRefs, err := vmi.GetVirtualMachineRefs()
if err != nil || len(instanceRefs) == 0 {
continue
}
vmList = append(vmList, instanceRefs[0].Uuid)
}
return vmList, nil
}
示例3: updateService
func (c *Controller) updateService(service *api.Service) {
glog.Infof("Update Service %s", service.Name)
serviceName := ServiceName(c.config, service.Labels)
err := c.serviceMgr.Create(service.Namespace, serviceName)
if err != nil {
return
}
pods, err := c.kube.Pods(service.Namespace).List(makeListOptSelector(service.Spec.Selector))
if err != nil {
glog.Errorf("List pods by service %s: %v", service.Name, err)
return
}
var serviceIp *types.FloatingIp = nil
if service.Spec.ClusterIP != "" {
serviceNetwork, err := c.serviceMgr.LocateServiceNetwork(service.Namespace, serviceName)
if err == nil {
serviceIp, err = c.networkMgr.LocateFloatingIp(
serviceNetwork, service.Name, service.Spec.ClusterIP)
}
} else {
serviceNetwork, err := c.serviceMgr.LookupServiceNetwork(service.Namespace, serviceName)
if err == nil {
c.networkMgr.DeleteFloatingIp(serviceNetwork, service.Name)
}
}
publicIp, err := c.updateServicePublicIP(service)
if err == nil && publicIp == nil {
resourceName := publicIpResourceName(service)
c.networkMgr.DeleteFloatingIp(c.networkMgr.GetPublicNetwork(), resourceName)
}
podIdMap := make(map[string]*api.Pod)
for _, pod := range pods.Items {
podIdMap[string(pod.UID)] = &pod
if serviceIp != nil {
// Connect serviceIp to VMI.
c.instanceMgr.AttachFloatingIp(pod.Name, pod.Namespace, serviceIp)
}
if publicIp != nil {
c.instanceMgr.AttachFloatingIp(pod.Name, pod.Namespace, publicIp)
}
}
// Detach the VIPs from pods which are no longer selected.
if serviceIp != nil {
refs, err := serviceIp.GetVirtualMachineInterfaceRefs()
if err == nil {
c.purgeStaleServiceRefs(serviceIp, refs, podIdMap)
}
}
if publicIp != nil {
refs, err := publicIp.GetVirtualMachineInterfaceRefs()
if err == nil {
c.purgeStaleServiceRefs(publicIp, refs, podIdMap)
}
}
}