// serviced template deploy TEMPLATEID POOLID DEPLOYMENTID [--manual-assign-ips]
174933
func (c *ServicedCli) cmdTemplateDeploy(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 3 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "deploy")
		return
	}

	cfg := api.DeployTemplateConfig{
		ID:              args[0],
		PoolID:          args[1],
		DeploymentID:    args[2],
		ManualAssignIPs: ctx.Bool("manual-assign-ips"),
	}

	fmt.Fprintln(os.Stderr, "Deploying template - please wait...")
	if svcs, err := c.driver.DeployServiceTemplate(cfg); err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else if svcs == nil {
		fmt.Fprintln(os.Stderr, "received nil service definition")
	} else {
		for _, svc := range svcs {
			fmt.Println(svc.ID)
		}
	}
}
411921
func (c *ServicedCli) printHostAddPrivate(ctx *cli.Context) {
	var output []string

	args := ctx.Args()
	switch len(args) {
	case 1:
		output = c.pools()
	}
	fmt.Println(strings.Join(output, "\n"))
}
35519
func (_m *ClientInterface) DeployTemplate(request servicetemplate.ServiceTemplateDeploymentRequest) ([]string, error) {
	ret := _m.Called(request)

	var r0 []string
	if rf, ok := ret.Get(0).(func(servicetemplate.ServiceTemplateDeploymentRequest) []string); ok {
		r0 = rf(request)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]string)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(servicetemplate.ServiceTemplateDeploymentRequest) error); ok {
		r1 = rf(request)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
200597
func ServeTemplate(w http.ResponseWriter, name string, data map[string]interface{}) {
	// cast the writer to the resposneWriter, get the router
	r := w.(*responseWriter).Router

	r.RLock()
	defer r.RUnlock()

	if data == nil {
		data = map[string]interface{}{}
	}

	// append global params to the template
	for k, v := range r.params {
		data[k] = v
	}

	var buf bytes.Buffer
	if err := r.views.ExecuteTemplate(&buf, name, data); err != nil {
		panic(err)
		return
	}

	// set the content length, type, etc
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	w.Write(buf.Bytes())
}
969116
func (s *TemplatesService) ApplyTemplate(accountID string, templateIdentifier string, domainIdentifier string) (*templateResponse, error) {
	path := versioned(fmt.Sprintf("%v/templates/%v", domainPath(accountID, domainIdentifier), templateIdentifier))
	templateResponse := &templateResponse{}

	resp, err := s.client.post(path, nil, nil)
	if err != nil {
		return nil, err
	}

	templateResponse.HttpResponse = resp
	return templateResponse, nil
}
1096261
func (c *ServicedCli) cmdServiceRestart(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "restart")
		c.exit(1)
		return
	}

	var sIds []string
	var instances []struct {
		Service  string
		Instance int
	}

	for _, arg := range args {
		svc, instanceID, err := c.searchForService(arg, ctx.Bool("no-prefix-match"))
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			c.exit(1)
			return
		}

		if instanceID < 0 {
			sIds = append(sIds, svc.ID)
		} else {
			instances = append(instances, struct {
				Service  string
				Instance int
			}{
				svc.ID,
				instanceID,
			})
		}
	}

	// Batch start services
	if len(sIds) > 0 {
		if ctx.Bool("rebalance") {
			if affected, err := c.driver.RebalanceService(api.SchedulerConfig{sIds, ctx.Bool("auto-launch"), ctx.Bool("sync")}); err != nil {
				fmt.Fprintln(os.Stderr, err)
				c.exit(1)
			} else {
				fmt.Printf("Restarting %d service(s)\n", affected)
			}
		} else {
			if affected, err := c.driver.RestartService(api.SchedulerConfig{sIds, ctx.Bool("auto-launch"), ctx.Bool("sync")}); err != nil {
				fmt.Fprintln(os.Stderr, err)
				c.exit(1)
			} else {
				fmt.Printf("Restarting %d service(s)\n", affected)
			}
		}
	}

	// Iterate and reschedule any instances specified
	for _, instance := range instances {
		if err := c.driver.StopServiceInstance(instance.Service, instance.Instance); err != nil {
			fmt.Fprintln(os.Stderr, err)
			c.exit(1)
		} else {
			fmt.Printf("Restarting instance %s/%d\n", instance.Service, instance.Instance)
		}
	}
	return
}
195129
func (c *ServicedCli) cmdMetric(ctx *cli.Context) error {
	args := ctx.Args()
	if len(args) < 2 {
		fmt.Println("Insufficient number of arguments")
		return fmt.Errorf("Insufficient number of arguments")
	}
	metricName := args[0]
	metricValue := args[1]
	message, err := c.driver.PostMetric(metricName, metricValue)
	if err != nil {
		return fmt.Errorf("could not post stats: %s", err)
	}
	return fmt.Errorf(message)
}
15691
func Convert_v1_BrokerTemplateInstanceSpec_To_template_BrokerTemplateInstanceSpec(in *v1.BrokerTemplateInstanceSpec, out *template.BrokerTemplateInstanceSpec, s conversion.Scope) error {
	return autoConvert_v1_BrokerTemplateInstanceSpec_To_template_BrokerTemplateInstanceSpec(in, out, s)
}
1144730
func (s *Service) NewTemplate(w http.ResponseWriter, r *http.Request) {
	id, err := paramID("id", r)
	if err != nil {
		Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
		return
	}

	ctx := r.Context()
	dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
	if err != nil {
		notFound(w, id, s.Logger)
		return
	}

	var template chronograf.Template
	if err := json.NewDecoder(r.Body).Decode(&template); err != nil {
		invalidJSON(w, s.Logger)
		return
	}

	if err := ValidTemplateRequest(&template); err != nil {
		invalidData(w, err, s.Logger)
		return
	}

	ids := idgen.UUID{}
	tid, err := ids.Generate()
	if err != nil {
		msg := fmt.Sprintf("Error creating template ID for dashboard %d: %v", id, err)
		Error(w, http.StatusInternalServerError, msg, s.Logger)
		return
	}
	template.ID = chronograf.TemplateID(tid)

	dash.Templates = append(dash.Templates, template)
	if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
		msg := fmt.Sprintf("Error adding template %s to dashboard %d: %v", tid, id, err)
		Error(w, http.StatusInternalServerError, msg, s.Logger)
		return
	}

	res := newTemplateResponse(dash.ID, template)
	encodeJSON(w, http.StatusOK, res, s.Logger)
}
7324
func (c *ServicedCli) cmdSetConnTimeout(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) != 2 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "set-conn-timeout")
		return
	}

	connTimeout, err := time.ParseDuration(args[1])
	if err != nil {
		fmt.Fprintf(os.Stderr, "could not parse duration: %s\n", err)
		return
	} else if connTimeout < 0 {
		fmt.Fprintln(os.Stderr, "duration cannot be negative")
		return
	}

	pool, err := c.driver.GetResourcePool(args[0])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	} else if pool == nil {
		fmt.Fprintln(os.Stderr, "pool not found")
		return
	}

	pool.ConnectionTimeout = int(connTimeout.Seconds() * 1000)
	if err := c.driver.UpdateResourcePool(*pool); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
}
201414
func (c *ServicedCli) initBackup() {
	c.app.Commands = append(
		c.app.Commands,
		cli.Command{
			Name:        "backup",
			Usage:       "Dump all templates and services to a tgz file",
			Description: "serviced backup DIRPATH",
			Action:      c.cmdBackup,
			Flags: []cli.Flag{
				cli.StringSliceFlag{
					Name:  "exclude",
					Value: &cli.StringSlice{},
					Usage: "Subdirectory of the tenant volume to exclude from backup",
				},
				cli.BoolFlag{
					Name: "check",
					Usage: "check space, but do not do backup",
				},
				cli.BoolFlag{
					Name: "force",
					Usage: "attempt backup even if space check fails",
				},
			},
		},
		cli.Command{
			Name:        "restore",
			Usage:       "Restore templates and services from a tgz file",
			Description: "serviced restore FILEPATH",
			Action:      c.cmdRestore,
		},
	)
}
641793
func DispatchedID(templateID string, t time.Time) string {
	u := uuid.Generate()[:8]
	return fmt.Sprintf("%s%s%d-%s", templateID, DispatchLaunchSuffix, t.Unix(), u)
}
685637
func (c *ServicedCli) cmdServiceEdit(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "edit")
		c.exit(1)
		return
	}

	svcDetails, _, err := c.searchForService(args[0], ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	service, err := c.driver.GetService(svcDetails.ID)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	jsonService, err := json.MarshalIndent(service, " ", "  ")
	if err != nil {
		fmt.Fprintf(os.Stderr, "error marshalling service: %s\n", err)
		c.exit(1)
		return
	}

	name := fmt.Sprintf("serviced_service_edit_%s", service.ID)
	reader, err := openEditor(jsonService, name, ctx.String("editor"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	if service, err := c.driver.UpdateService(reader); err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
	} else if service == nil {
		fmt.Fprintln(os.Stderr, "received nil service")
		c.exit(1)
	} else {
		fmt.Println(service.ID)
	}
	return
}
23733
func (_m *FacadeInterface) DeployTemplateActive() ([]map[string]string, error) {
	ret := _m.Called()

	var r0 []map[string]string
	if rf, ok := ret.Get(0).(func() []map[string]string); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]map[string]string)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
745215
func (c *Client) RegisterTemplate(p *RegisterTemplateParameter) (*Template, error) {
	obj, err := c.Request("registerTemplate", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Template), err
}
84006
func (service *Service) EvaluateHostnameTemplate(gs GetService, fc FindChildService, instanceID int) (err error) {
	err, result := service.evaluateTemplate(gs, fc, instanceID, service.Hostname)
	if err == nil {
		service.Hostname = result
	}
	return
}
808976
func (_m *FacadeInterface) DeployTemplate(ctx datastore.Context, poolID string, templateID string, deploymentID string) ([]string, error) {
	ret := _m.Called(ctx, poolID, templateID, deploymentID)

	var r0 []string
	if rf, ok := ret.Get(0).(func(datastore.Context, string, string, string) []string); ok {
		r0 = rf(ctx, poolID, templateID, deploymentID)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]string)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(datastore.Context, string, string, string) error); ok {
		r1 = rf(ctx, poolID, templateID, deploymentID)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}