Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config

This commit is contained in:
Adrien Delorme 2019-06-14 15:17:56 +02:00
commit daa9f9d34e
15 changed files with 61 additions and 30 deletions

View File

@ -161,6 +161,7 @@ func (c *ClientWrapper) WaitForExpected(args *WaitForExpectArgs) (responses.AcsR
timeoutPoint = time.Now().Add(args.RetryTimeout)
}
var lastResponse responses.AcsResponse
var lastError error
for i := 0; ; i++ {
@ -173,6 +174,7 @@ func (c *ClientWrapper) WaitForExpected(args *WaitForExpectArgs) (responses.AcsR
}
response, err := args.RequestFunc()
lastResponse = response
lastError = err
evalResult := args.EvalFunc(response, err)
@ -180,17 +182,21 @@ func (c *ClientWrapper) WaitForExpected(args *WaitForExpectArgs) (responses.AcsR
return response, nil
}
if evalResult.stopRetry {
return nil, err
return response, err
}
time.Sleep(args.RetryInterval)
}
if args.RetryTimeout > 0 {
return nil, fmt.Errorf("evaluate failed after %d seconds timeout with %d seconds retry interval: %s", int(args.RetryTimeout.Seconds()), int(args.RetryInterval.Seconds()), lastError)
if lastError == nil {
lastError = fmt.Errorf("<no error>")
}
return nil, fmt.Errorf("evaluate failed after %d times retry with %d seconds retry interval: %s", args.RetryTimes, int(args.RetryInterval.Seconds()), lastError)
if args.RetryTimeout > 0 {
return lastResponse, fmt.Errorf("evaluate failed after %d seconds timeout with %d seconds retry interval: %s", int(args.RetryTimeout.Seconds()), int(args.RetryInterval.Seconds()), lastError)
}
return lastResponse, fmt.Errorf("evaluate failed after %d times retry with %d seconds retry interval: %s", args.RetryTimes, int(args.RetryInterval.Seconds()), lastError)
}
func (c *ClientWrapper) WaitForInstanceStatus(regionId string, instanceId string, expectedStatus string) (responses.AcsResponse, error) {

View File

@ -17,9 +17,10 @@ type RunConfig struct {
AssociatePublicIpAddress bool `mapstructure:"associate_public_ip_address"`
// ID of the zone to which the disk belongs.
ZoneId string `mapstructure:"zone_id" required:"false"`
// Whether an ECS instance is I/O optimized or not.
// The default value is false.
IOOptimized bool `mapstructure:"io_optimized" required:"false"`
// Whether an ECS instance is I/O optimized or not. If this option is not
// provided, the value will be determined by product API according to what
// `instance_type` is used.
IOOptimized *bool `mapstructure:"io_optimized" required:"false"`
// Type of the instance. For values, see Instance
// Type
// Table.

View File

@ -52,17 +52,18 @@ func (s *stepCreateAlicloudImage) Run(ctx context.Context, state multistep.State
imageId := createImageResponse.(*ecs.CreateImageResponse).ImageId
imagesResponse, err := client.WaitForImageStatus(config.AlicloudRegion, imageId, ImageStatusAvailable, time.Duration(s.WaitSnapshotReadyTimeout)*time.Second)
if err != nil {
return halt(state, err, "Timeout waiting for image to be created")
}
// save image first for cleaning up if timeout
images := imagesResponse.(*ecs.DescribeImagesResponse).Images.Image
if len(images) == 0 {
return halt(state, err, "Unable to find created image")
}
s.image = &images[0]
if err != nil {
return halt(state, err, "Timeout waiting for image to be created")
}
var snapshotIds []string
for _, device := range images[0].DiskDeviceMappings.DiskDeviceMapping {
snapshotIds = append(snapshotIds, device.SnapshotId)

View File

@ -17,7 +17,7 @@ import (
)
type stepCreateAlicloudInstance struct {
IOOptimized bool
IOOptimized *bool
InstanceType string
UserData string
UserDataFile string
@ -142,11 +142,13 @@ func (s *stepCreateAlicloudInstance) buildCreateInstanceRequest(state multistep.
request.InternetChargeType = s.InternetChargeType
request.InternetMaxBandwidthOut = requests.Integer(convertNumber(s.InternetMaxBandwidthOut))
ioOptimized := IOOptimizedNone
if s.IOOptimized {
ioOptimized = IOOptimizedOptimized
if s.IOOptimized != nil {
if *s.IOOptimized {
request.IoOptimized = IOOptimizedOptimized
} else {
request.IoOptimized = IOOptimizedNone
}
}
request.IoOptimized = ioOptimized
config := state.Get("config").(*Config)
password := config.Comm.SSHPassword

View File

@ -102,7 +102,7 @@ func (s *StepCreateTags) Run(ctx context.Context, state multistep.StateBag) mult
}
return false
},
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30, Multiplier: 2}).Linear,
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
}.Run(ctx, func(ctx context.Context) error {
// Tag images and snapshots

View File

@ -76,12 +76,23 @@ func (cfg Config) Run(ctx context.Context, fn func(context.Context) error) error
}
}
// Backoff is a self contained backoff time calculator. This struct should be
// passed around as a copy as it changes its own fields upon any Backoff call.
// Backoff is not thread safe. For now only a Linear backoff call is
// implemented and the Exponential call will be implemented when needed.
type Backoff struct {
// Initial time to wait. A Backoff call will change this value.
InitialBackoff time.Duration
MaxBackoff time.Duration
Multiplier float64
// Maximum time returned.
MaxBackoff time.Duration
// For a Linear backoff, InitialBackoff will be multiplied by Multiplier
// after each call.
Multiplier float64
}
// Linear Backoff returns a linearly increasing Duration.
// n = n * Multiplier.
// the first value of n is InitialBackoff. n is maxed by MaxBackoff.
func (lb *Backoff) Linear() time.Duration {
wait := lb.InitialBackoff
lb.InitialBackoff = time.Duration(lb.Multiplier * float64(lb.InitialBackoff))
@ -90,3 +101,8 @@ func (lb *Backoff) Linear() time.Duration {
}
return wait
}
// Exponential backoff panics: not implemented, yet.
func (lb *Backoff) Exponential() time.Duration {
panic("not implemented, yet")
}

View File

@ -338,6 +338,12 @@ func (u *MachineReadableUi) Machine(category string, args ...string) {
args[i] = strings.Replace(v, ",", "%!(PACKER_COMMA)", -1)
args[i] = strings.Replace(args[i], "\r", "\\r", -1)
args[i] = strings.Replace(args[i], "\n", "\\n", -1)
// Use LogSecretFilter to scrub out sensitive variables
for s := range LogSecretFilter.s {
if s != "" {
args[i] = strings.Replace(args[i], s, "<sensitive>", -1)
}
}
}
argsString := strings.Join(args, ",")
@ -350,6 +356,7 @@ func (u *MachineReadableUi) Machine(category string, args ...string) {
panic(err)
}
}
log.Printf("%d,%s,%s,%s\n", now.Unix(), target, category, argsString)
}
// TimestampedUi is a UI that wraps another UI implementation and

View File

@ -27,11 +27,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, _ packer.Communicator) error {
_, retErr := sl.Run(ctx, ui, &p.config)
if retErr != nil {
return retErr
}
return nil
return retErr
}
func (p *Provisioner) Cancel() {

View File

@ -54,4 +54,4 @@ power of Packer templates.
## Other
- [suitcase](https://github.com/tmclaugh/suitcase) - Packer based build system for CentOS OS images
- [Undo-WinRMConfig](https://cloudywindows.io/post/winrm-for-provisioning---close-the-door-on-the-way-out-eh/) - Open source automation to stage WinRM reset to pristine state at next shtudown
- [Undo-WinRMConfig](https://cloudywindows.io/post/winrm-for-provisioning-close-the-door-on-the-way-out-eh/) - Open source automation to stage WinRM reset to pristine state at next shtudown

View File

@ -218,7 +218,8 @@ builder.
error is returned.
- `io_optimized` (boolean) - Whether an ECS instance is I/O optimized or not.
The default value is `false`.
If this option is not provided, the value will be determined by product API
according to what `instance_type` is used.
- `security_group_id` (string) - ID of the security group to which a newly
created instance belongs. Mutual access is allowed between instances in one

View File

@ -694,7 +694,7 @@ Finish proxy after sysprep -->
```
-> **Warning:** Please note that if you're setting up WinRM for provisioning, you'll probably want to turn it off or restrict its permissions as part of a shutdown script at the end of Packer's provisioning process. For more details on the why/how, check out this useful blog post and the associated code:
https://cloudywindows.io/post/winrm-for-provisioning---close-the-door-on-the-way-out-eh/
https://cloudywindows.io/post/winrm-for-provisioning-close-the-door-on-the-way-out-eh/
## Example For Ubuntu Vivid Generation 2

View File

@ -904,7 +904,7 @@ Finish proxy after sysprep -->
```
-> **Warning:** Please note that if you're setting up WinRM for provisioning, you'll probably want to turn it off or restrict its permissions as part of a shutdown script at the end of Packer's provisioning process. For more details on the why/how, check out this useful blog post and the associated code:
https://cloudywindows.io/post/winrm-for-provisioning---close-the-door-on-the-way-out-eh/
https://cloudywindows.io/post/winrm-for-provisioning-close-the-door-on-the-way-out-eh/
## Example For Ubuntu Vivid Generation 2

View File

@ -91,7 +91,7 @@ Here is a basic example for windows server.
}
-> **Warning:** Please note that if you're setting up WinRM for provisioning, you'll probably want to turn it off or restrict its permissions as part of a shutdown script at the end of Packer's provisioning process. For more details on the why/how, check out this useful blog post and the associated code:
https://cloudywindows.io/post/winrm-for-provisioning---close-the-door-on-the-way-out-eh/
https://cloudywindows.io/post/winrm-for-provisioning-close-the-door-on-the-way-out-eh/
Here is a basic example for linux server.

View File

@ -325,7 +325,7 @@ Platform:
```
-> **Warning:** Please note that if you're setting up WinRM for provisioning, you'll probably want to turn it off or restrict its permissions as part of a shutdown script at the end of Packer's provisioning process. For more details on the why/how, check out this useful blog post and the associated code:
https://cloudywindows.io/post/winrm-for-provisioning---close-the-door-on-the-way-out-eh/
https://cloudywindows.io/post/winrm-for-provisioning-close-the-door-on-the-way-out-eh/
### Post i/o timeout errors

View File

@ -405,7 +405,7 @@ Start-Service -Name WinRM
```
-> **Warning:** Please note that if you're setting up WinRM for provisioning, you'll probably want to turn it off or restrict its permissions as part of a shutdown script at the end of Packer's provisioning process. For more details on the why/how, check out this useful blog post and the associated code:
https://cloudywindows.io/post/winrm-for-provisioning---close-the-door-on-the-way-out-eh/
https://cloudywindows.io/post/winrm-for-provisioning-close-the-door-on-the-way-out-eh/
Save the above code in a file named `bootstrap_win.txt`.