Previous topic

Provider interface

Next topic

Publication interface

This Page

Service interface

The service class is in fact an interface. It represents the base for all user deployments (that is, consumable user services) that will be provided.

As such, the service is responsible for keeping the information that, at deployments, will be neded by provided user consumable services.

A good sample of a service can be a KVM machine that will be copied COW and that COWs will be assigned to users. In that case, we will collect which machine will be copied, where it is to be copied, an a few more params that the user deployments will need.

For a detailed example of a service provider, you can see the provided service sample

class uds.core.services.Service(environment, parent, values=None)

This class is in fact an interface, and represents a service, that is the definition of an offering for consumers (users).

Class derived from this one declares the behavior of the service, as well as custom parameter that will be needed to provide final consumable elements to users.

The behavior attributes must be declared always, although they have default values, this can change in a future and declaring all needed is a good way to avoid future problems. Of course, if you declare that do no do something (i.e. do not uses cache), you will not have to declare related attributes (i.e. cacheTooltip, usesCache_L2 and cacheTooltip_L2)

As you derive from this class, if you provide __init__ in your own class, remember to call ALWAYS at base class __init__ as this:

super(self.__class__, self).__init__(dbAuth, environment, values)

This is a MUST (if you override __init__), so internal structured gets filled correctly, so don’t forget it!.

The preferred method of provide initialization is to provide the initialize(), and do not override __init__ method. This (initialize) will be invoked after all internal initialization, so there will be available parent, environment and storage.

Normally objects of classes deriving from this one, will be serialized, called, deserialized. This means that all that you want to ensure that is kept inside the class must be serialized and unserialized, because there is no warrantee that the object will get two methods invoked without haven’t been removed from memory and loaded again. One thing to have into account on this are Form Fields, that default implementation marshals and unmashals them, so if your case is that you only need data that is keeped at form fields, marshal and unmarshal and in fact not needed.

initialize(values)

This method will be invoked from __init__ constructor. This is provided so you don’t have to provide your own __init__ method, and invoke base methods. This will get invoked when all initialization stuff is done

Args:
Values: If values is not none, this object is being initialized from administration interface, and not unmarshal will be done. If it’s None, this is initialized internally, and unmarshal will be called after this.

Default implementation does nothing

macGenerator()

Utility method to access provided macs generator (inside environment)

Returns the environment unique mac addresses generator

nameGenerator()

Utility method to access provided names generator (inside environment)

Returns the environment unique name generator

parent()

Utility method to access parent provider for this service

Returns

Parent provider instance object (not database object)
requestServicesForAssignation(**kwargs)

override this if mustAssignManualy is True @params kwargs: Named arguments @return an array with the services that we can assign (they must be of type deployedType) We will access the returned array in “name” basis. This means that the service will be assigned by “name”, so be care that every single service returned are not repeated... :-)