diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 45a4b727c..045555c31 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -310,9 +310,17 @@ my %status_info = ( RSPCONFIG_GET_RESPONSE => { process => \&rspconfig_response, }, - RSPCONFIG_SET_REQUEST => { + RSPCONFIG_SET_PASSWD_REQUEST => { + method => "POST", + init_url => "/xyz/openbmc_project/user/root/action/SetPassword", + data => "", + }, + "RSPCONFIG_PASSWD_VERIFY" => { + process => \&rspconfig_response, + }, + 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 => { @@ -839,8 +847,12 @@ 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, "The option 'hostname' can not work with other options." ]) if ($key eq "hostname" and $num_subcommand > 1); + return ([ 1, "Unsupported command: $command $key" ]) unless ($key =~ /^ip$|^netmask$|^gateway$|^hostname$|^vlan$|^admin_passwd$/); + return ([ 1, "The option '$key' can not work with other options." ]) if ($key =~ /^hostname$|^admin_passwd$/ and $num_subcommand > 1); + if ($key eq "admin_passwd") { + my $comma_num = $value =~ tr/,/,/; + return ([ 1, "Invalid parameter for option $key: $value" ]) if ($comma_num != 1); + } my $nodes_num = @$noderange; return ([ 1, "Invalid parameter for option $key" ]) unless ($value); @@ -1170,13 +1182,14 @@ 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_REQUEST}{init_url} .= "/config/attr/HostName"; + $status_info{RSPCONFIG_SET_HOSTNAME_REQUEST}{data} = $1; + $status_info{RSPCONFIG_SET_RESPONSE}{argv} = "Hostname"; + $status_info{RSPCONFIG_GET_RESPONSE}{argv} = "hostname"; return 0; } } @@ -1209,6 +1222,19 @@ sub parse_command_status { return 0; } + if ($subcommand =~ /^admin_passwd=(.+),(.+)/) { + my $currentpasswd = $1; + my $newpasswd = $2; + $next_status{LOGIN_RESPONSE} = "RSPCONFIG_PASSWD_VERIFY"; + $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_SET_PASSWD_REQUEST}{data} = "[\"$newpasswd\"]"; + $status_info{RSPCONFIG_SET_RESPONSE}{argv} = "Password"; + return 0; + } + my $type = "obj"; my %tmp_hash = (); foreach $subcommand (@$subcommands) { @@ -2483,9 +2509,18 @@ 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("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) { - 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); + } } } if ($node_info{$node}{cur_status} eq "RSPCONFIG_DHCP_RESPONSE") {