@@ -121,6 +121,8 @@ type MachineService interface {
121121 Shutdown (int ) error
122122 AddExternalIP (int , int ) error
123123 DeleteExternalIP (int , int , string ) error
124+ Stop (int , bool ) error
125+ Start (int , int ) error
124126}
125127
126128// MachineServiceOp handles communication with the machine related methods of the
@@ -306,6 +308,42 @@ func (s *MachineServiceOp) DeleteByID(machineID int) error {
306308 return err
307309}
308310
311+ // Stop stops a machine
312+ func (s * MachineServiceOp ) Stop (machineID int , force bool ) error {
313+ machineMap := make (map [string ]interface {})
314+ machineMap ["machineId" ] = machineID
315+ machineMap ["stop" ] = force
316+ machineJSON , err := json .Marshal (machineMap )
317+ if err != nil {
318+ return err
319+ }
320+ req , err := http .NewRequest ("POST" , s .client .ServerURL + "/cloudapi/machines/stop" , bytes .NewBuffer (machineJSON ))
321+ if err != nil {
322+ return err
323+ }
324+ _ , err = s .client .Do (req )
325+ return err
326+ }
327+
328+ // Start starts a machine, boots from ISO if diskID is given
329+ func (s * MachineServiceOp ) Start (machineID int , diskID int ) error {
330+ machineMap := make (map [string ]interface {})
331+ machineMap ["machineId" ] = machineID
332+ if diskID != 0 {
333+ machineMap ["diskId" ] = diskID
334+ }
335+ machineJSON , err := json .Marshal (machineMap )
336+ if err != nil {
337+ return err
338+ }
339+ req , err := http .NewRequest ("POST" , s .client .ServerURL + "/cloudapi/machines/start" , bytes .NewBuffer (machineJSON ))
340+ if err != nil {
341+ return err
342+ }
343+ _ , err = s .client .Do (req )
344+ return err
345+ }
346+
309347// Template creates an image of the existing machine by ID
310348func (s * MachineServiceOp ) Template (machineID int , templateName string ) error {
311349 machineMap := make (map [string ]interface {})
0 commit comments