Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(516)

Unified Diff: state/machine.go

Issue 85380043: state;api: Allow adding existing networks/NICs (Closed)
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/apiserver/testing/errors.go ('k') | state/machine_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/machine.go
=== modified file 'state/machine.go'
--- state/machine.go 2014-04-04 13:28:14 +0000
+++ state/machine.go 2014-04-08 10:20:15 +0000
@@ -960,11 +960,17 @@
// AddNetworkInterface creates a new network interface on the given
// network for the machine. The machine must be alive and not yet
// provisioned, and there must be no other interface with the same MAC
-// address for this to succeed.
+// address for this to succeed. If a network interface with the given
+// MAC address already exists, the returned error satisfies
+// errors.IsAlreadyExistsError.
func (m *Machine) AddNetworkInterface(macAddress, name, networkName string) (iface *NetworkInterface, err error) {
- defer utils.ErrorContextf(&err, "cannot add network interface to machine %s", m.doc.Id)
+ defer func() {
+ if !errors.IsAlreadyExistsError(err) {
+ utils.ErrorContextf(&err, "cannot add network interface to machine %s", m.doc.Id)
+ }
+ }()
- if _, err := net.ParseMAC(macAddress); err != nil {
+ if _, err = net.ParseMAC(macAddress); err != nil {
return nil, err
}
if name == "" {
@@ -1008,7 +1014,7 @@
return nil, fmt.Errorf("machine already provisioned: dynamic network interfaces not currently supported")
}
// Network and machine both OK, so the other assert must have failed.
- return nil, fmt.Errorf("interface with MAC address %q already exists", macAddress)
+ return nil, errors.NewAlreadyExistsError("interface with MAC address " + macAddress)
case nil:
return newNetworkInterface(m.st, doc), nil
default:
« no previous file with comments | « state/apiserver/testing/errors.go ('k') | state/machine_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b