/
clusterdefaults.go
executable file
·82 lines (71 loc) · 3.47 KB
/
clusterdefaults.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
/*
* Copyright 2018-2022, CS Systemes d'Information, http://csgroup.eu
*
* 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 propertiesv3
import (
"fmt"
"github.com/CS-SI/SafeScale/v21/lib/server/resources/enums/clusterproperty"
propertiesv2 "github.com/CS-SI/SafeScale/v21/lib/server/resources/properties/v2"
"github.com/CS-SI/SafeScale/v21/lib/utils/data"
"github.com/CS-SI/SafeScale/v21/lib/utils/data/serialize"
"github.com/CS-SI/SafeScale/v21/lib/utils/fail"
)
// ClusterDefaults ...
// !!! FROZEN !!!
type ClusterDefaults struct {
GatewaySizing propertiesv2.HostSizingRequirements `json:"gateway_sizing,omitempty"` // GatewaySizing keeps the default node definition
GatewayTemplateID string `json:"gateway_template_id,omitempty"` // template id used at creation for gateways
MasterSizing propertiesv2.HostSizingRequirements `json:"master_sizing,omitempty"` // MasterSizing keeps the default node definition
MasterTemplateID string `json:"master_template_id,omitempty"` // template ID used at creation for masters
NodeSizing propertiesv2.HostSizingRequirements `json:"node_sizing,omitempty"` // NodeSizing keeps the default node definition
NodeTemplateID string `json:"node_template_id,omitempty"` // template ID used at creation for nodes
Image string `json:"image,omitempty"` // Image keeps the default Linux image name to use
ImageID string `json:"image_id,omitempty"` // contains the ID of the image used at creation
FeatureParameters []string `json:"feature_params,omitempty"` // contains the parameters submitted for automatic installed Features during Cluster creation
}
func newClusterDefaults() *ClusterDefaults {
return &ClusterDefaults{}
}
// IsNull ...
// satisfies interface data.Clonable
func (cd *ClusterDefaults) IsNull() bool {
return cd == nil || (cd.GatewaySizing == propertiesv2.HostSizingRequirements{} && cd.MasterSizing == propertiesv2.HostSizingRequirements{} && cd.NodeSizing == propertiesv2.HostSizingRequirements{})
}
// Clone ...
// satisfies interface data.Clonable
func (cd ClusterDefaults) Clone() (data.Clonable, error) {
return newClusterDefaults().Replace(&cd)
}
// Replace ...
// satisfies interface data.Clonable
func (cd *ClusterDefaults) Replace(p data.Clonable) (data.Clonable, error) {
if cd == nil || p == nil {
return nil, fail.InvalidInstanceError()
}
src, ok := p.(*ClusterDefaults)
if !ok {
return nil, fmt.Errorf("p is not a *ClusterDefaults")
}
*cd = *src
length := len(src.FeatureParameters)
if length > 0 {
cd.FeatureParameters = make([]string, len(src.FeatureParameters))
copy(cd.FeatureParameters, src.FeatureParameters)
}
return cd, nil
}
func init() {
serialize.PropertyTypeRegistry.Register("resources.cluster", clusterproperty.DefaultsV3, newClusterDefaults())
}