class IStatusApp(model.Schema, IImageScaleTraversable): """ A collection of server status information """ cluster = schema.TextLine( title=_(u"Cluster"), description=_(u"Automatically updated server cluster information"), required=False, )
def __call__(self, context): STATES = { _(u"Operational"): 'operational', _(u"Degraded Performance"): 'degradation', _(u"Partial Outage"): 'partial', _(u"Major Outage"): 'outage', } return SimpleVocabulary([SimpleTerm(value, title=title) for title, value in STATES.iteritems()])
def __call__(self, context): TYPES = { _(u"Investigating"): 'investigating', _(u"Identified"): 'identified', _(u"Monitoring"): 'monitoring', _(u"Resolved"): 'resolved', } return SimpleVocabulary([SimpleTerm(value, title=title) for title, value in TYPES.iteritems()])
class IServerNode(model.Schema, IImageScaleTraversable): """ Server details """ server = schema.TextLine( title=_(u"Server Name"), description=_(u"Enter a fully qualified servername"), required=True) ip = schema.TextLine( title=_(u"IP Address"), required=False, ) machine = schema.TextLine( title=_(u"Physical Server"), description=_(u"name of the physical machine this virtual server " u"is located on"), required=False, ) protocol = schema.TextLine( title=_(u"Request Protocol"), description=_(u"Specify alternative protocol e.g. smtp for mx server"), default=u"http", required=True) form.mode(serverdetails='hidden') serverdetails = schema.TextLine( title=_(u"server Details"), description=_(u"Serverdetails json storage. You normally should have " u"no need to change this manually"), required=False, )
class IComponent(form.Schema, IImageScaleTraversable): """ A collection of services and associated server nodes """ status = schema.Choice( title=_(u"Component Status"), description=_(u"Switch component status to signal outages on the " u"public status page."), vocabulary=u"wigo.statusapp.ComponentStatus", default='operational', required=True, )
class IIncident(form.Schema, IImageScaleTraversable): """ A single incident containing status information """ title = schema.TextLine( title=_(u"Incident Name"), required=True, ) status = schema.Choice( title=_(u"Component Status"), description=_(u"Switch component status to signal outages on the " u"public status page."), vocabulary=u"wigo.statusapp.IncidentType", default='operational', required=True, )
def update(self): context = aq_inner(self.context) self.errors = {} unwanted = ('_authenticator', 'form.button.Submit') required = ('title') if 'form.button.Submit' in self.request: authenticator = getMultiAdapter((context, self.request), name=u"authenticator") if not authenticator.verify(): raise Unauthorized form = self.request.form form_data = {} form_errors = {} errorIdx = 0 for value in form: if value not in unwanted: form_data[value] = safe_unicode(form[value]) if not form[value] and value in required: error = {} error['active'] = True error['msg'] = _(u"This field is required") form_errors[value] = error errorIdx += 1 else: error = {} error['active'] = False error['msg'] = form[value] form_errors[value] = error if errorIdx > 0: self.errors = form_errors else: self._create_incident(form)
def update(self): context = aq_inner(self.context) self.errors = {} unwanted = ('_authenticator', 'form.button.Submit') required = ('title') if 'form.button.Submit' in self.request: authenticator = getMultiAdapter((context, self.request), name=u"authenticator") if not authenticator.verify(): raise Unauthorized form = self.request.form form_data = {} form_errors = {} errorIdx = 0 for value in form: if value not in unwanted: form_data[value] = safe_unicode(form[value]) if not form[value] and value in required: error = {} error['active'] = True error['msg'] = _(u"This field is required") form_errors[value] = error errorIdx += 1 else: error = {} error['active'] = False error['msg'] = form[value] form_errors[value] = error if errorIdx > 0: self.errors = form_errors else: self._create_incident(form)
class IMaintenance(form.Schema, IImageScaleTraversable): """ Scheduled maintenance timeframe and notifications """ start = schema.Datetime( title=_(u"Start date"), required=False, ) end = schema.Datetime( title=_(u"End date"), required=False, ) @invariant def validateStartEnd(data): if data.start is not None and data.end is not None: if data.start > data.end: raise StartBeforeEnd( _(u"The start date must be before the end date."))
def render(self): context = aq_inner(self.context) tool = getUtility(IWigoTool) hostname = getattr(context, 'server', '') if hostname is not None: data = tool.get(hostname=hostname) setattr(context, 'serverdetails', json.dumps(data)) modified(context) context.reindexObject(idxs='modified') IStatusMessage(self.request).addStatusMessage( _(u"The panel has successfully been updated"), type='info') next_url = context.absolute_url() return self.request.response.redirect(next_url)
def render(self): context = aq_inner(self.context) tool = getUtility(IWigoTool) hostname = getattr(context, 'server', '') if hostname is not None: data = tool.get(hostname=hostname) setattr(context, 'serverdetails', json.dumps(data)) modified(context) context.reindexObject(idxs='modified') IStatusMessage(self.request).addStatusMessage( _(u"The panel has successfully been updated"), type='info') next_url = context.absolute_url() return self.request.response.redirect(next_url)
def validateStartEnd(data): if data.start is not None and data.end is not None: if data.start > data.end: raise StartBeforeEnd( _(u"The start date must be before the end date."))
def validateStartEnd(data): if data.start is not None and data.end is not None: if data.start > data.end: raise StartBeforeEnd( _(u"The start date must be before the end date."))
class StartBeforeEnd(Invalid): __doc__ = _(u"The start or end date is invalid")