当前位置: 首页>>代码示例>>Golang>>正文


Golang FloatingIp.GetVirtualMachineInterfaceRefs方法代码示例

本文整理汇总了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)
	}
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:30,代码来源:instance.go

示例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
}
开发者ID:WIZARD-CXY,项目名称:contrail-kubernetes,代码行数:19,代码来源:controller_test.go

示例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)
		}
	}
}
开发者ID:sanabby,项目名称:contrail-kubernetes,代码行数:61,代码来源:controller.go


注:本文中的github.com/Juniper/contrail-go-api/types.FloatingIp.GetVirtualMachineInterfaceRefs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。