Skip to content
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

Issue 30 #129

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

Issue 30 #129

wants to merge 35 commits into from

Conversation

robertojrojas
Copy link
Contributor

Here is one implementation of the Monitor using the https://github.com/rgbkrk/libvirt-go package.
Let me know if you there is anything you would like me to change.

Roberto J Rojas and others added 29 commits October 8, 2016 21:52
Copy link
Contributor

@mdlayher mdlayher left a comment

Choose a reason for hiding this comment

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

There's a lot that needs to be cleaned up for this to be merged.

Follow the style of other files in this repository.

Use interfaces instead of swapping out functions in tests.

Only break long lines of code into multiple lines.

)

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.


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.")
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.

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.

)

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.


// We only support lifecycleEvents for now
if lifecycleEvent, ok :=
eventDetails.(libvirt.DomainLifecycleEvent); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this up on the same line as the assignment. Only break up excessively long lines.

Seconds int64 `json:"seconds"`
Microseconds int64 `json:"microseconds"`
}
timestamp := TimeStamp{
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the existing Timestamp type in this package.

Microseconds int64 `json:"microseconds"`
}
timestamp := TimeStamp{
int64(now.Second()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Used keyed struct literals.

}
timestamp := TimeStamp{
int64(now.Second()),
int64(now.Second() / int(time.Microsecond)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Used keyed struct literals.

@@ -0,0 +1,357 @@
// Copyright 2016 The go-qemu Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

All tests need to make use of interfaces instead of swapping out functions at the package level.

@robertojrojas
Copy link
Contributor Author

@mdlayher great points! Specially the use of interfaces for stubbing functions. I honestly didn't like my approach either, but no alternatives came to mind. I'll start working on this tonight.

@mdlayher
Copy link
Contributor

Sounds good. Apologies for all the comments; just trying to keep things consistent throughout the repo where possible.

@robertojrojas
Copy link
Contributor Author

@mdlayher any feedback on my latest commits?

suryatmodulus pushed a commit to suryatmodulus/go-qemu that referenced this pull request Oct 1, 2022
This involves some additional changes to overcome breaking changes from
go-libvirt.

These are the new changes in this revision of go-libvirt since the last
release go-qemu has been using:

* remove invitation to empty IRC channel
* rpc_test: use Libvirt.addStream to add streams
* MockLibvirt: deep-copy response before adding ID
* monitor socket conn state in initLibvirtComms
* libvirttest: use atomic to read "serial"
* integration: wait for Disconnected before assert
* add CODEOWNERS
* Merge pull request digitalocean#152 from clarkwalcott/readme_update_rpc_link
* Docs: Update README with working link
* expose Libvirt.Disconnected method
* Add NetworkUpdateCompat
* update libvirt configuration step for new releases
* search generated include directory for header files
* ci updates (digitalocean#142)
* integration tests (digitalocean#141)
* take dialer as input instead of already existing connection (digitalocean#140)
* support authentication via polkit (digitalocean#138)
* fix some stream problems (digitalocean#137)
* Merge pull request digitalocean#136 from digitalocean/jenni/fix_potential_segfault
* write lock only needed for actual write
* rm unneeded nil'ing of reader and writer
* socket Disconnect close can race with nil of conn
* Merge pull request digitalocean#135 from digitalocean/jenni/update_cgo
* run go get golang.org/x/tools/go/internal/cgo@v0.1.1
* Merge pull request digitalocean#134 from digitalocean/jenni/add_socket_type
* change socket to pointer ref
* Merge branch 'master' of github.com:digitalocean/go-libvirt into jenni/add_socket_type
* Merge pull request digitalocean#133 from digitalocean/jenni/fix_event_unsubscribe_race
* reorder stream shutdown/delete
* fix race in disconnect of event stream cleanup
* add socket type to handle socket connection management
* Merge pull request digitalocean#132 from digitalocean/jenni/fix_client_deadlock
* fix typo and func conciseness
* move listen and cleanup into a func
* add timeout on waiting for disconnected
* move temporary read error check to a function
* Libvirt chan socketCleanupDone -> disconnected
* fix accidental go fmt of generated files
* add connect/disconnect to unit tests
* add tests for callback cleanup on connection disconnect
* fix rpc lookup test
* fix deadlocked clients on lack of libvirt response
* add more robust connection error checking
* Merge pull request digitalocean#131 from digitalocean/jenni/fix_invalid_test_data
* fix incorrect test data
* Merge pull request digitalocean#130 from digitalocean/jenni/stream_shutdown
* fix missing stream shutdown in lifecycle subscribe
* Merge pull request digitalocean#129 from digitalocean/geoff/vet-cleanup
* remove travis config file
* Clean up some linter errors
* Merge pull request digitalocean#125 from dmacvicar/dmacvicar_puberror
* Run generators against libvirt 7.2.0
* Unexport From* (ErrorDomain)
* golint
* go fmt
* libvirt.Error: expose only Code and Message
* Run generators against libvirt 7.1.0
* go fmt
* Make libvirtError public (libvirt.Error)
* github actions (digitalocean#128)
* internal/event/stream: fixes unsafe queue access (digitalocean#127)
* Merge pull request digitalocean#124 from sam-github/check-wrapped-errors
* Check wrapped errors for IsNotFound()
* Fix two race conditions related to Disconnect (digitalocean#120)
* Merge pull request digitalocean#119 from weizhouapache/readme-add-tls-port
* README: Add missing tls port in example
* README: Add example connect to libvirt via TLS over TCP (digitalocean#118)
* Add overload for Connect() to allow other libvirt drivers (digitalocean#117)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants