Пример #1
0
func deploy(cmd *cobra.Command, args []string) error {
	//TODO this should be a validation method
	if Project == "" {
		log.Fatal("--project parameter is required to create a new deployment")
	}

	service, err := googlecloud.GetService()
	Check(err)

	Name, err = getName(uid)
	if err != nil {
		log.Warning(err)
		return err
	}

	log.Infof("Creating new deployment %s", Name)
	depBuilder := &DeploymentBuilder{
		DeploymentName:  Name,
		DeploymentDesc:  "",
		ConfigFilePath:  configpath,
		VarsDotYamlPath: varspath,
		CLIVars:         vars.vars,
	}

	d, err := depBuilder.GetDeployment()
	if err != nil {
		log.Warning(err)
		return err
	}

	//	d.Intent = "UPDATE"
	call := service.Deployments.Insert(Project, d)
	_, error := call.Do()
	Check(error)

	//TODO only set Vars if the varspath file actually exists
	dConfig := Deployment{
		Id:      Name,
		Project: Project,
		Config:  configpath,
		Vars:    varspath,
	}

	_, err = AppendDeployment(dConfig, true)
	if err != nil {
		log.Fatal(fmt.Sprintf("Config was deployed but there was an error writing the config file. You will not be able to use other `dm` commands, but the deployment will exist. Error was %s", err))
	}

	fmt.Printf("Created deployment %s.\n", Name)
	return nil
}
Пример #2
0
func stat(cmd *cobra.Command, args []string) error {
	service, err := googlecloud.GetService()
	Check(err)

	call := service.Resources.List(Project, Name)
	resources, error := call.Do()
	Check(error)

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 2, '\t', 0)
	fmt.Fprintln(w, "Resource Type\tName\t")
	for _, r := range resources.Resources {
		fmt.Fprintf(w, "%s\t%s\t\n", r.Type, r.Name)
	}
	w.Flush()
	return nil
}
Пример #3
0
func rm(cmd *cobra.Command, args []string) error {
	service, err := googlecloud.GetService()
	Check(err)

	config, err := ReadDeploymentConfig()
	Check(err)

	d := config.Deployments[Name]
	call := service.Deployments.Delete(d.Project, d.Id)
	_, err = call.Do()
	Check(err)

	err = RemoveDeployment(Name)
	Check(err)

	fmt.Printf("Deleted deployment %s\n", Name)
	return nil
}
Пример #4
0
func update(cmd *cobra.Command, args []string) error {
	// Get config from disk
	dmconf, err := ReadDeploymentConfig()
	if err != nil {
		return err
	}
	c := dmconf.Deployments[Name]

	depBuilder := &DeploymentBuilder{
		DeploymentName:  Name,
		DeploymentDesc:  "",
		ConfigFilePath:  c.Config,
		VarsDotYamlPath: c.Vars,
		CLIVars:         vars.vars,
	}

	d, err := depBuilder.GetDeployment()
	if err != nil {
		log.Warning(err)
		return err
	}

	//d.Intent = "UPDATE"
	existing, err := googlecloud.GetDeployment(c.Project, c.Id)
	if err != nil {
		return err
	}
	d.Fingerprint = existing.Fingerprint

	service, err := googlecloud.GetService()
	if err != nil {
		return err
	}
	log.Infof("Updating deployment %s", Name)
	_, err = service.Deployments.Update(Project, Name, d).Do()
	if err != nil {
		return err
	}
	fmt.Printf("Updated deployment %s.\n", Name)
	return nil
}