Provider options cpu and memory added. Those are used while creating

a new domain.
This commit is contained in:
pradels
2013-04-11 17:03:24 +02:00
parent e98c64c0be
commit 076e7dd8f5
3 changed files with 47 additions and 12 deletions

View File

@@ -33,8 +33,8 @@ $ vagrant plugin install vagrant-libvirt
### Possible problems with plugin installation ### Possible problems with plugin installation
In case of problems with building nokogiri gem, install missing development In case of problems with building nokogiri and ruby-libvirt gem, install
libraries for libxslt, libxml2 and libvirt. missing development libraries for libxslt, libxml2 and libvirt.
In Ubuntu, Debian, ... In Ubuntu, Debian, ...
``` ```
@@ -77,7 +77,7 @@ end
``` ```
### Configuration Options ### Libvirt Configuration Options
This provider exposes quite a few provider-specific 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 * `storage_pool_name` - Libvirt storage pool name, where box image and
instance snapshots will be stored. 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 ## Create Project - Vagrant up
In prepared project directory, run following command: 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. remote Libvirt storage pool as new volume.
3. Create COW diff image of base box image for new Libvirt domain. 3. Create COW diff image of base box image for new Libvirt domain.
4. Create and start new domain on Libvirt host. 4. Create and start new domain on Libvirt host.
5. Check for DHCP lease from dnsmasq server. Store IP address into 5. Check for DHCP lease from dnsmasq server.
machines *data_dir* for later use, when lease information is not 6. Wait till SSH is available.
available. Then wait till SSH is available. 7. Sync folders via `rsync` and run Vagrant provisioner on new domain if
6. Sync folders via `rsync` and run Vagrant provisioner on new domain if
setup in Vagrantfile. setup in Vagrantfile.
## Networks ## Networks

View File

@@ -13,11 +13,13 @@ module VagrantPlugins
end end
def call(env) def call(env)
# Get config.
config = env[:machine].provider_config
# Gather some info about domain # Gather some info about domain
# TODO from Vagrantfile
@name = env[:domain_name] @name = env[:domain_name]
@cpus = 1 @cpus = config.cpus
@memory_size = 512*1024 @memory_size = config.memory*1024
# TODO get type from driver config option # TODO get type from driver config option
@domain_type = 'kvm' @domain_type = 'kvm'

View File

@@ -22,6 +22,10 @@ module VagrantPlugins
# be stored. # be stored.
attr_accessor :storage_pool_name attr_accessor :storage_pool_name
# Domain specific settings used while creating new domain.
attr_accessor :memory
attr_accessor :cpus
def initialize def initialize
@driver = UNSET_VALUE @driver = UNSET_VALUE
@host = UNSET_VALUE @host = UNSET_VALUE
@@ -29,15 +33,23 @@ module VagrantPlugins
@username = UNSET_VALUE @username = UNSET_VALUE
@password = UNSET_VALUE @password = UNSET_VALUE
@storage_pool_name = UNSET_VALUE @storage_pool_name = UNSET_VALUE
# Domain specific settings.
@memory = UNSET_VALUE
@cpus = UNSET_VALUE
end end
def finalize! def finalize!
@driver = 'qemu' if @driver == UNSET_VALUE @driver = 'qemu' if @driver == UNSET_VALUE
@host = nil if @host == UNSET_VALUE @host = nil if @host == UNSET_VALUE
@connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE @connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE
@username = nil if @username == UNSET_VALUE @username = nil if @username == UNSET_VALUE
@password = nil if @password == UNSET_VALUE @password = nil if @password == UNSET_VALUE
@storage_pool_name = 'default' if @storage_pool_name == 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 end
def validate(machine) def validate(machine)