/
params.go
742 lines (638 loc) · 19 KB
/
params.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package params
import (
"bytes"
"encoding/json"
"fmt"
"github.com/juju/utils/proxy"
"github.com/juju/juju/charm"
"github.com/juju/juju/constraints"
"github.com/juju/juju/instance"
"github.com/juju/juju/utils/ssh"
"github.com/juju/juju/version"
)
// Entity identifies a single entity.
type Entity struct {
Tag string
}
// Entities identifies multiple entities.
type Entities struct {
Entities []Entity
}
// EntityPasswords holds the parameters for making a SetPasswords call.
type EntityPasswords struct {
Changes []EntityPassword
}
// EntityPassword specifies a password change for the entity
// with the given tag.
type EntityPassword struct {
Tag string
Password string
}
// ErrorResults holds the results of calling a bulk operation which
// returns no data, only an error result. The order and
// number of elements matches the operations specified in the request.
type ErrorResults struct {
// Results contains the error results from each operation.
Results []ErrorResult
}
// OneError returns the error from the result
// of a bulk operation on a single value.
func (result ErrorResults) OneError() error {
if n := len(result.Results); n != 1 {
return fmt.Errorf("expected 1 result, got %d", n)
}
if err := result.Results[0].Error; err != nil {
return err
}
return nil
}
// ErrorResult holds the error status of a single operation.
type ErrorResult struct {
Error *Error
}
// StatusData contains additional information for a status.
type StatusData map[string]interface{}
// AddRelation holds the parameters for making the AddRelation call.
// The endpoints specified are unordered.
type AddRelation struct {
Endpoints []string
}
// AddRelationResults holds the results of a AddRelation call. The Endpoints
// field maps service names to the involved endpoints.
type AddRelationResults struct {
Endpoints map[string]charm.Relation
}
// DestroyRelation holds the parameters for making the DestroyRelation call.
// The endpoints specified are unordered.
type DestroyRelation struct {
Endpoints []string
}
// AddMachineParams encapsulates the parameters used to create a new machine.
type AddMachineParams struct {
// The following fields hold attributes that will be given to the
// new machine when it is created.
Series string
Constraints constraints.Value
Jobs []MachineJob
// If Placement is non-nil, it contains a placement directive
// that will be used to decide how to instantiate the machine.
Placement *instance.Placement
// If ParentId is non-empty, it specifies the id of the
// parent machine within which the new machine will
// be created. In that case, ContainerType must also be
// set.
ParentId string
// ContainerType optionally gives the container type of the
// new machine. If it is non-empty, the new machine
// will be implemented by a container. If it is specified
// but ParentId is empty, a new top level machine will
// be created to hold the container with given series,
// constraints and jobs.
ContainerType instance.ContainerType
// If InstanceId is non-empty, it will be associated with
// the new machine along with the given nonce,
// hardware characteristics and addresses.
// All the following fields will be ignored if ContainerType
// is set.
InstanceId instance.Id
Nonce string
HardwareCharacteristics instance.HardwareCharacteristics
Addrs []instance.Address
}
// AddMachines holds the parameters for making the
// AddMachinesWithPlacement call.
type AddMachines struct {
MachineParams []AddMachineParams
}
// AddMachinesResults holds the results of an AddMachines call.
type AddMachinesResults struct {
Machines []AddMachinesResult
}
// AddMachinesResults holds the name of a machine added by the
// state.api.client.AddMachine call for a single machine.
type AddMachinesResult struct {
Machine string
Error *Error
}
// DestroyMachines holds parameters for the DestroyMachines call.
type DestroyMachines struct {
MachineNames []string
Force bool
}
// ServiceDeploy holds the parameters for making the ServiceDeploy call.
type ServiceDeploy struct {
ServiceName string
CharmUrl string
NumUnits int
Config map[string]string
ConfigYAML string // Takes precedence over config if both are present.
Constraints constraints.Value
ToMachineSpec string
Networks []string
}
// ServiceUpdate holds the parameters for making the ServiceUpdate call.
type ServiceUpdate struct {
ServiceName string
CharmUrl string
ForceCharmUrl bool
MinUnits *int
SettingsStrings map[string]string
SettingsYAML string // Takes precedence over SettingsStrings if both are present.
Constraints *constraints.Value
}
// ServiceSetCharm sets the charm for a given service.
type ServiceSetCharm struct {
ServiceName string
CharmUrl string
Force bool
}
// ServiceExpose holds the parameters for making the ServiceExpose call.
type ServiceExpose struct {
ServiceName string
}
// ServiceSet holds the parameters for a ServiceSet
// command. Options contains the configuration data.
type ServiceSet struct {
ServiceName string
Options map[string]string
}
// ServiceSetYAML holds the parameters for
// a ServiceSetYAML command. Config contains the
// configuration data in YAML format.
type ServiceSetYAML struct {
ServiceName string
Config string
}
// ServiceUnset holds the parameters for a ServiceUnset
// command. Options contains the option attribute names
// to unset.
type ServiceUnset struct {
ServiceName string
Options []string
}
// ServiceGet holds parameters for making the ServiceGet or
// ServiceGetCharmURL calls.
type ServiceGet struct {
ServiceName string
}
// ServiceGetResults holds results of the ServiceGet call.
type ServiceGetResults struct {
Service string
Charm string
Config map[string]interface{}
Constraints constraints.Value
}
// ServiceCharmRelations holds parameters for making the ServiceCharmRelations call.
type ServiceCharmRelations struct {
ServiceName string
}
// ServiceCharmRelationsResults holds the results of the ServiceCharmRelations call.
type ServiceCharmRelationsResults struct {
CharmRelations []string
}
// ServiceUnexpose holds parameters for the ServiceUnexpose call.
type ServiceUnexpose struct {
ServiceName string
}
// PublicAddress holds parameters for the PublicAddress call.
type PublicAddress struct {
Target string
}
// PublicAddressResults holds results of the PublicAddress call.
type PublicAddressResults struct {
PublicAddress string
}
// PrivateAddress holds parameters for the PrivateAddress call.
type PrivateAddress struct {
Target string
}
// PrivateAddressResults holds results of the PrivateAddress call.
type PrivateAddressResults struct {
PrivateAddress string
}
// Resolved holds parameters for the Resolved call.
type Resolved struct {
UnitName string
Retry bool
}
// ResolvedResults holds results of the Resolved call.
type ResolvedResults struct {
Service string
Charm string
Settings map[string]interface{}
}
// AddServiceUnitsResults holds the names of the units added by the
// AddServiceUnits call.
type AddServiceUnitsResults struct {
Units []string
}
// AddServiceUnits holds parameters for the AddUnits call.
type AddServiceUnits struct {
ServiceName string
NumUnits int
ToMachineSpec string
}
// DestroyServiceUnits holds parameters for the DestroyUnits call.
type DestroyServiceUnits struct {
UnitNames []string
}
// ServiceDestroy holds the parameters for making the ServiceDestroy call.
type ServiceDestroy struct {
ServiceName string
}
// Creds holds credentials for identifying an entity.
type Creds struct {
AuthTag string
Password string
Nonce string
}
// GetAnnotationsResults holds annotations associated with an entity.
type GetAnnotationsResults struct {
Annotations map[string]string
}
// GetAnnotations stores parameters for making the GetAnnotations call.
type GetAnnotations struct {
Tag string
}
// SetAnnotations stores parameters for making the SetAnnotations call.
type SetAnnotations struct {
Tag string
Pairs map[string]string
}
// GetServiceConstraints stores parameters for making the GetServiceConstraints call.
type GetServiceConstraints struct {
ServiceName string
}
// GetConstraintsResults holds results of the GetConstraints call.
type GetConstraintsResults struct {
Constraints constraints.Value
}
// SetConstraints stores parameters for making the SetConstraints call.
type SetConstraints struct {
ServiceName string //optional, if empty, environment constraints are set.
Constraints constraints.Value
}
// CharmInfo stores parameters for a CharmInfo call.
type CharmInfo struct {
CharmURL string
}
// ResolveCharms stores charm references for a ResolveCharms call.
type ResolveCharms struct {
References []charm.Reference
}
// ResolveCharmResult holds the result of resolving a charm reference to a URL, or any error that occurred.
type ResolveCharmResult struct {
URL *charm.URL `json:",omitempty"`
Error string `json:",omitempty"`
}
// ResolveCharmResults holds results of the ResolveCharms call.
type ResolveCharmResults struct {
URLs []ResolveCharmResult
}
// AllWatcherId holds the id of an AllWatcher.
type AllWatcherId struct {
AllWatcherId string
}
// AllWatcherNextResults holds deltas returned from calling AllWatcher.Next().
type AllWatcherNextResults struct {
Deltas []Delta
}
// Delta holds details of a change to the environment.
type Delta struct {
// If Removed is true, the entity has been removed;
// otherwise it has been created or changed.
Removed bool
// Entity holds data about the entity that has changed.
Entity EntityInfo
}
// ListSSHKeys stores parameters used for a KeyManager.ListKeys call.
type ListSSHKeys struct {
Entities
Mode ssh.ListMode
}
// ModifySSHKeys stores parameters used for a KeyManager.Add|Delete|Import call for a user.
type ModifyUserSSHKeys struct {
User string
Keys []string
}
// ModifyUsers holds the parameters for making a UserManager Add or Modify calls.
type ModifyUsers struct {
Changes []ModifyUser
}
// ModifyUser stores the parameters used for a UserManager.Add|Remove call
type ModifyUser struct {
// Tag is here purely for backwards compatability. Older clients will
// attempt to use the EntityPassword structure, so we need a Tag here
// (which will be treated as Username)
Tag string
Username string
DisplayName string
Password string
}
// MarshalJSON implements json.Marshaler.
func (d *Delta) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(d.Entity)
if err != nil {
return nil, err
}
var buf bytes.Buffer
buf.WriteByte('[')
c := "change"
if d.Removed {
c = "remove"
}
fmt.Fprintf(&buf, "%q,%q,", d.Entity.EntityId().Kind, c)
buf.Write(b)
buf.WriteByte(']')
return buf.Bytes(), nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (d *Delta) UnmarshalJSON(data []byte) error {
var elements []json.RawMessage
if err := json.Unmarshal(data, &elements); err != nil {
return err
}
if len(elements) != 3 {
return fmt.Errorf(
"Expected 3 elements in top-level of JSON but got %d",
len(elements))
}
var entityKind, operation string
if err := json.Unmarshal(elements[0], &entityKind); err != nil {
return err
}
if err := json.Unmarshal(elements[1], &operation); err != nil {
return err
}
if operation == "remove" {
d.Removed = true
} else if operation != "change" {
return fmt.Errorf("Unexpected operation %q", operation)
}
switch entityKind {
case "machine":
d.Entity = new(MachineInfo)
case "service":
d.Entity = new(ServiceInfo)
case "unit":
d.Entity = new(UnitInfo)
case "relation":
d.Entity = new(RelationInfo)
case "annotation":
d.Entity = new(AnnotationInfo)
default:
return fmt.Errorf("Unexpected entity name %q", entityKind)
}
if err := json.Unmarshal(elements[2], &d.Entity); err != nil {
return err
}
return nil
}
// EntityInfo is implemented by all entity Info types.
type EntityInfo interface {
// EntityId returns an identifier that will uniquely
// identify the entity within its kind
EntityId() EntityId
}
// IMPORTANT NOTE: the types below are direct subsets of the entity docs
// held in mongo, as defined in the state package (serviceDoc,
// machineDoc etc).
// In particular, the document marshalled into mongo
// must unmarshal correctly into these documents.
// If the format of a field in a document is changed in mongo, or
// a field is removed and it coincides with one of the
// fields below, a similar change must be made here.
//
// MachineInfo corresponds with state.machineDoc.
// ServiceInfo corresponds with state.serviceDoc.
// UnitInfo corresponds with state.unitDoc.
// RelationInfo corresponds with state.relationDoc.
// AnnotationInfo corresponds with state.annotatorDoc.
var (
_ EntityInfo = (*MachineInfo)(nil)
_ EntityInfo = (*ServiceInfo)(nil)
_ EntityInfo = (*UnitInfo)(nil)
_ EntityInfo = (*RelationInfo)(nil)
_ EntityInfo = (*AnnotationInfo)(nil)
)
type EntityId struct {
Kind string
Id interface{}
}
// StateServingInfo holds information needed by a state
// server.
type StateServingInfo struct {
APIPort int
StatePort int
Cert string
PrivateKey string
// this will be passed as the KeyFile argument to MongoDB
SharedSecret string
SystemIdentity string
}
// IsMasterResult holds the result of an IsMaster API call.
type IsMasterResult struct {
// Master reports whether the connected agent
// lives on the same instance as the mongo replica
// set master.
Master bool
}
// MachineInfo holds the information about a Machine
// that is watched by StateWatcher.
type MachineInfo struct {
Id string `bson:"_id"`
InstanceId string
Status Status
StatusInfo string
StatusData StatusData
Life Life
Series string
SupportedContainers []instance.ContainerType
SupportedContainersKnown bool
HardwareCharacteristics *instance.HardwareCharacteristics `json:",omitempty"`
Jobs []MachineJob
Addresses []instance.Address
}
func (i *MachineInfo) EntityId() EntityId {
return EntityId{
Kind: "machine",
Id: i.Id,
}
}
type ServiceInfo struct {
Name string `bson:"_id"`
Exposed bool
CharmURL string
OwnerTag string
Life Life
MinUnits int
Constraints constraints.Value
Config map[string]interface{}
}
func (i *ServiceInfo) EntityId() EntityId {
return EntityId{
Kind: "service",
Id: i.Name,
}
}
type UnitInfo struct {
Name string `bson:"_id"`
Service string
Series string
CharmURL string
PublicAddress string
PrivateAddress string
MachineId string
Ports []instance.Port
Status Status
StatusInfo string
StatusData StatusData
}
func (i *UnitInfo) EntityId() EntityId {
return EntityId{
Kind: "unit",
Id: i.Name,
}
}
type Endpoint struct {
ServiceName string
Relation charm.Relation
}
type RelationInfo struct {
Key string `bson:"_id"`
Id int
Endpoints []Endpoint
}
func (i *RelationInfo) EntityId() EntityId {
return EntityId{
Kind: "relation",
Id: i.Key,
}
}
type AnnotationInfo struct {
Tag string
Annotations map[string]string
}
func (i *AnnotationInfo) EntityId() EntityId {
return EntityId{
Kind: "annotation",
Id: i.Tag,
}
}
// ContainerManagerConfigParams contains the parameters for the
// ContainerManagerConfig provisioner API call.
type ContainerManagerConfigParams struct {
Type instance.ContainerType
}
// ContainerManagerConfig contains information from the environment config
// that is needed for configuring the container manager.
type ContainerManagerConfig struct {
ManagerConfig map[string]string
}
// ContainerConfig contains information from the environment config that is
// needed for container cloud-init.
type ContainerConfig struct {
ProviderType string
AuthorizedKeys string
SSLHostnameVerification bool
Proxy proxy.Settings
AptProxy proxy.Settings
}
// ProvisioningScriptParams contains the parameters for the
// ProvisioningScript client API call.
type ProvisioningScriptParams struct {
MachineId string
Nonce string
// DataDir may be "", in which case the default will be used.
DataDir string
// DisablePackageCommands may be set to disable all package-related
// commands. It is then the responsibility of the provisioner to
// ensure that all the packages required by Juju are available.
DisablePackageCommands bool
}
// ProvisioningScriptResult contains the result of the
// ProvisioningScript client API call.
type ProvisioningScriptResult struct {
Script string
}
// EnvironmentGetResults contains the result of EnvironmentGet client
// API call.
type EnvironmentGetResults struct {
Config map[string]interface{}
}
// EnvironmentSet contains the arguments for EnvironmentSet client API
// call.
type EnvironmentSet struct {
Config map[string]interface{}
}
// EnvironmentUnset contains the arguments for EnvironmentUnset client API
// call.
type EnvironmentUnset struct {
Keys []string
}
// SetEnvironAgentVersion contains the arguments for
// SetEnvironAgentVersion client API call.
type SetEnvironAgentVersion struct {
Version version.Number
}
// DeployerConnectionValues containers the result of deployer.ConnectionInfo
// API call.
type DeployerConnectionValues struct {
StateAddresses []string
APIAddresses []string
}
// StatusParams holds parameters for the Status call.
type StatusParams struct {
Patterns []string
}
// SetRsyslogCertParams holds parameters for the SetRsyslogCert call.
type SetRsyslogCertParams struct {
CACert []byte
}
// RsyslogConfigResult holds the result of a GetRsyslogConfig call.
type RsyslogConfigResult struct {
Error *Error
CACert string
// Port is only used by state servers as the port to listen on.
// Clients should use HostPorts for the rsyslog addresses to forward
// logs to.
Port int
HostPorts []instance.HostPort
}
// RsyslogConfigResults is the bulk form of RyslogConfigResult
type RsyslogConfigResults struct {
Results []RsyslogConfigResult
}
// DistributionGroupResult contains the result of
// the DistributionGroup provisioner API call.
type DistributionGroupResult struct {
Error *Error
Result []instance.Id
}
// DistributionGroupResults is the bulk form of
// DistributionGroupResult.
type DistributionGroupResults struct {
Results []DistributionGroupResult
}
// APIHostPortsResult holds the result of an APIHostPorts
// call. Each element in the top level slice holds
// the addresses for one API server.
type APIHostPortsResult struct {
Servers [][]instance.HostPort
}
// LoginResult holds the result of a Login call.
type LoginResult struct {
Servers [][]instance.HostPort
EnvironTag string
}
// EnsureAvailability contains arguments for
// the EnsureAvailability client API call.
type EnsureAvailability struct {
NumStateServers int
Constraints constraints.Value
// Series is the series to associate with new state server machines.
// If this is empty, then the environment's default series is used.
Series string
}