From 103186af8650d8168603031fc65c82c6f2df1fcf Mon Sep 17 00:00:00 2001 From: Stefan Henseler Date: Fri, 23 Feb 2018 20:19:26 +0100 Subject: [PATCH 01/82] Adds Support to configure hyper-v disk block size --- builder/hyperv/common/driver.go | 4 +- builder/hyperv/common/driver_mock.go | 8 +++- builder/hyperv/common/driver_ps_4.go | 8 ++-- builder/hyperv/common/step_create_vm.go | 8 +++- builder/hyperv/iso/builder.go | 32 +++++++++++++++ builder/hyperv/iso/builder_test.go | 53 +++++++++++++++++++++++++ common/powershell/hyperv/hyperv.go | 42 ++++++++++++++------ 7 files changed, 133 insertions(+), 22 deletions(-) diff --git a/builder/hyperv/common/driver.go b/builder/hyperv/common/driver.go index 571214acd..e7b58464e 100644 --- a/builder/hyperv/common/driver.go +++ b/builder/hyperv/common/driver.go @@ -66,9 +66,9 @@ type Driver interface { DeleteVirtualSwitch(string) error - CreateVirtualMachine(string, string, string, string, int64, int64, string, uint, bool) error + CreateVirtualMachine(string, string, string, string, int64, int64, int64, string, uint, bool) error - AddVirtualMachineHardDrive(string, string, string, int64, string) error + AddVirtualMachineHardDrive(string, string, string, int64, int64, string) error CloneVirtualMachine(string, string, string, bool, string, string, string, int64, string) error diff --git a/builder/hyperv/common/driver_mock.go b/builder/hyperv/common/driver_mock.go index 7d8e02c6a..8af637e66 100644 --- a/builder/hyperv/common/driver_mock.go +++ b/builder/hyperv/common/driver_mock.go @@ -112,6 +112,7 @@ type DriverMock struct { AddVirtualMachineHardDrive_VhdFile string AddVirtualMachineHardDrive_VhdName string AddVirtualMachineHardDrive_VhdSizeBytes int64 + AddVirtualMachineHardDrive_VhdBlockSize int64 AddVirtualMachineHardDrive_ControllerType string AddVirtualMachineHardDrive_Err error @@ -122,6 +123,7 @@ type DriverMock struct { CreateVirtualMachine_VhdPath string CreateVirtualMachine_Ram int64 CreateVirtualMachine_DiskSize int64 + CreateVirtualMachine_DiskBlockSize int64 CreateVirtualMachine_SwitchName string CreateVirtualMachine_Generation uint CreateVirtualMachine_DifferentialDisk bool @@ -377,17 +379,18 @@ func (d *DriverMock) CreateVirtualSwitch(switchName string, switchType string) ( return d.CreateVirtualSwitch_Return, d.CreateVirtualSwitch_Err } -func (d *DriverMock) AddVirtualMachineHardDrive(vmName string, vhdFile string, vhdName string, vhdSizeBytes int64, controllerType string) error { +func (d *DriverMock) AddVirtualMachineHardDrive(vmName string, vhdFile string, vhdName string, vhdSizeBytes int64, vhdDiskBlockSize int64, controllerType string) error { d.AddVirtualMachineHardDrive_Called = true d.AddVirtualMachineHardDrive_VmName = vmName d.AddVirtualMachineHardDrive_VhdFile = vhdFile d.AddVirtualMachineHardDrive_VhdName = vhdName d.AddVirtualMachineHardDrive_VhdSizeBytes = vhdSizeBytes + d.AddVirtualMachineHardDrive_VhdSizeBytes = vhdDiskBlockSize d.AddVirtualMachineHardDrive_ControllerType = controllerType return d.AddVirtualMachineHardDrive_Err } -func (d *DriverMock) CreateVirtualMachine(vmName string, path string, harddrivePath string, vhdPath string, ram int64, diskSize int64, switchName string, generation uint, diffDisks bool) error { +func (d *DriverMock) CreateVirtualMachine(vmName string, path string, harddrivePath string, vhdPath string, ram int64, diskSize int64, diskBlockSize int64, switchName string, generation uint, diffDisks bool) error { d.CreateVirtualMachine_Called = true d.CreateVirtualMachine_VmName = vmName d.CreateVirtualMachine_Path = path @@ -395,6 +398,7 @@ func (d *DriverMock) CreateVirtualMachine(vmName string, path string, harddriveP d.CreateVirtualMachine_VhdPath = vhdPath d.CreateVirtualMachine_Ram = ram d.CreateVirtualMachine_DiskSize = diskSize + d.CreateVirtualMachine_DiskBlockSize = diskBlockSize d.CreateVirtualMachine_SwitchName = switchName d.CreateVirtualMachine_Generation = generation d.CreateVirtualMachine_DifferentialDisk = diffDisks diff --git a/builder/hyperv/common/driver_ps_4.go b/builder/hyperv/common/driver_ps_4.go index a6c1b7352..34a9edbb5 100644 --- a/builder/hyperv/common/driver_ps_4.go +++ b/builder/hyperv/common/driver_ps_4.go @@ -174,12 +174,12 @@ func (d *HypervPS4Driver) CreateVirtualSwitch(switchName string, switchType stri return hyperv.CreateVirtualSwitch(switchName, switchType) } -func (d *HypervPS4Driver) AddVirtualMachineHardDrive(vmName string, vhdFile string, vhdName string, vhdSizeBytes int64, controllerType string) error { - return hyperv.AddVirtualMachineHardDiskDrive(vmName, vhdFile, vhdName, vhdSizeBytes, controllerType) +func (d *HypervPS4Driver) AddVirtualMachineHardDrive(vmName string, vhdFile string, vhdName string, vhdSizeBytes int64, diskBlockSize int64, controllerType string) error { + return hyperv.AddVirtualMachineHardDiskDrive(vmName, vhdFile, vhdName, vhdSizeBytes, diskBlockSize, controllerType) } -func (d *HypervPS4Driver) CreateVirtualMachine(vmName string, path string, harddrivePath string, vhdPath string, ram int64, diskSize int64, switchName string, generation uint, diffDisks bool) error { - return hyperv.CreateVirtualMachine(vmName, path, harddrivePath, vhdPath, ram, diskSize, switchName, generation, diffDisks) +func (d *HypervPS4Driver) CreateVirtualMachine(vmName string, path string, harddrivePath string, vhdPath string, ram int64, diskSize int64, diskBlockSize int64, switchName string, generation uint, diffDisks bool) error { + return hyperv.CreateVirtualMachine(vmName, path, harddrivePath, vhdPath, ram, diskSize, diskBlockSize, switchName, generation, diffDisks) } func (d *HypervPS4Driver) CloneVirtualMachine(cloneFromVmxcPath string, cloneFromVmName string, cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string, path string, harddrivePath string, ram int64, switchName string) error { diff --git a/builder/hyperv/common/step_create_vm.go b/builder/hyperv/common/step_create_vm.go index f046d1a48..f8125ed91 100644 --- a/builder/hyperv/common/step_create_vm.go +++ b/builder/hyperv/common/step_create_vm.go @@ -21,6 +21,7 @@ type StepCreateVM struct { HarddrivePath string RamSize uint DiskSize uint + DiskBlockSize uint Generation uint Cpu uint EnableMacSpoofing bool @@ -64,8 +65,9 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste // convert the MB to bytes ramSize := int64(s.RamSize * 1024 * 1024) diskSize := int64(s.DiskSize * 1024 * 1024) + diskBlockSize := int64(s.DiskBlockSize * 1024 * 1024) - err := driver.CreateVirtualMachine(s.VMName, path, harddrivePath, vhdPath, ramSize, diskSize, s.SwitchName, s.Generation, s.DifferencingDisk) + err := driver.CreateVirtualMachine(s.VMName, path, harddrivePath, vhdPath, ramSize, diskSize, diskBlockSize, s.SwitchName, s.Generation, s.DifferencingDisk) if err != nil { err := fmt.Errorf("Error creating virtual machine: %s", err) state.Put("error", err) @@ -124,7 +126,7 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste for index, size := range s.AdditionalDiskSize { diskSize := int64(size * 1024 * 1024) diskFile := fmt.Sprintf("%s-%d.vhdx", s.VMName, index) - err = driver.AddVirtualMachineHardDrive(s.VMName, vhdPath, diskFile, diskSize, "SCSI") + err = driver.AddVirtualMachineHardDrive(s.VMName, vhdPath, diskFile, diskSize, diskBlockSize, "SCSI") if err != nil { err := fmt.Errorf("Error creating and attaching additional disk drive: %s", err) state.Put("error", err) @@ -163,4 +165,6 @@ func (s *StepCreateVM) Cleanup(state multistep.StateBag) { if err != nil { ui.Error(fmt.Sprintf("Error deleting virtual machine: %s", err)) } + + // TODO: Clean up created VHDX } diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index b92e779df..a95814630 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -24,6 +24,10 @@ const ( MinDiskSize = 256 // 256MB MaxDiskSize = 64 * 1024 * 1024 // 64TB + DefaultDiskBlockSize = 32 // 32MB + MinDiskBlockSize = 1 // 1MB + MaxDiskBlockSize = 256 // 256MB + DefaultRamSize = 1 * 1024 // 1GB MinRamSize = 32 // 32MB MaxRamSize = 32 * 1024 // 32GB @@ -55,9 +59,15 @@ type Config struct { // The size, in megabytes, of the hard disk to create for the VM. // By default, this is 130048 (about 127 GB). DiskSize uint `mapstructure:"disk_size"` + + // The size, in megabytes, of the block size used to create the hard disk. + // By default, this is 32768 (about 32 MB) + DiskBlockSize uint `mapstructure:"disk_block_size"` + // The size, in megabytes, of the computer memory in the VM. // By default, this is 1024 (about 1 GB). RamSize uint `mapstructure:"ram_size"` + // SecondaryDvdImages []string `mapstructure:"secondary_iso_images"` @@ -141,6 +151,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } } + err = b.checkDiskBlockSize() + if err != nil { + errs = packer.MultiErrorAppend(errs, err) + } + err = b.checkRamSize() if err != nil { errs = packer.MultiErrorAppend(errs, err) @@ -352,6 +367,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe SwitchName: b.config.SwitchName, RamSize: b.config.RamSize, DiskSize: b.config.DiskSize, + DiskBlockSize: b.config.DiskBlockSize, Generation: b.config.Generation, Cpu: b.config.Cpu, EnableMacSpoofing: b.config.EnableMacSpoofing, @@ -492,6 +508,22 @@ func (b *Builder) checkDiskSize() error { return nil } +func (b *Builder) checkDiskBlockSize() error { + if b.config.DiskBlockSize == 0 { + b.config.DiskBlockSize = DefaultDiskBlockSize + } + + log.Println(fmt.Sprintf("%s: %v", "DiskBlockSize", b.config.DiskBlockSize)) + + if b.config.DiskBlockSize < MinDiskBlockSize { + return fmt.Errorf("disk_block_size: Virtual machine requires disk block size >= %v MB, but defined: %v", MinDiskBlockSize, b.config.DiskBlockSize) + } else if b.config.DiskBlockSize > MaxDiskBlockSize { + return fmt.Errorf("disk_block_size: Virtual machine requires disk block size <= %v MB, but defined: %v", MaxDiskBlockSize, b.config.DiskBlockSize) + } + + return nil +} + func (b *Builder) checkRamSize() error { if b.config.RamSize == 0 { b.config.RamSize = DefaultRamSize diff --git a/builder/hyperv/iso/builder_test.go b/builder/hyperv/iso/builder_test.go index b08a683f9..8523876ef 100644 --- a/builder/hyperv/iso/builder_test.go +++ b/builder/hyperv/iso/builder_test.go @@ -23,6 +23,7 @@ func testConfig() map[string]interface{} { "ssh_username": "foo", "ram_size": 64, "disk_size": 256, + "disk_block_size": 1, "guest_additions_mode": "none", "disk_additional_size": "50000,40000,30000", packer.BuildNameConfigKey: "foo", @@ -86,6 +87,58 @@ func TestBuilderPrepare_DiskSize(t *testing.T) { } } +func TestBuilderPrepare_DiskBlockSize(t *testing.T) { + var b Builder + config := testConfig() + expected_default_block_size := uint(32) + expected_min_block_size := uint(0) + expected_max_block_size := uint(256) + + // Test default with empty disk_block_size + delete(config, "disk_block_size") + warns, err := b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("bad err: %s", err) + } + if b.config.DiskBlockSize != expected_default_block_size { + t.Fatalf("bad default block size with empty config: %d. Expected %d", b.config.DiskBlockSize, expected_default_block_size) + } + + test_sizes := []uint{0, 1, 32, 256, 512, 1 * 1024, 32 * 1024} + for _, test_size := range test_sizes { + config["disk_block_size"] = test_size + b = Builder{} + warns, err = b.Prepare(config) + if test_size > expected_max_block_size || test_size < expected_min_block_size { + if len(warns) > 0 { + t.Fatalf("bad, should have no warns: %#v", warns) + } + if err == nil { + t.Fatalf("bad, should have error but didn't. disk_block_size=%d outside expected valid range [%d,%d]", test_size, expected_min_block_size, expected_max_block_size) + } + } else { + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("bad, should not have error: %s", err) + } + if test_size == 0 { + if b.config.DiskBlockSize != expected_default_block_size { + t.Fatalf("bad default block size with 0 value config: %d. Expected: %d", b.config.DiskBlockSize, expected_default_block_size) + } + } else { + if b.config.DiskBlockSize != test_size { + t.Fatalf("bad block size with 0 value config: %d. Expected: %d", b.config.DiskBlockSize, expected_default_block_size) + } + } + } + } +} + func TestBuilderPrepare_FloppyFiles(t *testing.T) { var b Builder config := testConfig() diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index d26ec5eeb..0a296cce2 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -53,6 +53,22 @@ $ip return cmdOut, err } +//func CreateVirtualHardDiskDrive(vmName string, diskPath string, diskSize int64, diskBlockSize int64, generation uint) (uint, uint, error) { +// +// var script = ` +//param([string]$vmName, [string]$path, +// +// +//[long]$memoryStartupBytes, [long]$newVHDSizeBytes, [string]$switchName, [int]$generation) +//$vhdx = $vmName + '.vhdx' +//$vhdPath = Join-Path -Path $path -ChildPath $vhdx +//New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -NewVHDPath $vhdPath -NewVHDSizeBytes $newVHDSizeBytes -SwitchName $switchName -Generation $generation +//` +// var ps powershell.PowerShellCmd +// err := ps.Run(script, vmName, path, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName, strconv.FormatInt(int64(generation), 10)) +// return err +//} + func CreateDvdDrive(vmName string, isoPath string, generation uint) (uint, uint, error) { var ps powershell.PowerShellCmd var script string @@ -187,45 +203,47 @@ Set-VMFloppyDiskDrive -VMName $vmName -Path $null return err } -func CreateVirtualMachine(vmName string, path string, harddrivePath string, vhdRoot string, ram int64, diskSize int64, switchName string, generation uint, diffDisks bool) error { +func CreateVirtualMachine(vmName string, path string, harddrivePath string, vhdRoot string, ram int64, diskSize int64, diskBlockSize int64, switchName string, generation uint, diffDisks bool) error { if generation == 2 { var script = ` -param([string]$vmName, [string]$path, [string]$harddrivePath, [string]$vhdRoot, [long]$memoryStartupBytes, [long]$newVHDSizeBytes, [string]$switchName, [int]$generation, [string]$diffDisks) +param([string]$vmName, [string]$path, [string]$harddrivePath, [string]$vhdRoot, [long]$memoryStartupBytes, [long]$newVHDSizeBytes, [long]$vhdBlockSizeBytes, [string]$switchName, [int]$generation, [string]$diffDisks) $vhdx = $vmName + '.vhdx' $vhdPath = Join-Path -Path $vhdRoot -ChildPath $vhdx if ($harddrivePath){ if($diffDisks -eq "true"){ - New-VHD -Path $vhdPath -ParentPath $harddrivePath -Differencing + New-VHD -Path $vhdPath -ParentPath $harddrivePath -Differencing -BlockSizeBytes $vhdBlockSizeBytes } else { Copy-Item -Path $harddrivePath -Destination $vhdPath } New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -VHDPath $vhdPath -SwitchName $switchName -Generation $generation } else { - New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -NewVHDPath $vhdPath -NewVHDSizeBytes $newVHDSizeBytes -SwitchName $switchName -Generation $generation + New-VHD -Path $vhdPath -SizeBytes $newVHDSizeBytes -BlockSizeBytes $vhdBlockSizeBytes + New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -VHDPath $vhdPath -SwitchName $switchName -Generation $generation } ` var ps powershell.PowerShellCmd - if err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName, strconv.FormatInt(int64(generation), 10), strconv.FormatBool(diffDisks)); err != nil { + if err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), strconv.FormatInt(diskBlockSize, 10), switchName, strconv.FormatInt(int64(generation), 10), strconv.FormatBool(diffDisks)); err != nil { return err } return DisableAutomaticCheckpoints(vmName) } else { var script = ` -param([string]$vmName, [string]$path, [string]$harddrivePath, [string]$vhdRoot, [long]$memoryStartupBytes, [long]$newVHDSizeBytes, [string]$switchName, [string]$diffDisks) +param([string]$vmName, [string]$path, [string]$harddrivePath, [string]$vhdRoot, [long]$memoryStartupBytes, [long]$newVHDSizeBytes, [long]$vhdBlockSizeBytes, [string]$switchName, [string]$diffDisks) $vhdx = $vmName + '.vhdx' $vhdPath = Join-Path -Path $vhdRoot -ChildPath $vhdx if ($harddrivePath){ if($diffDisks -eq "true"){ - New-VHD -Path $vhdPath -ParentPath $harddrivePath -Differencing + New-VHD -Path $vhdPath -ParentPath $harddrivePath -Differencing -BlockSizeBytes $vhdBlockSizeBytes } else{ Copy-Item -Path $harddrivePath -Destination $vhdPath } New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -VHDPath $vhdPath -SwitchName $switchName } else { - New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -NewVHDPath $vhdPath -NewVHDSizeBytes $newVHDSizeBytes -SwitchName $switchName + New-VHD -Path $vhdPath -SizeBytes $newVHDSizeBytes -BlockSizeBytes $vhdBlockSizeBytes + New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -VHDPath $vhdPath -SwitchName $switchName } ` var ps powershell.PowerShellCmd @@ -872,16 +890,16 @@ Get-VMNetworkAdapter -VMName $vmName | Connect-VMNetworkAdapter -SwitchName $swi return err } -func AddVirtualMachineHardDiskDrive(vmName string, vhdRoot string, vhdName string, vhdSizeBytes int64, controllerType string) error { +func AddVirtualMachineHardDiskDrive(vmName string, vhdRoot string, vhdName string, vhdSizeBytes int64, vhdBlockSize int64, controllerType string) error { var script = ` -param([string]$vmName,[string]$vhdRoot, [string]$vhdName, [string]$vhdSizeInBytes, [string]$controllerType) +param([string]$vmName,[string]$vhdRoot, [string]$vhdName, [string]$vhdSizeInBytes,[string]$vhdBlockSizeInBize [string]$controllerType) $vhdPath = Join-Path -Path $vhdRoot -ChildPath $vhdName -New-VHD $vhdPath -SizeBytes $vhdSizeInBytes +New-VHD -path $vhdPath -SizeBytes $vhdSizeInBytes -BlockSizeBytes $vhdBlockSizeInBize Add-VMHardDiskDrive -VMName $vmName -path $vhdPath -controllerType $controllerType ` var ps powershell.PowerShellCmd - err := ps.Run(script, vmName, vhdRoot, vhdName, strconv.FormatInt(vhdSizeBytes, 10), controllerType) + err := ps.Run(script, vmName, vhdRoot, vhdName, strconv.FormatInt(vhdSizeBytes, 10), strconv.FormatInt(vhdBlockSize, 10), controllerType) return err } From c877312a4d1b432e643608642e449ff0f16b5538 Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 20 Mar 2018 22:10:12 +0200 Subject: [PATCH 02/82] builder/triton: Add support to Skip TLS Verification of Triton URL In order to allow Packer to connect to Private Triton installations we now expose `insecure_skip_tls_verify` which, if set to true, will allow the user to make requests to Triton installations that use a certificate not signed by a trusted root CA --- builder/triton/access_config.go | 25 +++++++++++++++------ website/source/docs/builders/triton.html.md | 5 +++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/builder/triton/access_config.go b/builder/triton/access_config.go index 3212c37a1..3fe380e73 100644 --- a/builder/triton/access_config.go +++ b/builder/triton/access_config.go @@ -17,11 +17,12 @@ import ( // AccessConfig is for common configuration related to Triton access type AccessConfig struct { - Endpoint string `mapstructure:"triton_url"` - Account string `mapstructure:"triton_account"` - Username string `mapstructure:"triton_user"` - KeyID string `mapstructure:"triton_key_id"` - KeyMaterial string `mapstructure:"triton_key_material"` + Endpoint string `mapstructure:"triton_url"` + Account string `mapstructure:"triton_account"` + Username string `mapstructure:"triton_user"` + KeyID string `mapstructure:"triton_key_id"` + KeyMaterial string `mapstructure:"triton_key_material"` + InsecureSkipTLSVerify bool `mapstructure:"insecure_skip_tls_verify"` signer authentication.Signer } @@ -131,12 +132,14 @@ func (c *AccessConfig) CreateTritonClient() (*Client, error) { } return &Client{ - config: config, + config: config, + insecureSkipTLSVerify: c.InsecureSkipTLSVerify, }, nil } type Client struct { - config *tgo.ClientConfig + config *tgo.ClientConfig + insecureSkipTLSVerify bool } func (c *Client) Compute() (*compute.ComputeClient, error) { @@ -145,6 +148,10 @@ func (c *Client) Compute() (*compute.ComputeClient, error) { return nil, errwrap.Wrapf("Error Creating Triton Compute Client: {{err}}", err) } + if c.insecureSkipTLSVerify { + computeClient.Client.InsecureSkipTLSVerify() + } + return computeClient, nil } @@ -154,6 +161,10 @@ func (c *Client) Network() (*network.NetworkClient, error) { return nil, errwrap.Wrapf("Error Creating Triton Network Client: {{err}}", err) } + if c.insecureSkipTLSVerify { + networkClient.Client.InsecureSkipTLSVerify() + } + return networkClient, nil } diff --git a/website/source/docs/builders/triton.html.md b/website/source/docs/builders/triton.html.md index 2a62dbe12..889b0d9d8 100644 --- a/website/source/docs/builders/triton.html.md +++ b/website/source/docs/builders/triton.html.md @@ -95,6 +95,11 @@ builder. - `triton_user` (string) - The username of a user who has access to your Triton account. + +- `insecure_skip_tls_verify` - (bool) This allows skipping TLS verification of + the Triton endpoint. It is useful when connecting to a temporary Triton + installation such as Cloud-On-A-Laptop which does not generally use a + certificate signed by a trusted root CA. The default is `false`. - `source_machine_firewall_enabled` (boolean) - Whether or not the firewall of the VM used to create an image of is enabled. The Triton firewall only From 7184e411e5c34593e57f4b3d75660062d034aa1a Mon Sep 17 00:00:00 2001 From: Stefan Henseler Date: Wed, 21 Mar 2018 22:59:04 +0100 Subject: [PATCH 03/82] Adds documentation for hyperv-iso disk block size feature --- website/source/docs/builders/hyperv-iso.html.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/source/docs/builders/hyperv-iso.html.md b/website/source/docs/builders/hyperv-iso.html.md index e1454fea7..73e159277 100644 --- a/website/source/docs/builders/hyperv-iso.html.md +++ b/website/source/docs/builders/hyperv-iso.html.md @@ -230,6 +230,9 @@ can be configured for this builder. - `temp_path` (string) - This is the temporary path in which Packer will create the virtual machine. Default value is system `%temp%` +- `disk_block_size` (string) - The block size of the VHD to be created. + Recommended disk block size for Linux hyper-v guests is 1 MiB. This defaults to "32 MiB". + ## Boot Command The `boot_command` configuration is very important: it specifies the keys From 1f4212efa7fa459662dada64ac08e0e7d518e059 Mon Sep 17 00:00:00 2001 From: Yang Youseok Date: Tue, 20 Mar 2018 23:01:58 +0900 Subject: [PATCH 04/82] builder/openstack: Add instance_name config to OpenStack builder RFC952 restricts hostname not to use underline(_) and period(.), so private cloud with legacy DNS system does not allow just to use image_name for name of server. Add instance_name config option for servers which packer creates to make instance_name configurable. If instance_name is not specified, by default it works like the past using image_name for instance_name. --- builder/openstack/builder.go | 7 ++++++- builder/openstack/run_config.go | 1 + website/source/docs/builders/openstack.html.md | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index 42770c625..a718c3d59 100755 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -52,6 +52,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { return nil, errs } + // By default, instance name is same as image name + if b.config.InstanceName == "" { + b.config.InstanceName = b.config.ImageName + } + log.Println(common.ScrubConfig(b.config, b.config.Password)) return nil, nil } @@ -82,7 +87,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe SSHAgentAuth: b.config.RunConfig.Comm.SSHAgentAuth, }, &StepRunSourceServer{ - Name: b.config.ImageName, + Name: b.config.InstanceName, SourceImage: b.config.SourceImage, SourceImageName: b.config.SourceImageName, SecurityGroups: b.config.SecurityGroups, diff --git a/builder/openstack/run_config.go b/builder/openstack/run_config.go index 55da56271..6b4e0932e 100644 --- a/builder/openstack/run_config.go +++ b/builder/openstack/run_config.go @@ -30,6 +30,7 @@ type RunConfig struct { Networks []string `mapstructure:"networks"` UserData string `mapstructure:"user_data"` UserDataFile string `mapstructure:"user_data_file"` + InstanceName string `mapstructure:"instance_name"` InstanceMetadata map[string]string `mapstructure:"instance_metadata"` ConfigDrive bool `mapstructure:"config_drive"` diff --git a/website/source/docs/builders/openstack.html.md b/website/source/docs/builders/openstack.html.md index 0809b6545..37cc0de71 100755 --- a/website/source/docs/builders/openstack.html.md +++ b/website/source/docs/builders/openstack.html.md @@ -118,6 +118,9 @@ builder. - `metadata` (object of key/value strings) - Glance metadata that will be applied to the image. +- `instance_name` (string) - Name that is applied to the server instance + created by Packer. If this isn't specified, the default is same as `image_name`. + - `instance_metadata` (object of key/value strings) - Metadata that is applied to the server instance created by Packer. Also called server properties in some documentation. The strings have a max size of 255 bytes From d31e35075e603daa358cb5d268cec087ba35effb Mon Sep 17 00:00:00 2001 From: Stefan Henseler Date: Sun, 25 Mar 2018 16:27:57 +0200 Subject: [PATCH 05/82] Removes obsolete code --- common/powershell/hyperv/hyperv.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index 5fa6ea113..c019e55ce 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -53,22 +53,6 @@ $ip return cmdOut, err } -//func CreateVirtualHardDiskDrive(vmName string, diskPath string, diskSize int64, diskBlockSize int64, generation uint) (uint, uint, error) { -// -// var script = ` -//param([string]$vmName, [string]$path, -// -// -//[long]$memoryStartupBytes, [long]$newVHDSizeBytes, [string]$switchName, [int]$generation) -//$vhdx = $vmName + '.vhdx' -//$vhdPath = Join-Path -Path $path -ChildPath $vhdx -//New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -NewVHDPath $vhdPath -NewVHDSizeBytes $newVHDSizeBytes -SwitchName $switchName -Generation $generation -//` -// var ps powershell.PowerShellCmd -// err := ps.Run(script, vmName, path, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName, strconv.FormatInt(int64(generation), 10)) -// return err -//} - func CreateDvdDrive(vmName string, isoPath string, generation uint) (uint, uint, error) { var ps powershell.PowerShellCmd var script string From 03f0b4aa11fead9434e9e6cab6b889110ab4b81c Mon Sep 17 00:00:00 2001 From: Stefan Henseler Date: Sun, 25 Mar 2018 16:30:03 +0200 Subject: [PATCH 06/82] Fixes minor typo --- common/powershell/hyperv/hyperv.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index c019e55ce..54fa39d6d 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -877,9 +877,9 @@ Hyper-V\Get-VMNetworkAdapter -VMName $vmName | Hyper-V\Connect-VMNetworkAdapter func AddVirtualMachineHardDiskDrive(vmName string, vhdRoot string, vhdName string, vhdSizeBytes int64, vhdBlockSize int64, controllerType string) error { var script = ` -param([string]$vmName,[string]$vhdRoot, [string]$vhdName, [string]$vhdSizeInBytes,[string]$vhdBlockSizeInBize [string]$controllerType) +param([string]$vmName,[string]$vhdRoot, [string]$vhdName, [string]$vhdSizeInBytes,[string]$vhdBlockSizeInByte [string]$controllerType) $vhdPath = Join-Path -Path $vhdRoot -ChildPath $vhdName -Hyper-V\New-VHD -path $vhdPath -SizeBytes $vhdSizeInBytes -BlockSizeBytes $vhdBlockSizeInBize +Hyper-V\New-VHD -path $vhdPath -SizeBytes $vhdSizeInBytes -BlockSizeBytes $vhdBlockSizeInByte Hyper-V\Add-VMHardDiskDrive -VMName $vmName -path $vhdPath -controllerType $controllerType ` var ps powershell.PowerShellCmd From ee1ff3132d22035faeefefb81797f61421b963bd Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 10 Apr 2018 08:13:06 -0700 Subject: [PATCH 07/82] remove attempt to discover whether destination is a directory from upload function in various communicators --- builder/docker/communicator.go | 16 ----------- communicator/ssh/communicator.go | 49 -------------------------------- 2 files changed, 65 deletions(-) diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index 7b0ecae07..e898ecd1c 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -105,22 +105,6 @@ func (c *Communicator) uploadReader(dst string, src io.Reader) error { // uploadFile uses docker cp to copy the file from the host to the container func (c *Communicator) uploadFile(dst string, src io.Reader, fi *os.FileInfo) error { - // find out if it's a directory - testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, dst) - cmd := &packer.RemoteCmd{Command: testDirectoryCommand} - - err := c.Start(cmd) - - if err != nil { - log.Printf("Unable to check whether remote path is a dir: %s", err) - return err - } - cmd.Wait() - if cmd.ExitStatus == 0 { - log.Printf("path is a directory; copying file into directory.") - dst = filepath.Join(dst, filepath.Base((*fi).Name())) - } - // command format: docker cp /path/to/infile containerid:/path/to/outfile log.Printf("Copying to %s on container %s.", dst, c.ContainerID) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 218c11be6..6545d1d5c 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -410,27 +410,6 @@ func (c *comm) sftpUploadSession(path string, input io.Reader, fi *os.FileInfo) func (c *comm) sftpUploadFile(path string, input io.Reader, client *sftp.Client, fi *os.FileInfo) error { log.Printf("[DEBUG] sftp: uploading %s", path) - - // find out if destination is a directory (this is to replicate rsync behavior) - testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, path) - - cmd := &packer.RemoteCmd{ - Command: testDirectoryCommand, - } - - err := c.Start(cmd) - - if err != nil { - log.Printf("[ERROR] Unable to check whether remote path is a dir: %s", err) - return err - } - cmd.Wait() - if cmd.ExitStatus == 0 { - return fmt.Errorf( - "Destination path (%s) is a directory that already exists. "+ - "Please ensure the destination is writable.", path) - } - f, err := client.Create(path) if err != nil { return err @@ -586,34 +565,6 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e target_dir := filepath.Dir(path) target_file := filepath.Base(path) - // find out if destination is a directory (this is to replicate rsync behavior) - testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, path) - var stdout, stderr bytes.Buffer - cmd := &packer.RemoteCmd{ - Command: testDirectoryCommand, - Stdout: &stdout, - Stderr: &stderr, - } - - err := c.Start(cmd) - - if err != nil { - log.Printf("[ERROR] Unable to check whether remote path is a dir: %s", err) - return err - } - cmd.Wait() - if stdout.Len() > 0 { - return fmt.Errorf("%s", stdout.Bytes()) - } - if stderr.Len() > 0 { - return fmt.Errorf("%s", stderr.Bytes()) - } - if cmd.ExitStatus == 0 { - return fmt.Errorf( - "Destination path (%s) is a directory that already exists. "+ - "Please ensure the destination is writable.", path) - } - // On windows, filepath.Dir uses backslash separators (ie. "\tmp"). // This does not work when the target host is unix. Switch to forward slash // which works for unix and windows From 0f0fc1b99c29cae5f12ef0c56cadb8fe8d59ae52 Mon Sep 17 00:00:00 2001 From: andrew-best-diaxion Date: Fri, 13 Apr 2018 14:02:55 +1000 Subject: [PATCH 08/82] azure-cli output config check added Adds a check to contrib/azure-setup.sh which ensure the users azure-cli is configured to output json. --- contrib/azure-setup.sh | 394 +++++++++++++++++++++-------------------- 1 file changed, 202 insertions(+), 192 deletions(-) diff --git a/contrib/azure-setup.sh b/contrib/azure-setup.sh index 6149b38d0..40ad49697 100755 --- a/contrib/azure-setup.sh +++ b/contrib/azure-setup.sh @@ -12,257 +12,267 @@ azure_tenant_id= # Derived from the account after login location= azure_object_id= azureversion= +azurecliconfig= create_sleep=10 showhelp() { - echo "azure-setup" - echo "" - echo " azure-setup helps you generate packer credentials for azure" - echo "" - echo " The script creates a resource group, storage account, application" - echo " (client), service principal, and permissions and displays a snippet" - echo " for use in your packer templates." - echo "" - echo " For simplicity we make a lot of assumptions and choose reasonable" - echo " defaults. If you want more control over what happens, please use" - echo " the azure-cli directly." - echo "" - echo " Note that you must already have an Azure account, username," - echo " password, and subscription. You can create those here:" - echo "" - echo " - https://account.windowsazure.com/" - echo "" - echo "REQUIREMENTS" - echo "" - echo " - azure-cli" - echo " - jq" - echo "" - echo " Use the requirements command (below) for more info." - echo "" - echo "USAGE" - echo "" - echo " ./azure-setup.sh requirements" - echo " ./azure-setup.sh setup" - echo "" + echo "azure-setup" + echo "" + echo " azure-setup helps you generate packer credentials for azure" + echo "" + echo " The script creates a resource group, storage account, application" + echo " (client), service principal, and permissions and displays a snippet" + echo " for use in your packer templates." + echo "" + echo " For simplicity we make a lot of assumptions and choose reasonable" + echo " defaults. If you want more control over what happens, please use" + echo " the azure-cli directly." + echo "" + echo " Note that you must already have an Azure account, username," + echo " password, and subscription. You can create those here:" + echo "" + echo " - https://account.windowsazure.com/" + echo "" + echo "REQUIREMENTS" + echo "" + echo " - azure-cli" + echo " - jq" + echo "" + echo " Use the requirements command (below) for more info." + echo "" + echo "USAGE" + echo "" + echo " ./azure-setup.sh requirements" + echo " ./azure-setup.sh setup" + echo "" } requirements() { - found=0 + found=0 - azureversion=$(az --version) - if [ $? -eq 0 ]; then - found=$((found + 1)) - echo "Found azure-cli version: $azureversion" - else - echo "azure-cli is missing. Please install azure-cli from" - echo "https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest" - echo "Alternatively, you can use the Cloud Shell https://docs.microsoft.com/en-us/azure/cloud-shell/overview right from the Azure Portal or even VS Code." - fi + azureversion=$(az --version) + if [ $? -eq 0 ]; then + found=$((found + 1)) + echo "Found azure-cli version: $azureversion" + else + echo "azure-cli is missing. Please install azure-cli from" + echo "https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest" + echo "Alternatively, you can use the Cloud Shell https://docs.microsoft.com/en-us/azure/cloud-shell/overview right from the Azure Portal or even VS Code." + fi - jqversion=$(jq --version) - if [ $? -eq 0 ]; then - found=$((found + 1)) - echo "Found jq version: $jqversion" - else - echo "jq is missing. Please install jq from" - echo "https://stedolan.github.io/jq/" - fi + azurecliconfig=$(cat $HOME/.azure/config | grep output | awk -F'[ ]' '{print $3}') + if [ "$azurecliconfig" == "json" ]; then + found=$((found +1)) + echo "Found correct azure-cli output configuration: output = $azurecliconfig." + else + echo "azure-cli is configured for $azurecliconfig output." + echo "Please reconfigure your azure-cli client to output using json." + fi - if [ $found -lt 2 ]; then - exit 1 - fi + jqversion=$(jq --version) + if [ $? -eq 0 ]; then + found=$((found + 1)) + echo "Found jq version: $jqversion" + else + echo "jq is missing. Please install jq from" + echo "https://stedolan.github.io/jq/" + fi + + if [ $found -lt 3 ]; then + exit 1 + fi } askSubscription() { - az account list -otable - echo "" - echo "Please enter the Id of the account you wish to use. If you do not see" - echo "a valid account in the list press Ctrl+C to abort and create one." - echo "If you leave this blank we will use the Current account." - echo -n "> " - read azure_subscription_id + az account list -otable + echo "" + echo "Please enter the Id of the account you wish to use. If you do not see" + echo "a valid account in the list press Ctrl+C to abort and create one." + echo "If you leave this blank we will use the Current account." + echo -n "> " + read azure_subscription_id - if [ "$azure_subscription_id" != "" ]; then - az account set --subscription $azure_subscription_id - else - azure_subscription_id=$(az account list | jq -r '.[] | select(.isDefault==true) | .id') - fi - azure_tenant_id=$(az account list | jq -r '.[] | select(.id=="'$azure_subscription_id'") | .tenantId') - echo "Using subscription_id: $azure_subscription_id" - echo "Using tenant_id: $azure_tenant_id" + if [ "$azure_subscription_id" != "" ]; then + az account set --subscription $azure_subscription_id + else + azure_subscription_id=$(az account list | jq -r '.[] | select(.isDefault==true) | .id') + fi + azure_tenant_id=$(az account list | jq -r '.[] | select(.id=="'$azure_subscription_id'") | .tenantId') + echo "Using subscription_id: $azure_subscription_id" + echo "Using tenant_id: $azure_tenant_id" } askName() { - echo "" - echo "Choose a name for your resource group, storage account and client" - echo "client. This is arbitrary, but it must not already be in use by" - echo "any of those resources. ALPHANUMERIC ONLY. Ex: mypackerbuild" - echo -n "> " - read meta_name + echo "" + echo "Choose a name for your resource group, storage account and client" + echo "client. This is arbitrary, but it must not already be in use by" + echo "any of those resources. ALPHANUMERIC ONLY. Ex: mypackerbuild" + echo -n "> " + read meta_name } askSecret() { - echo "" - echo "Enter a secret for your application. We recommend generating one with" - echo "openssl rand -base64 24. If you leave this blank we will attempt to" - echo "generate one for you using openssl. THIS WILL BE SHOWN IN PLAINTEXT." - echo "Ex: mypackersecret8734" - echo -n "> " - read azure_client_secret - if [ "$azure_client_secret" = "" ]; then - azure_client_secret=$(openssl rand -base64 24) - if [ $? -ne 0 ]; then - echo "Error generating secret" - exit 1 - fi - echo "Generated client_secret: $azure_client_secret" + echo "" + echo "Enter a secret for your application. We recommend generating one with" + echo "openssl rand -base64 24. If you leave this blank we will attempt to" + echo "generate one for you using openssl. THIS WILL BE SHOWN IN PLAINTEXT." + echo "Ex: mypackersecret8734" + echo -n "> " + read azure_client_secret + if [ "$azure_client_secret" = "" ]; then + azure_client_secret=$(openssl rand -base64 24) + if [ $? -ne 0 ]; then + echo "Error generating secret" + exit 1 fi + echo "Generated client_secret: $azure_client_secret" + fi } askLocation() { - az account list-locations -otable - echo "" - echo "Choose which region your resource group and storage account will be created. example: westus" - echo -n "> " - read location + az account list-locations -otable + echo "" + echo "Choose which region your resource group and storage account will be created. example: westus" + echo -n "> " + read location } createResourceGroup() { - echo "==> Creating resource group" - az group create -n $meta_name -l $location - if [ $? -eq 0 ]; then - azure_group_name=$meta_name - else - echo "Error creating resource group: $meta_name" - return 1 - fi + echo "==> Creating resource group" + az group create -n $meta_name -l $location + if [ $? -eq 0 ]; then + azure_group_name=$meta_name + else + echo "Error creating resource group: $meta_name" + return 1 + fi } createStorageAccount() { - echo "==> Creating storage account" - az storage account create --name $meta_name --resource-group $meta_name --location $location --kind Storage --sku Standard_LRS - if [ $? -eq 0 ]; then - azure_storage_name=$meta_name - else - echo "Error creating storage account: $meta_name" - return 1 - fi + echo "==> Creating storage account" + az storage account create --name $meta_name --resource-group $meta_name --location $location --kind Storage --sku Standard_LRS + if [ $? -eq 0 ]; then + azure_storage_name=$meta_name + else + echo "Error creating storage account: $meta_name" + return 1 + fi } createApplication() { - echo "==> Creating application" - echo "==> Does application exist?" - azure_client_id=$(az ad app list | jq -r '.[] | select(.displayName | contains("'$meta_name'")) ') - - if [ "$azure_client_id" != "" ]; then - echo "==> application already exist, grab appId" - azure_client_id=$(az ad app list | jq -r '.[] | select(.displayName | contains("'$meta_name'")) .appId') - else - echo "==> application does not exist" - azure_client_id=$(az ad app create --display-name $meta_name --identifier-uris http://$meta_name --homepage http://$meta_name --password $azure_client_secret | jq -r .appId) - fi + echo "==> Creating application" + echo "==> Does application exist?" + azure_client_id=$(az ad app list | jq -r '.[] | select(.displayName | contains("'$meta_name'")) ') - if [ $? -ne 0 ]; then - echo "Error creating application: $meta_name @ http://$meta_name" - return 1 - fi + if [ "$azure_client_id" != "" ]; then + echo "==> application already exist, grab appId" + azure_client_id=$(az ad app list | jq -r '.[] | select(.displayName | contains("'$meta_name'")) .appId') + else + echo "==> application does not exist" + azure_client_id=$(az ad app create --display-name $meta_name --identifier-uris http://$meta_name --homepage http://$meta_name --password $azure_client_secret | jq -r .appId) + fi + + if [ $? -ne 0 ]; then + echo "Error creating application: $meta_name @ http://$meta_name" + return 1 + fi } createServicePrincipal() { - echo "==> Creating service principal" - azure_object_id=$(az ad sp create --id $azure_client_id | jq -r .objectId) - echo $azure_object_id "was selected." + echo "==> Creating service principal" + azure_object_id=$(az ad sp create --id $azure_client_id | jq -r .objectId) + echo $azure_object_id "was selected." - if [ $? -ne 0 ]; then - echo "Error creating service principal: $azure_client_id" - return 1 - fi + if [ $? -ne 0 ]; then + echo "Error creating service principal: $azure_client_id" + return 1 + fi } createPermissions() { - echo "==> Creating permissions" - az role assignment create --assignee $azure_object_id --role "Owner" --scope /subscriptions/$azure_subscription_id - # If the user wants to use a more conservative scope, she can. She must - # configure the Azure builder to use build_resource_group_name. The - # easiest solution is subscription wide permission. - # az role assignment create --spn http://$meta_name -g $azure_group_name -o "API Management Service Contributor" - if [ $? -ne 0 ]; then - echo "Error creating permissions for: http://$meta_name" - return 1 - fi + echo "==> Creating permissions" + az role assignment create --assignee $azure_object_id --role "Owner" --scope /subscriptions/$azure_subscription_id + # If the user wants to use a more conservative scope, she can. She must + # configure the Azure builder to use build_resource_group_name. The + # easiest solution is subscription wide permission. + # az role assignment create --spn http://$meta_name -g $azure_group_name -o "API Management Service Contributor" + if [ $? -ne 0 ]; then + echo "Error creating permissions for: http://$meta_name" + return 1 + fi } showConfigs() { - echo "" - echo "Use the following configuration for your packer template:" - echo "" - echo "{" - echo " \"client_id\": \"$azure_client_id\"," - echo " \"client_secret\": \"$azure_client_secret\"," - echo " \"object_id\": \"$azure_object_id\"," - echo " \"subscription_id\": \"$azure_subscription_id\"," - echo " \"tenant_id\": \"$azure_tenant_id\"," - echo " \"resource_group_name\": \"$azure_group_name\"," - echo " \"storage_account\": \"$azure_storage_name\"," - echo "}" - echo "" + echo "" + echo "Use the following configuration for your packer template:" + echo "" + echo "{" + echo " \"client_id\": \"$azure_client_id\"," + echo " \"client_secret\": \"$azure_client_secret\"," + echo " \"object_id\": \"$azure_object_id\"," + echo " \"subscription_id\": \"$azure_subscription_id\"," + echo " \"tenant_id\": \"$azure_tenant_id\"," + echo " \"resource_group_name\": \"$azure_group_name\"," + echo " \"storage_account\": \"$azure_storage_name\"," + echo "}" + echo "" } doSleep() { - local sleep_time=${PACKER_SLEEP_TIME-$create_sleep} - echo "" - echo "Sleeping for ${sleep_time} seconds to wait for resources to be " - echo "created. If you get an error about a resource not existing, you can " - echo "try increasing the amount of time we wait after creating resources " - echo "by setting PACKER_SLEEP_TIME to something higher than the default." - echo "" - sleep $sleep_time + local sleep_time=${PACKER_SLEEP_TIME-$create_sleep} + echo "" + echo "Sleeping for ${sleep_time} seconds to wait for resources to be " + echo "created. If you get an error about a resource not existing, you can " + echo "try increasing the amount of time we wait after creating resources " + echo "by setting PACKER_SLEEP_TIME to something higher than the default." + echo "" + sleep $sleep_time } retryable() { - n=0 - until [ $n -ge $1 ] - do - $2 && return 0 - echo "$2 failed. Retrying..." - n=$[$n+1] - doSleep - done - echo "$2 failed after $1 tries. Exiting." - exit 1 + n=0 + until [ $n -ge $1 ] + do + $2 && return 0 + echo "$2 failed. Retrying..." + n=$[$n+1] + doSleep + done + echo "$2 failed after $1 tries. Exiting." + exit 1 } setup() { - requirements + requirements - az login + az login - askSubscription - askName - askSecret - askLocation + askSubscription + askName + askSecret + askLocation - # Some of the resources take a while to converge in the API. To make the - # script more reliable we'll add a sleep after we create each resource. + # Some of the resources take a while to converge in the API. To make the + # script more reliable we'll add a sleep after we create each resource. - retryable 3 createResourceGroup - retryable 3 createStorageAccount - retryable 3 createApplication - retryable 3 createServicePrincipal - retryable 3 createPermissions + retryable 3 createResourceGroup + retryable 3 createStorageAccount + retryable 3 createApplication + retryable 3 createServicePrincipal + retryable 3 createPermissions - showConfigs + showConfigs } case "$1" in - requirements) - requirements - ;; - setup) - setup - ;; - *) - showhelp - ;; + requirements) + requirements + ;; + setup) + setup + ;; + *) + showhelp + ;; esac From 5e22942f3002c423267cfbe186721d6698e7acaf Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Fri, 13 Apr 2018 17:59:14 -0400 Subject: [PATCH 09/82] analytics script adjustments --- website/source/layouts/layout.erb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/website/source/layouts/layout.erb b/website/source/layouts/layout.erb index 768ea0a83..a6c615b72 100644 --- a/website/source/layouts/layout.erb +++ b/website/source/layouts/layout.erb @@ -112,23 +112,24 @@ - + + + <%= yield_content :head %> + + @@ -112,11 +120,6 @@ <%= yield_content :head %> - - @@ -119,20 +106,22 @@ + + <%= javascript_include_tag "application" %> + - - - - + + + <%= javascript_include_tag "application", defer: true %> + + + <%= yield_content :head %> @@ -106,22 +113,6 @@ - - <%= javascript_include_tag "application" %> - -