Example #1
0
func StartDeviceLogging(client *ei.BuildClient, device_id string) {
	logs, poll_url, err := client.GetDeviceLogs(device_id)
	if err != nil {
		logging.Fatal("Failed to get device logs %s", err.Error())
		return
	}

	logging.Debug("Poll Url %s", poll_url)
	for _, entry := range logs {
		fmt.Printf("%s: %s: %s\n", entry.Timestamp, entry.Type, entry.Message)
	}

	for {
		logs, err = client.ContinueDeviceLogs(poll_url)
		if err != nil {
			if _, ok := err.(*ei.Timeout); ok == false {
				logging.Fatal("Failed to get device logs %s", err.Error())
				return
			} else {
				logging.Debug("Long poll timed out...")
			}
		} else {
			for _, entry := range logs {
				fmt.Printf("%s: %s: %s\n", entry.Timestamp, entry.Type, entry.Message)
			}
		}
	}
}
Example #2
0
func RestartDevice(client *ei.BuildClient, device_id string) {
	err := client.RestartDevice(device_id)
	if err != nil {
		logging.Fatal("Failed to restart device %s with error %s", device_id, err.Error())
		return
	}
	fmt.Printf("Successfully restarted device and agent")
}
Example #3
0
func ListDevices(client *ei.BuildClient) {
	device_list, err := client.GetDeviceList()
	if err != nil {
		logging.Fatal("Failed to get device list %s", err.Error())
		return
	}

	for _, model := range device_list {
		fmt.Printf("Id: %s, Name: %s\n", model.Id, model.Name)
	}
}
Example #4
0
func ListModels(client *ei.BuildClient) {
	model_list, err := client.ListModels()
	if err != nil {
		logging.Fatal("Failed to get model list %s", err.Error())
		return
	}

	for _, model := range model_list.Models {
		fmt.Printf("Id: %s, Name: %s\n", model.Id, model.Name)
	}
}
Example #5
0
func AssignDeviceToModel(client *ei.BuildClient, device_id string, model_id string) {
	device, err := client.GetDevice(device_id)
	if err != nil {
		logging.Fatal("Failed to retrieve current model for model id: %s", model_id)
		return
	}

	// Don't do anything if its already the same
	if device.ModelId == model_id {
		return
	}

	device.ModelId = model_id
	updated_device, err := client.UpdateDevice(&device, device_id)
	logging.Debug("Model and new Devices: %s", updated_device)
}