@@ -693,6 +693,84 @@ func (v *V2) AnnounceHost(ctx context.Context, req *schedulerv2.AnnounceHostRequ
693693 return nil
694694}
695695
696+ // ListHosts lists hosts in scheduler.
697+ func (v * V2 ) ListHosts (ctx context.Context ) (* schedulerv2.ListHostsResponse , error ) {
698+ hosts := v .resource .HostManager ().LoadAll ()
699+
700+ resHosts := make ([]* commonv2.Host , len (hosts ))
701+ for i , host := range hosts {
702+ resHosts [i ] = & commonv2.Host {
703+ Id : host .ID ,
704+ Type : uint32 (host .Type ),
705+ Hostname : host .Hostname ,
706+ Ip : host .IP ,
707+ Port : host .Port ,
708+ DownloadPort : host .DownloadPort ,
709+ Os : host .OS ,
710+ Platform : host .Platform ,
711+ PlatformFamily : host .PlatformFamily ,
712+ PlatformVersion : host .PlatformVersion ,
713+ KernelVersion : host .KernelVersion ,
714+ Cpu : & commonv2.CPU {
715+ LogicalCount : host .CPU .LogicalCount ,
716+ PhysicalCount : host .CPU .PhysicalCount ,
717+ Percent : host .CPU .Percent ,
718+ ProcessPercent : host .CPU .ProcessPercent ,
719+ Times : & commonv2.CPUTimes {
720+ User : host .CPU .Times .User ,
721+ System : host .CPU .Times .System ,
722+ Idle : host .CPU .Times .Idle ,
723+ Nice : host .CPU .Times .Nice ,
724+ Iowait : host .CPU .Times .Iowait ,
725+ Irq : host .CPU .Times .Irq ,
726+ Softirq : host .CPU .Times .Softirq ,
727+ Steal : host .CPU .Times .Steal ,
728+ Guest : host .CPU .Times .Guest ,
729+ GuestNice : host .CPU .Times .GuestNice ,
730+ },
731+ },
732+ Memory : & commonv2.Memory {
733+ Total : host .Memory .Total ,
734+ Available : host .Memory .Available ,
735+ Used : host .Memory .Used ,
736+ UsedPercent : host .Memory .UsedPercent ,
737+ ProcessUsedPercent : host .Memory .ProcessUsedPercent ,
738+ Free : host .Memory .Free ,
739+ },
740+ Network : & commonv2.Network {
741+ TcpConnectionCount : host .Network .TCPConnectionCount ,
742+ UploadTcpConnectionCount : host .Network .UploadTCPConnectionCount ,
743+ Location : & host .Network .Location ,
744+ Idc : & host .Network .IDC ,
745+ },
746+ Disk : & commonv2.Disk {
747+ Total : host .Disk .Total ,
748+ Free : host .Disk .Free ,
749+ Used : host .Disk .Used ,
750+ UsedPercent : host .Disk .UsedPercent ,
751+ InodesTotal : host .Disk .InodesTotal ,
752+ InodesUsed : host .Disk .InodesUsed ,
753+ InodesFree : host .Disk .InodesFree ,
754+ InodesUsedPercent : host .Disk .InodesUsedPercent ,
755+ },
756+ Build : & commonv2.Build {
757+ GitVersion : host .Build .GitVersion ,
758+ GitCommit : & host .Build .GitCommit ,
759+ GoVersion : & host .Build .GoVersion ,
760+ Platform : & host .Build .Platform ,
761+ },
762+ SchedulerClusterId : host .SchedulerClusterID ,
763+ DisableShared : host .DisableShared ,
764+ }
765+ }
766+
767+ resp := & schedulerv2.ListHostsResponse {
768+ Hosts : resHosts ,
769+ }
770+
771+ return resp , nil
772+ }
773+
696774// DeleteHost releases host in scheduler.
697775func (v * V2 ) DeleteHost (ctx context.Context , req * schedulerv2.DeleteHostRequest ) error {
698776 log := logger .WithHostID (req .GetHostId ())
0 commit comments