Esempio n. 1
0
func getSerializableMachine(id string) (*machine, error) {
	m, err := vms.Machine(id)
	if err != nil {
		return nil, err
	}

	rt := machine{}

	rt.Id = m.Id()
	rt.Platform = m.Platform()

	rt.Name, err = m.Name()
	if err != nil {
		return nil, err
	}

	status, err := m.Status()
	if err != nil {
		return nil, err
	}
	rt.Status = vm.StatusToString(status)

	ip, err := m.IP()
	if err != nil {
		return nil, err
	}

	if ip != nil {
		rt.Ip = ip.String()
	}

	return &rt, nil
}
Esempio n. 2
0
func machinetoStruct(rawmachine vm.Machine) jsonMachine {
	var mach jsonMachine
	mach.Id = rawmachine.Id()
	mach.Name, _ = rawmachine.Name()
	status, _ := rawmachine.Status()
	mach.Status = vm.StatusToString(status)
	ip, _ := rawmachine.IP()
	mach.Ip = string(ip)
	return mach
}
Esempio n. 3
0
func ListRunningVM(c *echo.Context) error {
	machines, err := vms.Machines()
	if err != nil {
		return c.JSON(
			http.StatusInternalServerError, hash{
				"errors": [1]hash{
					hash{
						"detail": err.Error(),
					},
				},
			})
	}
	type attr struct {
		Name   string `json:"name"`
		Ip     string `json:"ip"`
		Status string `json:"status"`
		Id     string `json:"id"`
	}
	type virtmachine struct {
		Id  string `json:"id"`
		Att attr   `json:"attributes"`
	}
	var res = make([]virtmachine, len(machines))
	for i, val := range machines {
		res[i].Att.Name, err = val.Name()
		if err != nil {
			log.Error(err)
			return retJsonError(c, err)
		}
		res[i].Att.Id = val.Id()
		status, err := val.Status()
		if err != nil {
			log.Error(err)
			return retJsonError(c, err)
		}
		res[i].Att.Status = vm.StatusToString(status)
		ip, _ := val.IP()
		res[i].Att.Ip = string(ip)
		if err != nil {
			log.Error(err)
			return retJsonError(c, err)
		}
	}

	return c.JSON(http.StatusOK, hash{"data": res})
}
Esempio n. 4
0
func Machines(c *echo.Context) error {
	machines, err := vms.Machines()
	if err != nil {
		log.Error(err)
		return errors.UnableToRetrieveMachineList
	}

	res := make([]*machine, len(machines))

	for i, val := range machines {
		m := machine{}
		m.Name, err = val.Name()
		if err != nil {
			log.Error(err)
			return errors.UnableToRetrieveMachineList
		}

		m.Id = val.Id()
		status, err := val.Status()
		if err != nil {
			log.Error(err)
			return errors.UnableToRetrieveMachineList
		}

		m.Platform = val.Platform()

		m.Status = vm.StatusToString(status)

		progress, err := val.Progress()
		if err != nil {
			log.Errorf("Unable to get machine progress: %s", err)
		} else {
			m.Progress = int(progress)
		}

		ip, _ := val.IP()
		if ip != nil {
			m.Ip = ip.String()
		}

		res[i] = &m
	}

	return utils.JSON(c, http.StatusOK, res)
}