github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/apiserver/params/params.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package params 5 6 import ( 7 "fmt" 8 "strings" 9 "time" 10 11 "github.com/juju/errors" 12 "github.com/juju/utils/proxy" 13 "gopkg.in/juju/charm.v6-unstable" 14 "gopkg.in/macaroon.v1" 15 16 "github.com/juju/juju/constraints" 17 "github.com/juju/juju/instance" 18 "github.com/juju/juju/state/multiwatcher" 19 "github.com/juju/juju/storage" 20 "github.com/juju/juju/tools" 21 "github.com/juju/juju/utils/ssh" 22 "github.com/juju/juju/version" 23 ) 24 25 // FindTags wraps a slice of strings that are prefixes to use when 26 // searching for matching tags. 27 type FindTags struct { 28 Prefixes []string `json:"prefixes"` 29 } 30 31 // FindTagsResults wraps the mapping between the requested prefix and the 32 // matching tags for each requested prefix. 33 type FindTagsResults struct { 34 Matches map[string][]Entity `json:"matches"` 35 } 36 37 // Entity identifies a single entity. 38 type Entity struct { 39 Tag string 40 } 41 42 // Entities identifies multiple entities. 43 type Entities struct { 44 Entities []Entity 45 } 46 47 // EntityPasswords holds the parameters for making a SetPasswords call. 48 type EntityPasswords struct { 49 Changes []EntityPassword 50 } 51 52 // EntityPassword specifies a password change for the entity 53 // with the given tag. 54 type EntityPassword struct { 55 Tag string 56 Password string 57 } 58 59 // ErrorResults holds the results of calling a bulk operation which 60 // returns no data, only an error result. The order and 61 // number of elements matches the operations specified in the request. 62 type ErrorResults struct { 63 // Results contains the error results from each operation. 64 Results []ErrorResult 65 } 66 67 // OneError returns the error from the result 68 // of a bulk operation on a single value. 69 func (result ErrorResults) OneError() error { 70 if n := len(result.Results); n != 1 { 71 return fmt.Errorf("expected 1 result, got %d", n) 72 } 73 if err := result.Results[0].Error; err != nil { 74 return err 75 } 76 return nil 77 } 78 79 // Combine returns one error from the result which is an accumulation of the 80 // errors. If there are no errors in the result, the return value is nil. 81 // Otherwise the error values are combined with new-line characters. 82 func (result ErrorResults) Combine() error { 83 var errorStrings []string 84 for _, r := range result.Results { 85 if r.Error != nil { 86 errorStrings = append(errorStrings, r.Error.Error()) 87 } 88 } 89 if errorStrings != nil { 90 return errors.New(strings.Join(errorStrings, "\n")) 91 } 92 return nil 93 } 94 95 // ErrorResult holds the error status of a single operation. 96 type ErrorResult struct { 97 Error *Error 98 } 99 100 // AddRelation holds the parameters for making the AddRelation call. 101 // The endpoints specified are unordered. 102 type AddRelation struct { 103 Endpoints []string 104 } 105 106 // AddRelationResults holds the results of a AddRelation call. The Endpoints 107 // field maps service names to the involved endpoints. 108 type AddRelationResults struct { 109 Endpoints map[string]charm.Relation 110 } 111 112 // DestroyRelation holds the parameters for making the DestroyRelation call. 113 // The endpoints specified are unordered. 114 type DestroyRelation struct { 115 Endpoints []string 116 } 117 118 // AddCharmWithAuthorization holds the arguments for making an AddCharmWithAuthorization API call. 119 type AddCharmWithAuthorization struct { 120 URL string 121 CharmStoreMacaroon *macaroon.Macaroon 122 } 123 124 // AddMachineParams encapsulates the parameters used to create a new machine. 125 type AddMachineParams struct { 126 // The following fields hold attributes that will be given to the 127 // new machine when it is created. 128 Series string `json:"Series"` 129 Constraints constraints.Value `json:"Constraints"` 130 Jobs []multiwatcher.MachineJob `json:"Jobs"` 131 132 // Disks describes constraints for disks that must be attached to 133 // the machine when it is provisioned. 134 Disks []storage.Constraints `json:"Disks"` 135 136 // If Placement is non-nil, it contains a placement directive 137 // that will be used to decide how to instantiate the machine. 138 Placement *instance.Placement `json:"Placement"` 139 140 // If ParentId is non-empty, it specifies the id of the 141 // parent machine within which the new machine will 142 // be created. In that case, ContainerType must also be 143 // set. 144 ParentId string `json:"ParentId"` 145 146 // ContainerType optionally gives the container type of the 147 // new machine. If it is non-empty, the new machine 148 // will be implemented by a container. If it is specified 149 // but ParentId is empty, a new top level machine will 150 // be created to hold the container with given series, 151 // constraints and jobs. 152 ContainerType instance.ContainerType `json:"ContainerType"` 153 154 // If InstanceId is non-empty, it will be associated with 155 // the new machine along with the given nonce, 156 // hardware characteristics and addresses. 157 // All the following fields will be ignored if ContainerType 158 // is set. 159 InstanceId instance.Id `json:"InstanceId"` 160 Nonce string `json:"Nonce"` 161 HardwareCharacteristics instance.HardwareCharacteristics `json:"HardwareCharacteristics"` 162 Addrs []Address `json:"Addrs"` 163 } 164 165 // AddMachines holds the parameters for making the 166 // AddMachinesWithPlacement call. 167 type AddMachines struct { 168 MachineParams []AddMachineParams `json:"MachineParams"` 169 } 170 171 // AddMachinesResults holds the results of an AddMachines call. 172 type AddMachinesResults struct { 173 Machines []AddMachinesResult `json:"Machines"` 174 } 175 176 // AddMachinesResult holds the name of a machine added by the 177 // api.client.AddMachine call for a single machine. 178 type AddMachinesResult struct { 179 Machine string `json:"Machine"` 180 Error *Error `json:"Error"` 181 } 182 183 // DestroyMachines holds parameters for the DestroyMachines call. 184 type DestroyMachines struct { 185 MachineNames []string 186 Force bool 187 } 188 189 // ServicesDeploy holds the parameters for deploying one or more services. 190 type ServicesDeploy struct { 191 Services []ServiceDeploy 192 } 193 194 // ServiceDeploy holds the parameters for making the ServiceDeploy call. 195 type ServiceDeploy struct { 196 ServiceName string 197 CharmUrl string 198 NumUnits int 199 Config map[string]string 200 ConfigYAML string // Takes precedence over config if both are present. 201 Constraints constraints.Value 202 ToMachineSpec string 203 Placement []*instance.Placement 204 Networks []string 205 Storage map[string]storage.Constraints 206 } 207 208 // ServiceUpdate holds the parameters for making the ServiceUpdate call. 209 type ServiceUpdate struct { 210 ServiceName string 211 CharmUrl string 212 ForceCharmUrl bool 213 MinUnits *int 214 SettingsStrings map[string]string 215 SettingsYAML string // Takes precedence over SettingsStrings if both are present. 216 Constraints *constraints.Value 217 } 218 219 // ServiceSetCharm sets the charm for a given service. 220 type ServiceSetCharm struct { 221 ServiceName string 222 CharmUrl string 223 Force bool 224 } 225 226 // ServiceExpose holds the parameters for making the ServiceExpose call. 227 type ServiceExpose struct { 228 ServiceName string 229 } 230 231 // ServiceSet holds the parameters for a ServiceSet 232 // command. Options contains the configuration data. 233 type ServiceSet struct { 234 ServiceName string 235 Options map[string]string 236 } 237 238 // ServiceSetYAML holds the parameters for 239 // a ServiceSetYAML command. Config contains the 240 // configuration data in YAML format. 241 type ServiceSetYAML struct { 242 ServiceName string 243 Config string 244 } 245 246 // ServiceUnset holds the parameters for a ServiceUnset 247 // command. Options contains the option attribute names 248 // to unset. 249 type ServiceUnset struct { 250 ServiceName string 251 Options []string 252 } 253 254 // ServiceGet holds parameters for making the ServiceGet or 255 // ServiceGetCharmURL calls. 256 type ServiceGet struct { 257 ServiceName string 258 } 259 260 // ServiceGetResults holds results of the ServiceGet call. 261 type ServiceGetResults struct { 262 Service string 263 Charm string 264 Config map[string]interface{} 265 Constraints constraints.Value 266 } 267 268 // ServiceCharmRelations holds parameters for making the ServiceCharmRelations call. 269 type ServiceCharmRelations struct { 270 ServiceName string 271 } 272 273 // ServiceCharmRelationsResults holds the results of the ServiceCharmRelations call. 274 type ServiceCharmRelationsResults struct { 275 CharmRelations []string 276 } 277 278 // ServiceUnexpose holds parameters for the ServiceUnexpose call. 279 type ServiceUnexpose struct { 280 ServiceName string 281 } 282 283 // ServiceMetricCredential holds parameters for the SetServiceCredentials call. 284 type ServiceMetricCredential struct { 285 ServiceName string 286 MetricCredentials []byte 287 } 288 289 // ServiceMetricCredentials holds multiple ServiceMetricCredential parameters. 290 type ServiceMetricCredentials struct { 291 Creds []ServiceMetricCredential 292 } 293 294 // PublicAddress holds parameters for the PublicAddress call. 295 type PublicAddress struct { 296 Target string 297 } 298 299 // PublicAddressResults holds results of the PublicAddress call. 300 type PublicAddressResults struct { 301 PublicAddress string 302 } 303 304 // PrivateAddress holds parameters for the PrivateAddress call. 305 type PrivateAddress struct { 306 Target string 307 } 308 309 // PrivateAddressResults holds results of the PrivateAddress call. 310 type PrivateAddressResults struct { 311 PrivateAddress string 312 } 313 314 // Resolved holds parameters for the Resolved call. 315 type Resolved struct { 316 UnitName string 317 Retry bool 318 } 319 320 // ResolvedResults holds results of the Resolved call. 321 type ResolvedResults struct { 322 Service string 323 Charm string 324 Settings map[string]interface{} 325 } 326 327 // AddServiceUnitsResults holds the names of the units added by the 328 // AddServiceUnits call. 329 type AddServiceUnitsResults struct { 330 Units []string 331 } 332 333 // AddServiceUnits holds parameters for the AddUnits call. 334 type AddServiceUnits struct { 335 ServiceName string 336 NumUnits int 337 ToMachineSpec string 338 Placement []*instance.Placement 339 } 340 341 // DestroyServiceUnits holds parameters for the DestroyUnits call. 342 type DestroyServiceUnits struct { 343 UnitNames []string 344 } 345 346 // ServiceDestroy holds the parameters for making the ServiceDestroy call. 347 type ServiceDestroy struct { 348 ServiceName string 349 } 350 351 // Creds holds credentials for identifying an entity. 352 type Creds struct { 353 AuthTag string 354 Password string 355 Nonce string 356 } 357 358 // LoginRequest holds credentials for identifying an entity to the Login v1 359 // facade. 360 type LoginRequest struct { 361 AuthTag string `json:"auth-tag"` 362 Credentials string `json:"credentials"` 363 Nonce string `json:"nonce"` 364 } 365 366 // LoginRequestCompat holds credentials for identifying an entity to the Login v1 367 // or earlier (v0 or even pre-facade). 368 type LoginRequestCompat struct { 369 LoginRequest 370 Creds 371 } 372 373 // GetAnnotationsResults holds annotations associated with an entity. 374 type GetAnnotationsResults struct { 375 Annotations map[string]string 376 } 377 378 // GetAnnotations stores parameters for making the GetAnnotations call. 379 type GetAnnotations struct { 380 Tag string 381 } 382 383 // SetAnnotations stores parameters for making the SetAnnotations call. 384 type SetAnnotations struct { 385 Tag string 386 Pairs map[string]string 387 } 388 389 // GetServiceConstraints stores parameters for making the GetServiceConstraints call. 390 type GetServiceConstraints struct { 391 ServiceName string 392 } 393 394 // GetConstraintsResults holds results of the GetConstraints call. 395 type GetConstraintsResults struct { 396 Constraints constraints.Value 397 } 398 399 // SetConstraints stores parameters for making the SetConstraints call. 400 type SetConstraints struct { 401 ServiceName string //optional, if empty, environment constraints are set. 402 Constraints constraints.Value 403 } 404 405 // ResolveCharms stores charm references for a ResolveCharms call. 406 type ResolveCharms struct { 407 References []charm.Reference 408 } 409 410 // ResolveCharmResult holds the result of resolving a charm reference to a URL, or any error that occurred. 411 type ResolveCharmResult struct { 412 URL *charm.URL `json:",omitempty"` 413 Error string `json:",omitempty"` 414 } 415 416 // ResolveCharmResults holds results of the ResolveCharms call. 417 type ResolveCharmResults struct { 418 URLs []ResolveCharmResult 419 } 420 421 // AllWatcherId holds the id of an AllWatcher. 422 type AllWatcherId struct { 423 AllWatcherId string 424 } 425 426 // AllWatcherNextResults holds deltas returned from calling AllWatcher.Next(). 427 type AllWatcherNextResults struct { 428 Deltas []multiwatcher.Delta 429 } 430 431 // ListSSHKeys stores parameters used for a KeyManager.ListKeys call. 432 type ListSSHKeys struct { 433 Entities 434 Mode ssh.ListMode 435 } 436 437 // ModifyUserSSHKeys stores parameters used for a KeyManager.Add|Delete|Import call for a user. 438 type ModifyUserSSHKeys struct { 439 User string 440 Keys []string 441 } 442 443 // StateServingInfo holds information needed by a state 444 // server. 445 type StateServingInfo struct { 446 APIPort int 447 StatePort int 448 // The state server cert and corresponding private key. 449 Cert string 450 PrivateKey string 451 // The private key for the CA cert so that a new state server 452 // cert can be generated when needed. 453 CAPrivateKey string 454 // this will be passed as the KeyFile argument to MongoDB 455 SharedSecret string 456 SystemIdentity string 457 } 458 459 // IsMasterResult holds the result of an IsMaster API call. 460 type IsMasterResult struct { 461 // Master reports whether the connected agent 462 // lives on the same instance as the mongo replica 463 // set master. 464 Master bool 465 } 466 467 // ContainerManagerConfigParams contains the parameters for the 468 // ContainerManagerConfig provisioner API call. 469 type ContainerManagerConfigParams struct { 470 Type instance.ContainerType 471 } 472 473 // ContainerManagerConfig contains information from the environment config 474 // that is needed for configuring the container manager. 475 type ContainerManagerConfig struct { 476 ManagerConfig map[string]string 477 } 478 479 // UpdateBehavior contains settings that are duplicated in several 480 // places. Let's just embed this instead. 481 type UpdateBehavior struct { 482 EnableOSRefreshUpdate bool 483 EnableOSUpgrade bool 484 } 485 486 // ContainerConfig contains information from the environment config that is 487 // needed for container cloud-init. 488 type ContainerConfig struct { 489 ProviderType string 490 AuthorizedKeys string 491 SSLHostnameVerification bool 492 Proxy proxy.Settings 493 AptProxy proxy.Settings 494 AptMirror string 495 PreferIPv6 bool 496 AllowLXCLoopMounts bool 497 *UpdateBehavior 498 } 499 500 // ProvisioningScriptParams contains the parameters for the 501 // ProvisioningScript client API call. 502 type ProvisioningScriptParams struct { 503 MachineId string 504 Nonce string 505 506 // DataDir may be "", in which case the default will be used. 507 DataDir string 508 509 // DisablePackageCommands may be set to disable all 510 // package-related commands. It is then the responsibility of the 511 // provisioner to ensure that all the packages required by Juju 512 // are available. 513 DisablePackageCommands bool 514 } 515 516 // ProvisioningScriptResult contains the result of the 517 // ProvisioningScript client API call. 518 type ProvisioningScriptResult struct { 519 Script string 520 } 521 522 // DeployerConnectionValues containers the result of deployer.ConnectionInfo 523 // API call. 524 type DeployerConnectionValues struct { 525 StateAddresses []string 526 APIAddresses []string 527 } 528 529 // SetRsyslogCertParams holds parameters for the SetRsyslogCert call. 530 type SetRsyslogCertParams struct { 531 CACert []byte 532 CAKey []byte 533 } 534 535 // RsyslogConfigResult holds the result of a GetRsyslogConfig call. 536 type RsyslogConfigResult struct { 537 Error *Error `json:"Error"` 538 CACert string `json:"CACert"` 539 CAKey string `json:"CAKey"` 540 // Port is only used by state servers as the port to listen on. 541 // Clients should use HostPorts for the rsyslog addresses to forward 542 // logs to. 543 Port int `json:"Port"` 544 545 HostPorts []HostPort `json:"HostPorts"` 546 } 547 548 // RsyslogConfigResults is the bulk form of RyslogConfigResult 549 type RsyslogConfigResults struct { 550 Results []RsyslogConfigResult 551 } 552 553 // JobsResult holds the jobs for a machine that are returned by a call to Jobs. 554 type JobsResult struct { 555 Jobs []multiwatcher.MachineJob `json:"Jobs"` 556 Error *Error `json:"Error"` 557 } 558 559 // JobsResults holds the result of a call to Jobs. 560 type JobsResults struct { 561 Results []JobsResult `json:"Results"` 562 } 563 564 // DistributionGroupResult contains the result of 565 // the DistributionGroup provisioner API call. 566 type DistributionGroupResult struct { 567 Error *Error 568 Result []instance.Id 569 } 570 571 // DistributionGroupResults is the bulk form of 572 // DistributionGroupResult. 573 type DistributionGroupResults struct { 574 Results []DistributionGroupResult 575 } 576 577 // FacadeVersions describes the available Facades and what versions of each one 578 // are available 579 type FacadeVersions struct { 580 Name string 581 Versions []int 582 } 583 584 // LoginResult holds the result of a Login call. 585 type LoginResult struct { 586 Servers [][]HostPort `json:"Servers"` 587 EnvironTag string `json:"EnvironTag"` 588 LastConnection *time.Time `json:"LastConnection"` 589 Facades []FacadeVersions `json:"Facades"` 590 } 591 592 // ReauthRequest holds a challenge/response token meaningful to the identity 593 // provider. 594 type ReauthRequest struct { 595 Prompt string `json:"prompt"` 596 Nonce string `json:"nonce"` 597 } 598 599 // AuthUserInfo describes a logged-in local user or remote identity. 600 type AuthUserInfo struct { 601 DisplayName string `json:"display-name"` 602 Identity string `json:"identity"` 603 LastConnection *time.Time `json:"last-connection,omitempty"` 604 605 // Credentials contains an optional opaque credential value to be held by 606 // the client, if any. 607 Credentials *string `json:"credentials,omitempty"` 608 } 609 610 // LoginResultV1 holds the result of an Admin v1 Login call. 611 type LoginResultV1 struct { 612 // Servers is the list of API server addresses. 613 Servers [][]HostPort `json:"servers"` 614 615 // EnvironTag is the tag for the environment that is being connected to. 616 EnvironTag string `json:"environ-tag"` 617 618 // ServerTag is the tag for the environment that holds the API servers. 619 // This is the initial environment created when bootstrapping juju. 620 ServerTag string `json:"server-tag"` 621 622 // ReauthRequest can be used to relay any further authentication handshaking 623 // required on the part of the client to complete the Login, if any. 624 ReauthRequest *ReauthRequest `json:"reauth-request,omitempty"` 625 626 // UserInfo describes the authenticated user, if any. 627 UserInfo *AuthUserInfo `json:"user-info,omitempty"` 628 629 // Facades describes all the available API facade versions to the 630 // authenticated client. 631 Facades []FacadeVersions `json:"facades"` 632 633 // ServerVersion is the string representation of the server version 634 // if the server supports it. 635 ServerVersion string `json:"server-version,omitempty"` 636 } 637 638 // StateServersSpec contains arguments for 639 // the EnsureAvailability client API call. 640 type StateServersSpec struct { 641 EnvironTag string 642 NumStateServers int `json:"num-state-servers"` 643 Constraints constraints.Value `json:"constraints,omitempty"` 644 // Series is the series to associate with new state server machines. 645 // If this is empty, then the environment's default series is used. 646 Series string `json:"series,omitempty"` 647 // Placement defines specific machines to become new state server machines. 648 Placement []string `json:"placement,omitempty"` 649 } 650 651 // StateServersSpecs contains all the arguments 652 // for the EnsureAvailability API call. 653 type StateServersSpecs struct { 654 Specs []StateServersSpec 655 } 656 657 // StateServersChangeResult contains the results 658 // of a single EnsureAvailability API call or 659 // an error. 660 type StateServersChangeResult struct { 661 Result StateServersChanges 662 Error *Error 663 } 664 665 // StateServersChangeResults contains the results 666 // of the EnsureAvailability API call. 667 type StateServersChangeResults struct { 668 Results []StateServersChangeResult 669 } 670 671 // StateServersChanges lists the servers 672 // that have been added, removed or maintained in the 673 // pool as a result of an ensure-availability operation. 674 type StateServersChanges struct { 675 Added []string `json:"added,omitempty"` 676 Maintained []string `json:"maintained,omitempty"` 677 Removed []string `json:"removed,omitempty"` 678 Promoted []string `json:"promoted,omitempty"` 679 Demoted []string `json:"demoted,omitempty"` 680 Converted []string `json:"converted,omitempty"` 681 } 682 683 // FindToolsParams defines parameters for the FindTools method. 684 type FindToolsParams struct { 685 // Number will be used to match tools versions exactly if non-zero. 686 Number version.Number 687 688 // MajorVersion will be used to match the major version if non-zero. 689 MajorVersion int 690 691 // MinorVersion will be used to match the major version if greater 692 // than or equal to zero, and Number is zero. 693 MinorVersion int 694 695 // Arch will be used to match tools by architecture if non-empty. 696 Arch string 697 698 // Series will be used to match tools by series if non-empty. 699 Series string 700 } 701 702 // FindToolsResult holds a list of tools from FindTools and any error. 703 type FindToolsResult struct { 704 List tools.List 705 Error *Error 706 } 707 708 // ImageFilterParams holds the parameters used to specify images to delete. 709 type ImageFilterParams struct { 710 Images []ImageSpec `json:"images"` 711 } 712 713 // ImageSpec defines the parameters to select images list or delete. 714 type ImageSpec struct { 715 Kind string `json:"kind"` 716 Arch string `json:"arch"` 717 Series string `json:"series"` 718 } 719 720 // ListImageResult holds the results of querying images. 721 type ListImageResult struct { 722 Result []ImageMetadata `json:"result"` 723 } 724 725 // ImageMetadata represents an image in storage. 726 type ImageMetadata struct { 727 Kind string `json:"kind"` 728 Arch string `json:"arch"` 729 Series string `json:"series"` 730 URL string `json:"url"` 731 Created time.Time `json:"created"` 732 } 733 734 // RebootActionResults holds a list of RebootActionResult and any error. 735 type RebootActionResults struct { 736 Results []RebootActionResult `json:"results,omitempty"` 737 } 738 739 // RebootActionResult holds the result of a single call to 740 // machine.ShouldRebootOrShutdown. 741 type RebootActionResult struct { 742 Result RebootAction `json:"result,omitempty"` 743 Error *Error `json:"error,omitempty"` 744 }