Example #1
0
def connection_create(element1, element2, type=None, attrs=None):  # @ReservedAssignment
	"""
	Connects the given elements using the given type of connection, configuring
	it with the given attributes by the way. The order of the elements does not
	matter. The given connection type must support the element types.
	The elements that are connected can not be changed later.

	The connection types that are supported on this host and their attributes,
	as well as which elements can be connected can be obtained using
	:py:func:`~hostmanager.tomato.api.host.host_capabilities`

	Parameter *element1*:
	  The element id of the first element to include in the connection. The
	  elements that are connected can not be changed later.

	Parameter *element2*:
	  The element id of the second element to include in the connection. The
	  elements that are connected can not be changed later.

	Parameter *type*:
	  If the parameter *type* is specified, it must be a string identifying
	  one of the supported connection types. If *type* is not specified a
	  matching connection type will be determined based on the elements.

	Parameter *attrs*:
	  The attributes of the connection can be given as the parameter *attrs*.
	  This parameter must be a dict of attributes if given. Attributes can
	  later be changed using :py:func:`connection_modify`. This method should
	  behave like::

		 info = connection_create(element1, element2, type, {})
		 connection_modify(info["id"], attrs)

	Return value:
	  The return value of this method is the info dict of the new connection as
	  returned by :py:func:`connection_info`.
	  This info dict also contains the connection id that is needed for further
	  manipulation of that object.

	Exceptions are raised if:
	  * one of the elements does not exist or belongs to a different user
	  * one of the elements does not support to be connected in its current
		state
	  * one of the elements is already connected
	  * both elements are the same
	  * *type* is specified and the type can not be used to connect the
		elements
	  * *type* is not specified and no available connection type can be used to
		connect the elements
	"""
	if not attrs:
		attrs = {}
	el1 = _getElement(element1)
	el2 = _getElement(element2)
	con = connections.create(el1, el2, type, attrs)
	return con.info()
Example #2
0
def accounting_element_statistics(id, type=None, after=None, before=None): #@ReservedAssignment
    """
    Returns accounting statistics for one element.
    
    Parameter *id*:
      The id of the element.
      
    Parameter *type*:
      If this parameter is set, only usage records of the given type are
      returned.
      
    Parameter *after*:
      If this parameter is set, only usage records with a start date after
      the given date will be returned. The date must be given as the number
      of seconds since the epoch (1970-01-01 00:00:00).
      If this parameter is omitted, all usage records from begin of recording
      will be returned.
      
    Parameter *before*:
      If this parameter is set, only usage records with an end date before
      the given date will be returned. The date must be given as the number
      of seconds since the epoch (1970-01-01 00:00:00).
      If this parameter is omitted, all usage records until now will be 
      returned.
      
    Return value:
      This method returns usage statistics for the given element.
    """
    return _getElement(id).getUsageStatistics().info(type, after, before)
Example #3
0
def accounting_element_statistics(id,
                                  type=None,
                                  after=None,
                                  before=None):  #@ReservedAssignment
    """
    Returns accounting statistics for one element.
    
    Parameter *id*:
      The id of the element.
      
    Parameter *type*:
      If this parameter is set, only usage records of the given type are
      returned.
      
    Parameter *after*:
      If this parameter is set, only usage records with a start date after
      the given date will be returned. The date must be given as the number
      of seconds since the epoch (1970-01-01 00:00:00).
      If this parameter is omitted, all usage records from begin of recording
      will be returned.
      
    Parameter *before*:
      If this parameter is set, only usage records with an end date before
      the given date will be returned. The date must be given as the number
      of seconds since the epoch (1970-01-01 00:00:00).
      If this parameter is omitted, all usage records until now will be 
      returned.
      
    Return value:
      This method returns usage statistics for the given element.
    """
    return _getElement(id).getUsageStatistics().info(type, after, before)
Example #4
0
def connection_create(el1, el2, attrs=None):  #@ReservedAssignment
    """
	Connects the given elements using the given type of connection, configuring
	it with the given attributes by the way. The order of the elements does not
	matter. The given connection type must support the element types.
	The elements that are connected can not be changed later.
	The topology will be determined from the given elements. 
	
	Parameter *element1*:
	  The element id of the first element to include in the connection. The
	  elements that are connected can not be changed later.
	
	Parameter *element2*:
	  The element id of the second element to include in the connection. The
	  elements that are connected can not be changed later.
	
	Parameter *attrs*:
	  The attributes of the connection can be given as the parameter *attrs*.
	  This parameter must be a dict of attributes if given. Attributes can 
	  later be changed using :py:func:`connection_modify`. This method should
	  behave like::
	  
		 info = connection_create(element1, element2, {})
		 connection_modify(info["id"], attrs)
	
	Return value:
	  The return value of this method is the info dict of the new connection as
	  returned by :py:func:`connection_info`.
	  This info dict also contains the connection id that is needed for further 
	  manipulation of that object.
	
	Exceptions are raised if:	  
	  * one of the elements does not exist or belongs to a different user 
	  * one of the elements does not support to be connected in its current 
		state
	  * one of the elements is already connected
	  * both elements are the same
	"""
    if not attrs: attrs = {}
    UserError.check(currentUser(),
                    code=UserError.NOT_LOGGED_IN,
                    message="Unauthorized")
    el1 = _getElement(el1)
    el2 = _getElement(el2)
    con = connections.create(el1, el2, attrs)
    return con.info()
Example #5
0
def connection_create(el1, el2, attrs=None): #@ReservedAssignment
	"""
	Connects the given elements using the given type of connection, configuring
	it with the given attributes by the way. The order of the elements does not
	matter. The given connection type must support the element types.
	The elements that are connected can not be changed later.
	The topology will be determined from the given elements. 
	
	Parameter *element1*:
	  The element id of the first element to include in the connection. The
	  elements that are connected can not be changed later.
	
	Parameter *element2*:
	  The element id of the second element to include in the connection. The
	  elements that are connected can not be changed later.
	
	Parameter *attrs*:
	  The attributes of the connection can be given as the parameter *attrs*.
	  This parameter must be a dict of attributes if given. Attributes can 
	  later be changed using :py:func:`connection_modify`. This method should
	  behave like::
	  
		 info = connection_create(element1, element2, {})
		 connection_modify(info["id"], attrs)
	
	Return value:
	  The return value of this method is the info dict of the new connection as
	  returned by :py:func:`connection_info`.
	  This info dict also contains the connection id that is needed for further 
	  manipulation of that object.
	
	Exceptions are raised if:	  
	  * one of the elements does not exist or belongs to a different user 
	  * one of the elements does not support to be connected in its current 
		state
	  * one of the elements is already connected
	  * both elements are the same
	"""
	if not attrs: attrs = {}
	UserError.check(currentUser(), code=UserError.NOT_LOGGED_IN, message="Unauthorized")
	el1 = _getElement(el1)
	el2 = _getElement(el2)
	con = connections.create(el1, el2, attrs)
	return con.info()