Esempio n. 1
0
func (cmd *upload_template) run(pc *kingpin.ParseContext) error {
	file, err := os.Open(cmd.TemplatePath)
	if err != nil {
		return fmt.Errorf("oops! couldn't open file, path=%s: %v", cmd.TemplatePath, err)
	}
	defer file.Close()

	client, err := sscat.NewClient(*apiHost, *ssHost, *account, *apiToken)
	if err != nil {
		return fmt.Errorf("oops! couldn't create api client, account=%d: %v", *account, err)
	}

	fmt.Printf("looking for remote %s template...\n", cmd.TemplateName)
	if t, _ := client.FindTemplate(sscat.TemplateByName(cmd.TemplateName)); t != nil {
		fmt.Printf("deleting remote %s template...\n", cmd.TemplateName)
		if err := client.DeleteTemplate(t.Id); err != nil {
			return fmt.Errorf("oops! couldn't delete %s template: %v", cmd.TemplateName, err)
		}
	}

	fileName := path.Base(cmd.TemplatePath)
	fmt.Printf("uploading %s template %s...\n", cmd.TemplateName, fileName)
	t, err := client.UploadTemplate(cmd.TemplateName, fileName, file)
	if err != nil {
		return fmt.Errorf("oops! couldn't upload %s template: %v", cmd.TemplateName, err)
	}

	fmt.Printf("done uploading %s template, href=%s\n", cmd.TemplateName, t.Href)
	return nil
}
Esempio n. 2
0
func (cmd *launch_app) run(pc *kingpin.ParseContext) error {
	client, err := sscat.NewClient(*apiHost, *ssHost, *account, *apiToken)
	if err != nil {
		return fmt.Errorf("oops! couldn't create api client, account=%d: %v", *account, err)
	}

	fmt.Printf("looking for remote %s template...\n", cmd.TemplateName)
	template, err := client.FindTemplate(sscat.TemplateByName(cmd.TemplateName))
	if err != nil {
		return fmt.Errorf("oops! trouble looking for template: %v", err)
	}

	if template == nil {
		return fmt.Errorf("oops! %s template couldn't be found.", err)
	}

	appName := cmd.AppName
	if cmd.Haikunate {
		appName = haikunate(appName)
	}

	fmt.Printf("launching %s app, timeout=%v...\n", appName, cmd.Timeout)
	execution, err := client.StartExecution(appName, cmd.AppDescription, template.Href)
	if err != nil {
		return fmt.Errorf("oops! trouble starting launch: %v", err)
	}

	fmt.Printf("started execution, href=%s\n", execution.Href)
	fmt.Println("waiting for launch status...")
	for {
		select {
		case <-time.After(time.Second * 20):
			execution, err := client.Execution(execution.Id)
			if err != nil {
				return fmt.Errorf("oops! trouble waiting for execution: %v", err)
			}
			switch execution.Status {
			case "running":
				fmt.Printf("%s app is running.\n", appName)
				return nil
			case "launching", "starting", "enabling", "waiting_for_operations":
				fmt.Printf("waiting for launch, status=%s...\n", execution.Status)
				break
			default:
				return fmt.Errorf("oops! trouble waiting for execution, status=%s\n", execution.Status)
			}
		case <-time.After(cmd.Timeout):
			return fmt.Errorf("oops! timeout while waiting for launch.\n")
		}
	}

	return nil
}
Esempio n. 3
0
func (cmd *delete_template) run(pc *kingpin.ParseContext) error {
	client, err := sscat.NewClient(*apiHost, *ssHost, *account, *apiToken)
	if err != nil {
		return fmt.Errorf("oops! couldn't create api client, account=%d: %v", *account, err)
	}

	fmt.Printf("looking for remote %s template...\n", cmd.TemplateName)
	template, err := client.FindTemplate(sscat.TemplateByName(cmd.TemplateName))
	if err != nil {
		return fmt.Errorf("oops! trouble looking for template: %v", err)
	}

	if template == nil {
		fmt.Println("nothing to do.")
	} else {
		fmt.Printf("deleting remote %s template...\n", cmd.TemplateName)
		if err := client.DeleteTemplate(template.Id); err != nil {
			return fmt.Errorf("oops! couldn't delete %s template: %v", cmd.TemplateName, err)
		}

		fmt.Printf("done deleting %s template.\n", cmd.TemplateName)
	}
	return nil
}