func (p *chefsoloProvisioner) Bootstrap(box *provision.Box, w io.Writer) error { fmt.Fprintf(w, "--- bootstrap box (%s)\n", box.GetFullName()) actions := []*action.Action{ &createMachine, &updateStatusInRiak, &updateIpsInRiak, &appendAuthKeys, &updateStatusInRiak, &changeStateofMachine, } pipeline := action.NewPipeline(actions...) args := runMachineActionsArgs{ box: box, writer: w, machineStatus: constants.StatusBootstrapping, provisioner: p, } if err := pipeline.Execute(args); err != nil { return err } fmt.Fprintf(w, "--- bootstrap box (%s) OK\n", box.GetFullName()) return nil }
//make a box with the details for a provisioner. func (c *Component) mkBox() (provision.Box, error) { bt := provision.Box{ Id: c.Id, Level: provision.BoxSome, Name: c.Name, DomainName: c.domain(), Envs: c.envs(), Tosca: c.Tosca, Operations: c.Operations, Commit: "", Provider: c.provider(), PublicIp: c.publicIp(), } if &c.Repo != nil { bt.Repo = &repository.Repo{ Type: c.Repo.Rtype, Source: c.Repo.Source, OneClick: c.withOneClick(), URL: c.Repo.Rurl, } bt.Repo.Hook = upgrade.BuildHook(c.Operations, repository.CIHOOK) //MEGAMD } return bt, nil }
func (p *chefsoloProvisioner) Stateup(b *provision.Box, w io.Writer) error { fmt.Fprintf(w, "--- stateup box (%s)\n", b.GetFullName()) var repo string if b.Repo != nil { repo = b.Repo.Gitr() } DefaultAttributes, _ := json.Marshal(&Attributes{ RunList: []string{"recipe[" + p.Cookbook + "]"}, ToscaType: b.GetShortTosca(), Scm: repo, }) p.Attributes = string(DefaultAttributes) p.Format = DefaultFormat p.LogLevel = DefaultLogLevel p.RootPath = meta.MC.Dir p.Sudo = DefaultSudo return p.kickOffSolo(b, w) }
func (p *chefsoloProvisioner) Stop(b *provision.Box, w io.Writer) error { fmt.Fprintf(w, "--- stop box (%s)\n", b.GetFullName()) actions := []*action.Action{ &updateStatusInRiak, &stopBox, &updateStatusInRiak, } pipeline := action.NewPipeline(actions...) args := runMachineActionsArgs{ box: b, writer: w, machineStatus: constants.StatusStopping, provisioner: p, } if err := pipeline.Execute(args); err != nil { log.Errorf("error on execute stop pipeline for box %s - %s", b.GetFullName(), err) return err } fmt.Fprintf(w, "--- stop box (%s) OK\n", b.GetFullName()) return nil }
//1. &prepareJSON in generate the json file for chefsolo //2. &prepareConfig in generate the config file for chefsolo. //3. &updateStatus in Riak - Creating.. func (p *chefsoloProvisioner) kickOffSolo(b *provision.Box, w io.Writer) error { fmt.Fprintf(w, "--- kickofff chefsolo box (%s)\n", b.GetFullName()) soloAction := make([]*action.Action, 0, 4) soloAction = append(soloAction, &generateSoloJson, &generateSoloConfig, &cloneBox) if b.Level != provision.BoxNone { soloAction = append(soloAction, &chefSoloRun) } soloAction = append(soloAction, &updateStatusInRiak) actions := soloAction pipeline := action.NewPipeline(actions...) args := runMachineActionsArgs{ box: b, writer: w, machineStatus: constants.StatusRunning, provisioner: p, } if err := pipeline.Execute(args); err != nil { log.Errorf("error on execute chefsolo pipeline for box %s - %s", b.GetFullName(), err) return err } fmt.Fprintf(w, "--- kickofff chefsolo box (%s) OK\n", b.GetFullName()) return nil }