class ImageConfiguration( object ): def __init__( self, imageName ): self.log = gLogger.getSubLogger( 'ImageConfiguration' ) imageOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s' % imageName ) if not imageOptions[ 'OK' ]: self.log.error( imageOptions[ 'Message' ] ) imageOptions = {} else: imageOptions = imageOptions[ 'Value' ] self.__ic_DIRACImageName = imageName self.__ic_bootImageName = imageOptions.get( 'bootImageName' , None ) self.__ic_contextMethod = imageOptions.get( 'contextMethod' , None ) self.__ic_flavorName = imageOptions.get( 'flavorName' , None ) #self.__ic_contextConfig = ContextConfig( self.__ic_bootImageName, self.__ic_contextMethod ) self.__ic_contextConfig = ContextConfig( imageName, self.__ic_contextMethod ) def config( self ): config = { 'DIRACImageName' : self.__ic_DIRACImageName, 'bootImageName' : self.__ic_bootImageName, 'contextMethod' : self.__ic_contextMethod, 'flavorName' : self.__ic_flavorName, 'contextConfig' : self.__ic_contextConfig.config() } return config def validate( self ): if self.__ic_DIRACImageName is None: return S_ERROR( 'Specific image section does not exits in Images' ) if self.__ic_bootImageName is None: return S_ERROR( 'bootImageName option is None' ) if self.__ic_contextMethod is None: return S_ERROR( 'contextMethod option is None' ) if self.__ic_flavorName is None: return S_ERROR( 'flavorName option is None' ) validateContext = self.__ic_contextConfig.validate() if not validateContext[ 'OK' ]: self.log.error( validateContext[ 'Message' ] ) return validateContext self.log.info( 'Displaying image info' ) self.log.info( '*' * 50 ) self.log.info( 'ic_DIRACImageName %s' % self.__ic_DIRACImageName ) self.log.info( 'ic_bootImageName %s' % self.__ic_bootImageName ) self.log.info( 'ic_contextMethod %s' % self.__ic_contextMethod ) for key, value in self.__ic_contextConfig.config().iteritems(): self.log.info( '%s : %s' % ( key, value ) ) self.log.info( '*' * 50 ) return S_OK()
def __init__( self, imageName, endPointName ): self.log = gLogger.getSubLogger( 'ImageConfiguration' ) imageOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s' % imageName ) if not imageOptions[ 'OK' ]: self.log.error( imageOptions[ 'Message' ] ) imageOptions = {} else: imageOptions = imageOptions[ 'Value' ] self.__ic_DIRACImageName = imageName endPointName = endPointName.strip() # A DIRAC image can have different boot image names in the cloud endPoints bootImageOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s/BootImages' % imageName ) if not bootImageOptions[ 'OK' ]: self.log.error( bootImageOptions[ 'Message' ] ) return bootImageOptions = bootImageOptions[ 'Value' ] bootImageName = None for bootEndpoint, bootImage in bootImageOptions.items(): if endPointName == bootEndpoint: bootImageName = bootImage break if bootImageName is None: self.log.error( 'Missing mandatory boot image of the endPoint %s in BootImages section, image %s' % (endPointName, imageName) ) self.__ic_bootImageName = bootImageName # A DIRAC image can have different flavor names names in the cloud endPoints flavorOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s/Flavors' % imageName ) if not flavorOptions[ 'OK' ]: self.log.error( flavorOptions[ 'Message' ] ) return flavorOptions = flavorOptions[ 'Value' ] flavorName = None for bootEndpoint, flavor in flavorOptions.items(): if endPointName == bootEndpoint: flavorName = flavor break if flavorName is None: self.log.error( 'Missing mandatory flavor of the endPoint %s in BootImages section, image %s' % (endPointName, imageName) ) self.__ic_flavorName = flavorName self.__ic_contextMethod = imageOptions.get( 'contextMethod' , None ) #optional: self.__ic_maxAllowedPrice = imageOptions.get( 'maxAllowedPrice' , None ) self.__ic_keyName = imageOptions.get( 'keyName' , None ) #self.__ic_contextConfig = ContextConfig( self.__ic_bootImageName, self.__ic_contextMethod ) self.__ic_contextConfig = ContextConfig( imageName, self.__ic_contextMethod )
def __init__( self, imageName ): self.log = gLogger.getSubLogger( 'ImageConfiguration' ) imageOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s' % imageName ) if not imageOptions[ 'OK' ]: self.log.error( imageOptions[ 'Message' ] ) imageOptions = {} else: imageOptions = imageOptions[ 'Value' ] self.__ic_DIRACImageName = imageName self.__ic_bootImageName = imageOptions.get( 'bootImageName' , None ) self.__ic_contextMethod = imageOptions.get( 'contextMethod' , None ) self.__ic_flavorName = imageOptions.get( 'flavorName' , None ) #self.__ic_contextConfig = ContextConfig( self.__ic_bootImageName, self.__ic_contextMethod ) self.__ic_contextConfig = ContextConfig( imageName, self.__ic_contextMethod )
class ImageConfiguration( object ): def __init__( self, imageName, endPointName ): self.log = gLogger.getSubLogger( 'ImageConfiguration' ) imageOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s' % imageName ) if not imageOptions[ 'OK' ]: self.log.error( imageOptions[ 'Message' ] ) imageOptions = {} else: imageOptions = imageOptions[ 'Value' ] self.__ic_DIRACImageName = imageName endPointName = endPointName.strip() # A DIRAC image can have different boot image names in the cloud endPoints bootImageOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s/BootImages' % imageName ) if not bootImageOptions[ 'OK' ]: self.log.error( bootImageOptions[ 'Message' ] ) return bootImageOptions = bootImageOptions[ 'Value' ] bootImageName = None for bootEndpoint, bootImage in bootImageOptions.items(): if endPointName == bootEndpoint: bootImageName = bootImage break if bootImageName is None: self.log.error( 'Missing mandatory boot image of the endPoint %s in BootImages section, image %s' % (endPointName, imageName) ) self.__ic_bootImageName = bootImageName # A DIRAC image can have different flavor names names in the cloud endPoints flavorOptions = gConfig.getOptionsDict( '/Resources/VirtualMachines/Images/%s/Flavors' % imageName ) if not flavorOptions[ 'OK' ]: self.log.error( flavorOptions[ 'Message' ] ) return flavorOptions = flavorOptions[ 'Value' ] flavorName = None for bootEndpoint, flavor in flavorOptions.items(): if endPointName == bootEndpoint: flavorName = flavor break if flavorName is None: self.log.error( 'Missing mandatory flavor of the endPoint %s in BootImages section, image %s' % (endPointName, imageName) ) self.__ic_flavorName = flavorName self.__ic_contextMethod = imageOptions.get( 'contextMethod' , None ) #optional: self.__ic_maxAllowedPrice = imageOptions.get( 'maxAllowedPrice' , None ) self.__ic_keyName = imageOptions.get( 'keyName' , None ) #self.__ic_contextConfig = ContextConfig( self.__ic_bootImageName, self.__ic_contextMethod ) self.__ic_contextConfig = ContextConfig( imageName, self.__ic_contextMethod ) def config( self ): config = { 'DIRACImageName' : self.__ic_DIRACImageName, 'bootImageName' : self.__ic_bootImageName, 'contextMethod' : self.__ic_contextMethod, 'flavorName' : self.__ic_flavorName, 'maxAllowedPrice' : self.__ic_maxAllowedPrice, 'keyName' : self.__ic_keyName, 'contextConfig' : self.__ic_contextConfig.config() } return config def validate( self ): if self.__ic_DIRACImageName is None: return S_ERROR( 'self._ic_DIRACImageName is None' ) if self.__ic_bootImageName is None: return S_ERROR( 'self._ic_bootImageName is None' ) if self.__ic_flavorName is None: return S_ERROR( 'self._ic_flavorName is None' ) if self.__ic_contextMethod is None: return S_ERROR( 'self._ic_contextMethod is None' ) validateContext = self.__ic_contextConfig.validate() if not validateContext[ 'OK' ]: self.log.error( validateContext[ 'Message' ] ) return validateContext self.log.info( 'Displaying image info' ) self.log.info( '*' * 50 ) self.log.info( 'ic_DIRACImageName %s' % self.__ic_DIRACImageName ) self.log.info( 'ic_bootImageName %s' % self.__ic_bootImageName ) self.log.info( 'ic_flavorName %s' % self.__ic_flavorName ) if not self.__ic_maxAllowedPrice is None: self.log.info( 'ic_maxAllowedPrice %s' % self.__ic_maxAllowedPrice ) if not self.__ic_keyName is None: self.log.info( 'ic_keyName %s' % self.__ic_keyName ) self.log.info( 'ic_contextMethod %s' % self.__ic_contextMethod ) for key, value in self.__ic_contextConfig.config().iteritems(): self.log.info( '%s : %s' % ( key, value ) ) self.log.info( '*' * 50 ) return S_OK()