MCPcopy Create free account
hub / github.com/deepflowio/deepflow / suffixResourceOperation

Method suffixResourceOperation

server/controller/cloud/cloud.go:160–239  ·  view source on GitHub ↗
(resource model.Resource)

Source from the content-addressed store, hash-verified

158}
159
160func (c *Cloud) suffixResourceOperation(resource model.Resource) model.Resource {
161 hostIPToHostName, vmLcuuidToHostName, err := cloudcommon.GetHostAndVmHostNameByDomain(c.basicInfo.Lcuuid, c.db.DB)
162 if err != nil {
163 log.Errorf("cloud suffix operation get vtap info error : (%s)", err.Error(), logger.NewORGPrefix(c.orgID))
164 return resource
165 }
166
167 vinterfaceLcuuidToIP := map[string]string{}
168 for _, ip := range resource.IPs {
169 vinterfaceLcuuidToIP[ip.VInterfaceLcuuid] = ip.IP
170 }
171 vmIPToNetworkLcuuid := map[string]string{}
172 vmLcuuidToIPs := map[string][]string{}
173 for _, vinterface := range resource.VInterfaces {
174 if vinterface.DeviceType != common.VIF_DEVICE_TYPE_VM {
175 continue
176 }
177 ip, ok := vinterfaceLcuuidToIP[vinterface.Lcuuid]
178 if !ok || ip == "" {
179 continue
180 }
181 vmIPToNetworkLcuuid[vinterface.VPCLcuuid+ip] = vinterface.NetworkLcuuid
182 vmLcuuidToIPs[vinterface.DeviceLcuuid] = append(vmLcuuidToIPs[vinterface.DeviceLcuuid], ip)
183 }
184
185 var retHosts []model.Host
186 for _, host := range resource.Hosts {
187 // add hostname to host
188 if hostName, ok := hostIPToHostName[host.IP]; ok && host.Hostname == "" {
189 host.Hostname = hostName
190 }
191 retHosts = append(retHosts, host)
192 }
193
194 // get hostname of the vm where node is located
195 for _, sub := range resource.SubDomainResources {
196 nodeLcuuidToHostname := map[string]string{}
197 for _, node := range sub.PodNodes {
198 nodeLcuuidToHostname[node.Lcuuid] = node.Hostname
199 }
200 for _, con := range sub.VMPodNodeConnections {
201 vmHostname, ok := nodeLcuuidToHostname[con.PodNodeLcuuid]
202 if !ok {
203 continue
204 }
205 vmLcuuidToHostName[con.VMLcuuid] = vmHostname
206 }
207 }
208
209 var retVMs []model.VM
210 for _, vm := range resource.VMs {
211 // return a default map, when not found cloud tags
212 if vm.CloudTags == nil {
213 vm.CloudTags = map[string]string{}
214 }
215 // select the first of the existing ips, when the ip is empty
216 if vm.IP == "" {
217 ips, ok := vmLcuuidToIPs[vm.Lcuuid]

Callers 1

GetResourceMethod · 0.95

Calls 2

ErrorMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected