/
literal_loggable.go
145 lines (120 loc) · 4.95 KB
/
literal_loggable.go
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
// Copyright 2020 Google Inc. All Rights Reserved.
//
// 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 service
import "github.com/GoogleCloudPlatform/compute-image-tools/proto/go/pb"
type literalLoggable struct {
strings map[string]string
int64s map[string][]int64
bools map[string]bool
traceLogs []string
inspectionResults *pb.InspectionResults
}
func (w literalLoggable) GetInspectionResults() *pb.InspectionResults {
return w.inspectionResults
}
func (w literalLoggable) GetValue(key string) string { return w.strings[key] }
func (w literalLoggable) GetValueAsBool(key string) bool { return w.bools[key] }
func (w literalLoggable) GetValueAsInt64Slice(key string) []int64 { return w.int64s[key] }
func (w literalLoggable) ReadSerialPortLogs() []string { return w.traceLogs }
// SingleImageImportLoggableBuilder initializes and builds a Loggable with the metadata
// fields that are relevant when importing a single image.
type SingleImageImportLoggableBuilder struct {
literalLoggable
}
// NewSingleImageImportLoggableBuilder creates and initializes a SingleImageImportLoggableBuilder.
func NewSingleImageImportLoggableBuilder() *SingleImageImportLoggableBuilder {
return &SingleImageImportLoggableBuilder{literalLoggable{
strings: map[string]string{},
int64s: map[string][]int64{},
bools: map[string]bool{},
}}
}
// SetInspectionResults sets inspection results.
func (b *SingleImageImportLoggableBuilder) SetInspectionResults(inspectionResults *pb.InspectionResults) *SingleImageImportLoggableBuilder {
b.inspectionResults = inspectionResults
return b
}
// SetUEFIMetrics sets UEFI related metrics.
func (b *SingleImageImportLoggableBuilder) SetUEFIMetrics(isUEFICompatibleImageBool bool, isUEFIDetectedBool bool,
biosBootableBool bool, rootFSString string) *SingleImageImportLoggableBuilder {
b.bools[isUEFICompatibleImage] = isUEFICompatibleImageBool
b.bools[isUEFIDetected] = isUEFIDetectedBool
b.bools[uefiBootable] = isUEFIDetectedBool
b.bools[biosBootable] = biosBootableBool
b.strings[rootFS] = rootFSString
return b
}
// SetDiskAttributes sets disk related attributes.
func (b *SingleImageImportLoggableBuilder) SetDiskAttributes(fileFormat string, sourceSize int64,
targetSize int64) *SingleImageImportLoggableBuilder {
b.strings[importFileFormat] = fileFormat
b.int64s[sourceSizeGb] = []int64{sourceSize}
b.int64s[targetSizeGb] = []int64{targetSize}
return b
}
// SetInflationAttributes sets inflation related attributes.
func (b *SingleImageImportLoggableBuilder) SetInflationAttributes(matchResult string, inflationTypeStr string,
inflationTimeInt64 int64, shadowInflationTimeInt64 int64) *SingleImageImportLoggableBuilder {
b.strings[inflationType] = inflationTypeStr
b.strings[shadowDiskMatchResult] = matchResult
b.int64s[inflationTime] = []int64{inflationTimeInt64}
b.int64s[shadowInflationTime] = []int64{shadowInflationTimeInt64}
return b
}
// AppendTraceLogs sets trace logs during the import.
func (b *SingleImageImportLoggableBuilder) AppendTraceLogs(traceLogs []string) *SingleImageImportLoggableBuilder {
if b.traceLogs != nil {
b.traceLogs = append(b.traceLogs, traceLogs...)
} else {
b.traceLogs = traceLogs
}
return b
}
// Build builds the actual Loggable object.
func (b *SingleImageImportLoggableBuilder) Build() Loggable {
return b.literalLoggable
}
// OvfExportLoggableBuilder initializes and builds a Loggable with the metadata
// fields that are relevant when exporting OVF.
type OvfExportLoggableBuilder struct {
literalLoggable
}
// NewOvfExportLoggableBuilder creates and initializes a OvfExportLoggableBuilder.
func NewOvfExportLoggableBuilder() *OvfExportLoggableBuilder {
return &OvfExportLoggableBuilder{literalLoggable{
strings: map[string]string{},
int64s: map[string][]int64{},
bools: map[string]bool{},
}}
}
// SetDiskSizes sets disk sizes for OVF exported disks
func (b *OvfExportLoggableBuilder) SetDiskSizes(sourceSizes []int64,
targetSizes []int64) *OvfExportLoggableBuilder {
b.int64s[sourceSizeGb] = sourceSizes
b.int64s[targetSizeGb] = targetSizes
return b
}
// AppendTraceLogs sets trace logs during OVF export.
func (b *OvfExportLoggableBuilder) AppendTraceLogs(traceLogs []string) *OvfExportLoggableBuilder {
if b.traceLogs != nil {
b.traceLogs = append(b.traceLogs, traceLogs...)
} else {
b.traceLogs = traceLogs
}
return b
}
// Build builds the actual Loggable object.
func (b *OvfExportLoggableBuilder) Build() Loggable {
return b.literalLoggable
}