Exemplo n.º 1
0
	if owner != "" && description != "" {
		_, err := db.Exec("update virtualmachine set Owner=?,Description=? where Id=?", owner, description, this.Id)
		if err != nil {
			return err
		} else {
			return nil
		}
	} else { //can not be updated
		return errors.New("owner and description must have values")
	}
}

// global variables: do not like global variables
// cached VirConnection
//IpAddress => VirConnection
var ipaddressConnectionCache = utils.NewSafeMap()

func getVirtualMachine(db *sql.DB, Id int) *VirtualMachine {
	var (
		UUIDString    string
		Owner         string
		Description   string
		HostIpAddress string
	)

	row := db.QueryRow("select Id,UUIDString,Owner, Description, HostIpAddress from virtualmachine where Id=?", Id)
	if err := row.Scan(&Id, &UUIDString, &Owner, &Description, &HostIpAddress); err != nil {
		checkErr(err, "failed to scan in getVirtualMachine")
		return nil
	}
	vm, err := readLibvirtVM(HostIpAddress, UUIDString)
Exemplo n.º 2
0
	"fmt"
	"github.com/codegangsta/martini"
	"github.com/codegangsta/martini-contrib/render"
	_ "github.com/mattn/go-sqlite3"
	"log"
	"net"
	"net/http"
	_ "net/url"
	"strconv"
	"strings"
	"sync/atomic"
	"time"
)

// token_id <=> TokenContentForVMInstall
var tokenMap = utils.NewSafeMap()

// domain.name <=> callbackid
var callbackMap = utils.NewSafeMap()

type TokenContentForVMInstall struct {
	Ch        chan string
	Name      string
	Conn      libvirt.VirConnection
	IPAddress string
}

//TODO move all sql to model.go
func main() {
	/* init database */
	db, err := sql.Open("sqlite3", "/tmp/post_db.bin")