Exemplo n.º 1
0
Arquivo: gbox.go Projeto: gfrey/smutje
func (hp *gboxClient) UUID(name string) (string, error) {
	switch {
	case !gbox.ExistsVM(name):
		return "", nil
	case !gbox.RunningVM(name):
		return name, gbox.StartVM(name)
	default:
		return name, nil
	}

}
Exemplo n.º 2
0
Arquivo: gbox.go Projeto: gfrey/smutje
func (hp *gboxClient) Create(l logger.Logger, blueprint string) (string, error) {
	bp := new(gboxBlueprint)
	if err := json.Unmarshal([]byte(blueprint), &bp); err != nil {
		return "", errors.Wrap(err, "failed to unmarshal the blueprint")
	}

	if bp.Name == "" {
		return "", errors.Errorf("no name for VM specified in blueprint")
	}

	switch {
	case bp.Template == "":
		return "", errors.Errorf("no template specified in blueprint")
	case !gbox.ExistsTemplate(bp.Template):
		return "", errors.Errorf("template %q specified in blueprint, does not exist", bp.Template)
	}

	err := gbox.CreateVM(bp.Name, bp.Template)
	if err != nil {
		return "", errors.Wrap(err, "failed to create VM")
	}

	return bp.Name, errors.Wrap(gbox.StartVM(bp.Name), "failed to start VM")
}