{"action":"created","comment":{"url":"https://api.github.com/repos/apache/cloudstack/pulls/comments/183617380","pull_request_review_id":114647154,"id":183617380,"diff_hunk":"@@ -883,6 +885,73 @@ public void saveExtraDhcpOptions(final String networkUuid, final Long nicId, fin\n         return new Pair<NicProfile, Integer>(vmNic, Integer.valueOf(deviceId));\n     }\n \n+    /**\n+     * If the requested IPv4 address from the NicProfile was configured then it configures the IPv4 address, Netmask and Gateway to deploy the VM with the requested IP. \n+     */\n+    protected void configureNicProfileBasedOnRequestedIp(NicProfile requestedNicProfile, NicProfile nicProfile, Network network) {\n+        String requestedIpv4Address = requestedNicProfile.getRequestedIPv4();\n+        if (requestedIpv4Address == null) {\n+            s_logger.debug(String.format(\"The requested [IPv4 address=%s] is null\", requestedIpv4Address));\n+            return;\n+        }\n+        if (org.apache.commons.lang3.StringUtils.isBlank(requestedIpv4Address)) {\n+            throw new InvalidParameterValueException(String.format(\"The requested [IPv4 address='%s'] is empty or blank\", requestedIpv4Address));\n+        }\n+        if (!NetUtils.isValidIp4(requestedIpv4Address)) {\n+            throw new InvalidParameterValueException(String.format(\"The requested [IPv4 address='%s'] is not a valid IP address\", requestedIpv4Address));\n+        }\n+\n+        VlanVO vlanVo = _vlanDao.findByNetworkId(network.getId());\n+        if (vlanVo == null) {\n+            throw new CloudRuntimeException(String.format(\"Trying to configure a Nic with the requested [IPv4='%s'] but cannot find a Vlan for the [network id='%s']\",\n+                    requestedIpv4Address, network.getId()));\n+        }\n+\n+        acquireLockAndCheckIfIpv4IsFree(network, requestedIpv4Address);\n+\n+        String ipv4Gateway = vlanVo.getVlanGateway();\n+        String ipv4Netmask = vlanVo.getVlanNetmask();\n+\n+        if (org.apache.commons.lang3.StringUtils.isBlank(ipv4Gateway) || !NetUtils.isValidIp4(ipv4Gateway)) {\n+            throw new CloudRuntimeException(String.format(\"The [IPv4Gateway='%s'] from [VlanId='%s'] is not valid\", ipv4Gateway, vlanVo.getId()));\n+        }\n+        if (org.apache.commons.lang3.StringUtils.isBlank(ipv4Netmask) || !NetUtils.isValidIp4Netmask(ipv4Netmask)) {\n+            throw new CloudRuntimeException(String.format(\"The [IPv4Netmask='%s'] from [VlanId='%s'] is not valid\", ipv4Netmask, vlanVo.getId()));\n+        }\n+\n+        nicProfile.setIPv4Address(requestedIpv4Address);\n+        nicProfile.setIPv4Gateway(ipv4Gateway);\n+        nicProfile.setIPv4Netmask(ipv4Netmask);\n+\n+        if (nicProfile.getMacAddress() == null) {\n+            try {\n+                String macAddress = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());\n+                nicProfile.setMacAddress(macAddress);\n+            } catch (InsufficientAddressCapacityException e) {\n+                e.printStackTrace();","path":"engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java","position":56,"original_position":56,"commit_id":"03acbd227c392b28cc297d8b6fd409446d0084aa","original_commit_id":"03acbd227c392b28cc297d8b6fd409446d0084aa","user":{"login":"marcaurele","id":1081566,"avatar_url":"https://avatars3.githubusercontent.com/u/1081566?v=4","gravatar_id":"","url":"https://api.github.com/users/marcaurele","html_url":"https://github.com/marcaurele","followers_url":"https://api.github.com/users/marcaurele/followers","following_url":"https://api.github.com/users/marcaurele/following{/other_user}","gists_url":"https://api.github.com/users/marcaurele/gists{/gist_id}","starred_url":"https://api.github.com/users/marcaurele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcaurele/subscriptions","organizations_url":"https://api.github.com/users/marcaurele/orgs","repos_url":"https://api.github.com/users/marcaurele/repos","events_url":"https://api.github.com/users/marcaurele/events{/privacy}","received_events_url":"https://api.github.com/users/marcaurele/received_events","type":"User","site_admin":false},"body":"Require a logger here and to throw an exception","created_at":"2018-04-24T06:33:26Z","updated_at":"2018-04-24T06:33:27Z","html_url":"https://github.com/apache/cloudstack/pull/2595#discussion_r183617380","pull_request_url":"https://api.github.com/repos/apache/cloudstack/pulls/2595","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/cloudstack/pulls/comments/183617380"},"html":{"href":"https://github.com/apache/cloudstack/pull/2595#discussion_r183617380"},"pull_request":{"href":"https://api.github.com/repos/apache/cloudstack/pulls/2595"}}},"pull_request":{"url":"https://api.github.com/repos/apache/cloudstack/pulls/2595","id":183553843,"html_url":"https://github.com/apache/cloudstack/pull/2595","diff_url":"https://github.com/apache/cloudstack/pull/2595.diff","patch_url":"https://github.com/apache/cloudstack/pull/2595.patch","issue_url":"https://api.github.com/repos/apache/cloudstack/issues/2595","number":2595,"state":"open","locked":false,"title":"CLOUDSTACK-10199: Support requesting a specific IPv4 address","user":{"login":"GabrielBrascher","id":5025148,"avatar_url":"https://avatars0.githubusercontent.com/u/5025148?v=4","gravatar_id":"","url":"https://api.github.com/users/GabrielBrascher","html_url":"https://github.com/GabrielBrascher","followers_url":"https://api.github.com/users/GabrielBrascher/followers","following_url":"https://api.github.com/users/GabrielBrascher/following{/other_user}","gists_url":"https://api.github.com/users/GabrielBrascher/gists{/gist_id}","starred_url":"https://api.github.com/users/GabrielBrascher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GabrielBrascher/subscriptions","organizations_url":"https://api.github.com/users/GabrielBrascher/orgs","repos_url":"https://api.github.com/users/GabrielBrascher/repos","events_url":"https://api.github.com/users/GabrielBrascher/events{/privacy}","received_events_url":"https://api.github.com/users/GabrielBrascher/received_events","type":"User","site_admin":false},"body":"This pull request allows deploying VMs with a specific IPv4 address.\r\n\r\nDirectPodBasedNetworkGuru does not support requesting a custom IP-Address while creating a new NIC/Instance, throwing the following error:\r\n> Error 530: Does not support custom ip allocation at this time: NicProfile[0-0-null-null-null\r\n>     Unknown macro: { \"cserrorcode\"} \r\n\r\nSome use-cases prefer the ability to request the IPv4 address which the Instance will get.\r\n\r\nThis implementation adds unit test cases to cover and it was manually tested in Basic Networking. I can perform more tests if requested.\r\n\r\n## Types of changes\r\n<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->\r\n- [ ] Breaking change (fix or feature that would cause existing functionality to change)\r\n- [x] New feature (non-breaking change which adds functionality)\r\n- [x] Bug fix (non-breaking change which fixes an issue)\r\n- [ ] Enhancement (improves an existing feature and functionality)\r\n- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)\r\n\r\n## GitHub Issue/PRs\r\n<!-- If this PR is to fix an issue or another PR on GH, uncomment the section and provide the id of issue/PR -->\r\n<!-- When \"Fixes: #<id>\" is specified, the issue/PR will automatically be closed when this PR gets merged -->\r\n<!-- For addressing multiple issues/PRs, use multiple \"Fixes: #<id>\" -->\r\n\r\n<!-- Fixes: # -->\r\n\r\n## Screenshots (if appropriate):\r\n\r\n## How Has This Been Tested?\r\n\r\n<!-- Please describe in detail how you tested your changes. -->\r\n<!-- Include details of your testing environment, and the tests you ran to -->\r\n<!-- see how your change affects other areas of the code, etc. -->\r\n\r\n## Checklist:\r\n<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->\r\n<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->\r\n- [x] I have read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/master/CONTRIBUTING.md) document.\r\n- [ ] My code follows the code style of this project.\r\n- [ ] My change requires a change to the documentation.\r\n- [ ] I have updated the documentation accordingly.\r\nTesting\r\n- [x] I have added tests to cover my changes.\r\n- [ ] All relevant new and existing integration tests have passed.\r\n- [ ] A full integration testsuite with all test that can run on my environment has passed.\r\n\r\n","created_at":"2018-04-23T20:51:23Z","updated_at":"2018-04-24T06:33:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a42b045b9e82598128c8f1a966f80077bc4bb8b3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/cloudstack/pulls/2595/commits","review_comments_url":"https://api.github.com/repos/apache/cloudstack/pulls/2595/comments","review_comment_url":"https://api.github.com/repos/apache/cloudstack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/cloudstack/issues/2595/comments","statuses_url":"https://api.github.com/repos/apache/cloudstack/statuses/03acbd227c392b28cc297d8b6fd409446d0084aa","head":{"label":"GabrielBrascher:CLOUDSTACK-10199","ref":"CLOUDSTACK-10199","sha":"03acbd227c392b28cc297d8b6fd409446d0084aa","user":{"login":"GabrielBrascher","id":5025148,"avatar_url":"https://avatars0.githubusercontent.com/u/5025148?v=4","gravatar_id":"","url":"https://api.github.com/users/GabrielBrascher","html_url":"https://github.com/GabrielBrascher","followers_url":"https://api.github.com/users/GabrielBrascher/followers","following_url":"https://api.github.com/users/GabrielBrascher/following{/other_user}","gists_url":"https://api.github.com/users/GabrielBrascher/gists{/gist_id}","starred_url":"https://api.github.com/users/GabrielBrascher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GabrielBrascher/subscriptions","organizations_url":"https://api.github.com/users/GabrielBrascher/orgs","repos_url":"https://api.github.com/users/GabrielBrascher/repos","events_url":"https://api.github.com/users/GabrielBrascher/events{/privacy}","received_events_url":"https://api.github.com/users/GabrielBrascher/received_events","type":"User","site_admin":false},"repo":{"id":53541649,"name":"cloudstack","full_name":"GabrielBrascher/cloudstack","owner":{"login":"GabrielBrascher","id":5025148,"avatar_url":"https://avatars0.githubusercontent.com/u/5025148?v=4","gravatar_id":"","url":"https://api.github.com/users/GabrielBrascher","html_url":"https://github.com/GabrielBrascher","followers_url":"https://api.github.com/users/GabrielBrascher/followers","following_url":"https://api.github.com/users/GabrielBrascher/following{/other_user}","gists_url":"https://api.github.com/users/GabrielBrascher/gists{/gist_id}","starred_url":"https://api.github.com/users/GabrielBrascher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GabrielBrascher/subscriptions","organizations_url":"https://api.github.com/users/GabrielBrascher/orgs","repos_url":"https://api.github.com/users/GabrielBrascher/repos","events_url":"https://api.github.com/users/GabrielBrascher/events{/privacy}","received_events_url":"https://api.github.com/users/GabrielBrascher/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/GabrielBrascher/cloudstack","description":"Mirror of Apache Cloudstack","fork":true,"url":"https://api.github.com/repos/GabrielBrascher/cloudstack","forks_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/forks","keys_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/teams","hooks_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/hooks","issue_events_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/issues/events{/number}","events_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/events","assignees_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/assignees{/user}","branches_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/branches{/branch}","tags_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/tags","blobs_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/git/refs{/sha}","trees_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/statuses/{sha}","languages_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/languages","stargazers_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/stargazers","contributors_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/contributors","subscribers_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/subscribers","subscription_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/subscription","commits_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/commits{/sha}","git_commits_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/git/commits{/sha}","comments_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/comments{/number}","issue_comment_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/issues/comments{/number}","contents_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/contents/{+path}","compare_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/merges","archive_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/downloads","issues_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/issues{/number}","pulls_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/pulls{/number}","milestones_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/milestones{/number}","notifications_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/labels{/name}","releases_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/releases{/id}","deployments_url":"https://api.github.com/repos/GabrielBrascher/cloudstack/deployments","created_at":"2016-03-10T00:16:44Z","updated_at":"2016-03-10T00:17:13Z","pushed_at":"2018-04-23T21:01:46Z","git_url":"git://github.com/GabrielBrascher/cloudstack.git","ssh_url":"git@github.com:GabrielBrascher/cloudstack.git","clone_url":"https://github.com/GabrielBrascher/cloudstack.git","svn_url":"https://github.com/GabrielBrascher/cloudstack","homepage":null,"size":522949,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"f8b63754655daf378cf4a6cce9a76af9dd31d129","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":9759448,"name":"cloudstack","full_name":"apache/cloudstack","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/cloudstack","description":"Mirror of Apache Cloudstack","fork":false,"url":"https://api.github.com/repos/apache/cloudstack","forks_url":"https://api.github.com/repos/apache/cloudstack/forks","keys_url":"https://api.github.com/repos/apache/cloudstack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/cloudstack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/cloudstack/teams","hooks_url":"https://api.github.com/repos/apache/cloudstack/hooks","issue_events_url":"https://api.github.com/repos/apache/cloudstack/issues/events{/number}","events_url":"https://api.github.com/repos/apache/cloudstack/events","assignees_url":"https://api.github.com/repos/apache/cloudstack/assignees{/user}","branches_url":"https://api.github.com/repos/apache/cloudstack/branches{/branch}","tags_url":"https://api.github.com/repos/apache/cloudstack/tags","blobs_url":"https://api.github.com/repos/apache/cloudstack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/cloudstack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/cloudstack/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/cloudstack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/cloudstack/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/cloudstack/languages","stargazers_url":"https://api.github.com/repos/apache/cloudstack/stargazers","contributors_url":"https://api.github.com/repos/apache/cloudstack/contributors","subscribers_url":"https://api.github.com/repos/apache/cloudstack/subscribers","subscription_url":"https://api.github.com/repos/apache/cloudstack/subscription","commits_url":"https://api.github.com/repos/apache/cloudstack/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/cloudstack/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/cloudstack/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/cloudstack/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/cloudstack/contents/{+path}","compare_url":"https://api.github.com/repos/apache/cloudstack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/cloudstack/merges","archive_url":"https://api.github.com/repos/apache/cloudstack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/cloudstack/downloads","issues_url":"https://api.github.com/repos/apache/cloudstack/issues{/number}","pulls_url":"https://api.github.com/repos/apache/cloudstack/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/cloudstack/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/cloudstack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/cloudstack/labels{/name}","releases_url":"https://api.github.com/repos/apache/cloudstack/releases{/id}","deployments_url":"https://api.github.com/repos/apache/cloudstack/deployments","created_at":"2013-04-29T22:27:12Z","updated_at":"2018-04-23T14:54:58Z","pushed_at":"2018-04-24T06:29:14Z","git_url":"git://github.com/apache/cloudstack.git","ssh_url":"git@github.com:apache/cloudstack.git","clone_url":"https://github.com/apache/cloudstack.git","svn_url":"https://github.com/apache/cloudstack","homepage":null,"size":522685,"stargazers_count":556,"watchers_count":556,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":630,"mirror_url":null,"archived":false,"open_issues_count":137,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":630,"open_issues":137,"watchers":556,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/cloudstack/pulls/2595"},"html":{"href":"https://github.com/apache/cloudstack/pull/2595"},"issue":{"href":"https://api.github.com/repos/apache/cloudstack/issues/2595"},"comments":{"href":"https://api.github.com/repos/apache/cloudstack/issues/2595/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/cloudstack/pulls/2595/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/cloudstack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/cloudstack/pulls/2595/commits"},"statuses":{"href":"https://api.github.com/repos/apache/cloudstack/statuses/03acbd227c392b28cc297d8b6fd409446d0084aa"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"marcaurele"}}