summaryrefslogtreecommitdiff
path: root/importDomain.go
blob: ffc0614553f98b8159dc7fcf2b97c4dbfeb35361 (plain)
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
package main

import (
	"errors"
	"fmt"
	"net/http"

	pb "go.wit.com/lib/protobuf/virtbuf"
	"go.wit.com/log"
)

// attempts to create a new virtual machine

func importDomain(w http.ResponseWriter, r *http.Request) (string, error) {
	name := r.URL.Query().Get("domainName")
	if name == "" {
		result := "start failed. name is blank " + r.URL.Path
		log.Warn(result)
		fmt.Fprintln(w, result)
		return "", errors.New(result)
	}
	log.Warn("name is", name)
	fmt.Fprintln(w, "name is", name)

	d := me.cluster.FindDropletByName(name)
	if d == nil {
		result := "libvirt domain " + name + " could not be found on any hypervisor"
		log.Info(result)
		fmt.Fprintln(w, result)
		return result, errors.New(result)
	}
	start := fmt.Sprintf("%-9s %-20s", d.Current.Hypervisor, name)
	if d.Current.State != pb.DropletState_OFF {
		result := "libvirt domain " + name + " found on " + d.Current.Hypervisor
		log.Info(result)
		fmt.Fprintln(w, result)
	}
	if d.LocalOnly == "" {
		result := start + " local duplicate defined (need to resolve this)"
		log.Log(WARN, result)
		fmt.Fprintln(w, result)
		return result, nil
	}
	result := start + " local ready to import from hypervisor"
	log.Log(WARN, result)
	fmt.Fprintln(w, result)
	return result, nil
}