<s> '''<STR_LIT>''' <EOL> import httplib2 <EOL> import socket <EOL> def power_on ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __power_on_command__ ( ) ) <EOL> def power_off ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __power_off_command__ ( ) ) <EOL> def power_off_acpi ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __power_off_acpi_command__ ( ) ) <EOL> def power_cycle ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __power_cycle_command__ ( ) ) <EOL> def power_reset ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __power_reset_command__ ( ) ) <EOL> def pass_change ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( <EOL> hostname , username , password , <EOL> __pass_change_command__ ( kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] ) ) <EOL> def set_settings ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( <EOL> hostname , username , password , <EOL> __mod_global_settings_command__ ( ** kwargs ) + <EOL> __mod_network_settings_command__ ( ** kwargs ) + <EOL> __power_on_delay_command__ ( ** kwargs ) ) <EOL> def set_ldap_settings ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( <EOL> hostname , username , password , <EOL> __mod_directory_command__ ( ** kwargs ) ) <EOL> def boot_order ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __boot_order_command__ ( ** kwargs ) ) <EOL> def license_set ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __license_set_command__ ( ** kwargs ) ) <EOL> def bmc_reset ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __reset_rib_command__ ( ) ) <EOL> def bmc_factory_defaults ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __factory_defaults_command__ ( ) ) <EOL> def add_user ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __add_user_command__ ( ** kwargs ) ) <EOL> def remove_user ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __remove_user_command__ ( ** kwargs ) ) <EOL> def get_all_users ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return __send__ ( hostname , username , password , __get_all_users_command__ ( ** kwargs ) ) <EOL> def firmware_update ( hostname , username , password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> f = open ( kwargs [ '<STR_LIT>' ] ) . read ( ) <EOL> except IOError : <EOL> print "<STR_LIT>" <EOL> return False <EOL> content_type , body = encode_multipart_formdata ( <EOL> ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) , <EOL> ( ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] , f ) , ) , <EOL> ) <EOL> extras = { <EOL> '<STR_LIT:Content-Type>' : content_type , <EOL> '<STR_LIT:body>' : body , <EOL> } <EOL> try : <EOL> extras = { '<STR_LIT>' : extras [ '<STR_LIT>' ] } <EOL> except IndexError : <EOL> print "<STR_LIT>" <EOL> return False <EOL> return __send__ ( hostname , username , password , __firmware_update_command__ ( ** kwargs ) , extras ) <EOL> def __send__ ( hostname , username , password , command , extras = None ) : <EOL> h = httplib2 . Http ( disable_ssl_certificate_validation = True ) <EOL> body = '''<STR_LIT>''' % ( username , password , command ) <EOL> body = str ( body ) <EOL> headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> url = '<STR_LIT>' % str ( hostname ) <EOL> if extras is not None : <EOL> if '<STR_LIT:Content-Type>' in extras . keys ( ) : <EOL> headers . update ( { '<STR_LIT:Content-Type>' : extras [ '<STR_LIT:Content-Type>' ] } ) <EOL> body = str ( extras [ '<STR_LIT:body>' ] ) <EOL> url = '<STR_LIT>' % str ( hostname ) <EOL> else : <EOL> headers . update ( extras ) <EOL> try : <EOL> resp , content = h . request ( <EOL> url , '<STR_LIT:POST>' , body = body , headers = headers ) <EOL> except ( httplib2 . ServerNotFoundError , socket . error ) as e : <EOL> print e <EOL> return <EOL> if extras is not None and '<STR_LIT>' in resp : <EOL> extras [ '<STR_LIT>' ] = resp [ '<STR_LIT>' ] <EOL> return content <EOL> def encode_multipart_formdata ( fields , files ) : <EOL> '''<STR_LIT>''' <EOL> BOUNDARY = '<STR_LIT>' <EOL> CRLF = '<STR_LIT:\r\n>' <EOL> L = [ ] <EOL> for ( key , value ) in fields : <EOL> L . append ( '<STR_LIT>' + BOUNDARY ) <EOL> L . append ( '<STR_LIT>' % key ) <EOL> L . append ( '<STR_LIT>' ) <EOL> L . append ( value ) <EOL> for ( key , filename , value ) in files : <EOL> L . append ( '<STR_LIT>' + BOUNDARY ) <EOL> L . append ( '<STR_LIT>' % ( key , filename ) ) <EOL> L . append ( '<STR_LIT>' % ( '<STR_LIT>' ) ) <EOL> L . append ( '<STR_LIT>' ) <EOL> L . append ( value ) <EOL> L . append ( '<STR_LIT>' + BOUNDARY + '<STR_LIT>' ) <EOL> L . append ( '<STR_LIT>' ) <EOL> body = CRLF . join ( L ) <EOL> content_type = '<STR_LIT>' % BOUNDARY <EOL> return content_type , body <EOL> def __power_on_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __power_off_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __power_off_acpi_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __power_cycle_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __power_reset_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __pass_change_command__ ( username , newpass ) : <EOL> command = '''<STR_LIT>''' % ( username , newpass ) <EOL> return command . strip ( ) <EOL> def __mod_network_settings_command__ ( ** kwargs ) : <EOL> for i in kwargs . keys ( ) : <EOL> if kwargs [ i ] is None : <EOL> kwargs . pop ( i ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if '<STR_LIT>' in kwargs : <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> networksettings = '''<STR_LIT>''' % kwargs <EOL> else : <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> networksettings = '''<STR_LIT>''' % kwargs <EOL> othersettings = '''<STR_LIT>''' % kwargs <EOL> command = '''<STR_LIT>''' % ( networksettings , othersettings ) <EOL> return command <EOL> def __mod_global_settings_command__ ( ** kwargs ) : <EOL> for i in kwargs . keys ( ) : <EOL> if kwargs [ i ] is None : <EOL> kwargs . pop ( i ) <EOL> serial_speeds = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> } <EOL> if '<STR_LIT>' in kwargs : <EOL> try : <EOL> kwargs [ '<STR_LIT>' ] = serial_speeds [ kwargs [ '<STR_LIT>' ] ] <EOL> except KeyError : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:3>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:5>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:3>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> command = '''<STR_LIT>''' % kwargs <EOL> return command <EOL> def __boot_order_command__ ( ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if kwargs [ '<STR_LIT>' ] : <EOL> command = '''<STR_LIT>''' % kwargs [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> else : <EOL> boot_list = '<STR_LIT>' <EOL> for b in kwargs [ '<STR_LIT>' ] : <EOL> boot_list = boot_list + '<STR_LIT>' % b <EOL> command = '''<STR_LIT>''' % boot_list <EOL> return command <EOL> def __power_on_delay_command__ ( ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> command = '''<STR_LIT>''' % kwargs <EOL> return command <EOL> def __license_set_command__ ( ** kwargs ) : <EOL> command = '''<STR_LIT>''' % kwargs <EOL> return command <EOL> def __mod_directory_command__ ( ** kwargs ) : <EOL> for i in kwargs . keys ( ) : <EOL> if kwargs [ i ] is None : <EOL> kwargs . pop ( i ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:yes>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , ( ) ) <EOL> i = <NUM_LIT:0> <EOL> contexts_command = '<STR_LIT>' <EOL> for context in kwargs [ '<STR_LIT>' ] : <EOL> contexts_command += '<STR_LIT>' % ( i + <NUM_LIT:1> , kwargs [ '<STR_LIT>' ] [ i ] ) <EOL> i = i + <NUM_LIT:1> <EOL> kwargs . setdefault ( '<STR_LIT>' , ( ) ) <EOL> i = <NUM_LIT:0> <EOL> groupnames_command = '<STR_LIT>' <EOL> for groupname in kwargs [ '<STR_LIT>' ] : <EOL> groupnames_command += '<STR_LIT>' % ( i + <NUM_LIT:1> , kwargs [ '<STR_LIT>' ] [ i ] ) <EOL> i = i + <NUM_LIT:1> <EOL> kwargs . setdefault ( '<STR_LIT>' , ( ) ) <EOL> i = <NUM_LIT:0> <EOL> groupprivs_command = '<STR_LIT>' <EOL> for grouppriv in kwargs [ '<STR_LIT>' ] : <EOL> groupprivs_command += '<STR_LIT>' % ( i + <NUM_LIT:1> , kwargs [ '<STR_LIT>' ] [ i ] ) <EOL> i = i + <NUM_LIT:1> <EOL> kwargs . setdefault ( '<STR_LIT>' , ( ) ) <EOL> i = <NUM_LIT:0> <EOL> groupsids_command = '<STR_LIT>' <EOL> for groupsid in kwargs [ '<STR_LIT>' ] : <EOL> groupsids_command += '<STR_LIT>' % ( i + <NUM_LIT:1> , kwargs [ '<STR_LIT>' ] [ i ] ) <EOL> i = i + <NUM_LIT:1> <EOL> othersettings = '''<STR_LIT>''' % kwargs <EOL> command = '''<STR_LIT>''' % ( othersettings , contexts_command , groupnames_command , groupprivs_command , groupsids_command ) <EOL> return command <EOL> def __reset_rib_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __factory_defaults_command__ ( ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __add_user_command__ ( ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:Y>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT:N>' ) <EOL> command = '''<STR_LIT>''' % kwargs <EOL> return command . strip ( ) <EOL> def __get_all_users_command__ ( ** kwargs ) : <EOL> command = '''<STR_LIT>''' <EOL> return command . strip ( ) <EOL> def __remove_user_command__ ( ** kwargs ) : <EOL> command = '''<STR_LIT>''' % kwargs <EOL> return command . strip ( ) <EOL> def __firmware_update_command__ ( ** kwargs ) : <EOL> command = '''<STR_LIT>''' % kwargs <EOL> return command . strip ( ) </s>
