vagrant-xenserver-jc 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/CHANGELOG.md +40 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE +8 -0
  6. data/README.md +167 -0
  7. data/Rakefile +14 -0
  8. data/example_box/install_wheezy.sh +128 -0
  9. data/example_box/metadata.json +3 -0
  10. data/example_box/mkbox.sh +17 -0
  11. data/lib/vagrant-xenserver/action/clone_disk.rb +30 -0
  12. data/lib/vagrant-xenserver/action/clone_vm.rb +30 -0
  13. data/lib/vagrant-xenserver/action/configure_network.rb +61 -0
  14. data/lib/vagrant-xenserver/action/connect_xs.rb +47 -0
  15. data/lib/vagrant-xenserver/action/create_template.rb +87 -0
  16. data/lib/vagrant-xenserver/action/create_vifs.rb +86 -0
  17. data/lib/vagrant-xenserver/action/create_vm.rb +95 -0
  18. data/lib/vagrant-xenserver/action/destroy_vm.rb +37 -0
  19. data/lib/vagrant-xenserver/action/download_xva.rb +101 -0
  20. data/lib/vagrant-xenserver/action/dummy.rb +16 -0
  21. data/lib/vagrant-xenserver/action/halt_vm.rb +23 -0
  22. data/lib/vagrant-xenserver/action/is_created.rb +20 -0
  23. data/lib/vagrant-xenserver/action/is_running.rb +20 -0
  24. data/lib/vagrant-xenserver/action/is_suspended.rb +20 -0
  25. data/lib/vagrant-xenserver/action/prepare_nfs_settings.rb +85 -0
  26. data/lib/vagrant-xenserver/action/prepare_nfs_valid_ids.rb +17 -0
  27. data/lib/vagrant-xenserver/action/read_ssh_info.rb +97 -0
  28. data/lib/vagrant-xenserver/action/read_state.rb +35 -0
  29. data/lib/vagrant-xenserver/action/resume_vm.rb +30 -0
  30. data/lib/vagrant-xenserver/action/set_vm_params.rb +28 -0
  31. data/lib/vagrant-xenserver/action/start_vm.rb +31 -0
  32. data/lib/vagrant-xenserver/action/suspend_vm.rb +30 -0
  33. data/lib/vagrant-xenserver/action/upload_vhd.rb +164 -0
  34. data/lib/vagrant-xenserver/action/upload_xva.rb +100 -0
  35. data/lib/vagrant-xenserver/action/validate_network.rb +112 -0
  36. data/lib/vagrant-xenserver/action/wait_himn.rb +58 -0
  37. data/lib/vagrant-xenserver/action.rb +272 -0
  38. data/lib/vagrant-xenserver/config.rb +102 -0
  39. data/lib/vagrant-xenserver/errors.rb +68 -0
  40. data/lib/vagrant-xenserver/plugin.rb +70 -0
  41. data/lib/vagrant-xenserver/provider.rb +36 -0
  42. data/lib/vagrant-xenserver/util/exnhandler.rb +49 -0
  43. data/lib/vagrant-xenserver/util/uploader.rb +215 -0
  44. data/lib/vagrant-xenserver/version.rb +6 -0
  45. data/lib/vagrant-xenserver.rb +17 -0
  46. data/locales/en.yml +38 -0
  47. data/vagrant-xenserver.gemspec +27 -0
  48. metadata +173 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1ed842ec7f4b4c302be5ff3e982c208b299ad42
4
+ data.tar.gz: e4e066a6986994bc387bbf4ba413b793e3d9eb0d
5
+ SHA512:
6
+ metadata.gz: cd9b01b3dce4251497c4afd07e7ed1dee6f635deec9e181e06c79aeac8f28683cb8ceeb95d2619c927c6b135d46013b9b8ad0f34100857043f48cd6cde9d8629
7
+ data.tar.gz: 39b16bab580bb99ecdcbb31307ad602ba2d8d985d29c8fa1ddf610e7ee71e5475d5e52ff4bc64e368c4c87bc0b87ef9dad8b120935dbdc010f4fd54c817dc1d7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ # OS
2
+ *.DS_Store
3
+
4
+ # Editors
5
+ *.sw[po]
6
+ *~
7
+
8
+ # Ruby
9
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # 0.0.8 (8 September 2014)
2
+
3
+ * Correct typos
4
+
5
+ # 0.0.7 (8 September 2014)
6
+
7
+ * Use --insecure when uploading, as XS uses self-signed certs
8
+
9
+ # 0.0.6 (8 September 2014)
10
+
11
+ * Change other uploaders to https too
12
+
13
+ # 0.0.5 (5 September 2014)
14
+
15
+ * Upload VHDs over https rather than http
16
+ * Suspend/Resume (Simon Beaumont)
17
+
18
+ # 0.0.4 (10 July 2014)
19
+
20
+ * Enable NFS synced folders
21
+ * Add the halt action
22
+
23
+ # 0.0.3 (8 July 2014)
24
+
25
+ * Enable vagrant ssh -c
26
+
27
+ # 0.0.2 (7 July 2014)
28
+
29
+ * Support older versions of qemu-img that don't output
30
+ json
31
+
32
+ # 0.0.1 (7 July 2014)
33
+
34
+ * Use the md5 of the first meg of VHD to tag the base VDI
35
+ This is much more unique than the name/version pair
36
+
37
+ # 0.0.0 (1 July 2014)
38
+
39
+ * Initial release.
40
+
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ #gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
10
+ end
11
+
12
+ group :plugins do
13
+ gem "vagrant-xenserver-jc", :path => "."
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2014 Mitchell Hashimoto
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # Vagrant XenServer Provider (JogjaCamp fork)
2
+
3
+ This is a Vagrant plugin that adds a XenServer provider, allowing Vagrant to
4
+ control and provision machines on a XenServer host.
5
+
6
+ This fork add guest capability for configuring network and resolver
7
+
8
+ ## Dependencies
9
+ * Vagrant >= 1.5 (http://www.vagrantup.com/downloads.html)
10
+ * qemu-img
11
+
12
+ ## Installation
13
+ ```shell
14
+ vagrant plugin install vagrant-xenserver-jc
15
+ ```
16
+
17
+ # XenServer setup
18
+
19
+ Make sure the default_SR is set, and that a VHD-based SR is in
20
+ use. Currently the NFS SR is the recommended storage type.
21
+
22
+ # Usage
23
+
24
+ ## Boxes
25
+
26
+ Vagrant-xenserver supports 3 types of boxes today. These are:
27
+
28
+ 1. XVA URL - the box simply contains a URL that points to an XVA
29
+ (XenServer export) file.
30
+ 2. XVA - the box contains an XVA (XenServer export).
31
+ 3. VHD - the box contains a VHD file.
32
+
33
+ The recommended format is either 1 or 2, and it is suggested that
34
+ Packer is used to create the XVA files, which is available from
35
+ https://github.com/xenserver/packer-builder-xenserver . If this is not
36
+ available, there is an example script in the `example_box` directory
37
+ that automatically installs a Debian Wheezy guest and exports it. Once
38
+ an XVA file has been built, this can be turned into a box by archiving
39
+ it with `tar` with an included `metadata.json` and optionally a
40
+ `Vagrantfile`. For example, assuming an XVA has been created called
41
+ `ubuntu-15.10-amd64.xva`, to create an XVA URL box, upload the XVA to
42
+ your webserver and execute the following:
43
+
44
+ ```shell
45
+ echo "{\"provider\": \"xenserver\"}" > metadata.json
46
+ cat > Vagrantfile <<EOF
47
+ Vagrant.configure(2) do |config|
48
+ config.vm.provider :xenserver do |xs|
49
+ xs.xva_url = "http://my.web.server/ubuntu-15.10-amd64.xva"
50
+ end
51
+ end
52
+ EOF
53
+ tar cf ubuntu.box metadata.json Vagrantfile
54
+ ```
55
+
56
+ Or to create an XVA box:
57
+
58
+ ```shell
59
+ echo "{\"provider\": \"xenserver\"}" > metadata.json
60
+ cp /path/to/ubuntu-15.10-amd64.xva box.xva
61
+ tar cf ubuntu.box metadata.json Vagrantfile
62
+ ```
63
+
64
+ VHD based boxes are useful if you are converting from a box from
65
+ another provider. For example, to convert a VirtualBox box file:
66
+
67
+ * Download the box file (e.g. https://vagrantcloud.com/ubuntu/trusty64/version/1/provider/virtualbox.box)
68
+ * Unpack it:
69
+ ```shell
70
+ mkdir tmp
71
+ cd tmp
72
+ tar xvf ../virtualbox.box
73
+ ```
74
+ * Convert the disk image using qemu-img
75
+ ```shell
76
+ qemu-img convert *.vmdk -O vpc box.vhd
77
+ ```
78
+ * Remove the other files
79
+ ```shell
80
+ rm -f Vagrantfile box.ovf metadata.json
81
+ ```
82
+ * Make a new metadata file
83
+ ```shell
84
+ echo "{\"provider\": \"xenserver\"}" > metadata.json
85
+ ```
86
+ * Create the box:
87
+ ```shell
88
+ tar cf ../ubuntu.box .
89
+ ```
90
+
91
+ Note that since v0.0.12, vagrant-xenserver will assume by default that
92
+ boxes have the XenServer tools installed, which may not be the case
93
+ for converted boxes.
94
+
95
+ ## Add the box
96
+
97
+ Once you've created your box, this can simply be added to vagrant with
98
+ the following:
99
+
100
+ ```shell
101
+ vagrant box add ubuntu xenserver.box
102
+ ```
103
+
104
+ ## Create a Vagrantfile
105
+
106
+ ```ruby
107
+ # -*- mode: ruby -*-
108
+ # vi: set ft=ruby :
109
+
110
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
111
+ VAGRANTFILE_API_VERSION = "2"
112
+
113
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
114
+ config.vm.box = "ubuntu"
115
+
116
+ config.vm.provider :xenserver do |xs|
117
+ xs.xs_host = "st29.uk.xensource.com"
118
+ xs.xs_username = "root"
119
+ xs.xs_password = "xenroot"
120
+ xs.pv = true
121
+ xs.memory = 2048
122
+ xs.use_himn = false
123
+ end
124
+
125
+ config.vm.network "public_network", network: "Network 0"
126
+ end
127
+ ```
128
+
129
+ Note that by default there will be no connection to the external
130
+ network, so most configurations will require a 'public_network'
131
+ defined as in the above Vagrantfile. Alternatively you can use
132
+ network names using:
133
+
134
+ ```ruby
135
+ config.vm.network "public_network", network: "mynetwork-name"
136
+ ```
137
+
138
+ To bring the VM up, it should then be as simple as
139
+
140
+ ```shell
141
+ vagrant up --provider=xenserver
142
+ ```
143
+
144
+ ## XenServer host setup for HIMN forwarding
145
+
146
+ Since v0.0.12, boxes are assumed to have XenServer tools installed to
147
+ report the IP address. If the tools are not installed in the box, the
148
+ plugin supports using the 'host internal management network' (HIMN),
149
+ which is an internal-only network on which a DHCP server runs.
150
+ You will need to copy your ssh key to the Xenserver host:
151
+
152
+ ```shell
153
+ ssh-copy-id root@xenserver
154
+ ```
155
+
156
+ # Changes since 0.0.11
157
+ Note that since v0.0.11 the use of the host internal management network is now
158
+ not default. For backwards compatibility, add `use_himn = true` to the provider
159
+ specific settings in the Vagrantfile. For example:
160
+
161
+ ```ruby
162
+ config.vm.provider :xenserver do |xs|
163
+ xs.use_himn = true
164
+ end
165
+ ```
166
+
167
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ # Immediately sync all stdout so that tools like buildbot can
5
+ # immediately load in the output.
6
+ $stdout.sync = true
7
+ $stderr.sync = true
8
+
9
+ # Change to the directory of this file.
10
+ Dir.chdir(File.expand_path("../", __FILE__))
11
+
12
+ # This installs the tasks that help with gem creation and
13
+ # publishing.
14
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,128 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ set -x
5
+
6
+ SERVER=$1
7
+ USERNAME=$2
8
+ PASSWORD=$3
9
+ VMNAME=wheezy
10
+ DOMAINNAME=local
11
+
12
+ SERVERIP=`dig +search +short $SERVER`
13
+
14
+ if [ "x$SERVERIP" == "x" ]; then
15
+ SERVERIP=$SERVER
16
+ fi
17
+
18
+ template=`ssh root@$SERVER "xe template-list name-label='Debian Wheezy 7.0 (64-bit)' --minimal"`
19
+ vm=`ssh root@$SERVER xe vm-install template=$template new-name-label=$VMNAME`
20
+ network=`ssh root@$SERVER xe network-list bridge=xenbr0 --minimal`
21
+ vif=`ssh root@$SERVER xe vif-create vm-uuid=$vm network-uuid=$network device=0`
22
+ ssh root@$SERVER xe vm-cd-add uuid=$vm cd-name=guest-tools.iso device=3 || ssh root@$SERVER xe vm-cd-add uuid=$vm cd-name=xs-tools.iso device=3
23
+
24
+ preseed_blob=`ssh root@$SERVER xe blob-create vm-uuid=$vm name=preseed public=true`
25
+ preseed_file=/tmp/preseed
26
+
27
+ postinstall_blob=`ssh root@$SERVER xe blob-create vm-uuid=$vm name=postinstall public=true`
28
+ postinstall_file=/tmp/postinstall
29
+
30
+ cat > $preseed_file <<EOF
31
+ d-i debian-installer/locale string en_GB
32
+ d-i keyboard-configuration/layoutcode string en_GB
33
+ d-i keyboard-configuration/xkb-keymap string en_GB
34
+ d-i mirror/country string manual
35
+ d-i mirror/http/hostname string ftp.uk.debian.org
36
+ d-i mirror/http/directory string /debian/
37
+ d-i mirror/http/proxy string
38
+ #d-i debian-installer/allow_unauthenticated string true
39
+ #d-i anna/no_kernel_modules boolean true
40
+ d-i time/zone string string Europe/London
41
+ d-i partman-auto/method string regular
42
+ d-i partman-auto/choose_recipe \
43
+ select All files in one partition (recommended for new users)
44
+ d-i partman/confirm_write_new_label boolean true
45
+ d-i partman/choose_partition \
46
+ select Finish partitioning and write changes to disk
47
+ d-i partman/confirm boolean true
48
+ d-i partman/confirm_nooverwrite boolean true
49
+
50
+ d-i passwd/make-user boolean true
51
+
52
+ d-i passwd/user-fullname string vagrant
53
+ d-i passwd/user-password password vagrant
54
+ d-i passwd/user-password-again password vagrant
55
+ d-i passwd/username string vagrant
56
+
57
+ d-i passwd/root-password-again password vagrant
58
+ d-i passwd/root-password password vagrant
59
+
60
+ d-i apt-setup/local0/repository string http://www.uk.xensource.com/deb-guest lenny main
61
+ d-i debian-installer/allow_unauthenticated boolean true
62
+
63
+ popularity-contest popularity-contest/participate boolean false
64
+ tasksel tasksel/first multiselect standard
65
+ d-i pkgsel/include string openssh-server vim ntp ethtool tpcdump bridge-util rsync ssmtp strace gdb build-essential xe-guest-utilities wget sudo
66
+ #d-i mirror/udeb/suite string squeeze
67
+ #d-i mirror/suite string squeeze
68
+ #d-i mirror/udeb/suite string sid
69
+ #d-i mirror/suite string sid
70
+ d-i grub-installer/only_debian boolean true
71
+ d-i grub-installer/with_other_os boolean true
72
+ d-i preseed/late_command string \
73
+ wget http://$SERVERIP/blob?uuid=$postinstall_blob -O /target/post_install.sh;\
74
+ chmod 755 /target/post_install.sh; \
75
+ chroot /target /post_install.sh
76
+
77
+ d-i finish-install/reboot_in_progress note
78
+ #d-i debian-installer/exit/poweroff boolean true
79
+ #d-i debian-installer/exit/always_halt boolean true
80
+ #d-i debian-installer/exit/poweroff boolean true
81
+
82
+ EOF
83
+
84
+ cat > $postinstall_file <<EOF
85
+ #!/bin/bash
86
+
87
+ mount /dev/xvdd /mnt
88
+ cd /mnt/Linux
89
+ ./install.sh -n
90
+
91
+ mkdir ~vagrant/.ssh
92
+ wget --no-check-certificate \
93
+ 'https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub' \
94
+ -O ~vagrant/.ssh/authorized_keys
95
+ chown -R vagrant ~vagrant/.ssh
96
+ chmod -R go-rwsx ~vagrant/.ssh
97
+
98
+ echo 'vagrant ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/99_vagrant
99
+ chmod 440 /etc/sudoers.d/99_vagrant
100
+
101
+ EOF
102
+
103
+ scp $preseed_file root@$SERVER:$preseed_file
104
+ scp $postinstall_file root@$SERVER:$postinstall_file
105
+
106
+ ssh root@$SERVER xe blob-put uuid=$preseed_blob filename=$preseed_file
107
+ rm $preseed_file
108
+ ssh root@$SERVER rm $preseed_file
109
+
110
+ ssh root@$SERVER xe blob-put uuid=$postinstall_blob filename=$postinstall_file
111
+ rm $postinstall_file
112
+ ssh root@$SERVER rm $postinstall_file
113
+
114
+ ssh root@$SERVER xe vm-param-set uuid=$vm other-config:install-repository=http://ftp.uk.debian.org/debian other-config:debian-release=wheezy
115
+ ssh root@$SERVER "xe vm-param-set uuid=$vm PV-args=\"auto-install/enable=true url=http://$SERVERIP/blob?uuid=$preseed_blob interface=auto netcfg/dhcp_timeout=600 hostname=$VMNAME domain=$DOMAINNAME\""
116
+ ssh root@$SERVER xe vm-start uuid=$vm
117
+
118
+ sleep 30
119
+
120
+ starttime=`ssh root@$SERVER xe vm-param-get uuid=$vm param-name=start-time`
121
+ ssh root@$SERVER xe event-wait class=vm uuid=$vm start-time=/=$starttime
122
+ echo "rebooted..."
123
+ ssh root@$SERVER xe event-wait class=vm uuid=$vm networks=/=
124
+ echo "networks detected"
125
+ ssh root@$SERVER xe vm-shutdown uuid=$vm
126
+ echo $vm
127
+
128
+
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "xenserver"
3
+ }
@@ -0,0 +1,17 @@
1
+ #!/bin/bash
2
+
3
+ server=$1
4
+ username=$2
5
+ password=$3
6
+
7
+ vm=`./install_wheezy.sh $1 $2 $3 | tail -n 1`
8
+ rm -rf tmp
9
+ mkdir tmp
10
+ curl -k https://$username:$password@$server/export\?uuid=$vm\&use_compression=true -o tmp/box.xva
11
+ echo "{\"provider\": \"xenserver\"}" > tmp/metadata.json
12
+ pushd tmp
13
+ tar cf ../wheezy.box .
14
+ popd
15
+
16
+
17
+
@@ -0,0 +1,30 @@
1
+ require "log4r"
2
+ require "xmlrpc/client"
3
+ require "vagrant-xenserver/util/uploader"
4
+ require "rexml/document"
5
+ require "json"
6
+
7
+ module VagrantPlugins
8
+ module XenServer
9
+ module Action
10
+ class CloneDisk
11
+ def initialize(app, env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new("vagrant::xenserver::actions::clone_disk")
14
+ end
15
+
16
+ def call(env)
17
+ vdi_ref = env[:box_vdi]
18
+
19
+ clone = env[:xc].VDI.clone(vdi_ref, {})
20
+
21
+ env[:my_vdi] = clone
22
+
23
+ @logger.info("clone VDI=#{clone}")
24
+
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require "log4r"
2
+ require "xmlrpc/client"
3
+
4
+ module VagrantPlugins
5
+ module XenServer
6
+ module Action
7
+ class CloneVM
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant::xenserver::actions::clone_vm")
11
+ end
12
+
13
+ def call(env)
14
+ template_ref = env[:template]
15
+ username = Etc.getlogin
16
+ vm_name = "#{username}/#{env[:machine].name}"
17
+ vm = nil
18
+ Action.getlock.synchronize do
19
+ vm = env[:xc].VM.clone(template_ref, vm_name)
20
+ env[:xc].VM.provision(vm)
21
+ end
22
+
23
+ env[:machine].id = vm
24
+
25
+ @app.call env
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,61 @@
1
+ require "log4r"
2
+ require "xmlrpc/client"
3
+ require "vagrant-xenserver/util/uploader"
4
+ require "rexml/document"
5
+ require "json"
6
+
7
+ module VagrantPlugins
8
+ module XenServer
9
+ module Action
10
+ # This action will tell vagrant to activate configure_networks capability
11
+ # Interface configuration for a VM must be defined first in env[:vifs]
12
+ class ConfigureNetwork
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant::xenserver::actions::configure_network")
16
+ end
17
+
18
+ def call(env)
19
+ # Get machine first.
20
+ myvm = env[:machine].id
21
+
22
+ # Configure interfaces that user requested. Machine should be up and
23
+ # running now.
24
+ @logger.info("Configuring guest network")
25
+ env[:ui].output(I18n.t("vagrant.actions.vm.network.preparing"))
26
+ networks_to_configure = []
27
+
28
+ env[:vifs].each do |eth, option|
29
+ network = {
30
+ :interface => eth[-1, 1].to_i,
31
+ :type => option[:proto]
32
+ }
33
+
34
+ network[:ip] = option[:ip]
35
+ network[:netmask] = option[:netmask]
36
+ network[:gateway] = option[:gateway]
37
+
38
+ static_str = option[:ip].nil? ? "" : " / #{option[:ip]}"
39
+
40
+ env[:ui].detail(I18n.t(
41
+ "vagrant.virtualbox.network_adapter",
42
+ adapter: "#{eth} (#{option[:proto]}#{static_str})",
43
+ type: "#{option[:network_type]}",
44
+ extra: " on network #{option[:network]}",
45
+ ))
46
+
47
+ networks_to_configure << network
48
+ end
49
+
50
+ env[:ui].info I18n.t("vagrant.actions.vm.network.configuring")
51
+ env[:machine].guest.capability(
52
+ :configure_networks, networks_to_configure)
53
+
54
+ # Continue the middleware chain.
55
+ @app.call(env)
56
+
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,47 @@
1
+ require "log4r"
2
+ require "xenapi"
3
+ require "uri"
4
+
5
+ module VagrantPlugins
6
+ module XenServer
7
+ module Action
8
+ class ConnectXS
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant::xenserver::actions::connect_xs")
12
+ end
13
+
14
+ def call(env)
15
+ config = env[:machine].provider_config
16
+
17
+ # Only even try to connect if we've got a hostname
18
+ if (not env[:xc]) && (not config.xs_host.nil?)
19
+ uri = URI::Generic.new(config.xs_use_ssl ? 'https' : 'http',
20
+ nil,
21
+ config.xs_host,
22
+ config.xs_port,
23
+ nil,
24
+ "/",
25
+ nil,
26
+ nil, nil)
27
+ env[:xc] = XenApi::Client.new(uri.to_s, timeout = config.api_timeout)
28
+
29
+ @logger.info("Connecting to XenServer")
30
+
31
+ begin
32
+ result = env[:xc].login_with_password(config.xs_username, config.xs_password)
33
+ rescue XenApi::Errors::SessionAuthenticationFailed
34
+ raise Errors::LoginError
35
+ rescue
36
+ raise Errors::ConnectionError
37
+ end
38
+
39
+ @logger.info("Connected to XenServer")
40
+ end
41
+
42
+ @app.call(env)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,87 @@
1
+ require "log4r"
2
+ require "xmlrpc/client"
3
+ require "vagrant-xenserver/util/uploader"
4
+ require "rexml/document"
5
+ require "json"
6
+ require "etc"
7
+
8
+ module VagrantPlugins
9
+ module XenServer
10
+ module Action
11
+ class CreateTemplate
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new("vagrant::xenserver::actions::create_template")
15
+ end
16
+
17
+ def call(env)
18
+ if env[:template].nil?
19
+
20
+ box_name = env[:machine].box.name.to_s
21
+ box_version = env[:machine].box.version.to_s
22
+
23
+ # No template - that means it wasn't a downloaded XVA.
24
+ # Let's create a VM and attach the uploaded VDI to it.
25
+ # First see if we've done that already:
26
+
27
+ Action.getlock.synchronize do
28
+ templates = env[:xc].VM.get_all_records_where("field \"is_a_template\"=\"true\"")
29
+ template = templates.detect { |vm,vmr|
30
+ vmr["other_config"]["box_name"] == box_name &&
31
+ vmr["other_config"]["box_version"] == box_version
32
+ }
33
+
34
+ if template.nil?
35
+ vdi_ref = env[:box_vdi]
36
+
37
+ oim = env[:xc].VM.get_by_name_label("Other install media")[0]
38
+
39
+ template_name = "#{box_name}.#{box_version}"
40
+
41
+ template_ref = env[:xc].VM.clone(oim,template_name)
42
+
43
+ vbd_record = {
44
+ 'VM' => template_ref,
45
+ 'VDI' => env[:box_vdi],
46
+ 'userdevice' => '0',
47
+ 'bootable' => true,
48
+ 'mode' => 'RW',
49
+ 'type' => 'Disk',
50
+ 'unpluggable' => false,
51
+ 'empty' => false,
52
+ 'other_config' => {},
53
+ 'qos_algorithm_type' => '',
54
+ 'qos_algorithm_params' => {}
55
+ }
56
+
57
+ vbd_res = env[:xc].VBD.create(vbd_record)
58
+
59
+ @logger.info("vbd_res=" + vbd_res.to_s)
60
+
61
+ env[:xc].VM.add_to_other_config(template_ref, "box_name", box_name)
62
+ env[:xc].VM.add_to_other_config(template_ref, "box_version", box_version)
63
+
64
+ if env[:machine].provider_config.pv
65
+ env[:xc].VM.set_HVM_boot_policy(template_ref,"")
66
+ env[:xc].VM.set_PV_bootloader(template_ref,"pygrub")
67
+ end
68
+
69
+ mem = ((env[:machine].provider_config.memory) * (1024*1024)).to_s
70
+ env[:xc].VM.set_memory_limits(template_ref,mem,mem,mem,mem)
71
+
72
+ env[:template] = template_ref
73
+
74
+ else
75
+ @logger.info("Found pre-existing template for this box")
76
+ (template_ref, template_rec) = template
77
+ env[:template] = template_ref
78
+ end
79
+ end
80
+ end
81
+
82
+ @app.call env
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end