/
stop.go
44 lines (38 loc) · 1010 Bytes
/
stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
package cmd
import (
"fmt"
"github.com/cloudius-systems/capstan/hypervisor/gce"
"github.com/cloudius-systems/capstan/hypervisor/qemu"
"github.com/cloudius-systems/capstan/hypervisor/vbox"
"github.com/cloudius-systems/capstan/hypervisor/vmw"
"github.com/cloudius-systems/capstan/util"
)
func Stop(name string) error {
instanceName, instancePlatform := util.SearchInstance(name)
if instanceName == "" {
fmt.Printf("Instance: %s not found\n", name)
return nil
}
var err error
switch instancePlatform {
case "qemu":
err = qemu.StopVM(name)
case "vbox":
err = vbox.StopVM(name)
case "vmw":
err = vmw.StopVM(name)
case "gce":
err = gce.StopVM(name)
}
if err != nil {
fmt.Printf("Failed to stop instance: %s\n", name)
}
fmt.Printf("Stopped instance: %s\n", name)
return nil
}