def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic',
             client_timeout=60, do_async=True, **kwargs):
    """execute SCCI command

    This function calls SCCI server modules
    :param host: hostname or IP of iRMC
    :param userid: userid for iRMC with administrator privileges
    :param password: password for userid
    :param cmd: SCCI command
    :param port: port number of iRMC
    :param auth_method: irmc_username
    :param client_timeout: timeout for SCCI operations
    :param do_async: async call if True, sync call otherwise
    :returns: requests.Response from SCCI server
    :raises: SCCIInvalidInputError if port and/or auth_method params
             are invalid
    :raises: SCCIClientError if SCCI failed
    """
    auth_obj = None
    try:
        protocol = {80: 'http', 443: 'https'}[port]
        auth_obj = {
            'basic': requests.auth.HTTPBasicAuth(userid, password),
            'digest': requests.auth.HTTPDigestAuth(userid, password)
        }[auth_method.lower()]

    except KeyError:
        raise SCCIInvalidInputError(
            ("Invalid port %(port)d or " +
             "auth_method for method %(auth_method)s") %
            {'port': port, 'auth_method': auth_method})

    try:
        header = {'Content-type': 'application/x-www-form-urlencoded'}
        if kwargs.get('upgrade_type') == 'irmc':
            with open(cmd, 'rb') as file:
                data = file.read()
            config_type = '/irmcupdate?flashSelect=255'
        elif kwargs.get('upgrade_type') == 'bios':
            with open(cmd, 'rb') as file:
                data = file.read()
            config_type = '/biosupdate'
        else:
            data = cmd
            config_type = '/config'
        r = requests.post(protocol + '://' + host + config_type,
                          data=data,
                          headers=header,
                          verify=False,
                          timeout=client_timeout,
                          allow_redirects=False,
                          auth=auth_obj)

        if not do_async:
            time.sleep(5)
        if DEBUG:
            print(cmd)
            print(r.text)
            print("do_async = %s" % do_async)
        if r.status_code not in (200, 201):
            raise SCCIClientError(
                ('HTTP PROTOCOL ERROR, STATUS CODE = %s' %
                 str(r.status_code)))

        result_xml = ET.fromstring(r.text)
        status = result_xml.find("./Value")
        # severity = result_xml.find("./Severity")
        error = result_xml.find("./Error")
        message = result_xml.find("./Message")
        if not int(status.text) == 0:
            raise SCCIClientError(
                ('SCCI PROTOCOL ERROR, STATUS CODE = %s, '
                 'ERROR = %s, MESSAGE = %s' %
                 (str(status.text), error.text, message.text)))
        else:
            return r

    except IOError as input_error:
        raise SCCIClientError(input_error)

    except ET.ParseError as parse_error:
        raise SCCIClientError(parse_error)

    except requests.exceptions.RequestException as requests_exception:
        raise SCCIClientError(requests_exception)
def scci_cmd ( host , userid , password , cmd , port = 443 , auth_method = 'basic' , client_timeout = 60 , do_async = True , ** kwargs ) : auth_obj = None try : protocol = { 80 : 'http' , 443 : 'https' } [ port ] auth_obj = { 'basic' : requests . auth . HTTPBasicAuth ( userid , password ) , 'digest' : requests . auth . HTTPDigestAuth ( userid , password ) } [ auth_method . lower ( ) ] except KeyError : raise SCCIInvalidInputError ( ( "Invalid port %(port)d or " + "auth_method for method %(auth_method)s" ) % { 'port' : port , 'auth_method' : auth_method } ) try : header = { 'Content-type' : 'application/x-www-form-urlencoded' } if kwargs . get ( 'upgrade_type' ) == 'irmc' : with open ( cmd , 'rb' ) as file : data = file . read ( ) config_type = '/irmcupdate?flashSelect=255' elif kwargs . get ( 'upgrade_type' ) == 'bios' : with open ( cmd , 'rb' ) as file : data = file . read ( ) config_type = '/biosupdate' else : data = cmd config_type = '/config' r = requests . post ( protocol + '://' + host + config_type , data = data , headers = header , verify = False , timeout = client_timeout , allow_redirects = False , auth = auth_obj ) if not do_async : time . sleep ( 5 ) if DEBUG : print ( cmd ) print ( r . text ) print ( "do_async = %s" % do_async ) if r . status_code not in ( 200 , 201 ) : raise SCCIClientError ( ( 'HTTP PROTOCOL ERROR, STATUS CODE = %s' % str ( r . status_code ) ) ) result_xml = ET . fromstring ( r . text ) status = result_xml . find ( "./Value" ) error = result_xml . find ( "./Error" ) message = result_xml . find ( "./Message" ) if not int ( status . text ) == 0 : raise SCCIClientError ( ( 'SCCI PROTOCOL ERROR, STATUS CODE = %s, ' 'ERROR = %s, MESSAGE = %s' % ( str ( status . text ) , error . text , message . text ) ) ) else : return r except IOError as input_error : raise SCCIClientError ( input_error ) except ET . ParseError as parse_error : raise SCCIClientError ( parse_error ) except requests . exceptions . RequestException as requests_exception : raise SCCIClientError ( requests_exception )
execute SCCI command

    This function calls SCCI server modules
    :param host: hostname or IP of iRMC
    :param userid: userid for iRMC with administrator privileges
    :param password: password for userid
    :param cmd: SCCI command
    :param port: port number of iRMC
    :param auth_method: irmc_username
    :param client_timeout: timeout for SCCI operations
    :param do_async: async call if True, sync call otherwise
    :returns: requests.Response from SCCI server
    :raises: SCCIInvalidInputError if port and/or auth_method params
             are invalid
    :raises: SCCIClientError if SCCI failed