### Clone and Setup Repository Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Building-Packages-From-Source Initializes the repository with submodules and installs required Ruby dependencies. ```bash git clone --recursive https://github.com/cloudfoundry-incubator/bosh-windows-stemcell-builder bwsb cd bwsb git checkout gem install bundler bundle install ``` -------------------------------- ### Install Transform Package Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/tidwall/transform/README.md Use the go get command to install the package. ```sh $ go get -u github.com/tidwall/transform ``` -------------------------------- ### Install automaxprocs Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/go.uber.org/automaxprocs/README.md Use the go get command to add the package to your project. ```bash go get -u go.uber.org/automaxprocs ``` -------------------------------- ### Install the YAML package Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/gopkg.in/yaml.v2/README.md Use the go get command to download the package into your Go environment. ```bash go get gopkg.in/yaml.v2 ``` -------------------------------- ### Install go.yaml.in/yaml/v3 Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/go.yaml.in/yaml/v3/README.md Use 'go get' to install the YAML package for Go. This command fetches and installs the specified package and its dependencies. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Install go-ntlmssp package Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/Azure/go-ntlmssp/README.md Use the go get command to add the package to your project. ```bash go get github.com/Azure/go-ntlmssp ``` -------------------------------- ### Download and install Cloudbase-init Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Create-Manual-OpenStack-Stemcells Downloads the Cloudbase-init MSI installer using Invoke-WebRequest and then executes the installer. Ensure to configure Cloudbase-init settings appropriately during installation. ```powershell C:\Invoke-WebRequest -UseBasicParsing https://cloudbase.it/downloads/CloudbaseInitSetup_Stable_x64.msi -OutFile cloudbaseinit.msi . cloudbase-init.msi ``` -------------------------------- ### Install mapstructure Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/mitchellh/mapstructure/README.md Use the standard go get command to add the library to your project. ```bash $ go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Install Go Tree Command Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/a8m/tree/README.md Use 'go get' to install the tree command-line tool. This command fetches and installs the specified package and its dependencies. ```sh $ go get github.com/a8m/tree/cmd/tree ``` -------------------------------- ### Install Ginkgo Locally Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/onsi/ginkgo/v2/CONTRIBUTING.md Install the Ginkgo CLI locally using the go install command. This is a prerequisite for running tests and other development tasks. ```bash go install ./... ``` -------------------------------- ### Install UUID Package Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/gofrs/uuid/README.md Use the go get command to download the package if not using a dependency manager. ```Shell $ go get github.com/gofrs/uuid ``` -------------------------------- ### Create Root Logger in Go Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/go-logr/logr/README.md Initialize the root logger early in your application's setup. This example shows creating a logger using a hypothetical 'logimpl' implementation with initial parameters. ```go func main() { // ... other setup code ... // Create the "root" logger. We have chosen the "logimpl" implementation, // which takes some initial parameters and returns a logr.Logger. logger := logimpl.New(param1, param2) // ... other setup code ... } ``` -------------------------------- ### Install virtualization packages on Ubuntu Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Create-Manual-OpenStack-Stemcells Installs the required KVM and virtualization management tools. ```bash sudo apt install virtinst virt-manager qemu-kvm ``` -------------------------------- ### Clone Repository and Setup Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/go.uber.org/automaxprocs/CONTRIBUTING.md Clone the repository to your local machine and set up the remote upstream. This is the initial step for contributing. ```bash mkdir -p $GOPATH/src/go.uber.org cd $GOPATH/src/go.uber.org git clone git@github.com:your_github_username/automaxprocs.git cd automaxprocs git remote add upstream https://github.com/uber-go/automaxprocs.git git fetch upstream ``` -------------------------------- ### Install CF Features and Agent Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Create-Manual-OpenStack-Stemcells Configures the VM with necessary CF features and installs the BOSH agent. ```powershell Install-CFFeatures Protect-CFCell Install-Agent -IaaS openstack -agentZipPath ``` -------------------------------- ### WinRM Development Setup Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/masterzen/winrm/README.md Instructions for setting up the development environment for the winrm library. Requires Go, Mercurial, and Bazaar. Use 'make' for building and testing. ```bash make ``` ```bash make test ``` ```bash make format ``` ```bash make updatedeps ``` -------------------------------- ### Start Windows VM with virt-install Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Create-Manual-OpenStack-Stemcells Launches a Windows VM using virt-install, attaching the qcow2 disk, Windows ISO, and virtio drivers. Ensure the network model is set to 'virtio' for optimal performance. ```bash virt-install --connect qemu:///system \ --name ws2012 --ram 4096 --vcpus 2 \ --network network=default,model=virtio \ --disk path=ws2012.qcow2,format=qcow2,device=disk,bus=virtio \ --disk path=~/Downloads/windows2012-disk.iso,device=cdrom \ --disk path=~/Downloads/virtio-win-0.1.126.iso,device=cdrom \ --vnc --os-type windows --os-variant win2k12 ``` -------------------------------- ### Verify Go Installation Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/masterzen/winrm/README.md Check the installed version of Go to ensure compatibility with the library. ```sh go version ``` -------------------------------- ### Execute Setup Script Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/stemcell-automation/README.md Runs the automation setup script. Use the -SkipRandomPassword flag to prevent the Administrator password from being randomized. ```powershell .\Setup.ps1 ``` ```powershell .\Setup.ps1 -SkipRandomPassword ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/go.uber.org/automaxprocs/CONTRIBUTING.md Install the necessary dependencies for running tests. This command ensures your environment is ready for testing. ```bash make dependencies ``` -------------------------------- ### Install Dependencies Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/README.md Install the required Ruby dependencies using Bundler. ```bash gem install bundler bundle install ``` -------------------------------- ### Install UUID package Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/google/uuid/README.md Use this command to install the package via the Go toolchain. ```sh go get github.com/google/uuid ``` -------------------------------- ### Clone and Configure Repository Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/vmware/govmomi/CONTRIBUTING.md Initial setup for cloning the repository and configuring remote tracking for a personal fork. ```bash git clone https://github.com/vmware/govmomi.git && cd govmomi # prevent accidentally pushing to vmware/govmomi git config push.default nothing git remote rename origin vmware # add your fork git remote add $USER git@github.com:$USER/govmomi.git git fetch -av ``` -------------------------------- ### Install bosh-agent Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/modules/BOSH.Agent/README.md Use this command to install the bosh-agent. Ensure the agent zip path is correctly specified. ```powershell Install-Agent -IaaS $IaaS -AgentZipPath (Join-Path $PSScriptRoot 'agent.zip') ``` -------------------------------- ### Install BOSH Agent Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/[Deprecated]-Creating-a-vSphere-2012-R2-Windows-Stemcell Install the BOSH Agent using the `Install-Agent` PowerShell cmdlet. Specify the Infrastructure (`-IaaS`) and the path to the agent zip file (`-agentZipPath`). ```powershell Install-Agent -IaaS vsphere -agentZipPath ``` -------------------------------- ### Install Ruby Dependencies Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Install Ruby dependencies using Bundler. ```bash # Install Ruby dependencies gem install bundler bundle install ``` -------------------------------- ### Convert format strings to structured logging Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/github.com/go-logr/logr/README.md Examples demonstrating the migration from klog format-string logging to structured logr-style logging. ```go klog.V(4).Infof("Client is returning errors: code %v, error %v", responseCode, err) ``` ```go logger.Error(err, "client returned an error", "code", responseCode) ``` ```go klog.V(4).Infof("Got a Retry-After %ds response for attempt %d to %v", seconds, retries, url) ``` ```go logger.V(4).Info("got a retry-after response when requesting url", "attempt", retries, "after seconds", seconds, "url", url) ``` ```go log.Printf("unable to reflect over type %T") ``` ```go logger.Info("unable to reflect over type", "type", fmt.Sprintf("%T")) ``` -------------------------------- ### Install Counterfeiter to $GOPATH/bin Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/maxbrunsfeld/counterfeiter/v6/README.md Install `counterfeiter` globally to your `$GOPATH/bin` directory using `go install`. This allows you to invoke the `counterfeiter` command directly from your shell, even outside of a Go module context. ```shell go install github.com/maxbrunsfeld/counterfeiter/v6 ~/go/bin/counterfeiter USAGE counterfeiter [-generate>] [-o ] [-p] [--fake-name ] [-header ] [] [-] ``` -------------------------------- ### Configure HTTPS authentication Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/masterzen/winrm/README.md Setup HTTPS transport using client certificates. ```go package main import ( "github.com/masterzen/winrm" "log" "os" ) func main() { clientCert, err := os.ReadFile("/home/example/winrm_client_cert.pem") if err != nil { log.Fatalf("failed to read client certificate: %q", err) } clientKey, err := os.ReadFile("/home/example/winrm_client_key.pem") if err != nil { log.Fatalf("failed to read client key: %q", err) } winrm.DefaultParameters.TransportDecorator = func() winrm.Transporter { // winrm https module return &winrm.ClientAuthRequest{} } endpoint := winrm.NewEndpoint( "192.168.100.2", // host to connect to 5986, // winrm port ``` -------------------------------- ### Execute commands with WinRM Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/masterzen/winrm/README.md Basic examples for running commands on a remote host using HTTP transport. ```go package main import ( "github.com/masterzen/winrm" "os" ) endpoint := winrm.NewEndpoint(host, 5986, false, false, nil, nil, nil, 0) client, err := winrm.NewClient(endpoint, "Administrator", "secret") if err != nil { panic(err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() client.RunWithContext(ctx, "ipconfig /all", os.Stdout, os.Stderr) ``` ```go package main import ( "github.com/masterzen/winrm" "fmt" "os" ) endpoint := winrm.NewEndpoint("localhost", 5985, false, false, nil, nil, nil, 0) client, err := winrm.NewClient(endpoint,"Administrator", "secret") if err != nil { panic(err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() _, err := client.RunWithContextWithInput(ctx, "ipconfig", os.Stdout, os.Stderr, os.Stdin) if err != nil { panic(err) } ``` -------------------------------- ### Setup BOSH WinRM Module and Enable WinRM Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/scripts/aws/setup_winrm.txt This script configures the BOSH WinRM module and enables WinRM. It first creates a directory, downloads the module from a URL, and then enables WinRM. Ensure the execution policy is set to bypass for local machine. ```powershell $boshWinRMDir = 'C:\Program Files\WindowsPowerShell\Modules\BOSH.WinRM' Write-Log "Making bosh module directory: $boshWinRMDir" New-Item -Path $boshWinRMDir -ItemType Directory -Force $winrmUrl = 'https://raw.githubusercontent.com/cloudfoundry/bosh-psmodules/master/modules/BOSH.WinRM/BOSH.WinRM.psm1' Write-Log "Fetching bosh module $winrmUrl" Invoke-WebRequest $winrmUrl -OutFile "$boshWinRMDir\BOSH.WinRM.psm1" if (-not (Get-Command Enable-WinRM -errorAction SilentlyContinue)) { Write-Log "Enable-WinRM was not loaded. There may be a problem with $winrmUrl" } Write-Log "Invoking WinRM" Enable-WinRM Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine ``` -------------------------------- ### Ginkgo Spec Example Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/onsi/ginkgo/v2/README.md This example demonstrates a typical Ginkgo spec structure, including Describe, BeforeEach, When, Context, It, and Expect. It covers scenarios for checking out books from a library, including handling availability and holds. Use SpecTimeout for setting test durations. ```go import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ... ) var _ = Describe("Checking books out of the library", Label("library"), func() { var library *libraries.Library var book *books.Book var valjean *users.User BeforeEach(func() { library = libraries.NewClient() book = &books.Book{ Title: "Les Miserables", Author: "Victor Hugo", } valjean = users.NewUser("Jean Valjean") }) When("the library has the book in question", func() { BeforeEach(func(ctx SpecContext) { Expect(library.Store(ctx, book)).To(Succeed()) }) Context("and the book is available", func() { It("lends it to the reader", func(ctx SpecContext) { Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books()).To(ContainElement(book)) Expect(library.UserWithBook(ctx, book)).To(Equal(valjean)) }, SpecTimeout(time.Second * 5)) }) Context("but the book has already been checked out", func() { var javert *users.User BeforeEach(func(ctx SpecContext) { javert = users.NewUser("Javert") Expect(javert.Checkout(ctx, library, "Les Miserables")).To(Succeed()) }) It("tells the user", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is currently checked out")) }, SpecTimeout(time.Second * 5)) It("lets the user place a hold and get notified later", func(ctx SpecContext) { Expect(valjean.Hold(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Holds(ctx)).To(ContainElement(book)) By("when Javert returns the book") Expect(javert.Return(ctx, library, book)).To(Succeed()) By("it eventually informs Valjean") notification := "Les Miserables is ready for pick up" Eventually(ctx, valjean.Notifications).Should(ContainElement(notification)) Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books(ctx)).To(ContainElement(book)) Expect(valjean.Holds(ctx)).To(BeEmpty()) }, SpecTimeout(time.Second * 10)) }) }) When("the library does not have the book in question", func() { It("tells the reader the book is unavailable", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is not in the library catalog")) }, SpecTimeout(time.Second * 5)) }) }) ``` -------------------------------- ### Install BOSH Agent for Windows Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Installs the BOSH agent for Windows. The agent zip must contain specific executables and dependencies. ```powershell # Install BOSH Agent for OpenStack Install-Agent -IaaS openstack -agentZipPath "C:\provision\agent.zip" ``` ```powershell # Enable/Disable agent service Enable-AgentService # Sets service to automatic startup Disable-AgentService # Sets service to manual startup ``` -------------------------------- ### Install-Agent Cmdlet Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/modules/BOSH.Agent/README.md This cmdlet installs the bosh-agent for a specified Infrastructure as a Service (IAAS). ```APIDOC ## Install-Agent ### Description Installs the bosh-agent for a given IAAS. ### Method Cmdlet ### Parameters #### Path Parameters - **IaaS** (string) - Required - The Infrastructure as a Service provider (e.g., 'vsphere', 'azure'). - **AgentZipPath** (string) - Required - The full path to the agent zip file. ### Request Example ```powershell Install-Agent -IaaS "vsphere" -AgentZipPath "C:\path\to\agent.zip" ``` ### Response This cmdlet does not explicitly return a value upon successful execution, but indicates success by completing without errors. Errors will be thrown if the installation fails. #### Success Response (0) No explicit return value, indicates successful installation. #### Response Example (No specific response body, success is indicated by completion without error.) ``` -------------------------------- ### Install .NET 3.5 Feature Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Manual-Stemcell-DotNet-Version-Guide Run this PowerShell command before installing Windows Updates to enable .NET 3.5. Ensure you use the binary buildpack for deployment if using .NET 3.5 on Cloud Foundry. ```powershell Install-WindowsFeature Net-Framework-Core ``` -------------------------------- ### Install and Configure OpenSSH Server on Windows Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Installs and configures the OpenSSH server for BOSH-deployed VMs. This module enables SSH-based management, sets up firewall rules, and applies security policies. ```powershell # Import the module Import-Module BOSH.SSH ``` ```powershell # Install OpenSSH from a zip file Install-SSHD -SSHZipFile "C:\provision\OpenSSH-Win64.zip" ``` ```powershell # Enable SSHD service and configure firewall Enable-SSHD # This command: # - Creates firewall rule for SSH (port 22) # - Applies security policies using LGPO if available # - Sets sshd and ssh-agent services to automatic # - Removes existing host keys for regeneration on first boot ``` ```powershell # Remove existing SSH host keys (called by Enable-SSHD) Remove-SSHKeys # Keys will be regenerated on first service start ``` -------------------------------- ### BOSH.SSH Module Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Functions for installing and configuring OpenSSH server on Windows. ```APIDOC ## Install-SSHD ### Description Installs OpenSSH server from a provided zip file. ### Parameters #### Query Parameters - **SSHZipFile** (string) - Required - Path to the OpenSSH zip file. ## Enable-SSHD ### Description Enables the SSHD service, configures firewall rules for port 22, and applies security policies. ## Remove-SSHKeys ### Description Removes existing SSH host keys to allow regeneration on first boot. ``` -------------------------------- ### Install Cloud Foundry Features Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/[Deprecated]-Creating-a-vSphere-2012-R2-Windows-Stemcell Run the `Install-CFFeatures` PowerShell command to install necessary Windows features for Cloud Foundry and apply security configurations. The machine will restart automatically upon completion. ```powershell Install-CFFeatures ``` -------------------------------- ### Example Acceptance Test Configuration (config.json) Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/README.md This JSON structure is used to configure acceptance tests. Ensure all paths and credentials are correct for your BOSH environment. ```json { "bosh": { "ca_cert": "", "client": "", "client_secret": "", "target": "" }, "stemcell_path": "", "stemcell_os": "", "az": "", "vm_type": "", "vm_extensions": "", "network": "", "skip_cleanup": "" } ``` -------------------------------- ### Template Output Example Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/github.com/go-task/slim-sprig/v3/README.md The resulting output from the provided template function chain. ```text HELLO!HELLO!HELLO!HELLO!HELLO! ``` -------------------------------- ### Verify Installation of Required Executables Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Windows-Worker-and-Concourse-Setup Checks the system path for the presence of all required build tools. ```powershell $RequiredExes=@( "tar.exe", "packer.exe", "ovftool.exe", "go.exe", "ruby.exe" ) foreach ($exe in $RequiredExes) { Get-Command $exe } ``` -------------------------------- ### Install BOSH Agent via PowerShell Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Configures the BOSH agent service on Windows VMs. Use the appropriate IaaS flag to ensure correct configuration. ```powershell # Import the module Import-Module BOSH.Agent # Install BOSH Agent for vSphere Install-Agent -IaaS vsphere -agentZipPath "C:\provision\agent.zip" # Install BOSH Agent for AWS with ephemeral disk mounting Install-Agent -IaaS aws -agentZipPath "C:\provision\agent.zip" -EnableEphemeralDiskMounting # Install BOSH Agent for Azure Install-Agent -IaaS azure -agentZipPath "C:\provision\agent.zip" # Install BOSH Agent for GCP Install-Agent -IaaS gcp -agentZipPath "C:\provision\agent.zip" ``` -------------------------------- ### Define Ginkgo BDD Specs Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/github.com/onsi/ginkgo/v2/README.md A comprehensive example demonstrating the use of Describe, Context, and It blocks to test library book checkout scenarios. Requires the Ginkgo and Gomega packages. ```go import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ... ) var _ = Describe("Checking books out of the library", Label("library"), func() { var library *libraries.Library var book *books.Book var valjean *users.User BeforeEach(func() { library = libraries.NewClient() book = &books.Book{ Title: "Les Miserables", Author: "Victor Hugo", } valjean = users.NewUser("Jean Valjean") }) When("the library has the book in question", func() { BeforeEach(func(ctx SpecContext) { Expect(library.Store(ctx, book)).To(Succeed()) }) Context("and the book is available", func() { It("lends it to the reader", func(ctx SpecContext) { Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books()).To(ContainElement(book)) Expect(library.UserWithBook(ctx, book)).To(Equal(valjean)) }, SpecTimeout(time.Second * 5)) }) Context("but the book has already been checked out", func() { var javert *users.User BeforeEach(func(ctx SpecContext) { javert = users.NewUser("Javert") Expect(javert.Checkout(ctx, library, "Les Miserables")).To(Succeed()) }) It("tells the user", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is currently checked out")) }, SpecTimeout(time.Second * 5)) It("lets the user place a hold and get notified later", func(ctx SpecContext) { Expect(valjean.Hold(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Holds(ctx)).To(ContainElement(book)) By("when Javert returns the book") Expect(javert.Return(ctx, library, book)).To(Succeed()) By("it eventually informs Valjean") notification := "Les Miserables is ready for pick up" Eventually(ctx, valjean.Notifications).Should(ContainElement(notification)) Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books(ctx)).To(ContainElement(book)) Expect(valjean.Holds(ctx)).To(BeEmpty()) }, SpecTimeout(time.Second * 10)) }) }) When("the library does not have the book in question", func() { It("tells the reader the book is unavailable", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is not in the library catalog")) }, SpecTimeout(time.Second * 5)) }) }) ``` -------------------------------- ### Register and Run Subcommands in Go Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/google/subcommands/README.md Register built-in and custom subcommands using the default Commander and then execute them. This setup is typically done in the main function of a Go application. ```go func main() { subcommands.Register(subcommands.HelpCommand(), "") subcommands.Register(subcommands.FlagsCommand(), "") subcommands.Register(subcommands.CommandsCommand(), "") subcommands.Register(&printCmd{}, "") flag.Parse() ctx := context.Background() os.Exit(int(subcommands.Execute(ctx))) } ``` -------------------------------- ### Create and Use WinRM Client Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/masterzen/winrm/README.md Demonstrates creating a WinRM client with specific configurations and executing a command remotely. Ensure necessary imports and context handling are in place. ```go client, err := winrm.NewClient(endpoint, "Administrator", "") if err != nil { log.Fatalf("failed to create client: %q", err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() _, err = client.RunWithContext(ctx, "whoami", os.Stdout, os.Stderr) if err != nil { log.Fatalf("failed to run command: %q", err) } ``` -------------------------------- ### Log Message in Go Application Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/go-logr/logr/README.md An example of how an application object uses its logger to emit an informational message with a timestamp. This usage is independent of the specific logging implementation chosen during setup. ```go type appObject struct { // ... other fields ... logger logr.Logger // ... other fields ... } func (app *appObject) Run() { app.logger.Info("starting up", "timestamp", time.Now()) // ... app code ... } ``` -------------------------------- ### Run Pester Tests within pwsh on macOS Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/modules/README.md Commands to run after starting the Powershell interactive session (`pwsh`) on macOS. Installs Pester and navigates to the module directory to invoke tests. ```powershell Install-Module -Name Pester -Force cd stembuild/module/BOSH. Invoke-Pester ``` -------------------------------- ### Initialize automaxprocs in main Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/go.uber.org/automaxprocs/README.md Import the package with an underscore to trigger automatic GOMAXPROCS adjustment during application startup. ```go import _ "go.uber.org/automaxprocs" func main() { // Your application logic here. } ``` -------------------------------- ### Install Bundler Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Windows-Worker-and-Concourse-Setup Installs the Bundler gem required for managing Ruby dependencies. ```ruby gem install bundler ``` -------------------------------- ### Build All Files (Old System) Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/golang.org/x/sys/unix/README.md Use this script to generate Go files for your current OS and architecture using the old build system. Ensure GOOS and GOARCH are set correctly. Running with -n shows the commands without execution. ```bash mkall.sh ``` ```bash mkall.sh -n ``` -------------------------------- ### Build BOSH Agent Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Build the BOSH agent from source, producing an agent.zip file. ```bash # Build BOSH Agent rake package:agent # Output: agent.zip containing bosh-agent.exe and dependencies ``` -------------------------------- ### Install Red Hat Ethernet driver Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Create-Manual-OpenStack-Stemcells Installs the Red Hat Ethernet driver within a Windows VM using pnputil. This command should be run from a PowerShell terminal. ```powershell pnputil -i -a E:\NetKVM\2k12R2\amd64\netkvm.inf ``` -------------------------------- ### Install OpenSSH on Windows VM Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/[Deprecated]-Creating-a-vSphere-2012-R2-Windows-Stemcell Installs OpenSSH on a Windows VM, enabling 'bosh ssh' command functionality. Ensure the OpenSSH zip file is transferred to the VM before running. ```powershell Unblock-File 'C:\provision\OpenSSH-Win64.zip' ``` ```powershell Install-SSHD -SSHZipFile 'C:\provision\OpenSSH-Win64.zip' ``` -------------------------------- ### Create qcow2 disk image Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Create-Manual-OpenStack-Stemcells Use qemu-img to create a qcow2 disk image of a specified size. ```bash qemu-img create -f qcow2 ws2012.qcow2 30G ``` -------------------------------- ### Install Cloud Foundry Cell Features on Windows Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Installs necessary Windows features for Cloud Foundry cells and applies security hardening. This includes configuring container support and firewall rules. ```powershell # Import the module Import-Module BOSH.CFCell ``` ```powershell # Install CF Cell features for Azure Install-CFFeatures -IaaS azure ``` ```powershell # Install CF Cell features with forced reboot Install-CFFeatures -IaaS aws -ForceReboot ``` ```powershell # Install CF Cell features for vSphere Install-CFFeatures -IaaS vsphere # Installs: FS-Resource-Manager, Containers # Removes: Windows Defender ``` ```powershell # Protect the CF Cell (security hardening) Protect-CFCell -IaaS gcp # This command: # - Disables WinRM service # - Disables W3Svc (IIS) # - Disables RDP # - Configures firewall to block inbound, allow outbound # - Disables NetBIOS over TCP # - Configures metadata server firewall rules for cloud agents ``` -------------------------------- ### Build WinRM from Source Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/masterzen/winrm/README.md Clone the repository and build the project using the provided Makefile. ```sh git clone https://github.com/masterzen/winrm cd winrm make ``` -------------------------------- ### Preview Documentation Changes Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/onsi/ginkgo/v2/CONTRIBUTING.md Serve the documentation locally using Jekyll to preview your changes before committing. Ensure documentation is up-to-date with code modifications. ```bash bundle && bundle exec jekyll serve ``` -------------------------------- ### Generate and Parse UUIDs Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/gofrs/uuid/README.md Demonstrates creating Version 4 UUIDs and parsing UUID strings. Use uuid.Must for package-level initialization to panic on error. ```Go package main import ( "log" "github.com/gofrs/uuid" ) // Create a Version 4 UUID, panicking on error. // Use this form to initialize package-level variables. var u1 = uuid.Must(uuid.NewV4()) func main() { // Create a Version 4 UUID. u2, err := uuid.NewV4() if err != nil { log.Fatalf("failed to generate UUID: %v", err) } log.Printf("generated Version 4 UUID %v", u2) // Parse a UUID from a string. s := "6ba7b810-9dad-11d1-80b4-00c04fd430c8" u3, err := uuid.FromString(s) if err != nil { log.Fatalf("failed to parse UUID %q: %v", s, err) } log.Printf("successfully parsed UUID %v", u3) } ``` -------------------------------- ### Create and Check Version Constraints Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/Masterminds/semver/v3/README.md Use `semver.NewConstraint` to create a constraint and `semver.NewVersion` to parse a version. Then, use the `Check` method to see if the version meets the constraint. Handle potential errors during parsing. ```go c, err := semver.NewConstraint(">= 1.2.3") if err != nil { // Handle constraint not being parsable. } v, err := semver.NewVersion("1.3") if err != nil { // Handle version not being parsable. } // Check if the version meets the constraints. The variable a will be true. a := c.Check(v) ``` -------------------------------- ### Verify Worker Installation Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Windows-Worker-and-Concourse-Setup Validates the presence of required files, directories, and configuration placeholders. ```powershell # Required directories $Failed=$false foreach ($dir in @("C:\containers", "C:\concourse", "C:\vmx-data")) { if (-Not (Test-Path $dir)) { Write-Host -ForegroundColor Red "Error: Missing required directory: $dir" $Failed=$true } } $RequiredFiles=@( "concourse_windows_amd64.exe", "concourse.exe", "concourse.xml", "tsa-worker-private-key", "tsa-public-key.pub" ) foreach ($name in $RequiredFiles) { $path = "C:\concourse\$name" if (-Not (Test-Path $path)) { Write-Host -ForegroundColor Red "Error: missing required file: $path" $Failed=$true } } # Make sure TSA_HOST_ADDRESS and WORKER_TAG_NAME were replaced $Config="C:\concourse\concourse.xml" if (Test-Path $Config) { $Content=(Get-Content -Raw -Path $Config) if ($Content.Contains("TSA_HOST_ADDRESS")) { Write-Host -ForegroundColor Red "Error: '$Config' contains: TSA_HOST_ADDRESS" $Failed=$true } if ($Content.Contains("WORKER_TAG_NAME")) { Write-Host -ForegroundColor Red "Error: '$Config' contains: WORKER_TAG_NAME" $Failed=$true } } if ($Failed) { Write-Host -ForegroundColor Red "Error: check failed" } else { Write-Host -ForegroundColor Green "Success: check passed" } ``` -------------------------------- ### Initialize the root logger Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/github.com/go-logr/logr/README.md Create a root logger instance using a specific logging implementation early in the application lifecycle. ```go func main() { // ... other setup code ... // Create the "root" logger. We have chosen the "logimpl" implementation, // which takes some initial parameters and returns a logr.Logger. logger := logimpl.New(param1, param2) // ... other setup code ... ``` -------------------------------- ### YAML processing output Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/acceptance_test/vendor/gopkg.in/yaml.v3/README.md The expected output generated by the provided Go example code. ```text --- t: {Easy! {2 [3 4]}} --- t dump: a: Easy! b: c: 2 d: [3, 4] --- m: map[a:Easy! b:map[c:2 d:[3 4]]] --- m dump: a: Easy! b: c: 2 d: - 3 - 4 ``` -------------------------------- ### BOSH.CFCell Module Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Functions for installing Cloud Foundry cell features and applying security hardening. ```APIDOC ## Install-CFFeatures ### Description Installs Windows features required for Cloud Foundry cells. ### Parameters #### Query Parameters - **IaaS** (string) - Required - The target cloud platform (azure, aws, vsphere). - **ForceReboot** (switch) - Optional - Forces a reboot after installation. ## Protect-CFCell ### Description Applies security hardening to the CF cell, including disabling unnecessary services and configuring firewall rules. ### Parameters #### Query Parameters - **IaaS** (string) - Required - The target cloud platform (gcp). ``` -------------------------------- ### Monitor Provisioning Logs Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/stemcell-automation/README.md Follows the provisioning log file in real-time to monitor progress after a reboot. ```powershell Get-Content -Path "C:\provision\log.log" -Wait ``` -------------------------------- ### BOSH Agent Management Source: https://context7.com/cloudfoundry/bosh-windows-stemcell-builder/llms.txt Functions for installing the BOSH agent and managing its service state on Windows. ```APIDOC ## Install-Agent ### Description Installs the BOSH agent on the target IaaS. ### Parameters #### Query Parameters - **IaaS** (string) - Required - The target cloud platform (e.g., openstack). - **agentZipPath** (string) - Required - Local path to the agent zip file. ## Enable-AgentService ### Description Sets the BOSH agent service to automatic startup. ## Disable-AgentService ### Description Sets the BOSH agent service to manual startup. ``` -------------------------------- ### List all content library objects with `govc library.ls` Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/vmware/govmomi/vapi/library/finder/README.md Use `govc library.ls` with a wildcard pattern to list all items within content libraries. This command is useful for inventory management and understanding the structure of your content libraries. ```console $ govc library.ls '*/*/' /ISOs/CentOS-7-x86_64-Minimal-1804/CentOS-7-x86_64-Minimal-1804.iso /ISOs/CoreOS Production/coreos_production_iso_image.iso /ISOs/VMware-VCSA-all-6.7.0-8217866.iso/VMware-VCSA-all-6.7.0-8217866.iso /ISOs/VMware-VIM-all-6.7.0-8217866.iso/VMware-VIM-all-6.7.0-8217866.iso /ISOs/ubuntu-16.04.5-server-amd64/ubuntu-16.04.5-server-amd64.iso /ISOs/photon-2.0-304b817/photon-2.0-304b817.iso /OVAs/VMware-vCenter-Server-Appliance-6.7.0.10000-8217866_OVF10.ova/VMware-vCenter-Server-Appliance-6.7.0.10000-8217866_OVF10.ova /OVAs/coreos_production_vmware_ova/coreos_production_vmware_ova.ovf /OVAs/coreos_production_vmware_ova/coreos_production_vmware_ova-1.vmdk /OVAs/centos_cloud_template/centos_cloud_template-2.iso /OVAs/centos_cloud_template/centos_cloud_template.ovf /OVAs/centos_cloud_template/centos_cloud_template-1.vmdk /OVAs/centos_cloud_template/centos_cloud_template-3.nvram /OVAs/photon-custom-hw13-2.0-304b817/photon-ova-disk1.vmdk /OVAs/photon-custom-hw13-2.0-304b817/photon-ova.ovf /OVAs/yakity-centos/yakity-centos-2.nvram /OVAs/yakity-centos/yakity-centos-1.vmdk /OVAs/yakity-centos/yakity-centos.ovf /OVAs/yakity-photon/yakity-photon-1.vmdk /OVAs/yakity-photon/yakity-photon.ovf /OVAs/yakity-photon/yakity-photon-2.nvram /OVAs/ubuntu-16.04-server-cloudimg-amd64/ubuntu-16.04-server-cloudimg-amd64.ovf /OVAs/ubuntu-16.04-server-cloudimg-amd64/ubuntu-16.04-server-cloudimg-amd64-1.vmdk /sk8-TestUploadOVA/photon2-cloud-init/photon2-cloud-init.ovf /sk8-TestUploadOVA/photon2-cloud-init/photon2-cloud-init-1.vmdk /Public/photon2-cloud-init/photon2-cloud-init.ovf /Public/photon2-cloud-init/photon2-cloud-init-1.vmdk ``` -------------------------------- ### Create and Register Bin Directory Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/Windows-Worker-and-Concourse-Setup Creates a global binary directory and adds it to the system PATH for executable access. ```powershell New-Item -ItemType directory -Path C:\bin -Force [Environment]::SetEnvironmentVariable("Path", "$env:PATH;C:\bin", [System.EnvironmentVariableTarget]::Machine) ``` -------------------------------- ### Instantiate a Fake Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/maxbrunsfeld/counterfeiter/v6/README.md Import the generated fakes package and instantiate a fake of your interface. This fake can then be used in your tests. ```go import "my-repo/path/to/foo/foofakes" var fake = &foofakes.FakeMySpecialInterface{} ``` -------------------------------- ### Example JSON Data Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/blob/windows-2019/stembuild/vendor/github.com/mitchellh/mapstructure/README.md Sample JSON structure that requires dynamic decoding based on the type field. ```json { "type": "person", "name": "Mitchell" } ``` -------------------------------- ### Verify Windows Features via PowerShell Source: https://github.com/cloudfoundry/bosh-windows-stemcell-builder/wiki/[Deprecated]-Creating-a-vSphere-2012-R2-Windows-Stemcell Check the installation status of required Windows features for Garden-Windows deployments on Windows 2012R2. ```powershell Get-WindowsFeature "Web-Webserver" | Where InstallState -Eq "Installed" Get-WindowsFeature "Web-WebSockets" | Where InstallState -Eq "Installed" Get-WindowsFeature "AS-Web-Support" | Where InstallState -Eq "Installed" Get-WindowsFeature "AS-NET-Framework" | Where InstallState -Eq "Installed" Get-WindowsFeature "Web-WHC" | Where InstallState -Eq "Installed" Get-WindowsFeature "Web-ASP" | Where InstallState -Eq "Installed" ```