@@ -33,6 +33,9 @@ type Model interface {
33
33
HasStatus
34
34
HasStatusHistory
35
35
36
+ // AgentVersion returns the version currently in use by the model.
37
+ AgentVersion () string
38
+
36
39
Type () string
37
40
Cloud () string
38
41
CloudRegion () string
@@ -144,6 +147,9 @@ type Model interface {
144
147
// ModelArgs represent the bare minimum information that is needed
145
148
// to represent a model.
146
149
type ModelArgs struct {
150
+ // AgentVersion defines the current version in use by the model.
151
+ AgentVersion string
152
+
147
153
Type string
148
154
Owner names.UserTag
149
155
Config map [string ]interface {}
@@ -159,7 +165,8 @@ type ModelArgs struct {
159
165
// NewModel returns a Model based on the args specified.
160
166
func NewModel (args ModelArgs ) Model {
161
167
m := & model {
162
- Version : 10 ,
168
+ Version : 11 ,
169
+ AgentVersion_ : args .AgentVersion ,
163
170
Type_ : args .Type ,
164
171
Owner_ : args .Owner .Id (),
165
172
Config_ : args .Config ,
@@ -254,6 +261,9 @@ func parentId(machineId string) string {
254
261
type model struct {
255
262
Version int `yaml:"version"`
256
263
264
+ // AgentVersion_ defines the agent version in use by the model.
265
+ AgentVersion_ string `yaml:"agent-version"`
266
+
257
267
Type_ string `yaml:"type"`
258
268
Owner_ string `yaml:"owner"`
259
269
Config_ map [string ]interface {} `yaml:"config"`
@@ -314,6 +324,11 @@ type model struct {
314
324
PasswordHash_ string `yaml:"password-hash,omitempty"`
315
325
}
316
326
327
+ // AgentVersion returns the current agent version in use the by the model.
328
+ func (m * model ) AgentVersion () string {
329
+ return m .AgentVersion_
330
+ }
331
+
317
332
func (m * model ) Type () string {
318
333
return m .Type_
319
334
}
@@ -1092,6 +1107,15 @@ func (m *model) Validate() error {
1092
1107
return errors .NotValidf ("missing status" )
1093
1108
}
1094
1109
1110
+ if m .AgentVersion_ != "" {
1111
+ agentVersion , err := version .Parse (m .AgentVersion_ )
1112
+ if err != nil {
1113
+ return errors .Annotate (err , "agent version not parsable" )
1114
+ } else if agentVersion == version .Zero {
1115
+ return errors .NotValidf ("agent version cannot be zero" )
1116
+ }
1117
+ }
1118
+
1095
1119
validationCtx := newValidationContext ()
1096
1120
for _ , machine := range m .Machines_ .Machines_ {
1097
1121
if err := m .validateMachine (validationCtx , machine ); err != nil {
@@ -1522,6 +1546,7 @@ var modelDeserializationFuncs = map[int]modelDeserializationFunc{
1522
1546
8 : newModelImporter (8 , schema .FieldMap (modelV8Fields ())),
1523
1547
9 : newModelImporter (9 , schema .FieldMap (modelV9Fields ())),
1524
1548
10 : newModelImporter (10 , schema .FieldMap (modelV10Fields ())),
1549
+ 11 : newModelImporter (11 , schema .FieldMap (modelV11Fields ())),
1525
1550
}
1526
1551
1527
1552
func modelV1Fields () (schema.Fields , schema.Defaults ) {
@@ -1635,11 +1660,17 @@ func modelV10Fields() (schema.Fields, schema.Defaults) {
1635
1660
return fields , defaults
1636
1661
}
1637
1662
1663
+ func modelV11Fields () (schema.Fields , schema.Defaults ) {
1664
+ fields , defaults := modelV10Fields ()
1665
+ fields ["agent-version" ] = schema .String ()
1666
+ return fields , defaults
1667
+ }
1668
+
1638
1669
func newModelFromValid (valid map [string ]interface {}, importVersion int ) (* model , error ) {
1639
1670
// We're always making a version 8 model, no matter what we got on
1640
1671
// the way in.
1641
1672
result := & model {
1642
- Version : 10 ,
1673
+ Version : 11 ,
1643
1674
Type_ : IAAS ,
1644
1675
Owner_ : valid ["owner" ].(string ),
1645
1676
Config_ : valid ["config" ].(map [string ]interface {}),
@@ -1903,6 +1934,16 @@ func newModelFromValid(valid map[string]interface{}, importVersion int) (*model,
1903
1934
1904
1935
result .SecretBackendID_ = valid ["secret-backend-id" ].(string )
1905
1936
}
1937
+
1938
+ // When we are importing v11 onwards agent version will be a first class
1939
+ // citizen on the model. Before this we can attempt to get the value from
1940
+ // config.
1941
+ if importVersion >= 11 {
1942
+ result .AgentVersion_ = valid ["agent-version" ].(string )
1943
+ } else if result .Config_ != nil && result .Config_ ["agent-version" ] != nil {
1944
+ result .AgentVersion_ = result .Config_ ["agent-version" ].(string )
1945
+ }
1946
+
1906
1947
return result , nil
1907
1948
}
1908
1949
0 commit comments