close()
click to toggle source
def close
unless @channel.nil?
@channel.close
@channel = nil
end
unless @session.nil?
@session.close
@session = nil
end
@buffer = ''
end
connect(&cb)
click to toggle source
def connect(&cb)
run(cb) {
begin
@session = Libssh2.connect(@hostname, @username, @password) if @session.nil?
@channel = @session.exec('LANG=C virt-p2v-server') if @channel.nil?
end
begin
line = @channel.read(64)
if line !~ %r^VIRT_P2V_SERVER /
raise RemoteError.new("Unexpected response: #{line}")
end
rescue Libssh2::Channel::ApplicationError => ex
if ex.message =~ %rcommand not found/
raise RemoteError.new(
"virt-p2v-server is not installed on #{@hostname}")
else
raise RemoteError.new(ex.message)
end
end
begin
i = 0;
listener_result = lambda { |result|
if result.kind_of?(Exception)
cb.call(result)
else
i += 1
if i == @connection_listeners.length
cb.call(true)
else
Gtk.queue {
@connection_listeners[i].call(listener_result)
}
end
end
}
Gtk.queue { @connection_listeners[0].call(listener_result) }
rescue => ex
@channel.close unless @channel.nil?
raise ex
end
}
end
connected?()
click to toggle source
def connected?
return !@channel.nil?
end
container(type, &cb)
click to toggle source
def container(type, &cb)
raise NotConnectedError if @channel.nil?
run(cb) {
@channel.write("CONTAINER #{type}\n")
result = parse_return
Gtk.queue { cb.call(result) }
}
end
convert(&cb)
click to toggle source
def convert(&cb)
raise NotConnectedError if @channel.nil?
run(cb) {
@channel.write("CONVERT\n")
result = parse_return
Gtk.queue { cb.call(result) }
}
end
lang(lang, &cb)
click to toggle source
def lang(lang, &cb)
raise NotConnectedError if @channel.nil?
run(cb) {
@channel.write("LANG #{lang}\n")
result = parse_return
Gtk.queue { cb.call(result) }
}
end
list_profiles(&cb)
click to toggle source
def list_profiles(&cb)
raise NotConnectedError if @channel.nil?
run(cb) {
@channel.write("LIST_PROFILES\n")
result = parse_return
Gtk.queue { cb.call(result) }
}
end
on_connect(&cb)
click to toggle source
def on_connect(&cb)
@connection_listeners << cb
end
path(length, path, &cb)
click to toggle source
def path(length, path, &cb)
raise NotConnectedError if @channel.nil?
run(cb) {
@channel.write("PATH #{length} #{path}\n")
result = parse_return
Gtk.queue { cb.call(result) }
}
end
send_data(io, length, progress, &completion)
click to toggle source
def send_data(io, length, progress, &completion)
raise NotConnectedError if @channel.nil?
run(completion) {
@channel.write("DATA #{length}\n")
@channel.send_data(io) { |total|
Gtk.queue { progress.call(total) }
}
result = parse_return
Gtk.queue { progress.call(length); completion.call(result) }
}
end
set_profile(profile, &cb)
click to toggle source
def set_profile(profile, &cb)
raise NotConnectedError if @channel.nil?
run(cb) {
@channel.write("SET_PROFILE #{profile}\n")
result = parse_return
Gtk.queue { cb.call(result) }
}
end