-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosinfo.go
More file actions
167 lines (145 loc) · 4.04 KB
/
Copy pathosinfo.go
File metadata and controls
167 lines (145 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package osinfo
import (
"encoding/json"
"fmt"
"io/ioutil"
)
var OSInfoDBRepository = "https://gitlab.com/libosinfo/osinfo-db"
func Load(distro Distribution) (infoFiles []*InfoFile) {
filenames := distro.OSFiles()
for _, filename := range filenames {
fmt.Println("filename:", filename)
jsonBytes, _ := ioutil.ReadFile(filename)
infoFile := &InfoFile{}
err := json.Unmarshal(jsonBytes, &infoFile)
if err != nil {
fmt.Println("[error] error unmarshalling json data:", err)
}
infoFiles = append(infoFiles, infoFile)
}
fmt.Println("len(infoFiles):", len(infoFiles))
fmt.Println("osInfo:", infoFiles)
for _, file := range infoFiles {
fmt.Println("file:", file)
fmt.Println("file.LibOSInfo.OS.ReleaseVersion:")
fmt.Println("rv:", file.LibOSInfo.OS.ReleaseVersion)
}
return infoFiles
}
type InfoFile struct {
LibOSInfo struct {
InfoVersion string `json:"-version"`
OS struct {
ShortIDs []string `json:"short-id"`
ReleaseDate string `json:"release-date"`
ReleaseName string `json:"codename"`
ReleaseVersion string `json:"version"`
Vendor string `json:"_vendor"`
Family string `json:"linux"`
URL string `json:"-id"`
Name string `json:"name"`
Distro string `json:"distro"`
PreviousVersion struct {
URL string `json:"-id"`
} `json:"derives-from"`
Variant []struct {
Id string `json:"-id"`
Name string `json:"_name"`
} `json:"variant"`
Media []struct {
Arch string `json:"-arch"`
Variant struct {
Id string `json:"-id"`
} `json:"variant"`
URL string `json:"url"`
ISO struct {
VolumeID string `json:"volume-id"`
} `json:"iso"`
Kernel string `json:"kernel"`
Initrd string `json:"initrd"`
} `json:"media"`
Tree []struct {
Kernel string `json:"kernel"`
Initrd string `json:"initrd"`
Arch string `json:"-arch"`
URL string `json:"url"`
} `json:"tree"`
Image []struct {
Arch string `json:"-arch"`
Format string `json:"-format"`
Cloud string `json:"-cloud-init"`
URL string `json:"url"`
} `json:"image"`
Installer struct {
Script []struct {
Id string `json:"-id"`
} `json:"script"`
} `json:"installer"`
Upgrades struct {
Id string `json:"-id"`
} `json:"upgrades"`
Resources struct {
Arch string `json:"-arch"`
Recommended struct {
Storage string `json:"storage"`
CPU string `json:"cpu"`
RAM string `json:"ram"`
} `json:"recommended"`
Minimum struct {
Storage string `json:"storage"`
CPU string `json:"cpu"`
RAM string `json:"ram"`
CPUs string `json:"n-cpus"`
} `json:"minimum"`
} `json:"resources"`
} `json:"os"`
} `json:"libosinfo"`
}
type ByVersion []*InfoFile
func (self ByVersion) Len() int { return len(self) }
func (self ByVersion) Swap(i, j int) { self[i], self[j] = self[j], self[i] }
func (self ByVersion) Less(i, j int) bool {
return self[i].LibOSInfo.OS.ReleaseVersion < self[j].LibOSInfo.OS.ReleaseVersion
}
type Device struct {
URL string `xml:"attr,id"`
}
type Resources struct {
Arch string `xml:"arch,attr"`
Minimum Specs `xml:"minimum"`
Recommended Specs `xml:"recommended"`
}
type Specs struct {
CPU int `xml:"cpu"`
RAM int `xml:"ram"`
Storage int `xml:"storage"`
}
type Variant struct {
ID string `xml:"variant,attr"`
Name string `xml:"_name"`
}
type Media struct {
Arch string `xml:"media,attr"`
MediaType string `xml:"variant,attr"`
URL string `xml:"url"`
ISO string `xml:"iso,volume-id"`
Kernel string `xml:"kernel"`
Initrd string `xml:"initrd"`
}
type ArchTree struct {
Arch string `xml:"tree,attr"`
URL string `xml:"url"`
Kernel string `xml:"kernel"`
Initrd string `xml:"initrd"`
}
type Image struct {
Arch string `xml:"arch,attr"`
Format string `xml:"format,attr"`
Cloud bool `xml:"cloud-init,attr"`
}
type Installer struct {
Preseeds []Script `xml:"script"`
}
type Script struct {
PreseedURL string `xml:"id,attr"`
}