-
Notifications
You must be signed in to change notification settings - Fork 92
Issue 30 #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Issue 30 #129
Changes from 29 commits
1b2d460
f2b7da5
8bc24ba
84266ae
316181f
f8e85b6
f675e2d
e0a60fe
f5d43e3
b737dda
c4e662b
bfb4bef
e4d22a6
f92839f
85c6ceb
d550391
bea75d9
b35ebff
0a7d859
50f507f
06bd4ef
a4e3825
7acfe55
417cec6
daac6ad
4ef4ca4
c3c598c
f6749c9
4838752
64e311b
bab3bd7
20740c8
42ad391
aa14b77
98ca2de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2016 The go-qemu Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/digitalocean/go-qemu/qmp" | ||
) | ||
|
||
var ( | ||
uri = flag.String("uri", "qemu:///system", `URI to connect to the libvirtd host.`) | ||
domainName = flag.String("domainName", "mydomain", "This is the domain to run commands against.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove "This is". |
||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
libvirtGoMonitor := qmp.NewLibvirtGoMonitor(*uri, *domainName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just go with |
||
|
||
err := libvirtGoMonitor.Connect() | ||
if err != nil { | ||
log.Fatalf("Unable to connect: %v\n", err) | ||
} | ||
|
||
eventsChans, err := libvirtGoMonitor.Events() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if err != nil { | ||
log.Fatalf("Unable to register for events: %v\n", err) | ||
} | ||
|
||
fmt.Println("Waiting for Domain events...") | ||
go func() { | ||
for event := range eventsChans { | ||
fmt.Printf("Event: %#v\n", event) | ||
} | ||
}() | ||
|
||
fmt.Println("Press the Enter key to stop") | ||
fmt.Scanln() | ||
libvirtGoMonitor.Disconnect() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2016 The go-qemu Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/digitalocean/go-qemu/qmp" | ||
) | ||
|
||
var ( | ||
uri = flag.String("uri", "qemu:///system", `URI to connect to the libvirtd host.`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, use quotes instead of backticks since we don't need quotes inside the string. |
||
domainName = flag.String("domainName", "mydomain", "This is the domain to run commands against.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove "This is". |
||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
libvirtGoMonitor := qmp.NewLibvirtGoMonitor(*uri, *domainName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just go with mon for consistency with other documentation. |
||
|
||
err := libvirtGoMonitor.Connect() | ||
if err != nil { | ||
log.Fatalf("Unable to connect: %v\n", err) | ||
} | ||
|
||
command := []byte("{\"execute\" : \"query-cpus\"}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap the monitor in a |
||
cpus, err := libvirtGoMonitor.Run(command) | ||
if err != nil { | ||
log.Fatalf("Unable to run command: %v\n", err) | ||
} | ||
fmt.Printf("query-cpus: %s\n", string(cpus)) | ||
|
||
if err = libvirtGoMonitor.Disconnect(); err != nil { | ||
log.Fatalf("Unable to disconnect: %v\n", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2016 The go-qemu Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package qmp | ||
|
||
// LibvirtGoMonitor is a Monitor that wraps the libvirt-go package to | ||
// communicate with a QEMU Machine Protocol (QMP) socket. | ||
// Communication is provied via the libvirtd daemon. Multiple | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. *proxied |
||
// connections to the same hypervisor and domain are permitted. | ||
type LibvirtGoMonitor struct { | ||
Monitor | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, use quotes instead of backticks since we don't need quotes inside the string.