{"action":"created","comment":{"url":"https://api.github.com/repos/xcat2/xcat-core/pulls/comments/45707094","id":45707094,"diff_hunk":"@@ -0,0 +1,451 @@\n+# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html\n+#-------------------------------------------------------\n+\n+=head1\n+  xCAT plugin package to handle getadapters management\n+\n+   Supported command:\n+        getadapters->getadapters \n+        findadapter->getadapters \n+\n+=cut\n+\n+#-------------------------------------------------------\n+package xCAT_plugin::getadapter;\n+\n+BEGIN{   \n+   $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr';\n+}\n+use lib \"$::XCATROOT/lib/perl\";\n+\n+use xCAT::Table;\n+use xCAT::Utils;\n+use xCAT::MsgUtils;\n+use Data::Dumper;\n+use Getopt::Long;\n+use File::Path;\n+use IO::Select;\n+use Term::ANSIColor;\n+use Time::Local;\n+\n+my %usage = (\n+    \"getadapters\" => \"Usage:\\n\\tgetadapters [-h|--help|-v|--version|V]\\n\\tgetadapters <noderange> [-f]\",\n+);\n+\n+my $inforootdir = \"/var/lib/xcat/adapters/\";\n+my $VERBOSE=0;\n+#-------------------------------------------------------\n+\n+=head3  handled_commands\n+\n+Return list of commands handled by this plugin\n+\n+=cut\n+\n+#-------------------------------------------------------\n+\n+sub handled_commands\n+{\n+    return {\n+        getadapters => \"getadapter\",\n+        findadapter => \"getadapter\",\n+    };\n+}\n+\n+#-------------------------------------------------------\n+\n+=head3  process_request\n+\n+  Process the command\n+\n+=cut\n+\n+#-------------------------------------------------------\n+sub process_request\n+{\n+    my $request  = shift;\n+    my $callback = shift;\n+    my $subreq   = shift;\n+    my $command  = $request->{command}->[0];\n+\n+    if ($command eq \"getadapters\"){\n+        &handle_getadapters($request, $callback, $subreq);\n+    }\n+\n+    if ($command eq \"findadapter\"){\n+        &handle_findadapter($request, $callback);\n+    }\n+\n+    return;\n+}\n+\n+sub handle_getadapters{\n+    my $request  = shift;\n+    my $callback = shift;\n+    my $subreq   = shift;\n+    my $command  = $request->{command}->[0];\n+\n+    my @args=(); \n+    my $HELP;\n+    my $VERSION;\n+    my $FORCE;\n+    if (ref($request->{arg})) {\n+        @args=@{$request->{arg}};   \n+    } else {    \n+        @args=($request->{arg});\n+    }\n+    @ARGV = @args;\n+    Getopt::Long::Configure(\"bundling\");    \n+    Getopt::Long::Configure(\"no_pass_through\");\n+    if (!GetOptions(\"h|help\"    => \\$HELP, \n+           \"v|version\" => \\$VERSION,\n+           \"f\"         => \\$FORCE,\n+           \"V\"         => \\$VERBOSE\n+    ) ) {\n+        if($usage{$command}) {\n+            my $rsp = {};\n+            $rsp->{error}->[0] = $usage{$command};\n+            $rsp->{errorcode}->[0] = 1;\n+            $callback->($rsp);\n+        }\n+        return;\n+    }\n+\n+    if ($HELP) {\n+        if($usage{$command}) {\n+            my %rsp;\n+            $rsp{data}->[0]=$usage{$command};\n+            $callback->(\\%rsp);\n+        }\n+        return;\n+    }\n+\n+    if ($VERSION) {\n+        my $ver = xCAT::Utils->Version();\n+        my %rsp;\n+        $rsp{data}->[0]=\"$ver\";\n+        $callback->(\\%rsp);\n+        return; \n+    }\n+\n+    my $tmpnodes = join(\",\", @{$request->{node}});\n+    my $tmpargs = join(\",\", @args);\n+    xCAT::MsgUtils->trace($VERBOSE,\"d\",\"getadapters: handling command <$command $tmpnodes $tmpargs>\");\n+\n+    if($FORCE || ! -d $inforootdir) {\n+        my @tmpnodes = @{$request->{node}};\n+        $request->{missnode} = \\@tmpnodes;\n+        &scan_adapters($request, $callback, $subreq);\n+    }else{\n+        my @nodes = @{$request->{node}};\n+        my $node;\n+        my @missnodes = ();\n+        foreach $node (@nodes){\n+            if ( ! -e \"$inforootdir/$node.info\" || -z \"$inforootdir/$node.info\"){\n+                push @missnodes,$node;\n+            }  \n+        }\n+\n+        if(scalar(@missnodes) != 0){\n+           $request->{missnode} = \\@missnodes;\n+           &scan_adapters($request, $callback, $subreq); \n+        }\n+    }\n+\n+    &get_info_from_loacal($request, $callback); \n+    return;\n+\n+}\n+\n+sub handle_findadapter{\n+\n+    my $request  = shift;\n+    my $callback = shift;\n+    my $hostname = $request->{hostname}->[0];\n+\n+    xCAT::MsgUtils->trace($VERBOSE,\"d\",\"getadapters: receiving a findadapter response from $hostname\");\n+\n+    my $nicnum = scalar @{$request->{nic}};\n+    my $content = \"\";\n+    #print \"-----------nicnum = $nicnum----------------\\n\"; \n+    for (my $i = 1; $i <= $nicnum; $i++) {","path":"xCAT-server/lib/xcat/plugins/getadapter.pm","position":171,"original_position":171,"commit_id":"acd85703241a28f395a0641d2a1ab3e15c25be07","original_commit_id":"b30037e48505349e65803e6d31e02576f14186de","user":{"login":"neo954","id":12424088,"avatar_url":"https://avatars.githubusercontent.com/u/12424088?v=3","gravatar_id":"","url":"https://api.github.com/users/neo954","html_url":"https://github.com/neo954","followers_url":"https://api.github.com/users/neo954/followers","following_url":"https://api.github.com/users/neo954/following{/other_user}","gists_url":"https://api.github.com/users/neo954/gists{/gist_id}","starred_url":"https://api.github.com/users/neo954/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neo954/subscriptions","organizations_url":"https://api.github.com/users/neo954/orgs","repos_url":"https://api.github.com/users/neo954/repos","events_url":"https://api.github.com/users/neo954/events{/privacy}","received_events_url":"https://api.github.com/users/neo954/received_events","type":"User","site_admin":false},"body":"I think if the loop variable ``$i`` is from ``0`` to ``$nicnum - 1``, the code will look naturally. Something like the C-style code.\r\n\r\n``for (my $i = 0; $i < $nicnum; ++$i) {``\r\n``    # handle $i here instead of $i - 1``\r\n``    # ...``\r\n``}``","created_at":"2015-11-24T08:27:30Z","updated_at":"2015-11-24T08:27:30Z","html_url":"https://github.com/xcat2/xcat-core/pull/452#discussion_r45707094","pull_request_url":"https://api.github.com/repos/xcat2/xcat-core/pulls/452","_links":{"self":{"href":"https://api.github.com/repos/xcat2/xcat-core/pulls/comments/45707094"},"html":{"href":"https://github.com/xcat2/xcat-core/pull/452#discussion_r45707094"},"pull_request":{"href":"https://api.github.com/repos/xcat2/xcat-core/pulls/452"}}},"pull_request":{"url":"https://api.github.com/repos/xcat2/xcat-core/pulls/452","id":51460850,"html_url":"https://github.com/xcat2/xcat-core/pull/452","diff_url":"https://github.com/xcat2/xcat-core/pull/452.diff","patch_url":"https://github.com/xcat2/xcat-core/pull/452.patch","issue_url":"https://api.github.com/repos/xcat2/xcat-core/issues/452","number":452,"state":"open","locked":false,"title":"The initial implementation of getadapters","user":{"login":"hu-weihua","id":7370626,"avatar_url":"https://avatars.githubusercontent.com/u/7370626?v=3","gravatar_id":"","url":"https://api.github.com/users/hu-weihua","html_url":"https://github.com/hu-weihua","followers_url":"https://api.github.com/users/hu-weihua/followers","following_url":"https://api.github.com/users/hu-weihua/following{/other_user}","gists_url":"https://api.github.com/users/hu-weihua/gists{/gist_id}","starred_url":"https://api.github.com/users/hu-weihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hu-weihua/subscriptions","organizations_url":"https://api.github.com/users/hu-weihua/orgs","repos_url":"https://api.github.com/users/hu-weihua/repos","events_url":"https://api.github.com/users/hu-weihua/events{/privacy}","received_events_url":"https://api.github.com/users/hu-weihua/received_events","type":"User","site_admin":false},"body":"The mini design please refer to \r\nhttps://github.com/xcat2/xcat-core/wiki/Predict_long_nicname_for_RH7\r\n\r\nthe doc ``getadapters.rst`` located under ``/docs/source/advanced/networks`` temporarily is just for help to review the code.\r\n\r\n\r\n","created_at":"2015-11-22T09:04:24Z","updated_at":"2015-11-24T08:27:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"96a02c003577431f85c874fead8cdaf788e55a09","assignee":null,"milestone":{"url":"https://api.github.com/repos/xcat2/xcat-core/milestones/6","html_url":"https://github.com/xcat2/xcat-core/milestones/2.12","labels_url":"https://api.github.com/repos/xcat2/xcat-core/milestones/6/labels","id":1369794,"number":6,"title":"2.12","description":null,"creator":{"login":"zet809","id":8222144,"avatar_url":"https://avatars.githubusercontent.com/u/8222144?v=3","gravatar_id":"","url":"https://api.github.com/users/zet809","html_url":"https://github.com/zet809","followers_url":"https://api.github.com/users/zet809/followers","following_url":"https://api.github.com/users/zet809/following{/other_user}","gists_url":"https://api.github.com/users/zet809/gists{/gist_id}","starred_url":"https://api.github.com/users/zet809/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zet809/subscriptions","organizations_url":"https://api.github.com/users/zet809/orgs","repos_url":"https://api.github.com/users/zet809/repos","events_url":"https://api.github.com/users/zet809/events{/privacy}","received_events_url":"https://api.github.com/users/zet809/received_events","type":"User","site_admin":false},"open_issues":24,"closed_issues":1,"state":"open","created_at":"2015-10-22T07:51:37Z","updated_at":"2015-11-24T02:29:12Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/xcat2/xcat-core/pulls/452/commits","review_comments_url":"https://api.github.com/repos/xcat2/xcat-core/pulls/452/comments","review_comment_url":"https://api.github.com/repos/xcat2/xcat-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xcat2/xcat-core/issues/452/comments","statuses_url":"https://api.github.com/repos/xcat2/xcat-core/statuses/acd85703241a28f395a0641d2a1ab3e15c25be07","head":{"label":"hu-weihua:getadapters","ref":"getadapters","sha":"acd85703241a28f395a0641d2a1ab3e15c25be07","user":{"login":"hu-weihua","id":7370626,"avatar_url":"https://avatars.githubusercontent.com/u/7370626?v=3","gravatar_id":"","url":"https://api.github.com/users/hu-weihua","html_url":"https://github.com/hu-weihua","followers_url":"https://api.github.com/users/hu-weihua/followers","following_url":"https://api.github.com/users/hu-weihua/following{/other_user}","gists_url":"https://api.github.com/users/hu-weihua/gists{/gist_id}","starred_url":"https://api.github.com/users/hu-weihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hu-weihua/subscriptions","organizations_url":"https://api.github.com/users/hu-weihua/orgs","repos_url":"https://api.github.com/users/hu-weihua/repos","events_url":"https://api.github.com/users/hu-weihua/events{/privacy}","received_events_url":"https://api.github.com/users/hu-weihua/received_events","type":"User","site_admin":false},"repo":{"id":40430481,"name":"xcat-core","full_name":"hu-weihua/xcat-core","owner":{"login":"hu-weihua","id":7370626,"avatar_url":"https://avatars.githubusercontent.com/u/7370626?v=3","gravatar_id":"","url":"https://api.github.com/users/hu-weihua","html_url":"https://github.com/hu-weihua","followers_url":"https://api.github.com/users/hu-weihua/followers","following_url":"https://api.github.com/users/hu-weihua/following{/other_user}","gists_url":"https://api.github.com/users/hu-weihua/gists{/gist_id}","starred_url":"https://api.github.com/users/hu-weihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hu-weihua/subscriptions","organizations_url":"https://api.github.com/users/hu-weihua/orgs","repos_url":"https://api.github.com/users/hu-weihua/repos","events_url":"https://api.github.com/users/hu-weihua/events{/privacy}","received_events_url":"https://api.github.com/users/hu-weihua/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hu-weihua/xcat-core","description":"Code repo for xCAT core packages","fork":true,"url":"https://api.github.com/repos/hu-weihua/xcat-core","forks_url":"https://api.github.com/repos/hu-weihua/xcat-core/forks","keys_url":"https://api.github.com/repos/hu-weihua/xcat-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hu-weihua/xcat-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hu-weihua/xcat-core/teams","hooks_url":"https://api.github.com/repos/hu-weihua/xcat-core/hooks","issue_events_url":"https://api.github.com/repos/hu-weihua/xcat-core/issues/events{/number}","events_url":"https://api.github.com/repos/hu-weihua/xcat-core/events","assignees_url":"https://api.github.com/repos/hu-weihua/xcat-core/assignees{/user}","branches_url":"https://api.github.com/repos/hu-weihua/xcat-core/branches{/branch}","tags_url":"https://api.github.com/repos/hu-weihua/xcat-core/tags","blobs_url":"https://api.github.com/repos/hu-weihua/xcat-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hu-weihua/xcat-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hu-weihua/xcat-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/hu-weihua/xcat-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hu-weihua/xcat-core/statuses/{sha}","languages_url":"https://api.github.com/repos/hu-weihua/xcat-core/languages","stargazers_url":"https://api.github.com/repos/hu-weihua/xcat-core/stargazers","contributors_url":"https://api.github.com/repos/hu-weihua/xcat-core/contributors","subscribers_url":"https://api.github.com/repos/hu-weihua/xcat-core/subscribers","subscription_url":"https://api.github.com/repos/hu-weihua/xcat-core/subscription","commits_url":"https://api.github.com/repos/hu-weihua/xcat-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/hu-weihua/xcat-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/hu-weihua/xcat-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/hu-weihua/xcat-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/hu-weihua/xcat-core/contents/{+path}","compare_url":"https://api.github.com/repos/hu-weihua/xcat-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hu-weihua/xcat-core/merges","archive_url":"https://api.github.com/repos/hu-weihua/xcat-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hu-weihua/xcat-core/downloads","issues_url":"https://api.github.com/repos/hu-weihua/xcat-core/issues{/number}","pulls_url":"https://api.github.com/repos/hu-weihua/xcat-core/pulls{/number}","milestones_url":"https://api.github.com/repos/hu-weihua/xcat-core/milestones{/number}","notifications_url":"https://api.github.com/repos/hu-weihua/xcat-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hu-weihua/xcat-core/labels{/name}","releases_url":"https://api.github.com/repos/hu-weihua/xcat-core/releases{/id}","created_at":"2015-08-09T08:43:37Z","updated_at":"2015-08-09T08:43:43Z","pushed_at":"2015-11-24T08:25:42Z","git_url":"git://github.com/hu-weihua/xcat-core.git","ssh_url":"git@github.com:hu-weihua/xcat-core.git","clone_url":"https://github.com/hu-weihua/xcat-core.git","svn_url":"https://github.com/hu-weihua/xcat-core","homepage":null,"size":180980,"stargazers_count":0,"watchers_count":0,"language":"Perl","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":"xcat2:master","ref":"master","sha":"895ad1fa02cd4a69a35ffd07256ade3ffc6491aa","user":{"login":"xcat2","id":10124414,"avatar_url":"https://avatars.githubusercontent.com/u/10124414?v=3","gravatar_id":"","url":"https://api.github.com/users/xcat2","html_url":"https://github.com/xcat2","followers_url":"https://api.github.com/users/xcat2/followers","following_url":"https://api.github.com/users/xcat2/following{/other_user}","gists_url":"https://api.github.com/users/xcat2/gists{/gist_id}","starred_url":"https://api.github.com/users/xcat2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xcat2/subscriptions","organizations_url":"https://api.github.com/users/xcat2/orgs","repos_url":"https://api.github.com/users/xcat2/repos","events_url":"https://api.github.com/users/xcat2/events{/privacy}","received_events_url":"https://api.github.com/users/xcat2/received_events","type":"Organization","site_admin":false},"repo":{"id":27747508,"name":"xcat-core","full_name":"xcat2/xcat-core","owner":{"login":"xcat2","id":10124414,"avatar_url":"https://avatars.githubusercontent.com/u/10124414?v=3","gravatar_id":"","url":"https://api.github.com/users/xcat2","html_url":"https://github.com/xcat2","followers_url":"https://api.github.com/users/xcat2/followers","following_url":"https://api.github.com/users/xcat2/following{/other_user}","gists_url":"https://api.github.com/users/xcat2/gists{/gist_id}","starred_url":"https://api.github.com/users/xcat2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xcat2/subscriptions","organizations_url":"https://api.github.com/users/xcat2/orgs","repos_url":"https://api.github.com/users/xcat2/repos","events_url":"https://api.github.com/users/xcat2/events{/privacy}","received_events_url":"https://api.github.com/users/xcat2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xcat2/xcat-core","description":"Code repo for xCAT core packages","fork":false,"url":"https://api.github.com/repos/xcat2/xcat-core","forks_url":"https://api.github.com/repos/xcat2/xcat-core/forks","keys_url":"https://api.github.com/repos/xcat2/xcat-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xcat2/xcat-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xcat2/xcat-core/teams","hooks_url":"https://api.github.com/repos/xcat2/xcat-core/hooks","issue_events_url":"https://api.github.com/repos/xcat2/xcat-core/issues/events{/number}","events_url":"https://api.github.com/repos/xcat2/xcat-core/events","assignees_url":"https://api.github.com/repos/xcat2/xcat-core/assignees{/user}","branches_url":"https://api.github.com/repos/xcat2/xcat-core/branches{/branch}","tags_url":"https://api.github.com/repos/xcat2/xcat-core/tags","blobs_url":"https://api.github.com/repos/xcat2/xcat-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xcat2/xcat-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xcat2/xcat-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/xcat2/xcat-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xcat2/xcat-core/statuses/{sha}","languages_url":"https://api.github.com/repos/xcat2/xcat-core/languages","stargazers_url":"https://api.github.com/repos/xcat2/xcat-core/stargazers","contributors_url":"https://api.github.com/repos/xcat2/xcat-core/contributors","subscribers_url":"https://api.github.com/repos/xcat2/xcat-core/subscribers","subscription_url":"https://api.github.com/repos/xcat2/xcat-core/subscription","commits_url":"https://api.github.com/repos/xcat2/xcat-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/xcat2/xcat-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/xcat2/xcat-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/xcat2/xcat-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/xcat2/xcat-core/contents/{+path}","compare_url":"https://api.github.com/repos/xcat2/xcat-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xcat2/xcat-core/merges","archive_url":"https://api.github.com/repos/xcat2/xcat-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xcat2/xcat-core/downloads","issues_url":"https://api.github.com/repos/xcat2/xcat-core/issues{/number}","pulls_url":"https://api.github.com/repos/xcat2/xcat-core/pulls{/number}","milestones_url":"https://api.github.com/repos/xcat2/xcat-core/milestones{/number}","notifications_url":"https://api.github.com/repos/xcat2/xcat-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xcat2/xcat-core/labels{/name}","releases_url":"https://api.github.com/repos/xcat2/xcat-core/releases{/id}","created_at":"2014-12-09T03:21:50Z","updated_at":"2015-11-23T03:34:22Z","pushed_at":"2015-11-24T08:25:42Z","git_url":"git://github.com/xcat2/xcat-core.git","ssh_url":"git@github.com:xcat2/xcat-core.git","clone_url":"https://github.com/xcat2/xcat-core.git","svn_url":"https://github.com/xcat2/xcat-core","homepage":null,"size":181351,"stargazers_count":19,"watchers_count":19,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":52,"forks":36,"open_issues":52,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xcat2/xcat-core/pulls/452"},"html":{"href":"https://github.com/xcat2/xcat-core/pull/452"},"issue":{"href":"https://api.github.com/repos/xcat2/xcat-core/issues/452"},"comments":{"href":"https://api.github.com/repos/xcat2/xcat-core/issues/452/comments"},"review_comments":{"href":"https://api.github.com/repos/xcat2/xcat-core/pulls/452/comments"},"review_comment":{"href":"https://api.github.com/repos/xcat2/xcat-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xcat2/xcat-core/pulls/452/commits"},"statuses":{"href":"https://api.github.com/repos/xcat2/xcat-core/statuses/acd85703241a28f395a0641d2a1ab3e15c25be07"}}}}