Exemple #1
0
func CreateClient(key_file_path string) (*ei.BuildClient, error) {
	keyfile_data, err := ioutil.ReadFile(key_file_path)
	if err != nil {
		logging.Fatal("Could not open the keyfile: %s", key_file_path)
		return nil, err
	}

	keyfile := new(ApiKeyFile)
	err = json.Unmarshal(keyfile_data, keyfile)
	if err != nil {
		logging.Fatal("Could not parse keyfile: %s", key_file_path)
		return nil, err
	}

	client := ei.NewBuildClient(keyfile.Key)
	return client, nil
}
Exemple #2
0
func UploadFiles(cmd *Command, args []string) {
	logging.Info("Attempting to upload...")
	keyfile_data, err := ioutil.ReadFile(cmd.settings.ApiKeyFile)
	if err != nil {
		logging.Fatal("Could not open the keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	keyfile := new(ApiKeyFile)
	err = json.Unmarshal(keyfile_data, keyfile)
	if err != nil {
		logging.Fatal("Could not parse keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	agent_code, err := ioutil.ReadFile(cmd.settings.AgentFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the agent code: %s", cmd.settings.AgentFileOutPath)
		os.Exit(1)
		return
	}

	device_code, err := ioutil.ReadFile(cmd.settings.DeviceFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the device code %s", cmd.settings.DeviceFileOutPath)
		os.Exit(1)
		return
	}

	request := new(ei.CodeRevisionLong)
	client := ei.NewBuildClient(keyfile.Key)
	request.AgentCode = string(agent_code)
	request.DeviceCode = string(device_code)
	response, err := client.UpdateCodeRevision(cmd.settings.ModelKey, request)
	if err != nil {
		logging.Fatal("Failed to upload code to model %s, Error: %s", cmd.settings.ModelKey, err.Error())
		os.Exit(1)
		return
	}
	logging.Info("Succesfully uploaded version %d", response.Version)
}
Exemple #3
0
func UploadFiles(cmd *Command, args []string) {
	// Create our flags
	flag_set := flag.NewFlagSet("UploadFlagSet", flag.ExitOnError)
	restart_device := flag_set.Bool("r", false, "-r restarts the server on a successful model upload")
	flag_set.Parse(args[1:])

	logging.Info("Attempting to upload...")
	keyfile_data, err := ioutil.ReadFile(cmd.settings.ApiKeyFile)
	if err != nil {
		logging.Fatal("Could not open the keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	keyfile := new(ApiKeyFile)
	err = json.Unmarshal(keyfile_data, keyfile)
	if err != nil {
		logging.Fatal("Could not parse keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	agent_code, err := ioutil.ReadFile(cmd.settings.AgentFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the agent code: %s", cmd.settings.AgentFileOutPath)
		os.Exit(1)
		return
	}

	device_code, err := ioutil.ReadFile(cmd.settings.DeviceFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the device code %s", cmd.settings.DeviceFileOutPath)
		os.Exit(1)
		return
	}

	request := new(ei.CodeRevisionLong)
	client := ei.NewBuildClient(keyfile.Key)
	request.AgentCode = string(agent_code)
	request.DeviceCode = string(device_code)
	response, err := client.UpdateCodeRevision(cmd.settings.ModelKey, request)
	if err != nil {
		logging.Fatal("Failed to upload code to model %s, Error: %s", cmd.settings.ModelKey, err.Error())
		os.Exit(1)
		return
	}

	if response.Success == false {
		fmt.Println("There were errors in the build:")
		fmt.Printf("Error Code: %s \n", response.Error.Code)
		fmt.Printf("Message: %s \n", response.Error.FullMessage)
		return
	}

	logging.Info("Succesfully uploaded version %d", response.Revisions.Version)

	if *restart_device == true {
		err := client.RestartModelDevices(cmd.settings.ModelKey)
		if err != nil {
			logging.Fatal("Failed to restart devices after upload, Error: %s", err.Error())
			os.Exit(1)
		}

		model, err := client.GetModel(cmd.settings.ModelKey)
		if err != nil {
			fmt.Printf("Model: %s devices restarted.\n", cmd.settings.ModelKey)
			return
		} else {
			fmt.Printf("Model: %s restarted.\n", model.Name)
		}
	}
}