Ejemplo n.º 1
0
  def __init__( self, imageElementName, endpointElementName ):
    """
    Creates an instance that will manage appliances of a given type
    on a specific cloud infrastructure.  Separate instances must be
    created for different cloud infrastructures and different
    appliances.
    The configuration is validated only when the connect() method is
    called.  This method MUST be called before any of the other
    methods.

    :Parameters:
      **imageElementName** - `string`
        element name in CS:/Resources/VirtualMachines/Images describing
        the type of appliance (image) to instantiate

      **endpointElementName** - `string`
        element name in CS:/Resources/VirtualMachines/CloudEndpoint
        giving the configuration parameters for the StratusLab cloud
        endpoint

    """

    self.log = gLogger.getSubLogger( 'StratusLabImage_%s_%s: ' % ( endpointElementName, imageElementName ) )

    self._imageConfig    = ImageConfiguration( imageElementName )
    self._endpointConfig = StratusLabConfiguration( endpointElementName )

    self._impl = None
Ejemplo n.º 2
0
class StratusLabImage( object ):
  """
  Provides interface for managing virtual machine instances of a
  particular appliance on a StratusLab cloud infrastructure.
  """

  def __init__( self, imageElementName, endpointElementName ):
    """
    Creates an instance that will manage appliances of a given type
    on a specific cloud infrastructure.  Separate instances must be
    created for different cloud infrastructures and different
    appliances.
    The configuration is validated only when the connect() method is
    called.  This method MUST be called before any of the other
    methods.

    :Parameters:
      **imageElementName** - `string`
        element name in CS:/Resources/VirtualMachines/Images describing
        the type of appliance (image) to instantiate

      **endpointElementName** - `string`
        element name in CS:/Resources/VirtualMachines/CloudEndpoint
        giving the configuration parameters for the StratusLab cloud
        endpoint

    """

    self.log = gLogger.getSubLogger( 'StratusLabImage_%s_%s: ' % ( endpointElementName, imageElementName ) )

    self._imageConfig    = ImageConfiguration( imageElementName )
    self._endpointConfig = StratusLabConfiguration( endpointElementName )

    self._impl = None


  def connect(self):
    """
    Tests the connection to the StratusLab cloud infrastructure.  Validates
    the configuration and then makes a request to list active virtual
    machine instances to ensure that the connection works.

    :return: S_OK | S_ERROR
    """

    result = self._imageConfig.validate()
    self._logResult(result, 'image configuration check')
    if not result['OK']:
      return result

    result = self._endpointConfig.validate()
    self._logResult( result, 'endpoint configuration check' )
    if not result[ 'OK' ]:
      return result

    try:
      self._impl = StratusLabClient( self._endpointConfig, self._imageConfig )
    except Exception, e:
      return S_ERROR( e )

    result = self._impl.check_connection()
    return self._logResult( result, 'connect' )