{"action":"created","comment":{"url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/comments/128117683","pull_request_review_id":50767489,"id":128117683,"diff_hunk":"@@ -244,38 +251,200 @@ function provisionNfsVolumes(job, cb) {\n                         eq: ['state', 'ready']\n                     })\n                 }, function onListVolumes(listVolumesErr, volumes) {\n-                    var loadedVolume;\n                     var errMsg;\n                     var err;\n \n                     if (!listVolumesErr) {\n-                        if (!volumes || (volumes && volumes.length !== 1)) {\n-                            errMsg = 'zero or more single volume with name '\n+                        if (volumes && volumes.length > 1) {\n+                            errMsg = 'more than one volume with name '\n                                 + volumeName + ' and owner_uuid: '\n-                                + job.params.owner_uuid + ' when we expected '\n-                                + 'exactly one';\n+                                + job.params.owner_uuid + ' when we '\n+                                + 'expected exactly one';\n                             job.log.error({volumes: volumes},\n                                 'Error: ' + errMsg);\n \n                             err = new Error(errMsg);\n-                            callback(err);\n+                            next(err);\n                             return;\n                         }\n \n-                        loadedVolume = volumes[0];\n+                        if (volumes && volumes.length === 1) {\n+                            job.log.info({\n+                                volume: volumes[0]\n+                            }, 'Found volume');\n+                            ctx.volume = volumes[0];\n+                        } else {\n+                            job.log.info({\n+                                name: volumeName,\n+                                owner_uuid: job.params.owner_uuid\n+                            }, 'Did not find any volume');\n+                        }\n+\n+                        next();\n+                    } else {\n+                        job.log.error({\n+                            error: listVolumesErr\n+                        }, 'Error when listing volumes');\n+\n+                        /*\n+                         * Ignoring this error for now, since we'll try to\n+                         * create the volume later, and retry to load it if\n+                         * it already exists. If we get an error loading the\n+                         * volume then, we'll make the task fail.\n+                         */\n+                        next();\n                     }\n+                });\n+            },\n+            function reserve(ctx, next) {\n+                if (job.params.vm_uuid === undefined) {\n+                    job.params.vm_uuid = uuid.v4();\n+                }\n \n-                    job.log.info({loadedVolume: loadedVolume},\n-                        'Loaded existing volume');\n-                    callback(listVolumesErr, loadedVolume);\n-                    return;\n+                job.log.info({\n+                    volume_uuid: ctx.volumeUuid,\n+                    job_uuid: job.uuid,\n+                    vm_uuid: job.params.vm_uuid,\n+                    owner_uuid: job.params.owner_uuid\n+                }, 'Reserving volume');\n+\n+                volapi.reserveVolume({\n+                    owner_uuid: job.params.owner_uuid,\n+                    job_uuid: job.uuid,\n+                    vm_uuid: job.params.vm_uuid,\n+                    volume_name: volumeName\n+                }, function onVolRes(volResErr, volRes) {\n+                    ctx.volumeReservation = volRes;\n+                    next(volResErr);\n                 });\n-            } else {\n-                job.log.info({createdVolume: createdVolume},\n-                    'Created new volume');\n-                callback(volumeCreationErr, createdVolume);\n-            }\n-        });\n+            },\n+            function provision(ctx, next) {\n+                var volumeCreationParams;\n+\n+                if (ctx.volume) {\n+                    job.log.info({\n+                        volume: ctx.volume\n+                    }, 'Volume already exits, no need to create it');\n+                    next();\n+                    return;\n+                }\n+\n+                job.log.info('Volume does not exists, creating it');\n+\n+                volumeCreationParams = {\n+                    name: volumeName,\n+                    owner_uuid: job.params.owner_uuid,\n+                    type: 'tritonnfs'\n+                };\n+\n+                /*\n+                 * If the volume doesn't exist, then we created its uuid\n+                 * beforehand to register a reservation for it, so we must\n+                 * pass that uuid to VOLAPI so that it uses that uuid when\n+                 * creating the volume to match the reservation.\n+                 */\n+                if (ctx.volumeUuid !== undefined) {\n+                    volumeCreationParams.uuid = ctx.volumeUuid;\n+                }\n+\n+                volumeCreationParams.networks =\n+                    vmNics.map(function getOverlayNetwork(network) {\n+                        job.log.info({network: network}, 'network');\n+\n+                        if (typeof (network) !== 'object') {\n+                            callback('network must be an object');","path":"lib/workflows/nfs-volumes/index.js","position":195,"original_position":195,"commit_id":"5095e7c4e772352a7921de5eb4acf985bb9b92af","original_commit_id":"5095e7c4e772352a7921de5eb4acf985bb9b92af","user":{"login":"misterdjules","id":811047,"avatar_url":"https://avatars0.githubusercontent.com/u/811047?v=4","gravatar_id":"","url":"https://api.github.com/users/misterdjules","html_url":"https://github.com/misterdjules","followers_url":"https://api.github.com/users/misterdjules/followers","following_url":"https://api.github.com/users/misterdjules/following{/other_user}","gists_url":"https://api.github.com/users/misterdjules/gists{/gist_id}","starred_url":"https://api.github.com/users/misterdjules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/misterdjules/subscriptions","organizations_url":"https://api.github.com/users/misterdjules/orgs","repos_url":"https://api.github.com/users/misterdjules/repos","events_url":"https://api.github.com/users/misterdjules/events{/privacy}","received_events_url":"https://api.github.com/users/misterdjules/received_events","type":"User","site_admin":false},"body":"> If somehow we had more than one non-object in the vmNics, wouldn't this mean we'll call callback() multiple times?\r\n\r\nYes, good catch!\r\n\r\n> Would it make sense to assert instead on\r\n\r\nI don't want to assert in workflow jobs because that basically prevents any other task in the workflow from being executed, including the onerror tasks chain.\r\n\r\nSo instead I'll refactor this code to call the callback once if there's 1 or more nics that are not of the expected type/layout. How does that sound?","created_at":"2017-07-18T22:59:44Z","updated_at":"2017-07-18T22:59:44Z","html_url":"https://github.com/joyent/sdc-vmapi/pull/27#discussion_r128117683","pull_request_url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/comments/128117683"},"html":{"href":"https://github.com/joyent/sdc-vmapi/pull/27#discussion_r128117683"},"pull_request":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27","id":129778320,"html_url":"https://github.com/joyent/sdc-vmapi/pull/27","diff_url":"https://github.com/joyent/sdc-vmapi/pull/27.diff","patch_url":"https://github.com/joyent/sdc-vmapi/pull/27.patch","issue_url":"https://api.github.com/repos/joyent/sdc-vmapi/issues/27","number":27,"state":"open","locked":false,"title":"DOCKER-1034 support docker volume ls -f dangling=true","user":{"login":"misterdjules","id":811047,"avatar_url":"https://avatars0.githubusercontent.com/u/811047?v=4","gravatar_id":"","url":"https://api.github.com/users/misterdjules","html_url":"https://github.com/misterdjules","followers_url":"https://api.github.com/users/misterdjules/followers","following_url":"https://api.github.com/users/misterdjules/following{/other_user}","gists_url":"https://api.github.com/users/misterdjules/gists{/gist_id}","starred_url":"https://api.github.com/users/misterdjules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/misterdjules/subscriptions","organizations_url":"https://api.github.com/users/misterdjules/orgs","repos_url":"https://api.github.com/users/misterdjules/repos","events_url":"https://api.github.com/users/misterdjules/events{/privacy}","received_events_url":"https://api.github.com/users/misterdjules/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-07-10T21:30:41Z","updated_at":"2017-07-18T22:59:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b64c1e4f8c4112d752d416cf516762b9ccc26a8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27/commits","review_comments_url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27/comments","review_comment_url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/joyent/sdc-vmapi/issues/27/comments","statuses_url":"https://api.github.com/repos/joyent/sdc-vmapi/statuses/5095e7c4e772352a7921de5eb4acf985bb9b92af","head":{"label":"misterdjules:DOCKER-1034","ref":"DOCKER-1034","sha":"5095e7c4e772352a7921de5eb4acf985bb9b92af","user":{"login":"misterdjules","id":811047,"avatar_url":"https://avatars0.githubusercontent.com/u/811047?v=4","gravatar_id":"","url":"https://api.github.com/users/misterdjules","html_url":"https://github.com/misterdjules","followers_url":"https://api.github.com/users/misterdjules/followers","following_url":"https://api.github.com/users/misterdjules/following{/other_user}","gists_url":"https://api.github.com/users/misterdjules/gists{/gist_id}","starred_url":"https://api.github.com/users/misterdjules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/misterdjules/subscriptions","organizations_url":"https://api.github.com/users/misterdjules/orgs","repos_url":"https://api.github.com/users/misterdjules/repos","events_url":"https://api.github.com/users/misterdjules/events{/privacy}","received_events_url":"https://api.github.com/users/misterdjules/received_events","type":"User","site_admin":false},"repo":{"id":39848608,"name":"sdc-vmapi","full_name":"misterdjules/sdc-vmapi","owner":{"login":"misterdjules","id":811047,"avatar_url":"https://avatars0.githubusercontent.com/u/811047?v=4","gravatar_id":"","url":"https://api.github.com/users/misterdjules","html_url":"https://github.com/misterdjules","followers_url":"https://api.github.com/users/misterdjules/followers","following_url":"https://api.github.com/users/misterdjules/following{/other_user}","gists_url":"https://api.github.com/users/misterdjules/gists{/gist_id}","starred_url":"https://api.github.com/users/misterdjules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/misterdjules/subscriptions","organizations_url":"https://api.github.com/users/misterdjules/orgs","repos_url":"https://api.github.com/users/misterdjules/repos","events_url":"https://api.github.com/users/misterdjules/events{/privacy}","received_events_url":"https://api.github.com/users/misterdjules/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/misterdjules/sdc-vmapi","description":"SDC Virtual Machine API (internal API)","fork":true,"url":"https://api.github.com/repos/misterdjules/sdc-vmapi","forks_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/forks","keys_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/teams","hooks_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/hooks","issue_events_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/issues/events{/number}","events_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/events","assignees_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/assignees{/user}","branches_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/branches{/branch}","tags_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/tags","blobs_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/git/refs{/sha}","trees_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/statuses/{sha}","languages_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/languages","stargazers_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/stargazers","contributors_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/contributors","subscribers_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/subscribers","subscription_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/subscription","commits_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/commits{/sha}","git_commits_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/git/commits{/sha}","comments_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/comments{/number}","issue_comment_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/issues/comments{/number}","contents_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/contents/{+path}","compare_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/merges","archive_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/downloads","issues_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/issues{/number}","pulls_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/pulls{/number}","milestones_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/milestones{/number}","notifications_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/labels{/name}","releases_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/releases{/id}","deployments_url":"https://api.github.com/repos/misterdjules/sdc-vmapi/deployments","created_at":"2015-07-28T17:38:52Z","updated_at":"2016-10-14T22:07:19Z","pushed_at":"2017-07-13T23:07:04Z","git_url":"git://github.com/misterdjules/sdc-vmapi.git","ssh_url":"git@github.com:misterdjules/sdc-vmapi.git","clone_url":"https://github.com/misterdjules/sdc-vmapi.git","svn_url":"https://github.com/misterdjules/sdc-vmapi","homepage":"","size":1785,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"joyent:tritonnfs","ref":"tritonnfs","sha":"37ee05f78989cce04fbb9411033b33a8b22cd1b9","user":{"login":"joyent","id":10161,"avatar_url":"https://avatars0.githubusercontent.com/u/10161?v=4","gravatar_id":"","url":"https://api.github.com/users/joyent","html_url":"https://github.com/joyent","followers_url":"https://api.github.com/users/joyent/followers","following_url":"https://api.github.com/users/joyent/following{/other_user}","gists_url":"https://api.github.com/users/joyent/gists{/gist_id}","starred_url":"https://api.github.com/users/joyent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joyent/subscriptions","organizations_url":"https://api.github.com/users/joyent/orgs","repos_url":"https://api.github.com/users/joyent/repos","events_url":"https://api.github.com/users/joyent/events{/privacy}","received_events_url":"https://api.github.com/users/joyent/received_events","type":"Organization","site_admin":false},"repo":{"id":23405894,"name":"sdc-vmapi","full_name":"joyent/sdc-vmapi","owner":{"login":"joyent","id":10161,"avatar_url":"https://avatars0.githubusercontent.com/u/10161?v=4","gravatar_id":"","url":"https://api.github.com/users/joyent","html_url":"https://github.com/joyent","followers_url":"https://api.github.com/users/joyent/followers","following_url":"https://api.github.com/users/joyent/following{/other_user}","gists_url":"https://api.github.com/users/joyent/gists{/gist_id}","starred_url":"https://api.github.com/users/joyent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joyent/subscriptions","organizations_url":"https://api.github.com/users/joyent/orgs","repos_url":"https://api.github.com/users/joyent/repos","events_url":"https://api.github.com/users/joyent/events{/privacy}","received_events_url":"https://api.github.com/users/joyent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/joyent/sdc-vmapi","description":"SDC Virtual Machine API (internal API)","fork":false,"url":"https://api.github.com/repos/joyent/sdc-vmapi","forks_url":"https://api.github.com/repos/joyent/sdc-vmapi/forks","keys_url":"https://api.github.com/repos/joyent/sdc-vmapi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/joyent/sdc-vmapi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/joyent/sdc-vmapi/teams","hooks_url":"https://api.github.com/repos/joyent/sdc-vmapi/hooks","issue_events_url":"https://api.github.com/repos/joyent/sdc-vmapi/issues/events{/number}","events_url":"https://api.github.com/repos/joyent/sdc-vmapi/events","assignees_url":"https://api.github.com/repos/joyent/sdc-vmapi/assignees{/user}","branches_url":"https://api.github.com/repos/joyent/sdc-vmapi/branches{/branch}","tags_url":"https://api.github.com/repos/joyent/sdc-vmapi/tags","blobs_url":"https://api.github.com/repos/joyent/sdc-vmapi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/joyent/sdc-vmapi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/joyent/sdc-vmapi/git/refs{/sha}","trees_url":"https://api.github.com/repos/joyent/sdc-vmapi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/joyent/sdc-vmapi/statuses/{sha}","languages_url":"https://api.github.com/repos/joyent/sdc-vmapi/languages","stargazers_url":"https://api.github.com/repos/joyent/sdc-vmapi/stargazers","contributors_url":"https://api.github.com/repos/joyent/sdc-vmapi/contributors","subscribers_url":"https://api.github.com/repos/joyent/sdc-vmapi/subscribers","subscription_url":"https://api.github.com/repos/joyent/sdc-vmapi/subscription","commits_url":"https://api.github.com/repos/joyent/sdc-vmapi/commits{/sha}","git_commits_url":"https://api.github.com/repos/joyent/sdc-vmapi/git/commits{/sha}","comments_url":"https://api.github.com/repos/joyent/sdc-vmapi/comments{/number}","issue_comment_url":"https://api.github.com/repos/joyent/sdc-vmapi/issues/comments{/number}","contents_url":"https://api.github.com/repos/joyent/sdc-vmapi/contents/{+path}","compare_url":"https://api.github.com/repos/joyent/sdc-vmapi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/joyent/sdc-vmapi/merges","archive_url":"https://api.github.com/repos/joyent/sdc-vmapi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/joyent/sdc-vmapi/downloads","issues_url":"https://api.github.com/repos/joyent/sdc-vmapi/issues{/number}","pulls_url":"https://api.github.com/repos/joyent/sdc-vmapi/pulls{/number}","milestones_url":"https://api.github.com/repos/joyent/sdc-vmapi/milestones{/number}","notifications_url":"https://api.github.com/repos/joyent/sdc-vmapi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/joyent/sdc-vmapi/labels{/name}","releases_url":"https://api.github.com/repos/joyent/sdc-vmapi/releases{/id}","deployments_url":"https://api.github.com/repos/joyent/sdc-vmapi/deployments","created_at":"2014-08-27T21:22:16Z","updated_at":"2017-06-15T20:01:27Z","pushed_at":"2017-07-17T18:04:23Z","git_url":"git://github.com/joyent/sdc-vmapi.git","ssh_url":"git@github.com:joyent/sdc-vmapi.git","clone_url":"https://github.com/joyent/sdc-vmapi.git","svn_url":"https://github.com/joyent/sdc-vmapi","homepage":"","size":1715,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27"},"html":{"href":"https://github.com/joyent/sdc-vmapi/pull/27"},"issue":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/issues/27"},"comments":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/joyent/sdc-vmapi/statuses/5095e7c4e772352a7921de5eb4acf985bb9b92af"}}}}
{"actor":{"display_login":"misterdjules"}}