@@ -21,6 +21,7 @@ import (
2121
2222var (
2323 _ provider.Provider = & Provider {}
24+ _ provider.DeviceProvider = & Provider {}
2425 _ provider.InterfaceProvider = & Provider {}
2526)
2627
@@ -49,6 +50,58 @@ func (p *Provider) Disconnect(ctx context.Context, conn *deviceutil.Connection)
4950 return p .conn .Close ()
5051}
5152
53+ func (p * Provider ) ListPorts (ctx context.Context ) ([]provider.DevicePort , error ) {
54+ iFaces := new (Ifaces )
55+ err := p .client .GetConfig (ctx , iFaces )
56+ if err != nil {
57+ return nil , fmt .Errorf ("failed to list ports: %w" , err )
58+ }
59+
60+ dp := make ([]provider.DevicePort , 0 , len (iFaces .PhysIfList ))
61+ for _ , intf := range iFaces .PhysIfList {
62+ var speeds = []int32 {}
63+ s , _ := ExtractInterfaceSpeedFromName (intf .Name )
64+
65+ if n , err := MapInterfaceSpeedToNumeric (s ); err == nil {
66+ speeds = append (speeds , n )
67+ }
68+ // (fixme): name already contains the speed information, convert them to standardized string value (e.g. 10G, 25G, 40G, 100G)
69+ dp = append (dp , provider.DevicePort {
70+ ID : intf .Name ,
71+ Type : intf .Name ,
72+ SupportedSpeedsGbps : speeds ,
73+ })
74+ }
75+ return dp , nil
76+ }
77+
78+ func (p * Provider ) GetDeviceInfo (ctx context.Context ) (* provider.DeviceInfo , error ) {
79+ i := new (BasicDeviceInfo )
80+
81+ if err := p .client .GetState (ctx , i ); err != nil {
82+ return nil , err
83+ }
84+
85+ return & provider.DeviceInfo {
86+ Manufacturer : Manufacturer ,
87+ Model : i .Model ,
88+ SerialNumber : i .SerialNumber ,
89+ FirmwareVersion : i .FirmwareVersion ,
90+ }, nil
91+ }
92+
93+ func (p * Provider ) Reboot (ctx context.Context , conn * deviceutil.Connection ) error {
94+ return errors .New ("IOS XR Provider does not support rebooting the device" )
95+ }
96+
97+ func (p * Provider ) FactoryReset (ctx context.Context , conn * deviceutil.Connection ) error {
98+ return errors .New ("IOS XR Provider does not support factory reset" )
99+ }
100+
101+ func (p * Provider ) Reprovision (cxt context.Context , conn * deviceutil.Connection ) error {
102+ return errors .New ("IOS XR Provider does not support reprovisioning" )
103+ }
104+
52105func (p * Provider ) EnsureInterface (ctx context.Context , req * provider.EnsureInterfaceRequest ) error {
53106 if p .client == nil {
54107 return errors .New ("client is not connected" )
0 commit comments