diff --git a/lib/bosh-bootstrap/microbosh_providers/aws.rb b/lib/bosh-bootstrap/microbosh_providers/aws.rb index 03c1029..8540c7d 100644 --- a/lib/bosh-bootstrap/microbosh_providers/aws.rb +++ b/lib/bosh-bootstrap/microbosh_providers/aws.rb @@ -29,6 +29,9 @@ def to_hash data["apply_spec"]["properties"]["dns"] = {} data["apply_spec"]["properties"]["dns"]["recursor"] = dns end + if proxy? + data["apply_spec"]["properties"]["director"] = {"env" => proxy} + end data end diff --git a/lib/bosh-bootstrap/microbosh_providers/base.rb b/lib/bosh-bootstrap/microbosh_providers/base.rb index 091e275..827cd5d 100644 --- a/lib/bosh-bootstrap/microbosh_providers/base.rb +++ b/lib/bosh-bootstrap/microbosh_providers/base.rb @@ -55,6 +55,14 @@ def private_key_path settings.key_pair.path end + def proxy + settings.proxy.to_hash + end + + def proxy? + settings.exists?("proxy") + end + def jenkins_bucket "bosh-jenkins-artifacts" end diff --git a/lib/bosh-bootstrap/microbosh_providers/openstack.rb b/lib/bosh-bootstrap/microbosh_providers/openstack.rb index a28a89b..d8635e8 100644 --- a/lib/bosh-bootstrap/microbosh_providers/openstack.rb +++ b/lib/bosh-bootstrap/microbosh_providers/openstack.rb @@ -4,7 +4,7 @@ module Bosh::Bootstrap::MicroboshProviders class OpenStack < Base def to_hash - super.deep_merge({ + data = super.deep_merge({ "network"=>network_configuration, "resources"=> {"persistent_disk"=>persistent_disk, @@ -23,6 +23,10 @@ def to_hash "hm"=>{"resurrector_enabled" => true}, "ntp"=>["0.north-america.pool.ntp.org","1.north-america.pool.ntp.org"]}} }) + if proxy? + data["apply_spec"]["properties"]["director"]["env"] = proxy + end + data end # For Nova/Floating IP: diff --git a/spec/assets/microbosh_yml/micro_bosh.aws_vpc_proxy.yml b/spec/assets/microbosh_yml/micro_bosh.aws_vpc_proxy.yml new file mode 100644 index 0000000..30af523 --- /dev/null +++ b/spec/assets/microbosh_yml/micro_bosh.aws_vpc_proxy.yml @@ -0,0 +1,49 @@ +--- +name: test-bosh +logging: + level: DEBUG +network: + type: manual + ip: 1.2.3.4 + dns: + - 1.2.0.2 + cloud_properties: + subnet: subnet-123456 +resources: + persistent_disk: 32768 + cloud_properties: + instance_type: m3.medium + ephemeral_disk: + size: 163840 + type: gp2 +cloud: + plugin: aws + properties: + aws: + access_key_id: ACCESS + secret_access_key: SECRET + region: us-west-2 + ec2_endpoint: ec2.us-west-2.amazonaws.com + default_security_groups: + - ssh-vpc-123456 + - dns-server-vpc-123456 + - bosh-vpc-123456 + default_key_name: test-bosh + ec2_private_key: ~/.microbosh/ssh/test-bosh +apply_spec: + agent: + blobstore: + address: 1.2.3.4 + nats: + address: 1.2.3.4 + properties: + hm: + resurrector_enabled: true + aws_registry: + address: 1.2.3.4 + dns: + recursor: 1.2.0.2 + director: + env: + http_proxy: http://192.168.1.100:8080 + https_proxy: https://192.168.1.100:8080 diff --git a/spec/assets/microbosh_yml/micro_bosh.openstack.with_proxy.yml b/spec/assets/microbosh_yml/micro_bosh.openstack.with_proxy.yml new file mode 100644 index 0000000..f707a98 --- /dev/null +++ b/spec/assets/microbosh_yml/micro_bosh.openstack.with_proxy.yml @@ -0,0 +1,49 @@ +--- +name: test-bosh +logging: + level: DEBUG +network: + type: dynamic + vip: 1.2.3.4 + cloud_properties: + net_id: 7b8788eb-b49e-4424-9065-75a6b07094ea +resources: + persistent_disk: 32768 + cloud_properties: + instance_type: m1.medium +cloud: + plugin: openstack + properties: + openstack: + auth_url: http://10.0.0.2:5000/v2.0/tokens + username: USER + api_key: PASSWORD + tenant: TENANT + region: REGION + default_security_groups: + - ssh + - dns-server + - bosh + default_key_name: test-bosh + state_timeout: 300 + private_key: ~/.microbosh/ssh/test-bosh + connection_options: + ssl_verify_peer: false + boot_from_volume: false +apply_spec: + agent: + blobstore: + address: 1.2.3.4 + nats: + address: 1.2.3.4 + properties: + director: + max_threads: 3 + env: + http_proxy: http://192.168.1.100:8080 + https_proxy: https://192.168.1.100:8080 + hm: + resurrector_enabled: true + ntp: + - 0.north-america.pool.ntp.org + - 1.north-america.pool.ntp.org diff --git a/spec/unit/microbosh_providers/aws_spec.rb b/spec/unit/microbosh_providers/aws_spec.rb index 58c17e2..d32d06a 100644 --- a/spec/unit/microbosh_providers/aws_spec.rb +++ b/spec/unit/microbosh_providers/aws_spec.rb @@ -207,5 +207,28 @@ expect(File).to be_exists(microbosh_yml) yaml_files_match(microbosh_yml, spec_asset("microbosh_yml/micro_bosh.aws_vpc_recursor.yml")) end + + it "adds proxy if present" do + setting "provider.name", "aws" + setting "provider.region", "us-west-2" + setting "provider.credentials.aws_access_key_id", "ACCESS" + setting "provider.credentials.aws_secret_access_key", "SECRET" + setting "address.ip", "1.2.3.4" + setting "address.vpc_id", "vpc-123456" + setting "address.subnet_id", "subnet-123456" + setting "key_pair.path", "~/.microbosh/ssh/test-bosh" + setting "bosh.name", "test-bosh" + setting "bosh.salted_password", "salted_password" + setting "bosh.persistent_disk", 32768 + setting "proxy.http_proxy", "http://192.168.1.100:8080" + setting "proxy.https_proxy", "https://192.168.1.100:8080" + + + subject = Bosh::Bootstrap::MicroboshProviders::AWS.new(microbosh_yml, settings, fog_compute) + + subject.create_microbosh_yml(settings) + expect(File).to be_exists(microbosh_yml) + yaml_files_match(microbosh_yml, spec_asset("microbosh_yml/micro_bosh.aws_vpc_proxy.yml")) + end end end diff --git a/spec/unit/microbosh_providers/openstack_spec.rb b/spec/unit/microbosh_providers/openstack_spec.rb index 94390e0..a71e9ed 100644 --- a/spec/unit/microbosh_providers/openstack_spec.rb +++ b/spec/unit/microbosh_providers/openstack_spec.rb @@ -119,6 +119,30 @@ yaml_files_match(microbosh_yml, spec_asset("microbosh_yml/micro_bosh.openstack.with_recursor.yml")) end + it "adds proxy if present" do + setting "provider.name", "openstack" + setting "provider.credentials.openstack_auth_url", "http://10.0.0.2:5000/v2.0/tokens" + setting "provider.credentials.openstack_username", "USER" + setting "provider.credentials.openstack_api_key", "PASSWORD" + setting "provider.credentials.openstack_tenant", "TENANT" + setting "provider.credentials.openstack_region", "REGION" + setting "address.subnet_id", "7b8788eb-b49e-4424-9065-75a6b07094ea" + setting "address.pool_name", "INTERNET" + setting "address.ip", "1.2.3.4" # network.vip + setting "key_pair.path", "~/.microbosh/ssh/test-bosh" + setting "bosh.name", "test-bosh" + setting "bosh.salted_password", "salted_password" + setting "bosh.persistent_disk", 32768 + setting "proxy.http_proxy", "http://192.168.1.100:8080" + setting "proxy.https_proxy", "https://192.168.1.100:8080" + + subject = Bosh::Bootstrap::MicroboshProviders::OpenStack.new(microbosh_yml, settings, fog_compute) + + subject.create_microbosh_yml(settings) + expect(File).to be_exists(microbosh_yml) + yaml_files_match(microbosh_yml, spec_asset("microbosh_yml/micro_bosh.openstack.with_proxy.yml")) + end + it "adds state_timeout if provided" do setting "provider.name", "openstack" setting "provider.credentials.openstack_auth_url", "http://10.0.0.2:5000/v2.0/tokens"