'Performs a power operation on a system.
Internal method
@param System system Cobbler system
@param str power_operation power operation. Valid values: on, off, status.
Rebooting is implemented as a set of 2 operations (off and on) in
a higher level method.
@param str user power management user. If user and password are not
supplied, environment variables COBBLER_POWER_USER and
COBBLER_POWER_PASS will be used.
@param str password power management password
@param Logger logger logger
@return bool/None if power operation is \'status\', return if system is on;
otherwise, return None
@raise CX if there are errors'

def _power(self, system, power_operation, user=None, password=None, logger=None):

    if (logger is None):
        logger = self.logger
    power_command = get_power_command(system.power_type)
    if (not power_command):
        utils.die(logger, 'no    power    type    set    for    system')
    meta = utils.blender(self.api, False, system)
    meta['power_mode'] = power_operation
    if (user is not None):
        meta['power_user'] = user
    if (password is not None):
        meta['power_pass'] = password
    logger.info('cobbler    power    configuration    is:')
    logger.info(('                        type            :    %s' % system.power_type))
    logger.info(('                        address:    %s' % system.power_address))
    logger.info(('                        user            :    %s' % system.power_user))
    logger.info(('                        id                    :    %s' % system.power_id))
    if (meta.get('power_user', '') == ''):
        meta['power_user'] = os.environ.get('COBBLER_POWER_USER', '')
    if (meta.get('power_pass', '') == ''):
        meta['power_pass'] = os.environ.get('COBBLER_POWER_PASS', '')
    template = self.get_power_template(system.power_type)
    tmp = templar.Templar(self.collection_mgr)
    template_data = tmp.render(template, meta, None, system)
    logger.info(('power    command:    %s' % power_command))
    logger.info(('power    command    input:    %s' % template_data))
    for x in range(0, 5):
        (output, rc) = utils.subprocess_sp(logger, power_command, shell=False, input=template_data)
        if (rc == 0):
            if (power_operation == 'status'):
                match = re.match('^(Status:|.+power\\s=)\\s(on|off)$', output, (re.IGNORECASE | re.MULTILINE))
                if match:
                    power_status = match.groups()[1]
                    if (power_status.lower() == 'on'):
                        return True
                    else:
                        return False
                error_msg = ("command    succeeded    (rc=%s),    but    output    ('%s')    was    not    understood" % (rc, output))
                utils.die(logger, error_msg)
                raise CX(error_msg)
            return None
        else:
            time.sleep(2)
    if (not (rc == 0)):
        error_msg = ('command    failed    (rc=%s),    please    validate    the    physical    setup    and    cobbler    config' % rc)
        utils.die(logger, error_msg)
        raise CX(error_msg)
