From 19cd1d56290aa4772a51174b955b2383b386aa03 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Wed, 12 Aug 2020 21:26:36 +0100 Subject: [PATCH] let the user set the domain title and description --- README.md | 2 ++ lib/vagrant-libvirt/action/create_domain.rb | 4 ++++ lib/vagrant-libvirt/config.rb | 6 ++++++ lib/vagrant-libvirt/templates/domain.xml.erb | 2 ++ spec/unit/templates/domain_all_settings.xml | 2 ++ spec/unit/templates/domain_custom_cpu_model.xml | 2 ++ spec/unit/templates/domain_defaults.xml | 2 ++ spec/unit/templates/domain_spec.rb | 2 ++ 8 files changed, 22 insertions(+) diff --git a/README.md b/README.md index ee8ee14..ddac000 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,8 @@ end ### Domain Specific Options +* `title` - A short description of the domain. +* `description` - A human readable description of the virtual machine. * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not set. Possible values are documented in Libvirt's [description for _target_](http://libvirt.org/formatdomain.html#elementsDisks). NOTE: this diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index e9e5f04..d637f46 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -31,6 +31,8 @@ module VagrantPlugins # Gather some info about domain @name = env[:domain_name] + @title = config.title + @description = config.description @uuid = config.uuid @cpus = config.cpus.to_i @cpuset = config.cpuset @@ -195,6 +197,8 @@ module VagrantPlugins # Output the settings we're going to use to the user env[:ui].info(I18n.t('vagrant_libvirt.creating_domain')) env[:ui].info(" -- Name: #{@name}") + env[:ui].info(" -- Title: #{@title}") if @title != '' + env[:ui].info(" -- Description: #{@description}") if @description != '' env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != '' env[:ui].info(" -- Domain type: #{@domain_type}") env[:ui].info(" -- Cpus: #{@cpus}") diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index b8c3f37..c96051b 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -67,6 +67,8 @@ module VagrantPlugins attr_accessor :default_prefix # Domain specific settings used while creating new domain. + attr_accessor :title + attr_accessor :description attr_accessor :uuid attr_accessor :memory attr_accessor :nodeset @@ -197,6 +199,8 @@ module VagrantPlugins @system_uri = UNSET_VALUE # Domain specific settings. + @title = UNSET_VALUE + @description = UNSET_VALUE @uuid = UNSET_VALUE @memory = UNSET_VALUE @nodeset = UNSET_VALUE @@ -697,6 +701,8 @@ module VagrantPlugins @uri = _generate_uri if @uri == UNSET_VALUE # Domain specific settings. + @title = '' if @title == UNSET_VALUE + @description = '' if @description == UNSET_VALUE @uuid = '' if @uuid == UNSET_VALUE @memory = 512 if @memory == UNSET_VALUE @nodeset = nil if @nodeset == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 7118987..af48a25 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -1,5 +1,7 @@ <%= @name %> + <%= @title %> + <%= @description %> <%= @uuid %> <%= @memory_size %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %> diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index 5344051..1955360 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -1,5 +1,7 @@ + title + description 1 diff --git a/spec/unit/templates/domain_custom_cpu_model.xml b/spec/unit/templates/domain_custom_cpu_model.xml index e4875fc..1e90f3d 100644 --- a/spec/unit/templates/domain_custom_cpu_model.xml +++ b/spec/unit/templates/domain_custom_cpu_model.xml @@ -1,5 +1,7 @@ + + 1 diff --git a/spec/unit/templates/domain_defaults.xml b/spec/unit/templates/domain_defaults.xml index 24783e4..20cbde9 100644 --- a/spec/unit/templates/domain_defaults.xml +++ b/spec/unit/templates/domain_defaults.xml @@ -1,5 +1,7 @@ + + 1 diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb index 0bd647b..c800e05 100644 --- a/spec/unit/templates/domain_spec.rb +++ b/spec/unit/templates/domain_spec.rb @@ -27,6 +27,8 @@ describe 'templates/domain' do context 'when all settings enabled' do before do + domain.title = 'title' + domain.description = 'description' domain.instance_variable_set('@domain_type', 'kvm') domain.cpu_mode = 'custom' domain.cpu_feature(name: 'AAA', policy: 'required')