~cmars/juju-core/local-repo-resolve

« back to all changes in this revision

Viewing changes to state/api/provisioner/provisioner.go

[r=dimitern] state;api: Allow adding existing networks/NICs

Added an AlreadyExistsError in errors/ and in
state/api/params with IsAlreadyExistsError and
IsCodeAlreadyExists helpers. This is used in
the provisioner API to report networks and
interfaces that already exist, and is needed
so that when provisioning more machines on the
same network wont' lead to errors (trying to
add existing network/NIC is just ignored).

https://codereview.appspot.com/85380043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
}
146
146
 
147
147
// AddNetworks creates one or more networks with the given parameters.
148
 
// If any operation fails, the first error is returned.
 
148
// If any operation fails, the first error is returned. Trying to add
 
149
// an already existing network is not an error.
149
150
func (st *State) AddNetworks(networks []params.NetworkParams) error {
150
151
        var results params.ErrorResults
151
152
        args := params.AddNetworkParams{Networks: networks}
157
158
                return fmt.Errorf("expected %d result(s), got %d", len(networks), n)
158
159
        }
159
160
        for _, result := range results.Results {
160
 
                if err := result.Error; err != nil {
 
161
                if err := result.Error; err != nil && params.IsCodeAlreadyExists(err) {
 
162
                        continue
 
163
                } else if err != nil {
161
164
                        return err
162
165
                }
163
166
        }