2008-04-29 18:41:24 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
= head1
xCAT plugin package to handle getpostscript command
= cut
#-------------------------------------------------------
package xCAT_plugin::getpostscript ;
use xCAT::Utils ;
2008-08-20 16:51:06 +00:00
use xCAT::MsgUtils ;
2008-04-29 18:41:24 +00:00
use xCAT::NodeRange ;
1 ;
#-------------------------------------------------------
= head3 handled_commands
Return list of commands handled by this plugin
= cut
#-------------------------------------------------------
sub handled_commands
{
2010-11-23 19:00:09 +00:00
return {
'getpostscript' = > "getpostscript" ,
} ;
2008-04-29 18:41:24 +00:00
}
#-------------------------------------------------------
= head3 process_request
Process the command
= cut
#-------------------------------------------------------
sub process_request
{
my $ request = shift ;
my $ callback = shift ;
my $ nodes = $ request - > { node } ;
my $ command = $ request - > { command } - > [ 0 ] ;
my $ args = $ request - > { arg } ;
my $ envs = $ request - > { env } ;
my $ rsp ;
my $ i = 1 ;
my @ nodes = @$ nodes ;
# do your processing here
# return info
2013-01-06 05:36:47 +00:00
2010-11-23 19:00:09 +00:00
2008-04-29 18:41:24 +00:00
my $ client ;
2012-07-26 19:31:13 +00:00
if ( $ ::XCATSITEVALS { nodeauthentication } ) { #if requiring node authentication, this request will have a certificate associated with it, use it instead of name resolution
unless ( ref $ request - > { username } ) { return ; } #TODO: log an attempt without credentials?
$ client = $ request - > { username } - > [ 0 ] ;
} else {
unless ( $ request - > { '_xcat_clienthost' } - > [ 0 ] ) {
#ERROR? malformed request
return ; #nothing to do here...
}
$ client = $ request - > { '_xcat_clienthost' } - > [ 0 ] ;
2008-04-29 18:41:24 +00:00
}
2008-05-14 19:14:32 +00:00
2013-01-18 22:22:33 +00:00
my $ origclient = $ client ;
2008-04-29 18:41:24 +00:00
if ( $ client ) { ( $ client ) = noderange ( $ client ) } ;
unless ( $ client ) { #Not able to do identify the host in question
2013-01-18 22:22:33 +00:00
xCAT::MsgUtils - > message ( "S" , "Received getpostscript from $origclient, which couldn't be correlated to a node (domain mismatch?)" ) ;
2008-04-29 18:41:24 +00:00
return ;
}
2008-05-14 19:14:32 +00:00
my $ state ;
if ( $ request - > { scripttype } ) { $ state = $ request - > { scripttype } - > [ 0 ] ; }
2008-04-29 18:41:24 +00:00
2009-03-14 16:14:29 +00:00
require xCAT::Postage ;
2013-01-06 05:36:47 +00:00
my $ args = $ request - > { arg } ;
2013-01-17 21:43:27 +00:00
my @ scriptcontents ;
2013-05-16 13:56:17 +00:00
my $ version = 0 ;
2013-01-06 05:36:47 +00:00
if ( defined ( $ args ) && grep ( /version2/ , @$ args ) ) {
2013-05-16 13:56:17 +00:00
$ version = 2
2013-01-06 05:36:47 +00:00
}
2013-05-16 17:07:05 +00:00
my $ notmpfiles ;
my $ nofiles ;
# If not version=2, then we return the mypostscript file in an array.
2013-05-16 13:56:17 +00:00
if ( $ version != 2 ) {
2013-06-10 20:02:58 +00:00
$ notmpfiles = 1 ; # no tmp files and no files
2013-05-16 17:07:05 +00:00
$ nofiles = 1 ; # do not create /tftpboot/mypostscript/mypostscript.<nodename>
@ scriptcontents = xCAT::Postage:: makescript ( [ $ client ] , $ state , $ callback , $ notmpfiles , $ nofiles ) ;
2013-05-16 13:56:17 +00:00
`logger -t xCAT -p local4.info "getpostscript: sending data"` ;
2008-04-29 18:41:24 +00:00
$ rsp - > { data } = \ @ scriptcontents ;
2013-05-16 13:56:17 +00:00
$ callback - > ( $ rsp ) ;
2013-05-16 17:07:05 +00:00
} else { # version 2, make files, do not return array
# make the mypostscript.<nodename> file
# or the mypostscript.<nodename>.tmp file if precreatemypostscripts=0
# xcatdsklspost will wget the file
$ notmpfiles = 0 ;
$ nofiles = 0 ;
xCAT::Postage:: makescript ( [ $ client ] , $ state , $ callback , $ notmpfiles , $ nofiles ) ;
2008-04-29 18:41:24 +00:00
}
2013-05-16 13:56:17 +00:00
return 0 ;
2008-04-29 18:41:24 +00:00
}