~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/application/client.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
type SetCharmConfig struct {
136
136
        // ApplicationName is the name of the application to set the charm on.
137
137
        ApplicationName string
 
138
 
138
139
        // CharmID identifies the charm.
139
140
        CharmID charmstore.CharmID
 
141
 
 
142
        // ConfigSettings is the charm settings to set during the upgrade.
 
143
        // This field is only understood by Application facade version 2
 
144
        // and greater.
 
145
        ConfigSettings map[string]string `json:"config-settings,omitempty"`
 
146
 
 
147
        // ConfigSettingsYAML is the charm settings in YAML format to set
 
148
        // during the upgrade. If this is non-empty, it will take precedence
 
149
        // over ConfigSettings. This field is only understood by Application
 
150
        // facade version 2
 
151
        ConfigSettingsYAML string `json:"config-settings-yaml,omitempty"`
 
152
 
140
153
        // ForceSeries forces the use of the charm even if it doesn't match the
141
154
        // series of the unit.
142
155
        ForceSeries bool
 
156
 
143
157
        // ForceUnits forces the upgrade on units in an error state.
144
158
        ForceUnits bool
 
159
 
145
160
        // ResourceIDs is a map of resource names to resource IDs to activate during
146
161
        // the upgrade.
147
162
        ResourceIDs map[string]string
 
163
 
 
164
        // StorageConstraints is a map of storage names to storage constraints to
 
165
        // update during the upgrade. This field is only understood by Application
 
166
        // facade version 2 and greater.
 
167
        StorageConstraints map[string]storage.Constraints `json:"storage-constraints,omitempty"`
148
168
}
149
169
 
150
170
// SetCharm sets the charm for a given service.
151
171
func (c *Client) SetCharm(cfg SetCharmConfig) error {
 
172
        var storageConstraints map[string]params.StorageConstraints
 
173
        if len(cfg.StorageConstraints) > 0 {
 
174
                storageConstraints = make(map[string]params.StorageConstraints)
 
175
                for name, cons := range cfg.StorageConstraints {
 
176
                        size, count := cons.Size, cons.Count
 
177
                        var sizePtr, countPtr *uint64
 
178
                        if size > 0 {
 
179
                                sizePtr = &size
 
180
                        }
 
181
                        if count > 0 {
 
182
                                countPtr = &count
 
183
                        }
 
184
                        storageConstraints[name] = params.StorageConstraints{
 
185
                                Pool:  cons.Pool,
 
186
                                Size:  sizePtr,
 
187
                                Count: countPtr,
 
188
                        }
 
189
                }
 
190
        }
152
191
        args := params.ApplicationSetCharm{
153
 
                ApplicationName: cfg.ApplicationName,
154
 
                CharmUrl:        cfg.CharmID.URL.String(),
155
 
                Channel:         string(cfg.CharmID.Channel),
156
 
                ForceSeries:     cfg.ForceSeries,
157
 
                ForceUnits:      cfg.ForceUnits,
158
 
                ResourceIDs:     cfg.ResourceIDs,
 
192
                ApplicationName:    cfg.ApplicationName,
 
193
                CharmUrl:           cfg.CharmID.URL.String(),
 
194
                Channel:            string(cfg.CharmID.Channel),
 
195
                ConfigSettings:     cfg.ConfigSettings,
 
196
                ConfigSettingsYAML: cfg.ConfigSettingsYAML,
 
197
                ForceSeries:        cfg.ForceSeries,
 
198
                ForceUnits:         cfg.ForceUnits,
 
199
                ResourceIDs:        cfg.ResourceIDs,
 
200
                StorageConstraints: storageConstraints,
159
201
        }
160
202
        return c.facade.FacadeCall("SetCharm", args, nil)
161
203
}