[DRE-commits] [vagrant-libvirt] 21/104: Provider options cpu and memory added. Those are used while creating a new domain.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Apr 24 13:55:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag 0.0.11
in repository vagrant-libvirt.

commit 076e7dd8f50c8c39e934c50fd0b8e7c4b14c6ff2
Author: pradels <les.pradels at gmail.com>
Date:   Thu Apr 11 17:03:24 2013 +0200

    Provider options cpu and memory added. Those are used while creating
    a new domain.
---
 README.md                                   | 35 +++++++++++++++++++++++------
 lib/vagrant-libvirt/action/create_domain.rb |  8 ++++---
 lib/vagrant-libvirt/config.rb               | 16 +++++++++++--
 3 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index 6c1ad34..043b0e4 100644
--- a/README.md
+++ b/README.md
@@ -33,8 +33,8 @@ $ vagrant plugin install vagrant-libvirt
 
 ### Possible problems with plugin installation
 
-In case of problems with building nokogiri gem, install missing development
-libraries for libxslt, libxml2 and libvirt.
+In case of problems with building nokogiri and ruby-libvirt gem, install
+missing development libraries for libxslt, libxml2 and libvirt.
 
 In Ubuntu, Debian, ...
 ```
@@ -77,7 +77,7 @@ end
 
 ```
 
-### Configuration Options
+### Libvirt Configuration Options
 
 This provider exposes quite a few provider-specific configuration options:
 
@@ -89,6 +89,28 @@ This provider exposes quite a few provider-specific configuration options:
 * `storage_pool_name` - Libvirt storage pool name, where box image and
   instance snapshots will be stored.
 
+### Domain Specific Options
+
+* `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
+* `cpus` - Number of virtual cpus. Defaults to 1 if not set.
+
+Specific domain settings can be set for each domain separately in multi-VM
+environment. Example below shows a part of Vagrantfile, where specific options
+are set for dbserver domain.
+
+```ruby
+Vagrant.configure("2") do |config|
+  config.vm.define :dbserver do |dbserver|
+    dbserver.vm.box = "centos64"
+    dbserver.vm.provider :libvirt do |domain|
+      domain.memory = 2048
+      domain.cpus = 2
+    end
+  end
+
+  ...
+```
+
 ## Create Project - Vagrant up
 
 In prepared project directory, run following command:
@@ -111,10 +133,9 @@ Vagrant goes through steps below when creating new project:
 	remote Libvirt storage pool as new volume. 
 3.	Create COW diff image of base box image for new Libvirt domain.
 4.	Create and start new domain on Libvirt host.
-5.	Check for DHCP lease from dnsmasq server. Store IP address into
-	machines *data_dir* for later use, when lease information is not
-	available. Then wait till SSH is available.
-6.	Sync folders via `rsync` and run Vagrant provisioner on new domain if
+5.	Check for DHCP lease from dnsmasq server.
+6.	Wait till SSH is available.
+7.	Sync folders via `rsync` and run Vagrant provisioner on new domain if
 	setup in Vagrantfile.
 
 ## Networks
diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb
index 584caed..cead2f6 100644
--- a/lib/vagrant-libvirt/action/create_domain.rb
+++ b/lib/vagrant-libvirt/action/create_domain.rb
@@ -13,11 +13,13 @@ module VagrantPlugins
         end
 
         def call(env)
+          # Get config.
+          config = env[:machine].provider_config
+
           # Gather some info about domain
-          # TODO from Vagrantfile
           @name = env[:domain_name]
-          @cpus = 1
-          @memory_size = 512*1024
+          @cpus = config.cpus
+          @memory_size = config.memory*1024
 
           # TODO get type from driver config option
           @domain_type = 'kvm'
diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb
index 501effc..f48d630 100644
--- a/lib/vagrant-libvirt/config.rb
+++ b/lib/vagrant-libvirt/config.rb
@@ -22,6 +22,10 @@ module VagrantPlugins
       # be stored.
       attr_accessor :storage_pool_name
 
+      # Domain specific settings used while creating new domain.
+      attr_accessor :memory
+      attr_accessor :cpus
+
       def initialize
         @driver            = UNSET_VALUE
         @host              = UNSET_VALUE
@@ -29,15 +33,23 @@ module VagrantPlugins
         @username          = UNSET_VALUE
         @password          = UNSET_VALUE
         @storage_pool_name = UNSET_VALUE
+
+        # Domain specific settings.
+        @memory            = UNSET_VALUE
+        @cpus              = UNSET_VALUE
       end
 
       def finalize!
-        @driver   = 'qemu' if @driver == UNSET_VALUE
-        @host     = nil if @host     == UNSET_VALUE
+        @driver = 'qemu' if @driver == UNSET_VALUE
+        @host = nil if @host == UNSET_VALUE
         @connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE
         @username = nil if @username == UNSET_VALUE
         @password = nil if @password == UNSET_VALUE
         @storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE
+
+        # Domain specific settings.
+        @memory = 512 if @memory == UNSET_VALUE
+        @cpus = 1 if @cpus == UNSET_VALUE
       end
 
       def validate(machine)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git



More information about the Pkg-ruby-extras-commits mailing list