Advancing on XenServer Provider

This commit is contained in:
Adolfo Gómez 2014-05-12 06:13:47 +00:00
parent 87a795cd8b
commit a66d75bdc5
3 changed files with 32 additions and 21 deletions

View File

@ -105,10 +105,13 @@ class XenLinkedService(Service):
memory = gui.NumericField(label=_("Memory (Mb)"), length=4, defvalue=512, rdonly=False, order=5, memory = gui.NumericField(label=_("Memory (Mb)"), length=4, defvalue=512, rdonly=False, order=5,
tooltip=_('Memory assigned to machines'), required=True) tooltip=_('Memory assigned to machines'), required=True)
baseName = gui.TextField(label=_('Machine Names'), rdonly=False, order=6, tooltip=('Base name for clones from this machine'), required=True) shadow = gui.NumericField(label=_("Shadow"), lengh=1, defvalue=4, rdonly=True, order=6,
tooltip=_('Shadow memory multiplier (memory overcommit)'), required=True)
lenName = gui.NumericField(length=1, label=_('Name Length'), defvalue=5, order=7, baseName = gui.TextField(label=_('Machine Names'), rdonly=False, order=7, tooltip=('Base name for clones from this machine'), required=True)
tooltip=_('Length of numeric part for the names of this machines (betwen 3 and 6'), required=True)
lenName = gui.NumericField(length=1, label=_('Name Length'), defvalue=5, order=8,
tooltip=_('Length of numeric part for the names of this machines (beetwen 3 and 6'), required=True)
def initialize(self, values): def initialize(self, values):
''' '''
@ -149,6 +152,10 @@ class XenLinkedService(Service):
self.datastore.setValues(storages_list) self.datastore.setValues(storages_list)
def checkTaskFinished(self, task):
return self.parent().checkTaskFinished(task)
def datastoreHasSpace(self): def datastoreHasSpace(self):
# Get storages for that datacenter # Get storages for that datacenter
logger.debug('Checking datastore space for {0}'.format(self.datastore.value)) logger.debug('Checking datastore space for {0}'.format(self.datastore.value))
@ -185,18 +192,10 @@ class XenLinkedService(Service):
self.datastoreHasSpace() self.datastoreHasSpace()
return self.parent().cloneForTemplate(name, comments, self.machine.value, self.datastore.value) return self.parent().cloneForTemplate(name, comments, self.machine.value, self.datastore.value)
def getTemplateState(self, templateId): def convertToTemplate(self, machineId):
''' '''
Invokes getTemplateState from parent provider
Args:
templateId: templateId to remove
Returns nothing
Raises an exception if operation fails.
''' '''
return self.parent().getTemplateState(templateId) return self.parent.convertToTemplate(machineId, self.shadow.value)
def startDeployFromTemplate(self, name, comments, templateId): def startDeployFromTemplate(self, name, comments, templateId):
''' '''

View File

@ -211,7 +211,7 @@ class Provider(ServiceProvider):
''' '''
return self.__getApi().getSRInfo(storageId) return self.__getApi().getSRInfo(storageId)
def cloneForTemplate(self, machineId, name, comments, sr): def cloneForTemplate(self, name, comments, machineId, sr):
return self.__getApi().cloneVM(machineId, name, sr) return self.__getApi().cloneVM(machineId, name, sr)

View File

@ -61,13 +61,14 @@ class XenPublication(Publication):
self._reason = '' self._reason = ''
self._destroyAfter = 'f' self._destroyAfter = 'f'
self._templateId = '' self._templateId = ''
self._state = 'r' self._state = ''
self._task = ''
def marshal(self): def marshal(self):
''' '''
returns data from an instance of Sample Publication serialized returns data from an instance of Sample Publication serialized
''' '''
return '\t'.join(['v1', self._name, self._reason, self._destroyAfter, self._templateId, self._state]) return '\t'.join(['v1', self._name, self._reason, self._destroyAfter, self._templateId, self._state, self._task])
def unmarshal(self, data): def unmarshal(self, data):
''' '''
@ -76,20 +77,20 @@ class XenPublication(Publication):
logger.debug('Data: {0}'.format(data)) logger.debug('Data: {0}'.format(data))
vals = data.split('\t') vals = data.split('\t')
if vals[0] == 'v1': if vals[0] == 'v1':
self._name, self._reason, self._destroyAfter, self._templateId, self._state = vals[1:] self._name, self._reason, self._destroyAfter, self._templateId, self._state, self._task = vals[1:]
def publish(self): def publish(self):
''' '''
Realizes the publication of the service Realizes the publication of the service
''' '''
self._name = self.service().sanitizeVmName('UDSP ' + self.dsName() + "-" + str(self.revision())) self._name = self.service().sanitizeVmName('UDS Pub ' + self.dsName() + "-" + str(self.revision()))
comments = _('UDS pub for {0} at {1}').format(self.dsName(), str(datetime.now()).split('.')[0]) comments = _('UDS pub for {0} at {1}').format(self.dsName(), str(datetime.now()).split('.')[0])
self._reason = '' # No error, no reason for it self._reason = '' # No error, no reason for it
self._destroyAfter = 'f' self._destroyAfter = 'f'
self._state = 'locked' self._state = 'publishing'
try: try:
self._templateId = self.service().makeTemplate(self._name, comments) self._task = self.service().startDeployTemplate(self._name, comments)
except Exception as e: except Exception as e:
self._state = 'error' self._state = 'error'
self._reason = str(e) self._reason = str(e)
@ -101,12 +102,23 @@ class XenPublication(Publication):
''' '''
Checks state of publication creation Checks state of publication creation
''' '''
if self._state == 'ok': if self._state == 'finished':
return State.FINISHED return State.FINISHED
if self._state == 'error': if self._state == 'error':
return State.ERROR return State.ERROR
try:
state = self.service().checkTaskFinished(self._task)
if state is None: # Finished
if self._state == 'publishing':
self.service().convertToTemplate()
except Exception as e:
self._state = 'error'
self._reason = str(e)
return State.ERROR
self._state = self.service().getTemplateState(self._templateId) self._state = self.service().getTemplateState(self._templateId)
# If publication os done (template is ready), and cancel was requested, do it just after template becomes ready # If publication os done (template is ready), and cancel was requested, do it just after template becomes ready