examples: add examples/, fix README
This commit is contained in:
@ -32,7 +32,7 @@ Then connect to a guest agent server socket `/tmp/gqa.sock`:
|
|||||||
import qga
|
import qga
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
ga := qga.Client.new('/tmp/qga.sock')!
|
mut ga := qga.Client.new('/tmp/qga.sock')!
|
||||||
agent_version := ga.info()!.version
|
agent_version := ga.info()!.version
|
||||||
println('everything is fine! guest agent version is ${agent_version}')
|
println('everything is fine! guest agent version is ${agent_version}')
|
||||||
}
|
}
|
||||||
|
27
examples/runcmd.v
Normal file
27
examples/runcmd.v
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import time
|
||||||
|
import qga
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
args := arguments()[1..]
|
||||||
|
eprintln('Run this example as: `v -d trace_guest_agent run runcmd.v SOCKET_PATH COMMAND`')
|
||||||
|
eprintln('')
|
||||||
|
mut ga := qga.Client.new(args[0] or { panic('socket path is not provided') })!
|
||||||
|
eprintln('Ping guest agent...')
|
||||||
|
ga.ping() or { panic('ping failed...') }
|
||||||
|
eprintln('Ping successfull!')
|
||||||
|
eprintln('Run command!')
|
||||||
|
pid := ga.exec('/bin/sh',
|
||||||
|
args: ['-c', args[1] or { panic('COMMAND is not provided') }]
|
||||||
|
capture_output: true
|
||||||
|
)!
|
||||||
|
for {
|
||||||
|
status := ga.exec_status(pid)!
|
||||||
|
time.sleep(500 * time.millisecond)
|
||||||
|
if status.exited {
|
||||||
|
println(status)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user