<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> from __future__ import absolute_import <EOL> from future import standard_library <EOL> standard_library . install_aliases ( ) <EOL> from pprint import pprint <EOL> __title__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> __copyright__ = '<STR_LIT>' '<STR_LIT>' <EOL> __license__ = '<STR_LIT>' <EOL> __status__ = '<STR_LIT>' <EOL> from hpOneView . common import * <EOL> from hpOneView . connection import * <EOL> from hpOneView . activity import * <EOL> from hpOneView . exceptions import * <EOL> class servers ( object ) : <EOL> def __init__ ( self , con ) : <EOL> self . _con = con <EOL> self . _activity = activity ( con ) <EOL> def get_connections ( self , filter = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return get_members ( self . _con . get ( uri [ '<STR_LIT>' ] + filter ) ) <EOL> def get_connection ( self , server ) : <EOL> """<STR_LIT>""" <EOL> body = self . _con . get ( server [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_server_by_bay ( self , baynum ) : <EOL> servers = get_members ( self . _con . get ( uri [ '<STR_LIT>' ] ) ) <EOL> for server in servers : <EOL> if server [ '<STR_LIT>' ] == baynum : <EOL> return server <EOL> def get_server_by_name ( self , name ) : <EOL> servers = get_members ( self . _con . get ( uri [ '<STR_LIT>' ] ) ) <EOL> for server in servers : <EOL> if server [ '<STR_LIT:name>' ] == name : <EOL> return server <EOL> def get_available_servers ( self , server_hardware_type = None , <EOL> enclosure_group = None , server_profile = None ) : <EOL> filters = [ ] <EOL> if server_hardware_type : <EOL> filters . append ( '<STR_LIT>' + server_hardware_type [ '<STR_LIT>' ] ) <EOL> if enclosure_group : <EOL> filters . append ( '<STR_LIT>' + enclosure_group [ '<STR_LIT>' ] ) <EOL> if server_profile : <EOL> filters . append ( '<STR_LIT>' + server_profile [ '<STR_LIT>' ] ) <EOL> query_string = '<STR_LIT>' <EOL> if filters : <EOL> query_string = '<STR_LIT:?>' + '<STR_LIT:&>' . join ( filters ) <EOL> return self . _con . get ( uri [ '<STR_LIT>' ] + query_string ) <EOL> def get_servers ( self ) : <EOL> return get_members ( self . _con . get ( uri [ '<STR_LIT>' ] ) ) <EOL> def get_utilization ( self , server ) : <EOL> """<STR_LIT>""" <EOL> body = self . _con . get ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> return body <EOL> def get_env_conf ( self , server ) : <EOL> """<STR_LIT>""" <EOL> body = self . _con . get ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> return body <EOL> def set_server_powerstate ( self , server , state , force = False , blocking = True , <EOL> verbose = False ) : <EOL> if state == '<STR_LIT>' and force is True : <EOL> powerRequest = make_powerstate_dict ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif state == '<STR_LIT>' and force is False : <EOL> powerRequest = make_powerstate_dict ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif state == '<STR_LIT>' : <EOL> powerRequest = make_powerstate_dict ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif state == '<STR_LIT>' : <EOL> powerRequest = make_powerstate_dict ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> task , body = self . _con . put ( server [ '<STR_LIT>' ] + '<STR_LIT>' , powerRequest ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> return task <EOL> def delete_server ( self , server , force = False , blocking = True , verbose = False ) : <EOL> if force : <EOL> task , body = self . _con . delete ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> else : <EOL> task , body = self . _con . delete ( server [ '<STR_LIT>' ] ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> return task <EOL> def update_server ( self , server ) : <EOL> task , body = self . _con . put ( server [ '<STR_LIT>' ] , server ) <EOL> return body <EOL> def add_server ( self , server , blocking = True , verbose = False ) : <EOL> task , body = self . _con . post ( uri [ '<STR_LIT>' ] , server ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> if '<STR_LIT:type>' in task and task [ '<STR_LIT:type>' ] . startswith ( '<STR_LIT>' ) : <EOL> entity = self . _activity . get_task_associated_resource ( task ) <EOL> server = self . _con . get ( entity [ '<STR_LIT>' ] ) <EOL> return server <EOL> return task <EOL> def get_server_schema ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( uri [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def get_bios ( self , server ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def get_ilo_sso_url ( self , server ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def get_java_remote_console_url ( self , server ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def get_remote_console_url ( self , server ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( server [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def get_server_hardware_types ( self ) : <EOL> """<STR_LIT>""" <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return get_members ( body ) <EOL> def remove_server_hardware_type ( self , server_hardware_type , force = False , blocking = True , verbose = False ) : <EOL> """<STR_LIT>""" <EOL> if force : <EOL> task , body = self . _con . delete ( server_hardware_type [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> else : <EOL> task , body = self . _con . delete ( server_hardware_type [ '<STR_LIT>' ] ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> return task <EOL> def get_server_type_schema ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( uri [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def get_server_hardware_type ( self , server_type ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( server_type [ '<STR_LIT>' ] ) <EOL> def set_server_hardware_type ( self , server_hardware_type , name , description ) : <EOL> """<STR_LIT>""" <EOL> request = make_server_type_dict ( name , description ) <EOL> task , body = self . _con . put ( server_hardware_type [ '<STR_LIT>' ] , request ) <EOL> return task <EOL> def create_server_profile ( self , <EOL> affinity = '<STR_LIT>' , <EOL> biosSettings = None , <EOL> bootSettings = None , <EOL> bootModeSetting = None , <EOL> profileConnectionV4 = None , <EOL> description = None , <EOL> firmwareSettingsV3 = None , <EOL> hideUnusedFlexNics = True , <EOL> localStorageSettingsV3 = None , <EOL> macType = '<STR_LIT>' , <EOL> name = None , <EOL> sanStorageV3 = None , <EOL> serialNumber = None , <EOL> serialNumberType = '<STR_LIT>' , <EOL> serverHardwareTypeUri = None , <EOL> serverHardwareUri = None , <EOL> serverProfileTemplateUri = None , <EOL> uuid = None , <EOL> wwnType = '<STR_LIT>' , <EOL> blocking = True , verbose = False ) : <EOL> """<STR_LIT>""" <EOL> profile = make_ServerProfileV5 ( affinity , biosSettings , bootSettings , <EOL> bootModeSetting , profileConnectionV4 , <EOL> description , firmwareSettingsV3 , <EOL> hideUnusedFlexNics , <EOL> localStorageSettingsV3 , macType , name , <EOL> sanStorageV3 , serialNumber , <EOL> serialNumberType , serverHardwareTypeUri , <EOL> serverHardwareUri , <EOL> serverProfileTemplateUri , uuid , wwnType ) <EOL> task , body = self . _con . post ( uri [ '<STR_LIT>' ] , profile ) <EOL> if profile [ '<STR_LIT>' ] is None : <EOL> tout = <NUM_LIT> <EOL> else : <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout , verbose = verbose ) <EOL> if '<STR_LIT:type>' in task and task [ '<STR_LIT:type>' ] . startswith ( '<STR_LIT>' ) : <EOL> entity = self . _activity . get_task_associated_resource ( task ) <EOL> profile = self . _con . get ( entity [ '<STR_LIT>' ] ) <EOL> return profile <EOL> return task <EOL> def post_server_profile ( self , profile , blocking = True , verbose = False ) : <EOL> """<STR_LIT>""" <EOL> task , body = self . _con . post ( uri [ '<STR_LIT>' ] , profile ) <EOL> if profile [ '<STR_LIT>' ] is None : <EOL> tout = <NUM_LIT> <EOL> else : <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout , verbose = verbose ) <EOL> if '<STR_LIT:type>' in task and task [ '<STR_LIT:type>' ] . startswith ( '<STR_LIT>' ) : <EOL> entity = self . _activity . get_task_associated_resource ( task ) <EOL> profile = self . _con . get ( entity [ '<STR_LIT>' ] ) <EOL> return profile <EOL> return task <EOL> def remove_server_profile ( self , profile , force = False , blocking = True , verbose = False ) : <EOL> if force : <EOL> task , body = self . _con . delete ( profile [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> else : <EOL> task , body = self . _con . delete ( profile [ '<STR_LIT>' ] ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> return task <EOL> def get_server_profiles ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return get_members ( body ) <EOL> def update_server_profile ( self , profile , blocking = True , verbose = False ) : <EOL> task , body = self . _con . put ( profile [ '<STR_LIT>' ] , profile ) <EOL> try : <EOL> if profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] is None : <EOL> tout = <NUM_LIT> <EOL> else : <EOL> tout = <NUM_LIT> <EOL> except Exception : <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = tout , verbose = verbose ) <EOL> profileResource = self . _activity . get_task_associated_resource ( task ) <EOL> profile = self . _con . get ( profileResource [ '<STR_LIT>' ] ) <EOL> return profile <EOL> def update_server_profile_from_template ( self , profile , blocking = True , verbose = False ) : <EOL> patch_request = [ { '<STR_LIT>' : '<STR_LIT:replace>' , '<STR_LIT:path>' : '<STR_LIT>' , '<STR_LIT:value>' : '<STR_LIT>' } ] <EOL> task , body = self . _con . patch ( profile [ '<STR_LIT>' ] , patch_request ) <EOL> try : <EOL> if profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] is None : <EOL> tout = <NUM_LIT> <EOL> else : <EOL> tout = <NUM_LIT> <EOL> except Exception : <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = tout , verbose = verbose ) <EOL> profileResource = self . _activity . get_task_associated_resource ( task ) <EOL> profile = self . _con . get ( profileResource [ '<STR_LIT>' ] ) <EOL> return profile <EOL> def get_server_profile_by_name ( self , name ) : <EOL> body = self . _con . get_entity_byfield ( uri [ '<STR_LIT>' ] , '<STR_LIT:name>' , name ) <EOL> return body <EOL> def get_profile_message ( self , profile ) : <EOL> """<STR_LIT>""" <EOL> message = self . _con . get ( profile [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> return message <EOL> def get_profile_compliance_preview ( self , profile ) : <EOL> """<STR_LIT>""" <EOL> return self . _con . get ( profile [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> def create_server_profile_template ( <EOL> self , <EOL> name = None , <EOL> description = None , <EOL> serverProfileDescription = None , <EOL> serverHardwareTypeUri = None , <EOL> enclosureGroupUri = None , <EOL> affinity = None , <EOL> hideUnusedFlexNics = None , <EOL> profileConnectionV4 = None , <EOL> firmwareSettingsV3 = None , <EOL> bootSettings = None , <EOL> bootModeSetting = None , <EOL> blocking = True , <EOL> verbose = False ) : <EOL> """<STR_LIT>""" <EOL> profile_template = make_ServerProfileTemplateV1 ( name , <EOL> description , <EOL> serverProfileDescription , <EOL> serverHardwareTypeUri , <EOL> enclosureGroupUri , <EOL> affinity , <EOL> hideUnusedFlexNics , <EOL> profileConnectionV4 , <EOL> firmwareSettingsV3 , <EOL> bootSettings , <EOL> bootModeSetting ) <EOL> task , body = self . _con . post ( uri [ '<STR_LIT>' ] , profile_template ) <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout , verbose = verbose ) <EOL> if '<STR_LIT:type>' in task and task [ '<STR_LIT:type>' ] . startswith ( '<STR_LIT>' ) : <EOL> entity = self . _activity . get_task_associated_resource ( task ) <EOL> profile_template = self . _con . get ( entity [ '<STR_LIT>' ] ) <EOL> return profile_template <EOL> return task <EOL> def remove_server_profile_template ( self , profile_template , blocking = True , verbose = False ) : <EOL> task , body = self . _con . delete ( profile_template [ '<STR_LIT>' ] ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> return task <EOL> return body <EOL> def get_server_profile_templates ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return get_members ( body ) <EOL> def get_server_profile_template_by_name ( self , name ) : <EOL> body = self . _con . get_entity_byfield ( uri [ '<STR_LIT>' ] , '<STR_LIT:name>' , name ) <EOL> return body <EOL> def update_server_profile_template ( self , profile_template , blocking = True , verbose = False ) : <EOL> task , body = self . _con . put ( profile_template [ '<STR_LIT>' ] , profile_template ) <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = tout , verbose = verbose ) <EOL> profileTemplateResource = self . _activity . get_task_associated_resource ( task ) <EOL> profile = self . _con . get ( profileTemplateResource [ '<STR_LIT>' ] ) <EOL> return profile_template <EOL> def get_server_profile_from_template ( self , profile_template ) : <EOL> profile = self . _con . get ( profile_template [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> return profile <EOL> def get_enclosures ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return get_members ( body ) <EOL> def add_enclosure ( self , enclosure , blocking = True , verbose = False ) : <EOL> task , body = self . _con . post ( uri [ '<STR_LIT>' ] , enclosure ) <EOL> if enclosure [ '<STR_LIT:state>' ] is '<STR_LIT>' : <EOL> tout = <NUM_LIT> <EOL> elif enclosure [ '<STR_LIT>' ] is None : <EOL> tout = <NUM_LIT> <EOL> else : <EOL> tout = <NUM_LIT> <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout , verbose = verbose ) <EOL> if '<STR_LIT:type>' in task and task [ '<STR_LIT:type>' ] . startswith ( '<STR_LIT>' ) : <EOL> entity = self . _activity . get_task_associated_resource ( task ) <EOL> enclosure = self . _con . get ( entity [ '<STR_LIT>' ] ) <EOL> return enclosure <EOL> return task <EOL> def remove_enclosure ( self , enclosure , force = False , blocking = True , <EOL> verbose = False ) : <EOL> if force : <EOL> task , body = self . _con . delete ( enclosure [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> else : <EOL> task , body = self . _con . delete ( enclosure [ '<STR_LIT>' ] ) <EOL> if blocking is True : <EOL> task = self . _activity . wait4task ( task , tout = <NUM_LIT> , verbose = verbose ) <EOL> return task <EOL> def create_enclosure_group ( self , associatedLIGs , name , <EOL> powerMode = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> egroup = make_EnclosureGroupV200 ( associatedLIGs , name , powerMode ) <EOL> task , body = self . _con . post ( uri [ '<STR_LIT>' ] , egroup ) <EOL> return body <EOL> def delete_enclosure_group ( self , egroup ) : <EOL> self . _con . delete ( egroup [ '<STR_LIT>' ] ) <EOL> def get_enclosure_groups ( self ) : <EOL> return get_members ( self . _con . get ( uri [ '<STR_LIT>' ] ) ) <EOL> def update_enclosure_group ( self , enclosuregroup ) : <EOL> task , body = self . _con . put ( enclosuregroup [ '<STR_LIT>' ] , enclosuregroup ) <EOL> return body <EOL> def get_pool ( self , pooltype ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] + '<STR_LIT:/>' + pooltype ) <EOL> return body <EOL> def get_vmac_pool ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_vwwn_pool ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_vsn_pool ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_profile_networks ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_profile_schema ( self ) : <EOL> return self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> def get_profile_available_servers ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_profile_available_storage_systems ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def get_profile_ports ( self ) : <EOL> body = self . _con . get ( uri [ '<STR_LIT>' ] ) <EOL> return body <EOL> def allocate_pool_ids ( self , url , count ) : <EOL> allocatorUrl = '<STR_LIT>' % url <EOL> allocatorBody = { '<STR_LIT:count>' : count } <EOL> task , body = self . _con . put ( allocatorUrl , allocatorBody ) <EOL> return body <EOL> def release_pool_ids ( self , url , idList ) : <EOL> collectorUrl = '<STR_LIT>' % url <EOL> collectorBody = { '<STR_LIT>' : idList } <EOL> task , body = self . _con . put ( collectorUrl , collectorBody ) <EOL> return body <EOL> def allocate_range_ids ( self , allocatorUrl , count ) : <EOL> task , body = self . _con . put ( allocatorUrl , { '<STR_LIT:count>' : count } ) <EOL> return body <EOL> def release_range_ids ( self , collectorUrl , idList ) : <EOL> task , body = self . _con . put ( collectorUrl , { '<STR_LIT>' : idList } ) <EOL> return body <EOL> def enable_range ( self , url ) : <EOL> prange = self . _con . get ( url ) <EOL> prange [ '<STR_LIT>' ] = True <EOL> task , body = self . _con . put ( url , prange ) <EOL> return body <EOL> def disable_range ( self , url ) : <EOL> prange = self . _con . get ( url ) <EOL> prange [ '<STR_LIT>' ] = False <EOL> task , body = self . _con . put ( url , prange ) <EOL> return body </s>
