Пример #1
0
func prepareState(handler Handler) (*httptest.Server, *brkt.API, *multistep.BasicStateBag) {
	ts := httptest.NewServer(http.HandlerFunc(handler))

	api := brkt.NewAPIForCustomPortal(MOCK_ACCESS_TOKEN, MOCK_MAC_KEY, ts.URL+"/")

	// remove CA verification
	brkt.SetClientTransport(api.ApiClient.Session.Client, true)

	state := getTestState()
	state.Put("api", api)

	return ts, api, state
}
Пример #2
0
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
	api := brkt.NewAPIForCustomPortal(b.config.AccessToken, b.config.MacKey, b.config.PortalUrl)

	state := new(multistep.BasicStateBag)
	state.Put("api", api)
	state.Put("config", b.config)
	state.Put("hook", hook)
	state.Put("ui", ui)

	steps := []multistep.Step{
		&stepGetMachineType{
			MinCpuCores:   b.config.MachineTypeConfig.MinCpuCores,
			MinRam:        b.config.MachineTypeConfig.MinRam,
			AvatarEnabled: b.config.WorkloadConfig.MetavisorEnabled,
			MachineType:   b.config.MachineTypeConfig.MachineType,
		},
		&stepGetZone{
			Zone:          b.config.WorkloadConfig.Zone,
			ComputingCell: b.config.WorkloadConfig.ComputingCell,
		},
		&stepDeployInstance{
			ImageDefinition:  b.config.WorkloadConfig.ImageDefinition,
			BillingGroup:     b.config.WorkloadConfig.BillingGroup,
			CloudConfig:      b.config.WorkloadConfig.CloudConfig,
			SecurityGroup:    b.config.WorkloadConfig.SecurityGroup,
			MetavisorEnabled: b.config.WorkloadConfig.MetavisorEnabled,
		},
		&stepLoadKeyFile{
			PrivateKeyFile: b.config.Comm.SSHPrivateKey,
		},
		&communicator.StepConnect{
			Config: &b.config.Comm,
			Host:   SSHost,

			SSHConfig: SSHConfig(b.config.Comm.SSHUsername),
		},
		&common.StepProvision{},
		&stepCreateImage{
			ImageName: b.config.ImageConfig.ImageName,
		},
	}

	b.runner = &multistep.BasicRunner{Steps: steps}

	b.runner.Run(state)

	if rawErr, ok := state.GetOk("error"); ok {
		return nil, rawErr.(error)
	}

	imageId := state.Get("imageId").(string)
	imageName := state.Get("imageName").(string)

	artifact := Artifact{
		ImageId:        imageId,
		ImageName:      imageName,
		BuilderIdValue: BuilderId,
		ApiClient:      api.ApiClient,
	}

	return artifact, nil
}