Module: Susi
- Defined in:
- lib/vm.rb,
lib/qmp.rb,
lib/ssh.rb,
lib/vnc.rb,
lib/disk.rb,
lib/susi.rb,
lib/output.rb,
lib/version.rb
Defined Under Namespace
Classes: Disk, QMP, SSH, VM, VNC
Constant Summary
collapse
- CONFIG_FILE =
".susi.yml"
- SUSI_DIR =
"#{ENV['HOME']}/.susi"
- TEMPLATE_DIR =
"#{SUSI_DIR}/templates"
- DISK_DIR =
"#{SUSI_DIR}/disks"
- VERSION =
'0.0.9'
Class Method Summary
collapse
Class Method Details
.current_vm_name ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/susi.rb', line 19
def self.current_vm_name
if !File.exist?(CONFIG_FILE)
raise "susi is not initialized"
end
config = YAML.load_file(CONFIG_FILE)
config['name'] || Dir.pwd.split('/').last
end
|
.debug(msg) ⇒ Object
2
3
4
|
# File 'lib/output.rb', line 2
def self.debug(msg)
puts msg if DEBUG
end
|
.info(msg) ⇒ Object
6
7
8
|
# File 'lib/output.rb', line 6
def self.info(msg)
puts msg
end
|
.init ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/susi.rb', line 29
def self.init
if !File.exist?(CONFIG_FILE)
id = SecureRandom.uuid
File.open(CONFIG_FILE, "w") do |file|
file.puts <<-YAML
id: #{id}
template: DEFAULT
YAML
end
end
end
|
.rm ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/susi.rb', line 80
def self.rm
if !File.exist?(CONFIG_FILE)
raise "susi is not initialized"
end
config = YAML.load_file(CONFIG_FILE)
id = config['id']
disk_name = "#{DISK_DIR}/#{id}.qcow2"
if File.exist?(disk_name)
Susi::debug "removing #{disk_name}"
File.delete(disk_name)
end
end
|
.start ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/susi.rb', line 44
def self.start
if !File.exist?(CONFIG_FILE)
raise "susi is not initialized"
end
config = YAML.load_file(CONFIG_FILE)
id = config['id']
name = config['name'] || Dir.pwd.split('/').last
usb = config['usb']
shared_dir = config['shared_dir']
disk_template = "#{TEMPLATE_DIR}/#{config['template']}"
if VM.running?(name)
raise "VM #{name} is already running"
end
disk_name = "#{DISK_DIR}/#{id}"
if !File.exist?("#{disk_name}.qcow2")
Susi::debug "Disk not found, cloning..."
Disk.clone(disk_template, disk_name)
VM.start(name, disk_name, usb: usb, shared_dir: shared_dir)
SSH.set_hostname(name)
if shared_dir
SSH.setup_virtio_filesystem(name)
end
else
VM.start(name, disk_name, usb: usb, shared_dir: shared_dir)
end
end
|