{"action":"created","comment":{"url":"https://api.github.com/repos/rancherio/cattle/pulls/comments/31059776","id":31059776,"diff_hunk":"@@ -190,27 +236,108 @@ void setName(Map<String, Object> inspect, Map<String, Object> data, Instance ins\n     }\n \n     void setNetwork(Map<String, Object> inspect, Map<String, Object> data, Instance instance) {\n-        Network network = null;\n-        Network rancherNetwork = networkDao.getNetworkForObject(instance, KIND_HOSTONLY);\n-        String ip = getDockerIp(inspect);\n-        if (StringUtils.isNotEmpty(ip) && isIpInNetwork(ip, rancherNetwork)) {\n-            DataAccessor.fields(instance).withKey(FIELD_REQUESTED_IP_ADDRESS).set(ip);\n-            network = rancherNetwork;\n+        String networkMode = checkNoneNetwork(inspect);\n+        if (setNetworkModeIfNotNull(instance, networkMode))\n+            return;\n+\n+        String inspectNetMode = getInspectNetworkMode(inspect);\n+\n+        networkMode = checkHostNetwork(inspectNetMode);\n+        if (setNetworkModeIfNotNull(instance, networkMode))\n+            return;\n+\n+        networkMode = checkContainerNetwork(inspectNetMode, instance, data);\n+        if (setNetworkModeIfNotNull(instance, networkMode))\n+            return;\n+\n+        networkMode = checkBridgeOrManagedNetwork(inspectNetMode, inspect, data, instance);\n+        if (setNetworkModeIfNotNull(instance, networkMode))\n+            return;\n+\n+        log.warn(\"Could not determine network mode for container [externalId: {}]. Using none networking.\", instance.getExternalId());\n+        setNetworkModeIfNotNull(instance, NETWORK_MODE_NONE);\n+    }\n+\n+    private String getInspectNetworkMode(Map<String, Object> inspect) {\n+        Object tempNM = CollectionUtils.getNestedValue(inspect, \"HostConfig\", \"NetworkMode\");\n+        String inspectNetMode = tempNM == null ? \"\" : tempNM.toString();\n+        return inspectNetMode;\n+    }\n+\n+    private boolean setNetworkModeIfNotNull(Instance instance, String networkMode) {\n+        if (networkMode != null) {\n+            DataAccessor.fields(instance).withKey(FIELD_NETWORK_MODE).set(networkMode);\n+            return true;\n+        }\n+        return false;\n+    }\n+\n+    private String checkNoneNetwork(Map<String, Object> inspect) {\n+        Object netDisabledObj = CollectionUtils.getNestedValue(inspect, \"Config\", \"NetworkDisabled\");\n+        if (netDisabledObj != null && netDisabledObj instanceof Boolean && (Boolean)netDisabledObj) {","path":"code/iaas/logic/src/main/java/io/cattle/platform/process/containerevent/ContainerEventCreate.java","position":169,"original_position":169,"commit_id":"8067e51cd024ee5298cb41150c2eb108a9924201","original_commit_id":"8067e51cd024ee5298cb41150c2eb108a9924201","user":{"login":"alena1108","id":1562176,"avatar_url":"https://avatars.githubusercontent.com/u/1562176?v=3","gravatar_id":"","url":"https://api.github.com/users/alena1108","html_url":"https://github.com/alena1108","followers_url":"https://api.github.com/users/alena1108/followers","following_url":"https://api.github.com/users/alena1108/following{/other_user}","gists_url":"https://api.github.com/users/alena1108/gists{/gist_id}","starred_url":"https://api.github.com/users/alena1108/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alena1108/subscriptions","organizations_url":"https://api.github.com/users/alena1108/orgs","repos_url":"https://api.github.com/users/alena1108/repos","events_url":"https://api.github.com/users/alena1108/events{/privacy}","received_events_url":"https://api.github.com/users/alena1108/received_events","type":"User","site_admin":false},"body":"Nit: we can use \"Boolean.TRUE.equals(Object)\" structure here, and then you don't need extra not null/instanceof checks.","created_at":"2015-05-26T17:46:35Z","updated_at":"2015-05-26T17:46:35Z","html_url":"https://github.com/rancherio/cattle/pull/500#discussion_r31059776","pull_request_url":"https://api.github.com/repos/rancherio/cattle/pulls/500","_links":{"self":{"href":"https://api.github.com/repos/rancherio/cattle/pulls/comments/31059776"},"html":{"href":"https://github.com/rancherio/cattle/pull/500#discussion_r31059776"},"pull_request":{"href":"https://api.github.com/repos/rancherio/cattle/pulls/500"}}},"pull_request":{"url":"https://api.github.com/repos/rancherio/cattle/pulls/500","id":36225726,"html_url":"https://github.com/rancherio/cattle/pull/500","diff_url":"https://github.com/rancherio/cattle/pull/500.diff","patch_url":"https://github.com/rancherio/cattle/pull/500.patch","issue_url":"https://api.github.com/repos/rancherio/cattle/issues/500","number":500,"state":"open","locked":false,"title":"Support network modes in native-docker","user":{"login":"cjellick","id":2473240,"avatar_url":"https://avatars.githubusercontent.com/u/2473240?v=3","gravatar_id":"","url":"https://api.github.com/users/cjellick","html_url":"https://github.com/cjellick","followers_url":"https://api.github.com/users/cjellick/followers","following_url":"https://api.github.com/users/cjellick/following{/other_user}","gists_url":"https://api.github.com/users/cjellick/gists{/gist_id}","starred_url":"https://api.github.com/users/cjellick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjellick/subscriptions","organizations_url":"https://api.github.com/users/cjellick/orgs","repos_url":"https://api.github.com/users/cjellick/repos","events_url":"https://api.github.com/users/cjellick/events{/privacy}","received_events_url":"https://api.github.com/users/cjellick/received_events","type":"User","site_admin":false},"body":"Adds NetworkMode transformation to inspect transformer api (used by compose).\r\nAdds NetworkMode interpretation to native-docker container event\r\nprocessing.","created_at":"2015-05-26T17:26:42Z","updated_at":"2015-05-26T17:46:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c3ddb4389d5a0d31ca99bce0ed7921c806754473","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rancherio/cattle/pulls/500/commits","review_comments_url":"https://api.github.com/repos/rancherio/cattle/pulls/500/comments","review_comment_url":"https://api.github.com/repos/rancherio/cattle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rancherio/cattle/issues/500/comments","statuses_url":"https://api.github.com/repos/rancherio/cattle/statuses/8067e51cd024ee5298cb41150c2eb108a9924201","head":{"label":"cjellick:native-docker-net-modes","ref":"native-docker-net-modes","sha":"8067e51cd024ee5298cb41150c2eb108a9924201","user":{"login":"cjellick","id":2473240,"avatar_url":"https://avatars.githubusercontent.com/u/2473240?v=3","gravatar_id":"","url":"https://api.github.com/users/cjellick","html_url":"https://github.com/cjellick","followers_url":"https://api.github.com/users/cjellick/followers","following_url":"https://api.github.com/users/cjellick/following{/other_user}","gists_url":"https://api.github.com/users/cjellick/gists{/gist_id}","starred_url":"https://api.github.com/users/cjellick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjellick/subscriptions","organizations_url":"https://api.github.com/users/cjellick/orgs","repos_url":"https://api.github.com/users/cjellick/repos","events_url":"https://api.github.com/users/cjellick/events{/privacy}","received_events_url":"https://api.github.com/users/cjellick/received_events","type":"User","site_admin":false},"repo":{"id":26793817,"name":"cattle","full_name":"cjellick/cattle","owner":{"login":"cjellick","id":2473240,"avatar_url":"https://avatars.githubusercontent.com/u/2473240?v=3","gravatar_id":"","url":"https://api.github.com/users/cjellick","html_url":"https://github.com/cjellick","followers_url":"https://api.github.com/users/cjellick/followers","following_url":"https://api.github.com/users/cjellick/following{/other_user}","gists_url":"https://api.github.com/users/cjellick/gists{/gist_id}","starred_url":"https://api.github.com/users/cjellick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjellick/subscriptions","organizations_url":"https://api.github.com/users/cjellick/orgs","repos_url":"https://api.github.com/users/cjellick/repos","events_url":"https://api.github.com/users/cjellick/events{/privacy}","received_events_url":"https://api.github.com/users/cjellick/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cjellick/cattle","description":"Infrastructure orchestration platform","fork":true,"url":"https://api.github.com/repos/cjellick/cattle","forks_url":"https://api.github.com/repos/cjellick/cattle/forks","keys_url":"https://api.github.com/repos/cjellick/cattle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cjellick/cattle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cjellick/cattle/teams","hooks_url":"https://api.github.com/repos/cjellick/cattle/hooks","issue_events_url":"https://api.github.com/repos/cjellick/cattle/issues/events{/number}","events_url":"https://api.github.com/repos/cjellick/cattle/events","assignees_url":"https://api.github.com/repos/cjellick/cattle/assignees{/user}","branches_url":"https://api.github.com/repos/cjellick/cattle/branches{/branch}","tags_url":"https://api.github.com/repos/cjellick/cattle/tags","blobs_url":"https://api.github.com/repos/cjellick/cattle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cjellick/cattle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cjellick/cattle/git/refs{/sha}","trees_url":"https://api.github.com/repos/cjellick/cattle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cjellick/cattle/statuses/{sha}","languages_url":"https://api.github.com/repos/cjellick/cattle/languages","stargazers_url":"https://api.github.com/repos/cjellick/cattle/stargazers","contributors_url":"https://api.github.com/repos/cjellick/cattle/contributors","subscribers_url":"https://api.github.com/repos/cjellick/cattle/subscribers","subscription_url":"https://api.github.com/repos/cjellick/cattle/subscription","commits_url":"https://api.github.com/repos/cjellick/cattle/commits{/sha}","git_commits_url":"https://api.github.com/repos/cjellick/cattle/git/commits{/sha}","comments_url":"https://api.github.com/repos/cjellick/cattle/comments{/number}","issue_comment_url":"https://api.github.com/repos/cjellick/cattle/issues/comments{/number}","contents_url":"https://api.github.com/repos/cjellick/cattle/contents/{+path}","compare_url":"https://api.github.com/repos/cjellick/cattle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cjellick/cattle/merges","archive_url":"https://api.github.com/repos/cjellick/cattle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cjellick/cattle/downloads","issues_url":"https://api.github.com/repos/cjellick/cattle/issues{/number}","pulls_url":"https://api.github.com/repos/cjellick/cattle/pulls{/number}","milestones_url":"https://api.github.com/repos/cjellick/cattle/milestones{/number}","notifications_url":"https://api.github.com/repos/cjellick/cattle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cjellick/cattle/labels{/name}","releases_url":"https://api.github.com/repos/cjellick/cattle/releases{/id}","created_at":"2014-11-18T05:41:56Z","updated_at":"2015-04-02T20:43:46Z","pushed_at":"2015-05-26T17:19:59Z","git_url":"git://github.com/cjellick/cattle.git","ssh_url":"git@github.com:cjellick/cattle.git","clone_url":"https://github.com/cjellick/cattle.git","svn_url":"https://github.com/cjellick/cattle","homepage":"","size":18837,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"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":"rancherio:master","ref":"master","sha":"2bef5840ff02a5ede414005a349f25291288524a","user":{"login":"rancherio","id":9343010,"avatar_url":"https://avatars.githubusercontent.com/u/9343010?v=3","gravatar_id":"","url":"https://api.github.com/users/rancherio","html_url":"https://github.com/rancherio","followers_url":"https://api.github.com/users/rancherio/followers","following_url":"https://api.github.com/users/rancherio/following{/other_user}","gists_url":"https://api.github.com/users/rancherio/gists{/gist_id}","starred_url":"https://api.github.com/users/rancherio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rancherio/subscriptions","organizations_url":"https://api.github.com/users/rancherio/orgs","repos_url":"https://api.github.com/users/rancherio/repos","events_url":"https://api.github.com/users/rancherio/events{/privacy}","received_events_url":"https://api.github.com/users/rancherio/received_events","type":"Organization","site_admin":false},"repo":{"id":18023059,"name":"cattle","full_name":"rancherio/cattle","owner":{"login":"rancherio","id":9343010,"avatar_url":"https://avatars.githubusercontent.com/u/9343010?v=3","gravatar_id":"","url":"https://api.github.com/users/rancherio","html_url":"https://github.com/rancherio","followers_url":"https://api.github.com/users/rancherio/followers","following_url":"https://api.github.com/users/rancherio/following{/other_user}","gists_url":"https://api.github.com/users/rancherio/gists{/gist_id}","starred_url":"https://api.github.com/users/rancherio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rancherio/subscriptions","organizations_url":"https://api.github.com/users/rancherio/orgs","repos_url":"https://api.github.com/users/rancherio/repos","events_url":"https://api.github.com/users/rancherio/events{/privacy}","received_events_url":"https://api.github.com/users/rancherio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rancherio/cattle","description":"Infrastructure orchestration platform","fork":false,"url":"https://api.github.com/repos/rancherio/cattle","forks_url":"https://api.github.com/repos/rancherio/cattle/forks","keys_url":"https://api.github.com/repos/rancherio/cattle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rancherio/cattle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rancherio/cattle/teams","hooks_url":"https://api.github.com/repos/rancherio/cattle/hooks","issue_events_url":"https://api.github.com/repos/rancherio/cattle/issues/events{/number}","events_url":"https://api.github.com/repos/rancherio/cattle/events","assignees_url":"https://api.github.com/repos/rancherio/cattle/assignees{/user}","branches_url":"https://api.github.com/repos/rancherio/cattle/branches{/branch}","tags_url":"https://api.github.com/repos/rancherio/cattle/tags","blobs_url":"https://api.github.com/repos/rancherio/cattle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rancherio/cattle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rancherio/cattle/git/refs{/sha}","trees_url":"https://api.github.com/repos/rancherio/cattle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rancherio/cattle/statuses/{sha}","languages_url":"https://api.github.com/repos/rancherio/cattle/languages","stargazers_url":"https://api.github.com/repos/rancherio/cattle/stargazers","contributors_url":"https://api.github.com/repos/rancherio/cattle/contributors","subscribers_url":"https://api.github.com/repos/rancherio/cattle/subscribers","subscription_url":"https://api.github.com/repos/rancherio/cattle/subscription","commits_url":"https://api.github.com/repos/rancherio/cattle/commits{/sha}","git_commits_url":"https://api.github.com/repos/rancherio/cattle/git/commits{/sha}","comments_url":"https://api.github.com/repos/rancherio/cattle/comments{/number}","issue_comment_url":"https://api.github.com/repos/rancherio/cattle/issues/comments{/number}","contents_url":"https://api.github.com/repos/rancherio/cattle/contents/{+path}","compare_url":"https://api.github.com/repos/rancherio/cattle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rancherio/cattle/merges","archive_url":"https://api.github.com/repos/rancherio/cattle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rancherio/cattle/downloads","issues_url":"https://api.github.com/repos/rancherio/cattle/issues{/number}","pulls_url":"https://api.github.com/repos/rancherio/cattle/pulls{/number}","milestones_url":"https://api.github.com/repos/rancherio/cattle/milestones{/number}","notifications_url":"https://api.github.com/repos/rancherio/cattle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rancherio/cattle/labels{/name}","releases_url":"https://api.github.com/repos/rancherio/cattle/releases{/id}","created_at":"2014-03-23T00:19:52Z","updated_at":"2015-05-24T03:36:22Z","pushed_at":"2015-05-26T17:46:02Z","git_url":"git://github.com/rancherio/cattle.git","ssh_url":"git@github.com:rancherio/cattle.git","clone_url":"https://github.com/rancherio/cattle.git","svn_url":"https://github.com/rancherio/cattle","homepage":"","size":26897,"stargazers_count":138,"watchers_count":138,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":92,"forks":32,"open_issues":92,"watchers":138,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rancherio/cattle/pulls/500"},"html":{"href":"https://github.com/rancherio/cattle/pull/500"},"issue":{"href":"https://api.github.com/repos/rancherio/cattle/issues/500"},"comments":{"href":"https://api.github.com/repos/rancherio/cattle/issues/500/comments"},"review_comments":{"href":"https://api.github.com/repos/rancherio/cattle/pulls/500/comments"},"review_comment":{"href":"https://api.github.com/repos/rancherio/cattle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rancherio/cattle/pulls/500/commits"},"statuses":{"href":"https://api.github.com/repos/rancherio/cattle/statuses/8067e51cd024ee5298cb41150c2eb108a9924201"}}}}