def delete(self, request, tenant_id, id): """ Destroys the portprofile with the given id """ try: self._plugin.delete_portprofile(tenant_id, id) return exc.HTTPOk() except exception.PortProfileNotFound as exp: return faults.Fault(faults.PortprofileNotFound(exp))
def delete(self, request, tenant_id, id): """Destroys the credential with the given id.""" try: self._plugin.delete_credential(tenant_id, id) return exc.HTTPOk() except exception.CredentialNotFound as exp: return faults.Fault(faults.CredentialNotFound(exp))
def delete(self, request, tenant_id, id): """ Destroys the qos with the given id """ try: self._plugin.delete_qos(tenant_id, id) return exc.HTTPOk() except exception.QosNotFound as exp: return faults.Fault(faults.QosNotFound(exp))
def histogram(self, request): body = request.json_body try: metric = self.metric_from_request(Histogram, body) metric.observe(body['value']) except ValueError as ex: raise exc.HTTPBadRequest(body=str(ex)) return exc.HTTPOk()
def gauge_set(self, request): body = request.json_body try: metric = self.metric_from_request(Gauge, body) metric.set(body['value']) except ValueError as ex: raise exc.HTTPBadRequest(body=str(ex)) return exc.HTTPOk()
def counter(self, request): body = request.json_body try: metric = self.metric_from_request(Counter, body) metric.inc(body['value']) except ValueError as ex: raise exc.HTTPBadRequest(body=str(ex)) return exc.HTTPOk()
def export(self): sheet_name = fname = unicodedata.normalize('NFKD', self.data.title).encode( 'ascii', 'ignore') fname = re.sub('\W+', '_', fname.lower()) sheet_name = re.sub('\W+', ' ', sheet_name) f = StringIO() wb = xlwt.Workbook() ws = wb.add_sheet(sheet_name[:31]) sty = '' header_sty = xlwt.easyxf( sty + 'font: bold on; align: wrap on, vert centre, horiz center;') sty = xlwt.easyxf(sty) titles = [_(u'Column'), _(u'Title'), _(u'Description'), _(u'Due date')] if self.weighting_cards: titles.append(_(u'Weight')) titles.append(_(u'Comments')) for col, title in enumerate(titles): ws.write(0, col, title, style=header_sty) row = 1 max_len = len(titles) for col in self.columns: col = col().data for card in col.cards: colnumber = 0 ws.write(row, colnumber, _('Archived cards') if col.archive else col.title, sty) colnumber += 1 ws.write(row, colnumber, card.title, sty) colnumber += 1 ws.write(row, colnumber, card.description, sty) colnumber += 1 ws.write(row, colnumber, format_date(card.due_date) if card.due_date else u'', sty) colnumber += 1 if self.weighting_cards: ws.write(row, colnumber, card.weight, sty) colnumber += 1 for colno, comment in enumerate(card.comments, colnumber): ws.write(row, colno, comment.comment, sty) max_len = max(max_len, 4 + colno) row += 1 for col in xrange(len(titles)): ws.col(col).width = 0x3000 ws.set_panes_frozen(True) ws.set_horz_split_pos(1) wb.save(f) f.seek(0) e = exc.HTTPOk() e.content_type = 'application/vnd.ms-excel' e.content_disposition = u'attachment;filename=%s.xls' % fname e.body = f.getvalue() raise e
def handle_preflight_request(self, environ, start_response): method = environ.get('HTTP_ACCESS_CONTROL_REQUEST_METHOD') if method not in self.allowed_methods: return self.app(environ, start_response) headers = self.get_access_control_request_headers(environ) if not headers.issubset(self.allowed_headers): return self.app(environ, start_response) r = exc.HTTPOk(headers=self.get_response_headers(preflight=True)) return r(environ, start_response)
def download(self): buffer = StringIO() self.write() self.workbook.save(buffer) buffer.seek(0) e = exc.HTTPOk() e.content_type = 'application/vnd.ms-excel' e.content_disposition = u'attachment;filename=%s.xls' % self.filename e.body = buffer.getvalue() raise e
def associate_portprofile(self, request, tenant_id, id): """ associate a portprofile to the port """ content_type = request.best_match_content_type() try: req_params = \ self._parse_request_params(request, self._assignprofile_ops_param_list) except exc.HTTPError as exp: return faults.Fault(exp) net_id = req_params['network-id'].strip() port_id = req_params['port-id'].strip() try: self._plugin.associate_portprofile(tenant_id, net_id, port_id, id) return exc.HTTPOk() except exception.PortProfileNotFound as exp: return faults.Fault(faults.PortprofileNotFound(exp)) except qexception.PortNotFound as exp: return faults.Fault(faults.PortNotFound(exp))
def disassociate_portprofile(self, request, tenant_id, id): """ Disassociate a portprofile from a port """ content_type = request.best_match_content_type() try: body = self._deserialize(request.body, content_type) req_body = \ self._prepare_request_body(body, self._assignprofile_ops_param_list) req_params = req_body[self._resource_name] except exc.HTTPError as exp: return faults.Fault(exp) net_id = req_params['network-id'].strip() port_id = req_params['port-id'].strip() try: self._plugin.disassociate_portprofile(tenant_id, net_id, port_id, id) return exc.HTTPOk() except exception.PortProfileNotFound as exp: return faults.Fault(faults.PortprofileNotFound(exp)) except qexception.PortNotFound as exp: return faults.Fault(faults.PortNotFound(exp))
def report(self, request): headers = [('Content-type', 'text/plain; version=0.0.4; charset=utf-8') ] response = exc.HTTPOk(headers=headers, body=self.metric_registry.render()) return response
def view_content_response(content_type, content): e = exc.HTTPOk() # set response data e.content_type = str(content_type) e.body = str(content) return e