From 8a73d3b5cacfca6453f21f8e33fb80b541edf199 Mon Sep 17 00:00:00 2001 From: XuWei Date: Fri, 24 Nov 2017 03:14:25 -0500 Subject: [PATCH 1/2] rspconfig admin_password for OpenBMC --- xCAT-server/lib/xcat/plugins/openbmc.pm | 41 +++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index c24eb612b..5b2c21267 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -310,6 +310,14 @@ my %status_info = ( RSPCONFIG_GET_RESPONSE => { process => \&rspconfig_response, }, + RSPCONFIG_PASSWD_REQUEST => { + method => "POST", + init_url => "/xyz/openbmc_project/user/root/action/SetPassword", + data => "", + }, + "RSPCONFIG_PASSWD_VERIFY" => { + process => \&rspconfig_response, + }, RSPCONFIG_SET_REQUEST => { method => "PUT", init_url => "$openbmc_project_url/network", @@ -839,8 +847,9 @@ sub parse_args { my $key = $1; my $value = $2; return ([ 1, "Changing ipsrc value is currently not supported." ]) if ($key eq "ipsrc"); - return ([ 1, "Unsupported command: $command $key" ]) unless ($key =~ /^ip$|^netmask$|^gateway$|^hostname$|^vlan$/); + return ([ 1, "Unsupported command: $command $key" ]) unless ($key =~ /^ip$|^netmask$|^gateway$|^hostname$|^vlan$|^admin_passwd$/); return ([ 1, "The option 'hostname' can not work with other options." ]) if ($key eq "hostname" and $num_subcommand > 1); + return ([ 1, "Invalid parameter for option $key" ]) if ($key eq "admin_passwd" and $num_subcommand != 2); my $nodes_num = @$noderange; return ([ 1, "Invalid parameter for option $key" ]) unless ($value); @@ -1203,6 +1212,23 @@ sub parse_command_status { return 0; } + if ($subcommand =~ /^admin_passwd=(.+)/) { + my $currentpasswd = $1; + my $newpasswd; + my $passwd_cmd2 = $$subcommands[1]; + if ($passwd_cmd2 =~ /^admin_passwd=(.+)/) { + $newpasswd = $1; + } + $next_status{LOGIN_RESPONSE} = "RSPCONFIG_PASSWD_VERIFY"; + $next_status{RSPCONFIG_PASSWD_VERIFY} = "RSPCONFIG_PASSWD_REQUEST"; + $next_status{RSPCONFIG_PASSWD_REQUEST} = "RSPCONFIG_SET_RESPONSE"; + + $status_info{RSPCONFIG_PASSWD_VERIFY}{argv} = "$currentpasswd"; + $status_info{RSPCONFIG_PASSWD_REQUEST}{data} = "[\"$newpasswd\"]"; + $status_info{RSPCONFIG_SET_RESPONSE}{argv} = "password"; + return 0; + } + my $type = "obj"; my %tmp_hash = (); foreach $subcommand (@$subcommands) { @@ -2477,9 +2503,20 @@ sub rspconfig_response { } } + if ($node_info{$node}{cur_status} eq "RSPCONFIG_PASSWD_VERIFY") { + if ($status_info{RSPCONFIG_PASSWD_VERIFY}{argv} ne $node_info{$node}{password}) { + xCAT::SvrUtils::sendmsg("Please input correct BMC password.", $callback, $node); + $next_status{ $node_info{$node}{cur_status} } = ""; + } + } + if ($node_info{$node}{cur_status} eq "RSPCONFIG_SET_RESPONSE") { if ($response_info->{'message'} eq $::RESPONSE_OK) { - xCAT::SvrUtils::sendmsg("BMC Setting Hostname...", $callback, $node); + if (defined $status_info{RSPCONFIG_SET_RESPONSE}{argv} and $status_info{RSPCONFIG_SET_RESPONSE}{argv} eq "password") { + xCAT::SvrUtils::sendmsg("BMC Setting Password...", $callback, $node); + } else { + xCAT::SvrUtils::sendmsg("BMC Setting Hostname...", $callback, $node); + } } } if ($node_info{$node}{cur_status} eq "RSPCONFIG_DHCP_RESPONSE") { From 8d4d18bfbd6453fb6ed4f4d2014175bb0e592f2b Mon Sep 17 00:00:00 2001 From: XuWei Date: Mon, 27 Nov 2017 21:22:51 -0500 Subject: [PATCH 2/2] modified depending on comments --- xCAT-server/lib/xcat/plugins/openbmc.pm | 29 ++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 5b2c21267..246bd58be 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -310,7 +310,7 @@ my %status_info = ( RSPCONFIG_GET_RESPONSE => { process => \&rspconfig_response, }, - RSPCONFIG_PASSWD_REQUEST => { + RSPCONFIG_SET_PASSWD_REQUEST => { method => "POST", init_url => "/xyz/openbmc_project/user/root/action/SetPassword", data => "", @@ -318,9 +318,9 @@ my %status_info = ( "RSPCONFIG_PASSWD_VERIFY" => { process => \&rspconfig_response, }, - RSPCONFIG_SET_REQUEST => { + RSPCONFIG_SET_HOSTNAME_REQUEST => { method => "PUT", - init_url => "$openbmc_project_url/network", + init_url => "$openbmc_project_url/network/config/attr/HostName", data => "[]", }, RSPCONFIG_SET_RESPONSE => { @@ -1173,12 +1173,13 @@ sub parse_command_status { return 0; } if ($subcommand =~ /^hostname=(.+)/) { - $next_status{LOGIN_RESPONSE} = "RSPCONFIG_SET_REQUEST"; - $next_status{RSPCONFIG_SET_REQUEST} = "RSPCONFIG_SET_RESPONSE"; + $next_status{LOGIN_RESPONSE} = "RSPCONFIG_SET_HOSTNAME_REQUEST"; + $next_status{RSPCONFIG_SET_HOSTNAME_REQUEST} = "RSPCONFIG_SET_RESPONSE"; $next_status{RSPCONFIG_SET_RESPONSE} = "RSPCONFIG_GET_REQUEST"; $next_status{RSPCONFIG_GET_REQUEST} = "RSPCONFIG_GET_RESPONSE"; - $status_info{RSPCONFIG_SET_REQUEST}{data} = $1; + $status_info{RSPCONFIG_SET_HOSTNAME_REQUEST}{data} = $1; + $status_info{RSPCONFIG_SET_RESPONSE}{argv} = "Hostname"; $status_info{RSPCONFIG_GET_RESPONSE}{argv} = "hostname"; return 0; } @@ -1220,12 +1221,12 @@ sub parse_command_status { $newpasswd = $1; } $next_status{LOGIN_RESPONSE} = "RSPCONFIG_PASSWD_VERIFY"; - $next_status{RSPCONFIG_PASSWD_VERIFY} = "RSPCONFIG_PASSWD_REQUEST"; - $next_status{RSPCONFIG_PASSWD_REQUEST} = "RSPCONFIG_SET_RESPONSE"; + $next_status{RSPCONFIG_PASSWD_VERIFY} = "RSPCONFIG_SET_PASSWD_REQUEST"; + $next_status{RSPCONFIG_SET_PASSWD_REQUEST} = "RSPCONFIG_SET_RESPONSE"; $status_info{RSPCONFIG_PASSWD_VERIFY}{argv} = "$currentpasswd"; - $status_info{RSPCONFIG_PASSWD_REQUEST}{data} = "[\"$newpasswd\"]"; - $status_info{RSPCONFIG_SET_RESPONSE}{argv} = "password"; + $status_info{RSPCONFIG_SET_PASSWD_REQUEST}{data} = "[\"$newpasswd\"]"; + $status_info{RSPCONFIG_SET_RESPONSE}{argv} = "Password"; return 0; } @@ -2505,17 +2506,15 @@ sub rspconfig_response { if ($node_info{$node}{cur_status} eq "RSPCONFIG_PASSWD_VERIFY") { if ($status_info{RSPCONFIG_PASSWD_VERIFY}{argv} ne $node_info{$node}{password}) { - xCAT::SvrUtils::sendmsg("Please input correct BMC password.", $callback, $node); + xCAT::SvrUtils::sendmsg("Current BMC password is incorrect, cannot set the new password.", $callback, $node); $next_status{ $node_info{$node}{cur_status} } = ""; } } if ($node_info{$node}{cur_status} eq "RSPCONFIG_SET_RESPONSE") { if ($response_info->{'message'} eq $::RESPONSE_OK) { - if (defined $status_info{RSPCONFIG_SET_RESPONSE}{argv} and $status_info{RSPCONFIG_SET_RESPONSE}{argv} eq "password") { - xCAT::SvrUtils::sendmsg("BMC Setting Password...", $callback, $node); - } else { - xCAT::SvrUtils::sendmsg("BMC Setting Hostname...", $callback, $node); + if (defined $status_info{RSPCONFIG_SET_RESPONSE}{argv}) { + xCAT::SvrUtils::sendmsg("BMC Setting $status_info{RSPCONFIG_SET_RESPONSE}{argv}...", $callback, $node); } } }