{"action":"created","comment":{"url":"https://api.github.com/repos/juju/gomaasapi/pulls/comments/59484504","id":59484504,"diff_hunk":"@@ -109,6 +125,138 @@ func (i *interface_) Delete() error {\n \treturn nil\n }\n \n+// InterfaceLinkMode is the type of the various link mode constants used for\n+// LinkSubnetArgs.\n+type InterfaceLinkMode string\n+\n+const (\n+\t// LinkModeDHCP - Bring the interface up with DHCP on the given subnet. Only\n+\t// one subnet can be set to DHCP. If the subnet is managed this interface\n+\t// will pull from the dynamic IP range.\n+\tLinkModeDHCP InterfaceLinkMode = \"DHCP\"\n+\n+\t// LinkModeStatic - Bring the interface up with a STATIC IP address on the\n+\t// given subnet. Any number of STATIC links can exist on an interface.\n+\tLinkModeStatic InterfaceLinkMode = \"STATIC\"\n+\n+\t// LinkModeLinkUp - Bring the interface up only on the given subnet. No IP\n+\t// address will be assigned to this interface. The interface cannot have any\n+\t// current DHCP or STATIC links.\n+\tLinkModeLinkUp InterfaceLinkMode = \"LINK_UP\"\n+)\n+\n+// LinkSubnetArgs is an argument struct for passing parameters to\n+// the Interface.LinkSubnet method.\n+type LinkSubnetArgs struct {\n+\t// Mode is used to describe how the address is provided for the Link.\n+\t// Required field.\n+\tMode InterfaceLinkMode\n+\t// Subnet is the subnet to link to. Required field.\n+\tSubnet Subnet\n+\t// IPAddress is only valid when the Mode is set to LinkModeStatic. If\n+\t// not specified with a Mode of LinkModeStatic, an IP address from the\n+\t// subnet will be auto selected.\n+\tIPAddress string\n+\t// DefaultGateway will set the gateway IP address for the Subnet as the\n+\t// default gateway for the machine or device the interface belongs to.\n+\t// Option can only be used with mode LinkModeStatic.\n+\tDefaultGateway bool\n+}\n+\n+// Validate ensures that the Mode and Subnet are set, and that the other options\n+// are consistent with the Mode.\n+func (a *LinkSubnetArgs) Validate() error {\n+\tswitch a.Mode {\n+\tcase LinkModeDHCP, LinkModeLinkUp, LinkModeStatic:\n+\tcase \"\":\n+\t\treturn errors.NotValidf(\"missing Mode\")\n+\tdefault:\n+\t\treturn errors.NotValidf(\"unknown Mode value (%q)\", a.Mode)\n+\t}\n+\tif a.Subnet == nil {\n+\t\treturn errors.NotValidf(\"missing Subnet\")\n+\t}\n+\tif a.IPAddress != \"\" && a.Mode != LinkModeStatic {\n+\t\treturn errors.NotValidf(\"setting IP Address when Mode is not LinkModeStatic\")\n+\t}\n+\tif a.DefaultGateway && a.Mode != LinkModeStatic {\n+\t\treturn errors.NotValidf(\"specifying DefaultGateway for Mode %q\", a.Mode)\n+\t}\n+\treturn nil\n+}\n+\n+// LinkSubnet implements Interface.\n+func (i *interface_) LinkSubnet(args LinkSubnetArgs) error {\n+\tif err := args.Validate(); err != nil {\n+\t\treturn errors.Trace(err)\n+\t}\n+\tparams := NewURLParams()\n+\tparams.Values.Add(\"mode\", string(args.Mode))\n+\tparams.Values.Add(\"subnet\", fmt.Sprint(args.Subnet.ID()))\n+\tparams.MaybeAdd(\"ip_address\", args.IPAddress)\n+\tparams.MaybeAddBool(\"default_gateway\", args.DefaultGateway)\n+\tsource, err := i.controller.post(i.resourceURI, \"link_subnet\", params.Values)\n+\tif err != nil {\n+\t\tif svrErr, ok := errors.Cause(err).(ServerError); ok {\n+\t\t\tswitch svrErr.StatusCode {\n+\t\t\tcase http.StatusNotFound, http.StatusBadRequest:\n+\t\t\t\treturn errors.Wrap(err, NewBadRequestError(svrErr.BodyMessage))\n+\t\t\tcase http.StatusForbidden:\n+\t\t\t\treturn errors.Wrap(err, NewPermissionError(svrErr.BodyMessage))\n+\t\t\tcase http.StatusServiceUnavailable:\n+\t\t\t\treturn errors.Wrap(err, NewCannotCompleteError(svrErr.BodyMessage))\n+\t\t\t}\n+\t\t}\n+\t\treturn NewUnexpectedError(err)\n+\t}\n+\n+\tresponse, err := readInterface(i.controller.apiVersion, source)\n+\tif err != nil {\n+\t\treturn errors.Trace(err)\n+\t}\n+\ti.updateFrom(response)\n+\treturn nil\n+}\n+\n+// LinkSubnet implements Interface.\n+func (i *interface_) UnlinkSubnet(subnet Subnet) error {\n+\tif subnet == nil {\n+\t\treturn errors.NotValidf(\"missing Subnet\")\n+\t}\n+\tvar link Link\n+\tfor _, k := range i.links {\n+\t\tif s := k.Subnet(); s != nil && s.ID() == subnet.ID() {\n+\t\t\tlink = k\n+\t\t\tbreak\n+\t\t}\n+\t}\n+\tif link == nil {\n+\t\treturn errors.NotValidf(\"unlinked Subnet\")","path":"interface.go","position":140,"original_position":140,"commit_id":"f0a37df21079db6b38530baafe6ec80bb8ee5bfd","original_commit_id":"f0a37df21079db6b38530baafe6ec80bb8ee5bfd","user":{"login":"mjs","id":14993,"avatar_url":"https://avatars.githubusercontent.com/u/14993?v=3","gravatar_id":"","url":"https://api.github.com/users/mjs","html_url":"https://github.com/mjs","followers_url":"https://api.github.com/users/mjs/followers","following_url":"https://api.github.com/users/mjs/following{/other_user}","gists_url":"https://api.github.com/users/mjs/gists{/gist_id}","starred_url":"https://api.github.com/users/mjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjs/subscriptions","organizations_url":"https://api.github.com/users/mjs/orgs","repos_url":"https://api.github.com/users/mjs/repos","events_url":"https://api.github.com/users/mjs/events{/privacy}","received_events_url":"https://api.github.com/users/mjs/received_events","type":"User","site_admin":false},"body":"is this the right error text? An error here means that the subnet is linked to this interface but the error message implies the subnet isn't linked at all.","created_at":"2016-04-13T02:21:40Z","updated_at":"2016-04-13T02:21:40Z","html_url":"https://github.com/juju/gomaasapi/pull/33#discussion_r59484504","pull_request_url":"https://api.github.com/repos/juju/gomaasapi/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/juju/gomaasapi/pulls/comments/59484504"},"html":{"href":"https://github.com/juju/gomaasapi/pull/33#discussion_r59484504"},"pull_request":{"href":"https://api.github.com/repos/juju/gomaasapi/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/juju/gomaasapi/pulls/33","id":66239790,"html_url":"https://github.com/juju/gomaasapi/pull/33","diff_url":"https://github.com/juju/gomaasapi/pull/33.diff","patch_url":"https://github.com/juju/gomaasapi/pull/33.patch","issue_url":"https://api.github.com/repos/juju/gomaasapi/issues/33","number":33,"state":"open","locked":false,"title":"Link and Unlink Subnet to an interface","user":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars.githubusercontent.com/u/1744247?v=3","gravatar_id":"","url":"https://api.github.com/users/howbazaar","html_url":"https://github.com/howbazaar","followers_url":"https://api.github.com/users/howbazaar/followers","following_url":"https://api.github.com/users/howbazaar/following{/other_user}","gists_url":"https://api.github.com/users/howbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/howbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howbazaar/subscriptions","organizations_url":"https://api.github.com/users/howbazaar/orgs","repos_url":"https://api.github.com/users/howbazaar/repos","events_url":"https://api.github.com/users/howbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/howbazaar/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-12T22:37:47Z","updated_at":"2016-04-13T02:21:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0beb6ab9085c08418498ede3f472fd1bdb21091e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/juju/gomaasapi/pulls/33/commits","review_comments_url":"https://api.github.com/repos/juju/gomaasapi/pulls/33/comments","review_comment_url":"https://api.github.com/repos/juju/gomaasapi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/juju/gomaasapi/issues/33/comments","statuses_url":"https://api.github.com/repos/juju/gomaasapi/statuses/f0a37df21079db6b38530baafe6ec80bb8ee5bfd","head":{"label":"howbazaar:link-subnet","ref":"link-subnet","sha":"f0a37df21079db6b38530baafe6ec80bb8ee5bfd","user":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars.githubusercontent.com/u/1744247?v=3","gravatar_id":"","url":"https://api.github.com/users/howbazaar","html_url":"https://github.com/howbazaar","followers_url":"https://api.github.com/users/howbazaar/followers","following_url":"https://api.github.com/users/howbazaar/following{/other_user}","gists_url":"https://api.github.com/users/howbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/howbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howbazaar/subscriptions","organizations_url":"https://api.github.com/users/howbazaar/orgs","repos_url":"https://api.github.com/users/howbazaar/repos","events_url":"https://api.github.com/users/howbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/howbazaar/received_events","type":"User","site_admin":false},"repo":{"id":54937785,"name":"gomaasapi","full_name":"howbazaar/gomaasapi","owner":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars.githubusercontent.com/u/1744247?v=3","gravatar_id":"","url":"https://api.github.com/users/howbazaar","html_url":"https://github.com/howbazaar","followers_url":"https://api.github.com/users/howbazaar/followers","following_url":"https://api.github.com/users/howbazaar/following{/other_user}","gists_url":"https://api.github.com/users/howbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/howbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howbazaar/subscriptions","organizations_url":"https://api.github.com/users/howbazaar/orgs","repos_url":"https://api.github.com/users/howbazaar/repos","events_url":"https://api.github.com/users/howbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/howbazaar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/howbazaar/gomaasapi","description":"Go bindings for talking to MAAS","fork":true,"url":"https://api.github.com/repos/howbazaar/gomaasapi","forks_url":"https://api.github.com/repos/howbazaar/gomaasapi/forks","keys_url":"https://api.github.com/repos/howbazaar/gomaasapi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/howbazaar/gomaasapi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/howbazaar/gomaasapi/teams","hooks_url":"https://api.github.com/repos/howbazaar/gomaasapi/hooks","issue_events_url":"https://api.github.com/repos/howbazaar/gomaasapi/issues/events{/number}","events_url":"https://api.github.com/repos/howbazaar/gomaasapi/events","assignees_url":"https://api.github.com/repos/howbazaar/gomaasapi/assignees{/user}","branches_url":"https://api.github.com/repos/howbazaar/gomaasapi/branches{/branch}","tags_url":"https://api.github.com/repos/howbazaar/gomaasapi/tags","blobs_url":"https://api.github.com/repos/howbazaar/gomaasapi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/howbazaar/gomaasapi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/howbazaar/gomaasapi/git/refs{/sha}","trees_url":"https://api.github.com/repos/howbazaar/gomaasapi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/howbazaar/gomaasapi/statuses/{sha}","languages_url":"https://api.github.com/repos/howbazaar/gomaasapi/languages","stargazers_url":"https://api.github.com/repos/howbazaar/gomaasapi/stargazers","contributors_url":"https://api.github.com/repos/howbazaar/gomaasapi/contributors","subscribers_url":"https://api.github.com/repos/howbazaar/gomaasapi/subscribers","subscription_url":"https://api.github.com/repos/howbazaar/gomaasapi/subscription","commits_url":"https://api.github.com/repos/howbazaar/gomaasapi/commits{/sha}","git_commits_url":"https://api.github.com/repos/howbazaar/gomaasapi/git/commits{/sha}","comments_url":"https://api.github.com/repos/howbazaar/gomaasapi/comments{/number}","issue_comment_url":"https://api.github.com/repos/howbazaar/gomaasapi/issues/comments{/number}","contents_url":"https://api.github.com/repos/howbazaar/gomaasapi/contents/{+path}","compare_url":"https://api.github.com/repos/howbazaar/gomaasapi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/howbazaar/gomaasapi/merges","archive_url":"https://api.github.com/repos/howbazaar/gomaasapi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/howbazaar/gomaasapi/downloads","issues_url":"https://api.github.com/repos/howbazaar/gomaasapi/issues{/number}","pulls_url":"https://api.github.com/repos/howbazaar/gomaasapi/pulls{/number}","milestones_url":"https://api.github.com/repos/howbazaar/gomaasapi/milestones{/number}","notifications_url":"https://api.github.com/repos/howbazaar/gomaasapi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/howbazaar/gomaasapi/labels{/name}","releases_url":"https://api.github.com/repos/howbazaar/gomaasapi/releases{/id}","deployments_url":"https://api.github.com/repos/howbazaar/gomaasapi/deployments","created_at":"2016-03-29T02:00:28Z","updated_at":"2016-03-29T02:00:29Z","pushed_at":"2016-04-13T02:13:23Z","git_url":"git://github.com/howbazaar/gomaasapi.git","ssh_url":"git@github.com:howbazaar/gomaasapi.git","clone_url":"https://github.com/howbazaar/gomaasapi.git","svn_url":"https://github.com/howbazaar/gomaasapi","homepage":null,"size":496,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"juju:master","ref":"master","sha":"87a4495f27a7876fed2bf2e6faf07cca1ea2e2da","user":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=3","gravatar_id":"","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"repo":{"id":47433928,"name":"gomaasapi","full_name":"juju/gomaasapi","owner":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=3","gravatar_id":"","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/juju/gomaasapi","description":"Go bindings for talking to MAAS","fork":false,"url":"https://api.github.com/repos/juju/gomaasapi","forks_url":"https://api.github.com/repos/juju/gomaasapi/forks","keys_url":"https://api.github.com/repos/juju/gomaasapi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juju/gomaasapi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juju/gomaasapi/teams","hooks_url":"https://api.github.com/repos/juju/gomaasapi/hooks","issue_events_url":"https://api.github.com/repos/juju/gomaasapi/issues/events{/number}","events_url":"https://api.github.com/repos/juju/gomaasapi/events","assignees_url":"https://api.github.com/repos/juju/gomaasapi/assignees{/user}","branches_url":"https://api.github.com/repos/juju/gomaasapi/branches{/branch}","tags_url":"https://api.github.com/repos/juju/gomaasapi/tags","blobs_url":"https://api.github.com/repos/juju/gomaasapi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juju/gomaasapi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juju/gomaasapi/git/refs{/sha}","trees_url":"https://api.github.com/repos/juju/gomaasapi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juju/gomaasapi/statuses/{sha}","languages_url":"https://api.github.com/repos/juju/gomaasapi/languages","stargazers_url":"https://api.github.com/repos/juju/gomaasapi/stargazers","contributors_url":"https://api.github.com/repos/juju/gomaasapi/contributors","subscribers_url":"https://api.github.com/repos/juju/gomaasapi/subscribers","subscription_url":"https://api.github.com/repos/juju/gomaasapi/subscription","commits_url":"https://api.github.com/repos/juju/gomaasapi/commits{/sha}","git_commits_url":"https://api.github.com/repos/juju/gomaasapi/git/commits{/sha}","comments_url":"https://api.github.com/repos/juju/gomaasapi/comments{/number}","issue_comment_url":"https://api.github.com/repos/juju/gomaasapi/issues/comments{/number}","contents_url":"https://api.github.com/repos/juju/gomaasapi/contents/{+path}","compare_url":"https://api.github.com/repos/juju/gomaasapi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juju/gomaasapi/merges","archive_url":"https://api.github.com/repos/juju/gomaasapi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juju/gomaasapi/downloads","issues_url":"https://api.github.com/repos/juju/gomaasapi/issues{/number}","pulls_url":"https://api.github.com/repos/juju/gomaasapi/pulls{/number}","milestones_url":"https://api.github.com/repos/juju/gomaasapi/milestones{/number}","notifications_url":"https://api.github.com/repos/juju/gomaasapi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juju/gomaasapi/labels{/name}","releases_url":"https://api.github.com/repos/juju/gomaasapi/releases{/id}","deployments_url":"https://api.github.com/repos/juju/gomaasapi/deployments","created_at":"2015-12-04T23:27:09Z","updated_at":"2016-01-19T01:47:09Z","pushed_at":"2016-04-13T02:14:09Z","git_url":"git://github.com/juju/gomaasapi.git","ssh_url":"git@github.com:juju/gomaasapi.git","clone_url":"https://github.com/juju/gomaasapi.git","svn_url":"https://github.com/juju/gomaasapi","homepage":null,"size":439,"stargazers_count":3,"watchers_count":3,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":2,"forks":6,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/juju/gomaasapi/pulls/33"},"html":{"href":"https://github.com/juju/gomaasapi/pull/33"},"issue":{"href":"https://api.github.com/repos/juju/gomaasapi/issues/33"},"comments":{"href":"https://api.github.com/repos/juju/gomaasapi/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/juju/gomaasapi/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/juju/gomaasapi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/juju/gomaasapi/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/juju/gomaasapi/statuses/f0a37df21079db6b38530baafe6ec80bb8ee5bfd"}}}}