Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easily override instance name #169

Closed
xmik opened this issue May 20, 2015 · 8 comments
Closed

Easily override instance name #169

xmik opened this issue May 20, 2015 · 8 comments

Comments

@xmik
Copy link
Contributor

xmik commented May 20, 2015

I'd like to differentiate virtual machines by name at a cloud dashboard. (Especially I want to know which machines were created by Test-Kitchen.) When I use Vagrant, I can set instance name in Vagrantfile in the following way:

Vagrant.configure('2') do |config|
  config.vm.define "my-vagrant-vm", primary: true do |my_vm|
    my_vm.vm.provision :chef_solo do |chef|
      ...
    end
  end
end

In result when I look at a cloud dashboard, I see the name of virtual machine created with Vagrant is "my-vagrant-vm". (I tested it with vagrant-openstack-provider 0.6.1 and Vagrant 1.6.5). I'd like to be able to set instance name in .kitchen.yml and see the same result.

kitchen-openstack has a nice feature to add only a prefix in instance name (server_name_prefix option) while the rest of the name is generated. But setting the whole instance name is enough for my case.

This is related to #144, but for me setting vm.name in Vagrantfile never worked, when I run vagrant status I get this error The following settings shouldn't exist: name. I must have set it in bad scope. When I set it in provider scope, it works:

config.vm.provider :openstack do |os|
      os.server_name = 'my-vagrant-vm'
end

However due to #171 I could not set it in .kitchen.yml in customize section.

EDIT: I should have added that setting vm_hostname in .kitchen.yml had no effect, the instance name and hostname was "default". (Most probably kitchen-vagrant is not the place for fixing it).

After #172 is merged, this is not longer needed to meet my initial goal. Still I offer a pull request which sets config.vm.define "<your_machine_name>" in generated Vagrantfile, because this way:

  • you can set this even if your vagrant provider does not support this
  • you don't have to set it explicitly in each .kitchen.yml (by default machine name and hostname is "kt-{kitchen_root_directory}-{instance_name}")

As I see in Readme some people do not like changing their hostname, so I'll update my PR so that setting in .kitchen.yml vm_hostname = false will result in not changing hostname and machine name in cloud dashboard.

xmik added a commit to ai-traders/kitchen-vagrant that referenced this issue May 21, 2015
Default vm instance name and hostname is now:
"kt-<kitchen_root_directory>-<instance_name>".
It can be overriden in .kitchen.yml by setting "instance_name" option.
xmik added a commit to ai-traders/kitchen-vagrant that referenced this issue May 26, 2015
When in .kitchen.yml:
* vm_hostname is set to false, then use previous default behavior: not
setting hostname (not using 'c.vm.define' in generated Vagrantfile)
* vm_name is set to some string, leads to setting hostname and machine
name in cloud dashboard
* vm_name is not set and vm_hostname is not set to false, then the
hostname and machine name in cloud dashboard is
"kt-<kitchen_root_directory>-<instance_name>"

Changed instance_name to vm_name, to avoid taking it for Test Kitchen
instance.name.
@xmik
Copy link
Contributor Author

xmik commented May 26, 2015

I updated the PR with the 2nd commit. Let me know if you want that behavior, I can then update tests which verify generated Vagrantfile.

@arielsalvo
Copy link

+1

Hi,

I also have issue with using {kitchen_root_directory} as part of the instance name due to directories with the same name or too long.

How about using a CRC32 of the full path?
It would make the instance name unique and shorter, getting the actual path would still be easy by running vagrant global-status and it should be quite easy to implement too.

Any thoughts?

@cheeseplus
Copy link
Contributor

It appears that #172 was already merged - I feel like the issue should be closed unless that PR didn't actually fix things?

@xmik can you comment?

@arielsalvo
Copy link

Ah, I see what you mean about #172 .

Do you think I should open a new issue regarding my comment about {kitchen_root_directory} ?

@cheeseplus
Copy link
Contributor

That would be great! If it's still a problem we'd love make sure it at least gets recorded and if you're feeling up to it a PR would be even better :D

@arielsalvo
Copy link

Will do!
I was looking at what needs to change in the code.

Thanks!

@cheeseplus
Copy link
Contributor

Closing this issue as discussed.

@xmik
Copy link
Contributor Author

xmik commented Feb 20, 2016

Since #171 was merged, I've been setting vm name under customize section (using vagrant-openstack-provider), e.g.:

platforms:
  - name: ubuntu-vagrant
    driver:
      name: vagrant
    driver_config:
      customize:
        server_name: 'kt-my_cookbook-ubuntu'

Here I also suggested to set default machine name to kt-{kitchen_root_directory}-{instance_name}, but it could end up being really long and I don't use the #169 PR anymore. So it's good you closed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants