// Convert kubernetes pod response to Openstack response body
Convert kubernetes pod response to Openstack response body
// Convert kubernetes pod response to Openstack response body
func ConvertToOpenstackResponse(obj runtime.Object) runtime.Object {
	typeStr := reflect.TypeOf(obj).String()
	switch typeStr {
	case "*apps.ReplicaSet":
		rs := obj.(*apps.ReplicaSet)
		osObj := &OpenstackBatchResponse{}
		osObj.Reservation_Id = rs.Name
		return osObj
	case "*core.PodList":
		pl := obj.(*core.PodList)
		osObj := &OpenstackServerListResponse{}
		osObj.Servers = make([]OpenstackResponse, len(pl.Items))
		for i, pod := range pl.Items {
			osObj.Servers[i].Id = pod.Name
			osObj.Servers[i].Links = []LinkType{{convertPodSelfLink(pod.GetSelfLink()), ""}}
			i++
		}
		return osObj
	case "*core.Pod":
		pod := obj.(*core.Pod)
		osObj := &OpenstackResponse{}
		osObj.Id = pod.Name
		osObj.Links = []LinkType{{convertPodSelfLink(pod.GetSelfLink()), ""}}
		osObj.Image = &ImageType{Name: pod.Spec.VirtualMachine.Image}
		osObj.Tenant = pod.Tenant
		if pod.Status.VirtualMachineStatus != nil {
			osObj.Status = string(pod.Status.VirtualMachineStatus.State)
			osObj.OS_EXT_STS_Power_state = string(pod.Status.VirtualMachineStatus.PowerState)
		} else {
			osObj.Status = "statusUnknown"
			osObj.OS_EXT_STS_Power_state = string(core.NoState)
		}
		if pod.Status.StartTime != nil {
			osObj.CreatedAt = pod.Status.StartTime.String()
		}
		osObj.AccessIpV4 = pod.Status.PodIP
		osObj.Flavor = &FlavorType{Vcpus: int(pod.Spec.VirtualMachine.Resources.Requests.Cpu().Value()),
			MemoryMb: int(pod.Spec.VirtualMachine.Resources.Requests.Memory().Value() / 1024 / 1024)} 
		osObj.HostId = pod.Spec.Hostname
		if v, found := pod.Annotations["mizar.com/vpc"]; found {
			osObj.Vpc = v
		}
		if v, found := pod.Annotations["mizar.com/subnet"]; found {
			osObj.Subnet = v
		}
		return osObj
	default:
		klog.Errorf("Unsupported response type: %s", typeStr)
		return nil
	}
}
func ConvertToOpenstackResponse ( obj runtime . Object ) runtime . Object { typeStr := reflect . TypeOf ( obj ) . String ( ) switch typeStr { case " " : rs := obj . ( * apps . ReplicaSet ) osObj := & OpenstackBatchResponse { } osObj . Reservation_Id = rs . Name return osObj case " " : pl := obj . ( * core . PodList ) osObj := & OpenstackServerListResponse { } osObj . Servers = make ( [ ] OpenstackResponse , len ( pl . Items ) ) for i , pod := range pl . Items { osObj . Servers [ i ] . Id = pod . Name osObj . Servers [ i ] . Links = [ ] LinkType { { convertPodSelfLink ( pod . GetSelfLink ( ) ) , " " } } i ++ } return osObj case " " : pod := obj . ( * core . Pod ) osObj := & OpenstackResponse { } osObj . Id = pod . Name osObj . Links = [ ] LinkType { { convertPodSelfLink ( pod . GetSelfLink ( ) ) , " " } } osObj . Image = & ImageType { Name : pod . Spec . VirtualMachine . Image } osObj . Tenant = pod . Tenant if pod . Status . VirtualMachineStatus != nil { osObj . Status = string ( pod . Status . VirtualMachineStatus . State ) osObj . OS_EXT_STS_Power_state = string ( pod . Status . VirtualMachineStatus . PowerState ) } else { osObj . Status = " " osObj . OS_EXT_STS_Power_state = string ( core . NoState ) } if pod . Status . StartTime != nil { osObj . CreatedAt = pod . Status . StartTime . String ( ) } osObj . AccessIpV4 = pod . Status . PodIP osObj . Flavor = & FlavorType { Vcpus : int ( pod . Spec . VirtualMachine . Resources . Requests . Cpu ( ) . Value ( ) ) , MemoryMb : int ( pod . Spec . VirtualMachine . Resources . Requests . Memory ( ) . Value ( ) / 1024 / 1024 ) } osObj . HostId = pod . Spec . Hostname if v , found := pod . Annotations [ " " ] ; found { osObj . Vpc = v } if v , found := pod . Annotations [ " " ] ; found { osObj . Subnet = v } return osObj default : klog . Errorf ( " " , typeStr ) return nil } }
Convert kubernetes pod response to Openstack response body
Convert kubernetes pod response to Openstack response body
// display in Mi