### Install Bundler Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Install the Ruby gem Bundler, which is required for the vendoring script. ```ruby gem install bundler ``` -------------------------------- ### Get BOSH AWS CPI Information Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Returns CPI information, including supported stemcell formats and the API version. The example shows the expected output structure. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) info = cpi.info # Returns: # { # "stemcell_formats" => ["aws-raw", "aws-light"], # "api_version" => 1 # } ``` -------------------------------- ### Get Attached Disk IDs using BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Returns the volume IDs of all EBS volumes attached to a specified EC2 instance. The example shows the expected output format. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) disk_ids = cpi.get_disks("i-0123456789abcdef0") # Returns: ["vol-root123", "vol-ephemeral456", "vol-persistent789"] ``` -------------------------------- ### Create BOSH Release Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Create the BOSH release artifact. This command should be run from the root directory of the project. ```bash bosh create-release --force ``` -------------------------------- ### Source Lifecycle Environment File Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Load the environment variables defined in the `lifecycle.env` file. This is a prerequisite for running lifecycle tests. ```bash . ~/scratch/aws/lifecycle.env ``` -------------------------------- ### Create Disk with BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates an EBS volume with specific size and properties, optionally associated with an instance for AZ placement. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) # Create a 100 GB gp3 disk disk_id = cpi.create_disk( 102400, # size in MiB (100 GB) { # cloud_properties "type" => "gp3", "iops" => 3000, "throughput" => 125, "encrypted" => true, "kms_key_arn" => "arn:aws:kms:us-east-1:123456789012:key/..." }, "i-0123456789abcdef0" # instance_id (for AZ placement) ) # Returns: "vol-0123456789abcdef0" ``` -------------------------------- ### Configure Lifecycle Test Environment Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Set up the necessary environment variables for running lifecycle tests. This includes AWS credentials, KMS key ARNs, and optionally the default region or session token. ```bash export AWS_ACCESS_KEY_ID="AKIAINSxxxxxxxxxxxxx" export AWS_SECRET_ACCESS_KEY="LvgQOmCtjL1yhcxxxxxxxxxxxxxxxxxxxxxxxxxx" # KMS keys used for encrypted disk tests export BOSH_AWS_KMS_KEY_ARN="arn:aws:kms:us-east-1:" export BOSH_AWS_KMS_KEY_ARN_OVERRIDE="arn:aws:kms:us-east-1:" # Optionally use alternate region # export AWS_DEFAULT_REGION="us-west-1" # Optionally use STS Tokens # export AWS_SESSION_TOKEN="xxxxxxxx" ``` -------------------------------- ### Create Disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates an EBS disk with specified properties. Supports different disk types like 'io1' with configurable IOPS. ```APIDOC ## POST /disks ### Description Creates an EBS disk with specified properties. Supports different disk types like 'io1' with configurable IOPS. ### Method POST ### Endpoint /disks ### Parameters #### Query Parameters - **size** (integer) - Required - The size of the disk in MiB. - **disk_type** (object) - Required - Specifies the type of disk and its properties. - **type** (string) - Required - The type of EBS volume (e.g., "io1", "gp2", "st1", "sc1", "standard"). - **iops** (integer) - Optional - The number of I/O operations per second (required for "io1" type). - **instance_id** (string) - Optional - The ID of the EC2 instance to which the disk should be attached upon creation. ### Request Example ```json { "size": 204800, "disk_type": { "type": "io1", "iops": 10000 }, "instance_id": "i-0123456789abcdef0" } ``` ### Response #### Success Response (200) - **disk_id** (string) - The ID of the newly created EBS volume. #### Response Example ```json { "disk_id": "vol-0123456789abcdef0" } ``` ``` -------------------------------- ### Create IOPS-provisioned io1 disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates an io1 high-performance EBS disk with specified IOPS. Requires disk size in GiB and IOPS. ```ruby disk_id = cpi.create_disk( 204800, # 200 GB { "type" => "io1", "iops" => 10000 }, "i-0123456789abcdef0" ) ``` -------------------------------- ### Run Vendoring Script Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Execute the vendoring script to manage Ruby gems. This should be run from the `src/bosh_aws_cpi` directory. ```bash ./vendor_gems ``` -------------------------------- ### create_disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates a new EBS volume with specified size and properties. ```APIDOC ## create_disk ### Description Creates a new EBS volume with specified size and properties. Returns the volume ID. ### Parameters - **size** (integer) - Required - Size of the disk in MiB. - **cloud_properties** (object) - Required - Disk configuration including type, IOPS, throughput, and encryption settings. - **instance_id** (string) - Optional - Instance ID for AZ placement. ### Response - **volume_id** (string) - The ID of the created EBS volume. ``` -------------------------------- ### create_vm Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates a new EC2 instance with the specified stemcell, instance type, and network configuration. ```APIDOC ## create_vm ### Description Creates a new EC2 instance with the specified stemcell, instance type, and network configuration. Returns the instance ID and network info. ### Parameters - **agent_id** (string) - Required - Unique identifier for the BOSH agent. - **stemcell_id** (string) - Required - The AMI ID to use for the instance. - **vm_type** (object) - Required - Resource pool configuration including instance type, disk settings, and spot instance options. - **network_spec** (object) - Required - Network configuration including subnets and VIPs. - **disk_locality** (array) - Optional - List of volume IDs for placement hints. - **environment** (object) - Optional - Environment tags for the instance. ### Response - **instance_id** (string) - The ID of the created EC2 instance. - **network_info** (object) - The network configuration applied to the instance. ``` -------------------------------- ### Run Unit Tests Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Execute the unit tests for the CPI Ruby code. Ensure you are in the project's root directory. ```bash source .envrc ./src/bosh_aws_cpi/bin/test-unit ``` ```bash cd src/bosh_aws_cpi ./bin/test-unit ``` -------------------------------- ### Run Integration Tests Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Execute the integration tests for the BOSH AWS CPI. This command assumes the environment variables for testing have been sourced. ```bash src/bosh_aws_cpi/bin/test-integration ``` -------------------------------- ### Create VM with BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Provisions a new EC2 instance using the CPI v2 API, specifying stemcell, instance type, and network configuration. ```ruby # Create a VM with CPI v2 cpi = Bosh::AwsCloud::CloudV2.new(cloud_config) instance_id, network_info = cpi.create_vm( "agent-id-12345", # agent_id "ami-0123456789abcdef0", # stemcell_id (AMI) { # vm_type (resource pool) "instance_type" => "m5.large", "availability_zone" => "us-east-1a", "ephemeral_disk" => { "size" => 25000, "type" => "gp3", "iops" => 3000, "throughput" => 125, "encrypted" => true }, "root_disk" => { "size" => 50000, "type" => "gp3" }, "spot_bid_price" => 0.05, # Optional: use spot instances "spot_ondemand_fallback" => true, # Fallback to on-demand if spot fails "lb_target_groups" => ["my-target-group"], "elbs" => ["my-classic-elb"], "iam_instance_profile" => "my-iam-role", "source_dest_check" => false, "advertised_routes" => [ {"table_id" => "rtb-12345", "destination" => "10.0.0.0/8"} ] }, { # network_spec "default" => { "type" => "manual", "ip" => "10.0.1.10", "netmask" => "255.255.255.0", "gateway" => "10.0.1.1", "dns" => ["10.0.0.2"], "cloud_properties" => { "subnet" => "subnet-12345678", "security_groups" => ["sg-12345678"] } }, "vip" => { "type" => "vip", "ip" => "52.1.2.3" # Elastic IP to associate } }, ["vol-12345678"], # disk_locality (placement hint) {"bosh" => {"tags" => {"env" => "prod"}}} # environment (tags) ) # Returns: ["i-0123456789abcdef0", {"default" => {...}, "vip" => {...}}] ``` -------------------------------- ### calculate_vm_cloud_properties Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Maps generic VM requirements to AWS-specific cloud properties. ```APIDOC ## calculate_vm_cloud_properties ### Description Maps generic VM requirements (cpu, ram, disk) to AWS-specific instance types and properties. ### Request Body - **cpu** (integer) - Required - Number of CPUs - **ram** (integer) - Required - RAM in MB - **ephemeral_disk_size** (integer) - Required - Disk size in MB ### Response #### Success Response (200) - **instance_type** (string) - The mapped AWS instance type - **ephemeral_disk** (object) - Configuration for the ephemeral disk ``` -------------------------------- ### Create stemcell from light image Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Registers a light stemcell by verifying the existence of a specified AMI. Returns the AMI ID with 'light' suffix. ```ruby # Create from light stemcell (just verifies AMI exists) stemcell_id = cpi.create_stemcell( "/tmp/light-bosh-stemcell.tgz", { "ami" => { "us-east-1" => "ami-0123456789abcdef0", "us-west-2" => "ami-0987654321fedcba0" } } ) # Returns: "ami-0123456789abcdef0 light" ``` -------------------------------- ### Snapshot Disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates a snapshot of an EBS volume and applies metadata tags. The operation waits until the snapshot creation is completed. ```APIDOC ## POST /disks/{disk_id}/snapshots ### Description Creates a snapshot of an EBS volume and applies metadata tags. The operation waits until the snapshot creation is completed. ### Method POST ### Endpoint /disks/{disk_id}/snapshots ### Parameters #### Path Parameters - **disk_id** (string) - Required - The ID of the EBS volume to snapshot. #### Request Body - **metadata** (object) - Optional - Metadata tags to apply to the snapshot. - **deployment** (string) - Optional - Deployment name. - **job** (string) - Optional - Job name. - **index** (string) - Optional - Instance index. - **instance_id** (string) - Optional - Instance ID. - **director_name** (string) - Optional - Director name. ### Request Example ```json { "metadata": { "deployment": "my-deployment", "job": "my-job", "index": "0", "instance_id": "abc-123", "director_name": "my-director" } } ``` ### Response #### Success Response (200) - **snapshot_id** (string) - The ID of the created EBS snapshot. #### Response Example ```json { "snapshot_id": "snap-0123456789abcdef0" } ``` ``` -------------------------------- ### Calculate VM Cloud Properties using BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Maps generic VM requirements (CPU, RAM, ephemeral disk size) to AWS-specific cloud properties, determining the appropriate EC2 instance type and ephemeral disk configuration. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) cloud_props = cpi.calculate_vm_cloud_properties({ "cpu" => 4, "ram" => 8192, "ephemeral_disk_size" => 50000 }) # Returns: # { # "instance_type" => "m5.xlarge", # "ephemeral_disk" => {"size" => 50000} # } ``` -------------------------------- ### Create stemcell from heavy image Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates a stemcell (AMI) from a local stemcell image file. Requires running on EC2 and returns the AMI ID. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) # Create from heavy stemcell (requires running on EC2) stemcell_id = cpi.create_stemcell( "/tmp/bosh-stemcell.tgz", { "name" => "bosh-aws-xen-hvm-ubuntu-jammy-go_agent", "version" => "1.234", "architecture" => "x86_64", "root_device_name" => "/dev/sda1", "disk" => 3072 } ) # Returns: "ami-0123456789abcdef0" ``` -------------------------------- ### Ad-hoc Testing: Deploy BOSH Director Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Deploy a BOSH director for ad-hoc testing purposes without running the standard integration tests. This involves commenting out lines in the test script and using `bosh create-env` with Terraform state outputs. ```bash . ~/scratch/aws/lifecycle.env src/bosh_aws_cpi/bin/test-integration bosh create-env ~/scratch/aws/bosh-minimal.yml \ -v PublicSubnetID=$(jq -r '.modules[0].outputs.PublicSubnetID.value' < /tmp/integration-terraform-state-us-west-1.tfstate) \ -v DeploymentEIP=$(jq -r '.modules[0].outputs.DeploymentEIP.value' < /tmp/integration-terraform-state-us-west-1.tfstate) \ -v access_key_id=$AWS_ACCESS_KEY_ID \ -v secret_access_key=$AWS_SECRET_ACCESS_KEY ``` -------------------------------- ### Run Specific Integration Tests Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Execute a specific integration test by providing RSpec arguments. This allows targeting a particular test file and line number. ```bash RSPEC_ARGUMENTS=spec/integration/lifecycle_spec.rb:247 src/bosh_aws_cpi/bin/test-integration ``` -------------------------------- ### Create EBS volume snapshot Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates a snapshot of an EBS volume and applies metadata tags. The operation returns the snapshot ID and waits for the snapshot state to become 'completed'. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) snapshot_id = cpi.snapshot_disk( "vol-0123456789abcdef0", { "deployment" => "my-deployment", "job" => "my-job", "index" => "0", "instance_id" => "abc-123", "director_name" => "my-director" } ) # Returns: "snap-0123456789abcdef0" # Waits until snapshot state becomes 'completed' ``` -------------------------------- ### info Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Returns CPI information including supported stemcell formats and API version. ```APIDOC ## info ### Description Returns metadata about the CPI capabilities. ### Response #### Success Response (200) - **stemcell_formats** (array) - Supported stemcell formats - **api_version** (integer) - The CPI API version ``` -------------------------------- ### reboot_vm Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Soft reboots an EC2 instance. ```APIDOC ## reboot_vm ### Description Soft reboots an EC2 instance. ### Parameters #### Path Parameters - **vm_id** (string) - Required - The ID of the EC2 instance to reboot. ``` -------------------------------- ### Has VM? Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Checks if an EC2 instance exists and is not in a terminated state. ```APIDOC ## GET /instances/{instance_id}/exists ### Description Checks if an EC2 instance exists and is not in a terminated state. ### Method GET ### Endpoint /instances/{instance_id}/exists ### Parameters #### Path Parameters - **instance_id** (string) - Required - The ID of the EC2 instance. ### Response #### Success Response (200) - **exists** (boolean) - True if the instance exists and is not terminated, false otherwise. #### Response Example ```json { "exists": true } ``` ``` -------------------------------- ### Configure BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt JSON configuration file defining AWS credentials, region, and default settings for the BOSH Director. ```json { "cloud": { "plugin": "aws", "properties": { "aws": { "credentials_source": "static", "access_key_id": "AKIAIOSFODNN7EXAMPLE", "secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "region": "us-east-1", "default_key_name": "bosh", "default_security_groups": ["bosh-sg"], "default_iam_instance_profile": "bosh-director", "max_retries": 8, "encrypted": true, "kms_key_arn": "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012", "metadata_options": { "http_endpoint": "enabled", "http_tokens": "required" }, "dualstack": false }, "registry": { "endpoint": "http://admin:password@registry.example.com:25777", "user": "admin", "password": "password" }, "agent": { "ntp": ["0.pool.ntp.org", "1.pool.ntp.org"], "mbus": "nats://nats:password@nats.example.com:4222" } } } } ``` -------------------------------- ### Create encrypted light stemcell Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates an encrypted copy of a light stemcell by specifying an AMI and KMS key ARN. Returns the encrypted AMI ID. ```ruby # Create encrypted copy of light stemcell stemcell_id = cpi.create_stemcell( "/tmp/light-bosh-stemcell.tgz", { "ami" => {"us-east-1" => "ami-0123456789abcdef0"}, "encrypted" => true, "kms_key_arn" => "arn:aws:kms:us-east-1:123456789012:key/..." } ) # Returns encrypted AMI ID (copies and encrypts the source AMI) ``` -------------------------------- ### Set Disk Metadata Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Sets tags on an EBS volume. ```APIDOC ## PUT /disks/{disk_id}/metadata ### Description Sets tags on an EBS volume. ### Method PUT ### Endpoint /disks/{disk_id}/metadata ### Parameters #### Path Parameters - **disk_id** (string) - Required - The ID of the EBS volume. #### Request Body - **metadata** (object) - Required - A key-value map of metadata tags to set. - **deployment** (string) - Optional - Deployment name. - **instance_group** (string) - Optional - Instance group name. - **attached_at** (string) - Optional - Timestamp of attachment. ### Request Example ```json { "metadata": { "deployment": "my-deployment", "instance_group": "database", "attached_at": "2024-01-15T10:30:00Z" } } ``` ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` -------------------------------- ### Set VM Metadata Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Sets tags on an EC2 instance and all its attached volumes. The 'Name' tag is automatically set based on job/index or an explicit 'name' field. ```APIDOC ## PUT /instances/{instance_id}/metadata ### Description Sets tags on an EC2 instance and all its attached volumes. The 'Name' tag is automatically set based on job/index or an explicit 'name' field. ### Method PUT ### Endpoint /instances/{instance_id}/metadata ### Parameters #### Path Parameters - **instance_id** (string) - Required - The ID of the EC2 instance. #### Request Body - **metadata** (object) - Required - A key-value map of metadata tags to set. - **job** (string) - Optional - Job name. - **index** (string) - Optional - Instance index. - **name** (string) - Optional - Explicit name for the instance. - **deployment** (string) - Optional - Deployment name. - **director** (string) - Optional - Director name. - **created_at** (string) - Optional - Timestamp of creation. ### Request Example ```json { "metadata": { "job": "web", "index": "0", "name": "web/0", "deployment": "my-deployment", "director": "my-director", "created_at": "2024-01-15T10:30:00Z" } } ``` ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` -------------------------------- ### Create Stemcell Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Creates a stemcell (AMI) from a stemcell image or registers a light stemcell. Supports creating encrypted copies of light stemcells. ```APIDOC ## POST /stemcells ### Description Creates a stemcell (AMI) from a stemcell image or registers a light stemcell. Supports creating encrypted copies of light stemcells. ### Method POST ### Endpoint /stemcells ### Parameters #### Request Body - **image_path** (string) - Required - Path to the stemcell image archive (e.g., a .tgz file). - **manifest** (object) - Required - Manifest details of the stemcell. - **name** (string) - Required - Name of the stemcell. - **version** (string) - Required - Version of the stemcell. - **architecture** (string) - Required - Architecture of the stemcell (e.g., "x86_64"). - **root_device_name** (string) - Required - The root device name for the AMI. - **disk** (integer) - Required - The size of the root disk in GiB. - **ami** (object) - Optional - Mapping of region to AMI ID for light stemcells. - **region** (string) - Required - AWS region (e.g., "us-east-1"). - **ami_id** (string) - Required - AMI ID for the specified region. - **encrypted** (boolean) - Optional - If true, creates an encrypted copy of the light stemcell. - **kms_key_arn** (string) - Optional - The ARN of the KMS key to use for encryption (required if `encrypted` is true). ### Request Example (Heavy Stemcell) ```json { "image_path": "/tmp/bosh-stemcell.tgz", "manifest": { "name": "bosh-aws-xen-hvm-ubuntu-jammy-go_agent", "version": "1.234", "architecture": "x86_64", "root_device_name": "/dev/sda1", "disk": 3072 } } ``` ### Request Example (Light Stemcell) ```json { "image_path": "/tmp/light-bosh-stemcell.tgz", "manifest": { "ami": { "us-east-1": "ami-0123456789abcdef0", "us-west-2": "ami-0987654321fedcba0" } } } ``` ### Request Example (Encrypted Light Stemcell) ```json { "image_path": "/tmp/light-bosh-stemcell.tgz", "manifest": { "ami": {"us-east-1": "ami-0123456789abcdef0"}, "encrypted": true, "kms_key_arn": "arn:aws:kms:us-east-1:123456789012:key/..." } } ``` ### Response #### Success Response (200) - **stemcell_id** (string) - The ID of the created stemcell (AMI ID). For light stemcells, it might include " light" suffix. #### Response Example ```json { "stemcell_id": "ami-0123456789abcdef0" } ``` ``` -------------------------------- ### Set disk metadata (tags) on EBS volume Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Sets tags on an EBS volume to provide metadata for identification and management. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) cpi.set_disk_metadata( "vol-0123456789abcdef0", { "deployment" => "my-deployment", "instance_group" => "database", "attached_at" => "2024-01-15T10:30:00Z" } ) ``` -------------------------------- ### Attach Disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Attaches an EBS volume to an EC2 instance. Returns a device path hint for the attached disk. ```APIDOC ## POST /instances/{instance_id}/disks ### Description Attaches an EBS volume to an EC2 instance. Returns a device path hint for the attached disk. ### Method POST ### Endpoint /instances/{instance_id}/disks ### Parameters #### Path Parameters - **instance_id** (string) - Required - The ID of the EC2 instance. #### Request Body - **disk_id** (string) - Required - The ID of the EBS volume to attach. ### Request Example ```json { "disk_id": "vol-0123456789abcdef0" } ``` ### Response #### Success Response (200) - **device_path** (string) - A hint for the device path where the disk is attached (e.g., "/dev/sdf" or "/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0123456789abcdef0"). #### Response Example ```json { "device_path": "/dev/sdf" } ``` ``` -------------------------------- ### delete_vm Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Terminates an EC2 instance and cleans up associated resources. ```APIDOC ## delete_vm ### Description Terminates an EC2 instance and cleans up associated resources including registry settings. ### Parameters - **instance_id** (string) - Required - The ID of the EC2 instance to terminate. ``` -------------------------------- ### Reboot VM using BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Soft reboots an EC2 instance. Initiates the reboot process and returns immediately without tracking the instance state. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) cpi.reboot_vm("i-0123456789abcdef0") # Initiates reboot, returns immediately (no state tracking) ``` -------------------------------- ### Keep Terraform Environment After Integration Tests Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Run integration tests while keeping the Terraform-created environment persistent after successful execution. This is useful for debugging. ```bash src/bosh_aws_cpi/bin/test-integration keep-alive ``` -------------------------------- ### get_disks Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Returns the volume IDs of all EBS volumes attached to an instance. ```APIDOC ## get_disks ### Description Returns the volume IDs of all EBS volumes attached to an instance. ### Parameters #### Path Parameters - **vm_id** (string) - Required - The ID of the EC2 instance. ### Response #### Success Response (200) - **disk_ids** (array) - List of EBS volume IDs. ``` -------------------------------- ### Attach EBS volume to EC2 instance Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Attaches an EBS volume to an EC2 instance. CPI v2 returns a device path hint for the attached volume. ```ruby cpi = Bosh::AwsCloud::CloudV2.new(cloud_config) # Attach disk to instance (CPI v2 returns device path) device_path = cpi.attach_disk("i-0123456789abcdef0", "vol-0123456789abcdef0") # Returns device path based on instance type: # - Standard instances: "/dev/sdf" through "/dev/sdp" # - NVMe/Nitro instances: "/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0123456789abcdef0" ``` -------------------------------- ### Run ERB Job Templates Unit Tests Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Execute unit tests specifically for the ERB templates rendered by the jobs. This can be run separately from other unit tests. ```bash source .envrc ./src/bosh_aws_cpi/bin/test-unit spec/unit/bosh_release ``` ```bash cd src/bosh_aws_cpi ./bin/test-unit spec/unit/bosh_release ``` -------------------------------- ### Set VM metadata (tags) on EC2 instance and volumes Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Sets AWS tags on an EC2 instance and all its attached EBS volumes. The 'Name' tag is automatically generated from job/index or an explicit 'name' field. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) cpi.set_vm_metadata( "i-0123456789abcdef0", { "job" => "web", "index" => "0", "name" => "web/0", "deployment" => "my-deployment", "director" => "my-director", "created_at" => "2024-01-15T10:30:00Z" } ) # Creates AWS tags on instance and all attached volumes # 'Name' tag is automatically set from job/index or explicit 'name' ``` -------------------------------- ### Delete VM with BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Terminates an EC2 instance by its ID. The operation waits for the instance state to reach 'terminated'. ```ruby cpi = Bosh::AwsCloud::CloudV2.new(cloud_config) # Delete a VM by instance ID cpi.delete_vm("i-0123456789abcdef0") # Instance will be terminated and wait until state becomes 'terminated' # Fast path delete (marks for deletion but doesn't wait) # Controlled by aws.fast_path_delete config option ``` -------------------------------- ### Has Disk? Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Checks if an EBS volume exists. Returns false if the volume is not found (InvalidVolume.NotFound). ```APIDOC ## GET /disks/{disk_id}/exists ### Description Checks if an EBS volume exists. Returns false if the volume is not found (InvalidVolume.NotFound). ### Method GET ### Endpoint /disks/{disk_id}/exists ### Parameters #### Path Parameters - **disk_id** (string) - Required - The ID of the EBS volume. ### Response #### Success Response (200) - **exists** (boolean) - True if the volume exists, false otherwise. #### Response Example ```json { "exists": true } ``` ``` -------------------------------- ### Resize EBS volume Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Extends an EBS volume to a larger size; shrinking is not supported. The volume must be detached before resizing, and the operation waits for modification completion or optimization. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) # Resize disk to 200 GB (size in MiB) cpi.resize_disk("vol-0123456789abcdef0", 204800) # Volume must be detached before resizing # Waits until modification completes or is optimizing ``` -------------------------------- ### Check if EC2 instance exists Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Checks if an EC2 instance exists and is not in a 'terminated' state. Returns true if the instance exists and is active, false otherwise. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) exists = cpi.has_vm?("i-0123456789abcdef0") # Returns: true if instance exists and state is not 'terminated' # Returns: false otherwise ``` -------------------------------- ### Retrieve Current VM ID using BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Retrieves the instance ID of the current EC2 instance. This method only works when the CPI is running on EC2 and uses the EC2 metadata service (IMDSv2 with token). It throws a CloudError if not running on EC2 or if metadata is unavailable. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) instance_id = cpi.current_vm_id # Returns: "i-0123456789abcdef0" # Uses EC2 metadata service (IMDSv2 with token) # Throws CloudError if not running on EC2 or metadata unavailable ``` -------------------------------- ### Destroy Terraform Environment Without Running Tests Source: https://github.com/cloudfoundry/bosh-aws-cpi-release/blob/master/docs/development.md Force the destruction of the Terraform-created environment without executing any tests. This is useful for cleanup. ```bash src/bosh_aws_cpi/bin/test-integration destroy ``` -------------------------------- ### current_vm_id Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Retrieves the instance ID of the current EC2 instance. ```APIDOC ## current_vm_id ### Description Retrieves the instance ID of the current EC2 instance. Only works when the CPI is running on an EC2 instance using the metadata service. ### Response #### Success Response (200) - **instance_id** (string) - The ID of the current EC2 instance. ``` -------------------------------- ### Resize Disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Extends an EBS volume to a larger size. This operation requires the volume to be detached and waits for the modification to complete or optimize. ```APIDOC ## PUT /disks/{disk_id} ### Description Extends an EBS volume to a larger size. This operation requires the volume to be detached and waits for the modification to complete or optimize. Cannot shrink volumes. ### Method PUT ### Endpoint /disks/{disk_id} ### Parameters #### Path Parameters - **disk_id** (string) - Required - The ID of the EBS volume to resize. #### Request Body - **size** (integer) - Required - The new desired size of the disk in MiB. ### Request Example ```json { "size": 204800 } ``` ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` -------------------------------- ### Check if EBS volume exists Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Checks if an EBS volume exists by its ID. Returns true if the volume exists, and false if it is not found (InvalidVolume.NotFound). ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) exists = cpi.has_disk?("vol-0123456789abcdef0") # Returns: true if volume exists # Returns: false if InvalidVolume.NotFound ``` -------------------------------- ### Minimum IAM Policy for BOSH AWS CPI Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt The baseline IAM policy required for the BOSH AWS CPI to function. Additional permissions may be necessary depending on the specific features being used, such as heavy stemcells, snapshots, Elastic IPs, or load balancers. ```json { "Version": "2012-10-17", "Statement": [ { "Sid": "BaselinePolicy", "Effect": "Allow", "Action": [ "ec2:AttachVolume", "ec2:CreateTags", "ec2:CreateVolume", "ec2:DeleteVolume", "ec2:DescribeAvailabilityZones", "ec2:DescribeImages", "ec2:DescribeInstances", "ec2:DescribeRegions", "ec2:DescribeSecurityGroups", "ec2:DescribeSubnets", "ec2:DescribeVolumes", "ec2:DetachVolume", "ec2:RebootInstances", "ec2:RunInstances", "ec2:TerminateInstances", "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:DescribeNetworkInterfaces", "ec2:ModifyNetworkInterfaceAttribute" ], "Resource": "*" }, { "Sid": "RequiredIfUsingHeavyStemcells", "Effect": "Allow", "Action": ["ec2:RegisterImage", "ec2:DeregisterImage"], "Resource": "*" }, { "Sid": "RequiredIfUsingSnapshotsFeature", "Effect": "Allow", "Action": ["ec2:CreateSnapshot", "ec2:DeleteSnapshot", "ec2:DescribeSnapshots"], "Resource": "*" }, { "Sid": "RequiredIfUsingElasticIPs", "Effect": "Allow", "Action": ["ec2:AssociateAddress", "ec2:DescribeAddresses"], "Resource": "*" }, { "Sid": "RequiredIfUsingELBCloudProperties", "Effect": "Allow", "Action": [ "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:RegisterInstancesWithLoadBalancer" ], "Resource": "*" }, { "Sid": "RequiredIfUsingLBTargetGroupCloudProperties", "Effect": "Allow", "Action": [ "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetHealth", "elasticloadbalancing:RegisterTargets" ], "Resource": "*" }, { "Sid": "RequiredIfUsingCustomKMSKeys", "Effect": "Allow", "Action": ["kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:CreateGrant", "kms:DescribeKey*"], "Resource": ["arn:aws:kms:REGION:ACCOUNT:key/KEY_ID"] } ] } ``` -------------------------------- ### Delete stemcell (AMI and snapshots) Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Deletes a stemcell by deregistering the AMI and removing associated EBS snapshots. Handles both regular and light stemcells. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) cpi.delete_stemcell("ami-0123456789abcdef0") # For light stemcells: "ami-0123456789abcdef0 light" # Deregisters AMI and deletes all associated EBS snapshots ``` -------------------------------- ### Detach Disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Detaches an EBS volume from an EC2 instance. The operation waits until the volume state becomes 'available'. ```APIDOC ## DELETE /instances/{instance_id}/disks/{disk_id} ### Description Detaches an EBS volume from an EC2 instance. The operation waits until the volume state becomes 'available'. ### Method DELETE ### Endpoint /instances/{instance_id}/disks/{disk_id} ### Parameters #### Path Parameters - **instance_id** (string) - Required - The ID of the EC2 instance. - **disk_id** (string) - Required - The ID of the EBS volume to detach. ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` -------------------------------- ### Detach EBS volume from EC2 instance Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Detaches an EBS volume from an EC2 instance. The operation waits until the volume state becomes 'available'. ```ruby cpi = Bosh::AwsCloud::CloudV2.new(cloud_config) # Detach disk from instance cpi.detach_disk("i-0123456789abcdef0", "vol-0123456789abcdef0") # Waits until the volume state becomes 'available' ``` -------------------------------- ### Delete EBS snapshot Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Deletes an EBS snapshot. This operation silently succeeds if the snapshot does not exist. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) cpi.delete_snapshot("snap-0123456789abcdef0") # Silently succeeds if snapshot doesn't exist ``` -------------------------------- ### Delete Disk Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Deletes an EBS volume after ensuring it is detached. The operation may retry if the volume is still in use and waits for deletion completion unless fast path delete is enabled. ```APIDOC ## DELETE /disks/{disk_id} ### Description Deletes an EBS volume after ensuring it is detached. The operation may retry if the volume is still in use and waits for deletion completion unless fast path delete is enabled. ### Method DELETE ### Endpoint /disks/{disk_id} ### Parameters #### Path Parameters - **disk_id** (string) - Required - The ID of the EBS volume to delete. ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` -------------------------------- ### Delete EBS volume Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Deletes an EBS volume after ensuring it is detached. The CPI will retry if the volume is still in use and waits for deletion unless fast_path_delete is enabled. ```ruby cpi = Bosh::AwsCloud::CloudV1.new(cloud_config) # Delete a disk by volume ID cpi.delete_disk("vol-0123456789abcdef0") # Will retry if volume is still in use # Waits until volume is deleted (unless fast_path_delete is enabled) ``` -------------------------------- ### Delete Stemcell Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Deletes a stemcell by deregistering the AMI and deleting associated EBS snapshots. ```APIDOC ## DELETE /stemcells/{stemcell_id} ### Description Deletes a stemcell by deregistering the AMI and deleting associated EBS snapshots. ### Method DELETE ### Endpoint /stemcells/{stemcell_id} ### Parameters #### Path Parameters - **stemcell_id** (string) - Required - The ID of the stemcell (AMI ID) to delete. For light stemcells, append " light" to the ID. ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` -------------------------------- ### Delete Snapshot Source: https://context7.com/cloudfoundry/bosh-aws-cpi-release/llms.txt Deletes an EBS snapshot. This operation silently succeeds if the snapshot does not exist. ```APIDOC ## DELETE /snapshots/{snapshot_id} ### Description Deletes an EBS snapshot. This operation silently succeeds if the snapshot does not exist. ### Method DELETE ### Endpoint /snapshots/{snapshot_id} ### Parameters #### Path Parameters - **snapshot_id** (string) - Required - The ID of the EBS snapshot to delete. ### Response #### Success Response (200) - (No content) #### Response Example (No content) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.