@@ -18,7 +18,7 @@ func (c *FleetClient) SSH(name string) (err error) {
1818
1919 timeout := time .Duration (Flags .SSHTimeout * 1000 ) * time .Millisecond
2020
21- ms , err := machineState (name )
21+ ms , err := machineState (c , name )
2222 if err != nil {
2323 return err
2424 }
@@ -31,13 +31,13 @@ func (c *FleetClient) SSH(name string) (err error) {
3131 return err
3232 }
3333
34- machID , err := findUnit (units [0 ])
34+ machID , err := findUnit (c , units [0 ])
3535
3636 if err != nil {
3737 return err
3838 }
3939
40- ms , err = machineState (machID )
40+ ms , err = machineState (c , machID )
4141
4242 if err != nil || ms == nil {
4343 return err
@@ -62,15 +62,15 @@ func (c *FleetClient) SSH(name string) (err error) {
6262
6363// runCommand will attempt to run a command on a given machine. It will attempt
6464// to SSH to the machine if it is identified as being remote.
65- func runCommand (cmd string , machID string ) (retcode int ) {
65+ func runCommand (c * FleetClient , cmd string , machID string ) (retcode int ) {
6666 var err error
6767 if machine .IsLocalMachineID (machID ) {
6868 retcode , err = runLocalCommand (cmd )
6969 if err != nil {
7070 fmt .Printf ("Error running local command: %v\n " , err )
7171 }
7272 } else {
73- ms , err := machineState (machID )
73+ ms , err := machineState (c , machID )
7474 if err != nil || ms == nil {
7575 fmt .Printf ("Error getting machine IP: %v\n " , err )
7676 } else {
@@ -125,8 +125,8 @@ func runRemoteCommand(cmd string, addr string, timeout time.Duration) (exit int,
125125}
126126
127127// findUnits returns the machine ID of a running unit
128- func findUnit (name string ) (machID string , err error ) {
129- u , err := cAPI .Unit (name )
128+ func findUnit (c * FleetClient , name string ) (machID string , err error ) {
129+ u , err := c . Fleet .Unit (name )
130130 if err != nil {
131131 return "" , fmt .Errorf ("Error retrieving Unit %s: %v" , name , err )
132132 }
@@ -142,8 +142,8 @@ func findUnit(name string) (machID string, err error) {
142142 return u .MachineID , nil
143143}
144144
145- func machineState (machID string ) (* machine.MachineState , error ) {
146- machines , err := cAPI .Machines ()
145+ func machineState (c * FleetClient , machID string ) (* machine.MachineState , error ) {
146+ machines , err := c . Fleet .Machines ()
147147 if err != nil {
148148 return nil , err
149149 }
@@ -158,16 +158,16 @@ func machineState(machID string) (*machine.MachineState, error) {
158158// cachedMachineState makes a best-effort to retrieve the MachineState of the given machine ID.
159159// It memoizes MachineState information for the life of a fleetctl invocation.
160160// Any error encountered retrieving the list of machines is ignored.
161- func cachedMachineState (machID string ) (ms * machine.MachineState ) {
162- if machineStates == nil {
163- machineStates = make (map [string ]* machine.MachineState )
164- ms , err := cAPI .Machines ()
161+ func cachedMachineState (c * FleetClient , machID string ) (ms * machine.MachineState ) {
162+ if c . machineStates == nil {
163+ c . machineStates = make (map [string ]* machine.MachineState )
164+ ms , err := c . Fleet .Machines ()
165165 if err != nil {
166166 return nil
167167 }
168168 for i , m := range ms {
169- machineStates [m .ID ] = & ms [i ]
169+ c . machineStates [m .ID ] = & ms [i ]
170170 }
171171 }
172- return machineStates [machID ]
172+ return c . machineStates [machID ]
173173}
0 commit comments