vagrant-xenserver 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +14 -0
- data/LICENSE +8 -0
- data/README.md +251 -0
- data/Rakefile +14 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-xenserver.rb +17 -0
- data/lib/vagrant-xenserver/action.rb +130 -0
- data/lib/vagrant-xenserver/action/clone_disk.rb +30 -0
- data/lib/vagrant-xenserver/action/connect_xs.rb +34 -0
- data/lib/vagrant-xenserver/action/create_vm.rb +83 -0
- data/lib/vagrant-xenserver/action/destroy_vm.rb +34 -0
- data/lib/vagrant-xenserver/action/dummy.rb +16 -0
- data/lib/vagrant-xenserver/action/is_created.rb +20 -0
- data/lib/vagrant-xenserver/action/is_running.rb +20 -0
- data/lib/vagrant-xenserver/action/maybe_upload_disk.rb +84 -0
- data/lib/vagrant-xenserver/action/read_ssh_info.rb +61 -0
- data/lib/vagrant-xenserver/action/read_state.rb +35 -0
- data/lib/vagrant-xenserver/action/start_vm.rb +26 -0
- data/lib/vagrant-xenserver/action/upload_vhd.rb +135 -0
- data/lib/vagrant-xenserver/action/upload_xva.rb +84 -0
- data/lib/vagrant-xenserver/config.rb +57 -0
- data/lib/vagrant-xenserver/errors.rb +29 -0
- data/lib/vagrant-xenserver/plugin.rb +29 -0
- data/lib/vagrant-xenserver/provider.rb +36 -0
- data/lib/vagrant-xenserver/util/uploader.rb +215 -0
- data/lib/vagrant-xenserver/version.rb +6 -0
- data/locales/en.yml +10 -0
- data/test +0 -0
- data/vagrant-xenserver.gemspec +22 -0
- metadata +87 -0
@@ -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::upload_xva")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
vdi_ref = env[:box_vdi]
|
18
|
+
|
19
|
+
clone = env[:xc].call("VDI.clone", env[:session], vdi_ref, {})['Value']
|
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,34 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "xmlrpc/client"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module XenServer
|
6
|
+
module Action
|
7
|
+
class ConnectXS
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant_xenserver::actions::connect_xs")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if not env[:session]
|
15
|
+
env[:xc] = XMLRPC::Client.new(env[:machine].provider_config.xs_host, "/", "80")
|
16
|
+
|
17
|
+
@logger.info("Connecting to XenServer")
|
18
|
+
|
19
|
+
sess_result = env[:xc].call("session.login_with_password", env[:machine].provider_config.xs_username, env[:machine].provider_config.xs_password,"1.0")
|
20
|
+
|
21
|
+
if sess_result["Status"] != "Success"
|
22
|
+
raise Errors::LoginError
|
23
|
+
end
|
24
|
+
|
25
|
+
env[:session] = sess_result["Value"]
|
26
|
+
end
|
27
|
+
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,83 @@
|
|
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 CreateVM
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@logger = Log4r::Logger.new("vagrant::xenserver::actions::create_vm")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
vdi_ref = env[:my_vdi]
|
18
|
+
|
19
|
+
networks = env[:xc].call("network.get_all_records",env[:session])['Value']
|
20
|
+
|
21
|
+
himn = networks.find { |ref,net| net['other_config']['is_host_internal_management_network'] }
|
22
|
+
(himn_ref,himn_rec) = himn
|
23
|
+
|
24
|
+
@logger.info("himn_uuid="+himn_rec['uuid'])
|
25
|
+
|
26
|
+
oim = env[:xc].call("VM.get_by_name_label",env[:session],"Other install media")['Value'][0]
|
27
|
+
|
28
|
+
vm_ref = env[:xc].call("VM.clone",env[:session],oim,env[:machine].box.name.to_s)['Value']
|
29
|
+
|
30
|
+
vbd_record = {
|
31
|
+
'VM' => vm_ref,
|
32
|
+
'VDI' => env[:my_vdi],
|
33
|
+
'userdevice' => '0',
|
34
|
+
'bootable' => true,
|
35
|
+
'mode' => 'RW',
|
36
|
+
'type' => 'Disk',
|
37
|
+
'unpluggable' => false,
|
38
|
+
'empty' => false,
|
39
|
+
'other_config' => {},
|
40
|
+
'qos_algorithm_type' => '',
|
41
|
+
'qos_algorithm_params' => {}
|
42
|
+
}
|
43
|
+
|
44
|
+
vbd_res = env[:xc].call("VBD.create",env[:session],vbd_record)
|
45
|
+
|
46
|
+
@logger.info("vbd_res=" + vbd_res.to_s)
|
47
|
+
|
48
|
+
vif_record = {
|
49
|
+
'VM' => vm_ref,
|
50
|
+
'network' => himn_ref,
|
51
|
+
'device' => '0',
|
52
|
+
'MAC' => '',
|
53
|
+
'MTU' => '1500',
|
54
|
+
'other_config' => {},
|
55
|
+
'qos_algorithm_type' => '',
|
56
|
+
'qos_algorithm_params' => {},
|
57
|
+
'locking_mode' => 'network_default',
|
58
|
+
'ipv4_allowed' => [],
|
59
|
+
'ipv6_allowed' => []
|
60
|
+
}
|
61
|
+
|
62
|
+
vif_res = env[:xc].call("VIF.create",env[:session],vif_record)
|
63
|
+
|
64
|
+
@logger.info("vif_res=" + vif_res.to_s)
|
65
|
+
|
66
|
+
if env[:machine].provider_config.pv
|
67
|
+
env[:xc].call("VM.set_HVM_boot_policy",env[:session],vm_ref,"")
|
68
|
+
env[:xc].call("VM.set_PV_bootloader",env[:session],vm_ref,"pygrub")
|
69
|
+
end
|
70
|
+
|
71
|
+
mem = ((env[:machine].provider_config.memory) * (1024*1024)).to_s
|
72
|
+
|
73
|
+
env[:xc].call("VM.set_memory_limits",env[:session],vm_ref,mem,mem,mem,mem)
|
74
|
+
env[:xc].call("VM.provision",env[:session],vm_ref)
|
75
|
+
|
76
|
+
env[:machine].id = vm_ref
|
77
|
+
|
78
|
+
@app.call env
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "xmlrpc/client"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module XenServer
|
6
|
+
module Action
|
7
|
+
class DestroyVM
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant::xenserver::actions::destroy_vm")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
env[:xc].call("VM.hard_shutdown",env[:session],env[:machine].id)
|
15
|
+
|
16
|
+
vbds = env[:xc].call("VM.get_VBDs",env[:session],env[:machine].id)['Value']
|
17
|
+
|
18
|
+
vbds.each { |vbd|
|
19
|
+
vbd_rec = env[:xc].call("VBD.get_record",env[:session],vbd)['Value']
|
20
|
+
if vbd_rec['type'] == "Disk"
|
21
|
+
env[:xc].call("VDI.destroy",env[:session],vbd_rec['VDI'])
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
env[:xc].call("VM.destroy",env[:session],env[:machine].id)
|
26
|
+
|
27
|
+
env[:machine].id = nil
|
28
|
+
|
29
|
+
@app.call env
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module XenServer
|
5
|
+
module Action
|
6
|
+
class IsCreated
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_xenserver::action::is_created')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:result] = env[:machine].state.id != :not_created
|
14
|
+
@logger.info("env[:machine].state.id="+env[:machine].state.id.to_s)
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module XenServer
|
5
|
+
module Action
|
6
|
+
class IsRunning
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_xenserver::action::is_running')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
@logger.info("env[:machine].state.id="+env[:machine].state.id.to_s)
|
14
|
+
env[:result] = env[:machine].state.id == 'Running'
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "xmlrpc/client"
|
3
|
+
require "vagrant-xenserver/util/uploader"
|
4
|
+
require "rexml/document"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module XenServer
|
8
|
+
module Action
|
9
|
+
class UploadXVA
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant::xenserver::actions::upload_xva")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
#box_image_file = env[:machine].box.directory.join('export.xva').to_s
|
17
|
+
box_image_file = "/home/jludlam/devel/vagrant-xenserver/centos-6.5.vhd"
|
18
|
+
hostname = env[:machine].provider_config.xs_host
|
19
|
+
session = env[:session]
|
20
|
+
|
21
|
+
@logger.info("box name=" + env[:machine].box.name.to_s)
|
22
|
+
@logger.info("box version=" + env[:machine].box.version.to_s)
|
23
|
+
|
24
|
+
# Create a task to so we can get the result of the upload
|
25
|
+
task_result = env[:xc].call("task.create", env[:session], "vagrant-xva-upload",
|
26
|
+
"Task to track progress of the XVA upload from vagrant")
|
27
|
+
|
28
|
+
if task_result["Status"] != "Success"
|
29
|
+
raise Errors::APIError
|
30
|
+
end
|
31
|
+
|
32
|
+
task = task_result["Value"]
|
33
|
+
|
34
|
+
url = "http://#{hostname}/import?session_id=#{session}&task_id=#{task}"
|
35
|
+
|
36
|
+
uploader_options = {}
|
37
|
+
uploader_options[:ui] = env[:ui]
|
38
|
+
|
39
|
+
uploader = MyUtil::Uploader.new(box_image_file, url, uploader_options)
|
40
|
+
|
41
|
+
begin
|
42
|
+
uploader.upload!
|
43
|
+
rescue Errors::UploaderInterrupted
|
44
|
+
env[:ui].info(I18n.t("vagrant.xenserver.action.upload_xva.interrupted"))
|
45
|
+
raise
|
46
|
+
end
|
47
|
+
|
48
|
+
task_status = ""
|
49
|
+
|
50
|
+
begin
|
51
|
+
sleep(0.2)
|
52
|
+
task_status_result = env[:xc].call("task.get_status",env[:session],task)
|
53
|
+
if task_status_result["Status"] != "Success"
|
54
|
+
raise Errors::APIError
|
55
|
+
end
|
56
|
+
task_status = task_status_result["Value"]
|
57
|
+
end while task_status == "pending"
|
58
|
+
|
59
|
+
@logger.info("task_status="+task_status)
|
60
|
+
|
61
|
+
if task_status != "success"
|
62
|
+
raise Errors::APIError
|
63
|
+
end
|
64
|
+
|
65
|
+
task_result_result = env[:xc].call("task.get_result",env[:session],task)
|
66
|
+
if task_result_result["Status"] != "Success"
|
67
|
+
raise Errors::APIError
|
68
|
+
end
|
69
|
+
|
70
|
+
task_result = task_result_result["Value"]
|
71
|
+
|
72
|
+
doc = REXML::Document.new(task_result)
|
73
|
+
|
74
|
+
doc.elements.each('value/array/data/value') do |ele|
|
75
|
+
@logger.info("ele=" + ele.text)
|
76
|
+
end
|
77
|
+
|
78
|
+
@logger.info("task_result=" + task_result)
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module XenServer
|
5
|
+
module Action
|
6
|
+
# This action reads the SSH info for the machine and puts it into the
|
7
|
+
# `:machine_ssh_info` key in the environment.
|
8
|
+
class ReadSSHInfo
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_xenserver::action::read_ssh_info")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_ssh_info] = read_ssh_info(env)
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_ssh_info(env)
|
21
|
+
machine = env[:machine]
|
22
|
+
return nil if machine.id.nil?
|
23
|
+
|
24
|
+
# Find the machine
|
25
|
+
networks = env[:xc].call("network.get_all_records",env[:session])['Value']
|
26
|
+
vif_result = env[:xc].call("VM.get_VIFs",env[:session],machine.id)
|
27
|
+
|
28
|
+
himn = networks.find { |ref,net| net['other_config']['is_host_internal_management_network'] }
|
29
|
+
(himn_ref,himn_rec) = himn
|
30
|
+
|
31
|
+
if vif_result['Status']=='Failure'
|
32
|
+
# The machine can't be found
|
33
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
34
|
+
machine.id = nil
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
|
38
|
+
vifs = vif_result['Value']
|
39
|
+
assigned_ips = himn_rec['assigned_ips']
|
40
|
+
(vif,ip) = assigned_ips.find { |vif,ip| vifs.include? vif }
|
41
|
+
|
42
|
+
ssh_info = {
|
43
|
+
:host => ip,
|
44
|
+
:port => machine.config.ssh.guest_port,
|
45
|
+
:username => machine.config.ssh.username,
|
46
|
+
:forward_agent => machine.config.ssh.forward_agent,
|
47
|
+
:forward_x11 => machine.config.ssh.forward_x11,
|
48
|
+
}
|
49
|
+
|
50
|
+
ssh_info[:proxy_command] = "ssh '#{machine.provider_config.xs_host}' -l '#{machine.provider_config.xs_username}' nc %h %p"
|
51
|
+
|
52
|
+
if not ssh_info[:username]
|
53
|
+
ssh_info[:username] = machine.config.ssh.default.username
|
54
|
+
end
|
55
|
+
|
56
|
+
ssh_info
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module XenServer
|
5
|
+
module Action
|
6
|
+
class ReadState
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant::xenserver::actions::readstate")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
@logger.debug("XXXXX In ReadState")
|
14
|
+
env[:machine_state_id] = read_state(env[:xc], env[:session], env[:machine])
|
15
|
+
@logger.debug("state="+env[:machine_state_id].to_s)
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_state(xc, session, machine)
|
20
|
+
return :not_created if machine.id.nil?
|
21
|
+
|
22
|
+
result = xc.call("VM.get_record",session,machine.id)
|
23
|
+
|
24
|
+
if result["Status"] != "Success"
|
25
|
+
@logger.info("Machine not found. Assuming it has been destroyed.")
|
26
|
+
machine.id = nil
|
27
|
+
return :not_created
|
28
|
+
end
|
29
|
+
|
30
|
+
return result["Value"]['power_state']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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 StartVM
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@logger = Log4r::Logger.new("vagrant::xenserver::actions::start_vm")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
myvm = env[:machine].id
|
18
|
+
|
19
|
+
env[:xc].call("VM.start",env[:session],myvm,false,false)
|
20
|
+
|
21
|
+
@app.call env
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|