Re: [libvirt] [PATCH] version: Add ParseVersion and a Version struct

2018-12-06 Thread John Ferlan



On 12/6/18 4:04 PM, John Ferlan wrote:
> 
> 
> On 10/11/18 7:58 PM, W. Trevor King wrote:
>> Make it easier to convert version integers to the more human-readable
>> major.minor.release format.

Oh, and I'll need you to "OK" me adding an Signed-off-by: or you need to
provide one. See:

https://libvirt.org/hacking.html

and point 6 of general tips:

Contributors to libvirt projects must assert that they are in compliance
with the Developer Certificate of Origin 1.1. This is achieved by adding
a "Signed-off-by" line containing the contributor's name and e-mail to
every commit message. The presence of this line attests that the
contributor has read the above lined DCO and agrees with its statements.

https://developercertificate.org/

John

>> ---
>>  connect.go  |  8 
>>  version.go  | 52 ++
>>  version_test.go | 64 
>> +
>>  3 files changed, 124 insertions(+)
>>  create mode 100644 version.go
>>  create mode 100644 version_test.go
>>
> 
> Well I'm far from the expert here, but since this has been "out there"
> for a while, I'll given it a go.
> 
> [...]
> 
>> diff --git a/version_test.go b/version_test.go
> 
> [...]
> 
>> +func TestParseVersion(t *testing.T) {
>> +for _, testCase := range []struct{
>> +inputuint32
>> +expected *Version
>> +}{
>> +{
>> +input: 3009000,
>> +expected: {Major: 3, Minor: 9},
> 
> NIT: Should the above have the "Release: 0" if nothing more than to
> prove your algorithm?  I can add it or leave it as is.
> 
> Reviewed-by: John Ferlan 
> 
> John
> 
> [let me know either way on the above and I can push this]
> 
> [...]
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] version: Add ParseVersion and a Version struct

2018-12-06 Thread John Ferlan



On 10/11/18 7:58 PM, W. Trevor King wrote:
> Make it easier to convert version integers to the more human-readable
> major.minor.release format.
> ---
>  connect.go  |  8 
>  version.go  | 52 ++
>  version_test.go | 64 
> +
>  3 files changed, 124 insertions(+)
>  create mode 100644 version.go
>  create mode 100644 version_test.go
> 

Well I'm far from the expert here, but since this has been "out there"
for a while, I'll given it a go.

[...]

> diff --git a/version_test.go b/version_test.go

[...]

> +func TestParseVersion(t *testing.T) {
> + for _, testCase := range []struct{
> + inputuint32
> + expected *Version
> + }{
> + {
> + input: 3009000,
> + expected: {Major: 3, Minor: 9},

NIT: Should the above have the "Release: 0" if nothing more than to
prove your algorithm?  I can add it or leave it as is.

Reviewed-by: John Ferlan 

John

[let me know either way on the above and I can push this]

[...]

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] version: Add ParseVersion and a Version struct

2018-10-15 Thread W. Trevor King
Make it easier to convert version integers to the more human-readable
major.minor.release format.
---
 connect.go  |  8 
 version.go  | 52 ++
 version_test.go | 64 +
 3 files changed, 124 insertions(+)
 create mode 100644 version.go
 create mode 100644 version_test.go

diff --git a/connect.go b/connect.go
index 8cc7cc7..fac45da 100644
--- a/connect.go
+++ b/connect.go
@@ -46,6 +46,7 @@ func init() {
 }
 
 const (
+   // VERSION_NUMBER is the version of the linked libvirt.
VERSION_NUMBER = uint32(C.LIBVIR_VERSION_NUMBER)
 )
 
@@ -306,7 +307,9 @@ func releaseConnectionData(c *Connect) {
delete(connections, c.ptr)
 }
 
+// GetVersion returns the version of the linked libvirt.
 // See also https://libvirt.org/html/libvirt-libvirt-host.html#virGetVersion
+// and ParseVersion.
 func GetVersion() (uint32, error) {
var version C.ulong
var err C.virError
@@ -540,7 +543,10 @@ func (c *Connect) GetHostname() (string, error) {
return hostname, nil
 }
 
+// GetLibVersion returns the version of libvirt used by the daemon
+// running on the connected host.
 // See also 
https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetLibVersion
+// and ParseVersion.
 func (c *Connect) GetLibVersion() (uint32, error) {
var version C.ulong
var err C.virError
@@ -2272,7 +2278,9 @@ func (c *Connect) GetDomainCapabilities(emulatorbin 
string, arch string, machine
return C.GoString(ret), nil
 }
 
+// GetVersion returns the hypervisor version.
 // See also 
https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetVersion
+// and ParseVersion.
 func (c *Connect) GetVersion() (uint32, error) {
var hvVer C.ulong
var err C.virError
diff --git a/version.go b/version.go
new file mode 100644
index 000..1a07fa3
--- /dev/null
+++ b/version.go
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ */
+
+package libvirt
+
+import (
+   "fmt"
+)
+
+// Version represents the libvirt version.
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virGetVersion
+type Version struct {
+   Major   uint32
+   Minor   uint32
+   Release uint32
+}
+
+// String returns the "major.minor.release" version string.
+func (v *Version) String() string {
+   return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Release)
+}
+
+// ParseVersion converts a version integer to a structured Version instance.
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virGetVersion
+func ParseVersion(version uint32) *Version {
+   return {
+   Major: version / 100,
+   Minor: (version / 1000) % 1000,
+   Release: version % 1000,
+   }
+}
diff --git a/version_test.go b/version_test.go
new file mode 100644
index 000..ecafe5d
--- /dev/null
+++ b/version_test.go
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL