Skip to content
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1b2d460
started libvirt-go monitor
Oct 9, 2016
f2b7da5
libvirtgo: added new, connect, run, and disconnect
robertojrojas Oct 9, 2016
8bc24ba
Merge remote-tracking branch 'upstream/master' into issue_30
Oct 10, 2016
84266ae
Merge remote-tracking branch 'upstream/master' into issue_30
Oct 11, 2016
316181f
qmp/libvirt-go: start build tag support
Oct 12, 2016
f8e85b6
Merge remote-tracking branch 'upstream/master' into issue_30
Oct 12, 2016
f675e2d
qmp/libvirtgo: better code distribution
Oct 12, 2016
e0a60fe
qmp/libvirtgo: move exported methods to implementation
Oct 12, 2016
f5d43e3
qmp/libvirtgo: move domain, uri to implementation
robertojrojas Oct 12, 2016
b737dda
qmp/libvirtgo: fix pointer bug on Connect, Run methods
robertojrojas Oct 13, 2016
c4e662b
qmp/libvirtgo: add command example
robertojrojas Oct 13, 2016
bfb4bef
qmp/libvirtgo: start events notificaiton
Oct 15, 2016
e4d22a6
qmp/libvirtgo: compiles on linux
robertojrojas Oct 15, 2016
f92839f
qmp/libvirtgo: remove doneChan. change log messages.
Oct 16, 2016
85c6ceb
qmp/libvirtgo: fixed return val issue.
robertojrojas Oct 16, 2016
d550391
qmp/libvirtgo: fix bugs. add more comments.
robertojrojas Oct 17, 2016
bea75d9
qmp/libvirtgo: change libvirtgo_events example.
robertojrojas Oct 17, 2016
b35ebff
qmp/libvirtgo: remove fmt package. add events interval env variable
robertojrojas Oct 17, 2016
0a7d859
qmp/libvirtgo: construct event changes.
Oct 17, 2016
50f507f
qmp/libvirtgo: fix bug
robertojrojas Oct 17, 2016
06bd4ef
Merge remote-tracking branch 'upstream/master' into issue_30
Oct 17, 2016
a4e3825
qmp/libvirtgo: prepare for tests.
Oct 18, 2016
7acfe55
qmp/libvirtgo: fix typos and bugs.
robertojrojas Oct 18, 2016
417cec6
qmp/libvirtgo: start unit tests
robertojrojas Oct 18, 2016
daac6ad
qmp/libvirtgo: add more test
robertojrojas Oct 18, 2016
4ef4ca4
qmp/libvirtgo: add getPollInterval tests
robertojrojas Oct 18, 2016
c3c598c
qmp/libvirtgo: add events OK test
robertojrojas Oct 18, 2016
f6749c9
qmp/libvirtgo: add libvirtgo_run_command to README section
Oct 18, 2016
4838752
qmp/libvirtgo: add libvirtgo_events example to README section
Oct 18, 2016
64e311b
qmp/libvirtgo: changes PR review
Oct 21, 2016
bab3bd7
qmp/libvirtgo: use interfaces for internal implmentation
robertojrojas Oct 21, 2016
20740c8
qmp/libvirtgo: fix events test
robertojrojas Oct 21, 2016
42ad391
qmp/libvirtgo: add events loop interval parameter
robertojrojas Oct 24, 2016
aa14b77
qmp/libvirtgo: add libvirtgo to README
robertojrojas Oct 24, 2016
98ca2de
Merge remote-tracking branch 'upstream/master' into issue_30
Oct 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,49 @@ You should have an output similar to this:
```{r, engine='bash', count_lines}
Connecting to unix:///var/run/libvirt/libvirt-sock
Domain should be shut off now
```

#### libvirtgo_run_command

[libvirtgo_run_command](./libvirtgo_run_command) demonstrates how to use
the [libvirtGoMonitorLinux](https://godoc.org/github.com/digitalocean/go-qemu/libvirtGoMonitorLinux)
package to send a QMP command to the specified domain.

To run:
```{r, engine='bash', count_lines}
$ go get github.com/digitalocean/go-qemu
$ go run examples/libvirtgo_run_command/main.go -uri="qemu:///system" -domainName="centos7"
```


You should see an output similar to this:
```{r, engine='bash', count_lines}
query-cpus: {"return":[{"current":true,"CPU":0,"qom_path":"/machine/unattached/device[0]","pc":-2130342250,"halted":true,"thread_id":2462}],"id":"libvirt-36"}
```

#### libvirtgo_events

[libvirtgo_events](./libvirtgo_events) demonstrates how to use
the [libvirtGoMonitorLinux](https://godoc.org/github.com/digitalocean/go-qemu/libvirtGoMonitorLinux)
package to wait for lifecycle events from the specified domain.

To run:
```{r, engine='bash', count_lines}
$ go get github.com/digitalocean/go-qemu

Terminal 1:
$ go run examples/libvirtgo_events/main.go -uri="qemu:///system" -domainName="ubuntu14.04"

Terminal 2:
virsh -c qemu:///system
virsh # start ubuntu14.04
```


You should see an output similar to this on Terminal 1:
```{r, engine='bash', count_lines}
Waiting for Domain events...
Press the Enter key to stop
Event: qmp.Event{Event:"Domain event=\"resumed\" detail=\"unpaused\"", Data:map[string]interface {}{"details":libvirt.DomainLifecycleEvent{Event:4, Detail:0}}, Timestamp:struct { Seconds int64 "json:\"seconds\""; Microseconds int64 "json:\"microseconds\"" }{Seconds:11, Microseconds:0}}
Event: qmp.Event{Event:"Domain event=\"started\" detail=\"booted\"", Data:map[string]interface {}{"details":libvirt.DomainLifecycleEvent{Event:2, Detail:0}}, Timestamp:struct { Seconds int64 "json:\"seconds\""; Microseconds int64 "json:\"microseconds\"" }{Seconds:12, Microseconds:0}}
```
55 changes: 55 additions & 0 deletions examples/libvirtgo_events/main.go
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.`)
Copy link
Contributor

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.

domainName = flag.String("domainName", "mydomain", "This is the domain to run commands against.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "This is".

)

func main() {
flag.Parse()

libvirtGoMonitor := qmp.NewLibvirtGoMonitor(*uri, *domainName)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
}

eventsChans, err := libvirtGoMonitor.Events()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events for consistency with other documentation.

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()
}
50 changes: 50 additions & 0 deletions examples/libvirtgo_run_command/main.go
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.`)
Copy link
Contributor

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.

domainName = flag.String("domainName", "mydomain", "This is the domain to run commands against.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "This is".

)

func main() {
flag.Parse()

libvirtGoMonitor := qmp.NewLibvirtGoMonitor(*uri, *domainName)
Copy link
Contributor

Choose a reason for hiding this comment

The 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\"}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the monitor in a qemu.Domain and call its CPUs() method instead.

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)
}
}
23 changes: 23 additions & 0 deletions qmp/libvirtgo.go
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
Loading