forked from cloudius-systems/capstan
/
delete.go
48 lines (43 loc) · 1.09 KB
/
delete.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
45
46
47
48
/*
* 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 Delete(name string) error {
var err error
instanceName, instancePlatform := util.SearchInstance(name)
if instanceName == "" {
fmt.Printf("Instance: %s not found\n", name)
return nil
}
switch instancePlatform {
case "qemu":
qemu.StopVM(name)
err = qemu.DeleteVM(name)
case "vbox":
vbox.StopVM(name)
err = vbox.DeleteVM(name)
case "vmw":
vmw.StopVM(name)
err = vmw.DeleteVM(name)
case "gce":
gce.StopVM(name)
err = gce.DeleteVM(name)
}
if err != nil {
fmt.Printf("Failed to delete instance: %s\n", name)
return err
}
fmt.Printf("Deleted instance: %s\n", name)
return nil
}