Skip to content

Commit

Permalink
MINOR: Vagrant AWS overrideable EC2 instance name prefix
Browse files Browse the repository at this point in the history
ewencp
This small change allows users to use Vagrantfile.local to specify a custom prefix for names of ec2 instances brought up with vagrant.

This makes management of multiple aws test clusters a little easier since individual clusters can be assigned different name prefixes.

if `ec2_instance_name_prefix` is not specified in `Vagrantfile.local`, behavior will be exactly the same as before this change.

Testing:
- aws: I verified worker nodes, broker nodes, zk nodes with and without the prefix override. Behavior is as expected
- locally: I verified that bringing up worker nodes, broker nodes, zk nodes on a local machine is not impacted by this change.

Author: Geoff Anderson <[email protected]>

Reviewers: Ewen Cheslack-Postava <[email protected]>

Closes apache#801 from granders/minor-vagrant-aws-overrideable-prefix
  • Loading branch information
Geoff Anderson authored and ewencp committed Jan 22, 2016
1 parent 4922a51 commit 7b22639
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ec2_az = nil # Uses set by AWS
ec2_ami = "ami-9eaa1cf6"
ec2_instance_type = "m3.medium"
ec2_user = "ubuntu"
ec2_instance_name_prefix = "kafka-vagrant"
ec2_security_groups = nil
ec2_subnet_id = nil
# Only override this by setting it to false if you're running in a VPC and you
Expand Down Expand Up @@ -151,10 +152,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
override.vm.synced_folder ".", "/vagrant", type: "rsync", :rsync_excludes => ['.git', 'core/data/', 'logs/', 'tests/results/', 'results/']
end

def name_node(node, name)
def name_node(node, name, ec2_instance_name_prefix)
node.vm.hostname = name
node.vm.provider :aws do |aws|
aws.tags = { 'Name' => "kafka-vagrant-" + Socket.gethostname + "-" + name }
aws.tags = { 'Name' => ec2_instance_name_prefix + "-" + Socket.gethostname + "-" + name }
end
end

Expand All @@ -170,7 +171,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
name = "zk" + i.to_s
zookeepers.push(name)
config.vm.define name do |zookeeper|
name_node(zookeeper, name)
name_node(zookeeper, name, ec2_instance_name_prefix)
ip_address = "192.168.50." + (10 + i).to_s
assign_local_ip(zookeeper, ip_address)
zookeeper.vm.provision "shell", path: "vagrant/base.sh"
Expand All @@ -182,7 +183,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
(1..num_brokers).each { |i|
name = "broker" + i.to_s
config.vm.define name do |broker|
name_node(broker, name)
name_node(broker, name, ec2_instance_name_prefix)
ip_address = "192.168.50." + (50 + i).to_s
assign_local_ip(broker, ip_address)
# We need to be careful about what we list as the publicly routable
Expand All @@ -199,7 +200,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
(1..num_workers).each { |i|
name = "worker" + i.to_s
config.vm.define name do |worker|
name_node(worker, name)
name_node(worker, name, ec2_instance_name_prefix)
ip_address = "192.168.50." + (100 + i).to_s
assign_local_ip(worker, ip_address)
worker.vm.provision "shell", path: "vagrant/base.sh"
Expand Down

0 comments on commit 7b22639

Please sign in to comment.