<s> __version__ = '<STR_LIT>' <EOL> import os <EOL> import ConfigParser <EOL> from distutils . util import strtobool <EOL> from openstack . compute . backup_schedules import ( BackupSchedule , BackupScheduleManager , <EOL> BACKUP_WEEKLY_DISABLED , BACKUP_WEEKLY_SUNDAY , BACKUP_WEEKLY_MONDAY , <EOL> BACKUP_WEEKLY_TUESDAY , BACKUP_WEEKLY_WEDNESDAY , <EOL> BACKUP_WEEKLY_THURSDAY , BACKUP_WEEKLY_FRIDAY , BACKUP_WEEKLY_SATURDAY , <EOL> BACKUP_DAILY_DISABLED , BACKUP_DAILY_H_0000_0200 , <EOL> BACKUP_DAILY_H_0200_0400 , BACKUP_DAILY_H_0400_0600 , <EOL> BACKUP_DAILY_H_0600_0800 , BACKUP_DAILY_H_0800_1000 , <EOL> BACKUP_DAILY_H_1000_1200 , BACKUP_DAILY_H_1200_1400 , <EOL> BACKUP_DAILY_H_1400_1600 , BACKUP_DAILY_H_1600_1800 , <EOL> BACKUP_DAILY_H_1800_2000 , BACKUP_DAILY_H_2000_2200 , <EOL> BACKUP_DAILY_H_2200_0000 ) <EOL> from openstack . compute . client import ComputeClient <EOL> from openstack . compute . exceptions import ( ComputeException , BadRequest , Unauthorized , <EOL> Forbidden , NotFound , OverLimit ) <EOL> from openstack . compute . flavors import FlavorManager , Flavor <EOL> from openstack . compute . images import ImageManager , Image <EOL> from openstack . compute . ipgroups import IPGroupManager , IPGroup <EOL> from openstack . compute . servers import ServerManager , Server , REBOOT_HARD , REBOOT_SOFT <EOL> from openstack . compute . api import API_OPTIONS <EOL> DEFAULT_CONFIG_FILE = os . path . expanduser ( '<STR_LIT>' ) <EOL> class Compute ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . config = self . _get_config ( kwargs ) <EOL> self . backup_schedules = BackupScheduleManager ( self ) <EOL> self . client = ComputeClient ( self . config ) <EOL> self . flavors = FlavorManager ( self ) <EOL> self . images = ImageManager ( self ) <EOL> self . servers = ServerManager ( self ) <EOL> if '<STR_LIT>' in API_OPTIONS [ self . config . cloud_api ] : <EOL> self . ipgroups = IPGroupManager ( self ) <EOL> def authenticate ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . authenticate ( ) <EOL> def _get_config ( self , kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Config ( <EOL> config_file = kwargs . pop ( '<STR_LIT>' , None ) , <EOL> env = kwargs . pop ( '<STR_LIT>' , None ) , <EOL> overrides = kwargs , <EOL> ) <EOL> class Config ( object ) : <EOL> """<STR_LIT>""" <EOL> DEFAULTS = { <EOL> '<STR_LIT:username>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' % __version__ , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , config_file , env , overrides , env_prefix = "<STR_LIT>" ) : <EOL> config_file = config_file or DEFAULT_CONFIG_FILE <EOL> env = env or os . environ <EOL> self . config = self . DEFAULTS . copy ( ) <EOL> self . update_config_from_file ( config_file ) <EOL> self . update_config_from_env ( env , env_prefix ) <EOL> self . config . update ( dict ( ( k , v ) for ( k , v ) in overrides . items ( ) if v is not None ) ) <EOL> self . apply_fixups ( ) <EOL> def __getattr__ ( self , attr ) : <EOL> try : <EOL> return self . config [ attr ] <EOL> except KeyError : <EOL> raise AttributeError ( attr ) <EOL> def update_config_from_file ( self , config_file ) : <EOL> """<STR_LIT>""" <EOL> configparser = ConfigParser . RawConfigParser ( ) <EOL> if os . path . exists ( config_file ) : <EOL> configparser . read ( [ config_file ] ) <EOL> for section in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if configparser . has_section ( section ) : <EOL> self . config . update ( dict ( configparser . items ( section ) ) ) <EOL> def update_config_from_env ( self , env , env_prefix ) : <EOL> """<STR_LIT>""" <EOL> for key , value in env . iteritems ( ) : <EOL> if key . startswith ( env_prefix ) : <EOL> key = key . replace ( env_prefix , '<STR_LIT>' ) . lower ( ) <EOL> self . config [ key ] = value <EOL> def apply_fixups ( self ) : <EOL> """<STR_LIT>""" <EOL> for key , value in self . DEFAULTS . iteritems ( ) : <EOL> if isinstance ( value , bool ) and not isinstance ( self . config [ key ] , bool ) : <EOL> self . config [ key ] = strtobool ( self . config [ key ] ) </s>
