Skip to content

Commit 8ec2ab0

Browse files
committed
remove CommandOutput, new impl.
Signed-off-by: Songpon Srisawai <[email protected]>
1 parent 13571f8 commit 8ec2ab0

File tree

13 files changed

+245
-33
lines changed

13 files changed

+245
-33
lines changed

pkg/guestagent/api/client/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@ func (c *GuestAgentClient) Tunnel(ctx context.Context) (api.GuestService_TunnelC
7676
}
7777
return stream, nil
7878
}
79+
80+
func (c *GuestAgentClient) GetIP(ctx context.Context, req *api.GetIPRequest) (*api.GetIPRespond, error) {
81+
return c.cli.GetIP(ctx, req)
82+
}
83+
84+
85+

pkg/guestagent/api/guestservice.pb.desc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
�
2+
�
33
guestservice.protogoogle/protobuf/empty.protogoogle/protobuf/timestamp.proto"0
44
Info(
55
local_ports ( 2.IPPortR
@@ -23,9 +23,15 @@ mount_path ( R mountPath.
2323
data ( Rdata
2424

2525
guest_addr ( R guestAddr&
26-
udp_target_addr ( RudpTargetAddr2�
26+
udp_target_addr ( RudpTargetAddr"-
27+
GetIPRequest
28+
29+
ip_version ( R ipVersion"
30+
GetIPRespond
31+
ip ( Rip2�
2732
GuestService(
2833
GetInfo.google.protobuf.Empty.Info-
2934
GetEvents.google.protobuf.Empty.Event01
3035
PostInotify.Inotify.google.protobuf.Empty(,
31-
Tunnel.TunnelMessage.TunnelMessage(0B/Z-github.com/lima-vm/lima/v2/pkg/guestagent/apibproto3
36+
Tunnel.TunnelMessage.TunnelMessage(0%
37+
GetIP.GetIPRequest.GetIPRespondB/Z-github.com/lima-vm/lima/v2/pkg/guestagent/apibproto3

pkg/guestagent/api/guestservice.pb.go

Lines changed: 122 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/guestagent/api/guestservice.proto

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ service GuestService {
1111
rpc PostInotify(stream Inotify) returns (google.protobuf.Empty);
1212

1313
rpc Tunnel(stream TunnelMessage) returns (stream TunnelMessage);
14-
}
1514

16-
message Info {
17-
repeated IPPort local_ports = 1;
15+
rpc GetIP(GetIPRequest) returns (GetIPRespond);
1816
}
1917

18+
message Info { repeated IPPort local_ports = 1; }
19+
2020
message Event {
2121
google.protobuf.Timestamp time = 1;
2222
repeated IPPort added_local_ports = 2;
@@ -42,3 +42,6 @@ message TunnelMessage {
4242
string guest_addr = 4;
4343
string udp_target_addr = 5;
4444
}
45+
46+
message GetIPRequest { string ip_version = 1; }
47+
message GetIPRespond { string ip = 1; }

pkg/guestagent/api/guestservice_grpc.pb.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/guestagent/api/server/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ func (s *GuestServer) PostInotify(server api.GuestService_PostInotifyServer) err
5656
func (s *GuestServer) Tunnel(stream api.GuestService_TunnelServer) error {
5757
return s.TunnelS.Start(stream)
5858
}
59+
60+
func (s *GuestServer) GetIP(ctx context.Context, req *api.GetIPRequest) (*api.GetIPRespond, error) {
61+
return s.Agent.IP(ctx, req.IpVersion)
62+
// return s.Agent.IP(ctx, "4")
63+
}

pkg/guestagent/guestagent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ type Agent interface {
1414
Events(ctx context.Context, ch chan *api.Event)
1515
LocalPorts(ctx context.Context) ([]*api.IPPort, error)
1616
HandleInotify(event *api.Inotify)
17+
IP(ctx context.Context, ipVersion string)(*api.GetIPRespond, error)
1718
}

pkg/guestagent/guestagent_linux.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lima-vm/lima/v2/pkg/guestagent/api"
2121
"github.com/lima-vm/lima/v2/pkg/guestagent/iptables"
2222
"github.com/lima-vm/lima/v2/pkg/guestagent/kubernetesservice"
23+
"github.com/lima-vm/lima/v2/pkg/guestagent/metricutil"
2324
"github.com/lima-vm/lima/v2/pkg/guestagent/procnettcp"
2425
"github.com/lima-vm/lima/v2/pkg/guestagent/ticker"
2526
"github.com/lima-vm/lima/v2/pkg/guestagent/timesync"
@@ -45,8 +46,7 @@ func New(ctx context.Context, ticker ticker.Ticker, iptablesIdle time.Duration)
4546

4647
auditStatus, err := auditClient.GetStatus()
4748
if err != nil {
48-
// syscall.EPERM is returned when using audit from a non-initial namespace
49-
// https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
49+
// syscall.EPERM is returned when using audit from a non-initial namespace https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
5050
if !errors.Is(err, syscall.EPERM) {
5151
return nil, err
5252
}
@@ -371,3 +371,8 @@ func (a *agent) HandleInotify(event *api.Inotify) {
371371
}
372372
}
373373
}
374+
375+
func (a *agent) IP(ctx context.Context, ipVersion string)(*api.GetIPRespond, error) {
376+
out, err := metricutil.GetDefaultIP(ipVersion)
377+
return &api.GetIPRespond{Ip: out}, err
378+
}

0 commit comments

Comments
 (0)