From e74b6cb8dc57b99d3fa17ff02b22c86af75cc038 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 12 Mar 2013 09:01:25 -0700 Subject: [PATCH] Ability to specify server name --- README.md | 3 +++ lib/vagrant-rackspace/action/create_server.rb | 6 +++++- lib/vagrant-rackspace/config.rb | 7 +++++++ spec/vagrant-rackspace/config_spec.rb | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da2a498..57a3258 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ This provider exposes quite a few provider-specific configuration options: * `public_key_path` - The path to a public key to initialize with the remote server. This should be the matching pair for the private key configured with `config.ssh.private_key_path` on Vagrant. +* `server_name` - The name of the server within RackSpace Cloud. This + defaults to the name of the Vagrant machine (via `config.vm.define`), but + can be overridden with this. * `username` - The username with which to access Rackspace. These can be set like typical provider-specific configuration: diff --git a/lib/vagrant-rackspace/action/create_server.rb b/lib/vagrant-rackspace/action/create_server.rb index 5b37b34..eb4f23e 100644 --- a/lib/vagrant-rackspace/action/create_server.rb +++ b/lib/vagrant-rackspace/action/create_server.rb @@ -29,16 +29,20 @@ def call(env) image = find_matching(env[:rackspace_compute].images.all, config.image) raise Errors::NoMatchingImage if !image + # Figure out the name for the server + server_name = config.server_name || env[:machine].name + # Output the settings we're going to use to the user env[:ui].info(I18n.t("vagrant_rackspace.launching_server")) env[:ui].info(" -- Flavor: #{flavor.name}") env[:ui].info(" -- Image: #{image.name}") + env[:ui].info(" -- Name: #{server_name}") # Build the options for launching... options = { :flavor_id => flavor.id, :image_id => image.id, - :name => env[:machine].name, + :name => server_name, :personality => [ { :path => "/root/.ssh/authorized_keys", diff --git a/lib/vagrant-rackspace/config.rb b/lib/vagrant-rackspace/config.rb index abb1df0..d0087b8 100644 --- a/lib/vagrant-rackspace/config.rb +++ b/lib/vagrant-rackspace/config.rb @@ -28,6 +28,11 @@ class Config < Vagrant.plugin("2", :config) # @return [String] attr_accessor :public_key_path + # The name of the server. This defaults to the name of the machine + # defined by Vagrant (via `config.vm.define`), but can be overriden + # here. + attr_accessor :server_name + # The username to access RackSpace. # # @return [String] @@ -39,6 +44,7 @@ def initialize @flavor = UNSET_VALUE @image = UNSET_VALUE @public_key_path = UNSET_VALUE + @server_name = UNSET_VALUE @username = UNSET_VALUE end @@ -47,6 +53,7 @@ def finalize! @endpoint = nil if @endpoint == UNSET_VALUE @flavor = /512MB/ if @flavor == UNSET_VALUE @image = /Ubuntu/ if @image == UNSET_VALUE + @server_name = nil if @server_name == UNSET_VALUE @username = nil if @username == UNSET_VALUE if @public_key_path == UNSET_VALUE diff --git a/spec/vagrant-rackspace/config_spec.rb b/spec/vagrant-rackspace/config_spec.rb index d60d8d9..bcf642e 100644 --- a/spec/vagrant-rackspace/config_spec.rb +++ b/spec/vagrant-rackspace/config_spec.rb @@ -15,6 +15,7 @@ its(:flavor) { should eq(/512MB/) } its(:image) { should eq(/Ubuntu/) } its(:public_key_path) { should eql(vagrant_public_key) } + its(:server_name) { should be_nil } its(:username) { should be_nil } end @@ -24,6 +25,7 @@ :flavor, :image, :public_key_path, + :server_name, :username].each do |attribute| it "should not default #{attribute} if overridden" do subject.send("#{attribute}=".to_sym, "foo")