def deploy_run(task_id, deploy_type, category_id): instance = APIGateWay.objects.get(id=task_id) kwargs = instance.to_dict() kwargs['instance'] = instance kwargs['deploy_type'] = deploy_type kwargs['category_id'] = category_id obj = Nginx(**kwargs) return obj.run()
def delete(self, *args, **kwargs): from commands.apigateway import Nginx kwargs = self.to_dict() kwargs['deploy_type'] = 'maps' kwargs['instance'] = self.apigateway kwargs['category_id'] = self.id nginx = Nginx(**kwargs) status = nginx.destory() if status: super(Maps, self).delete() assert not False == status, ('%s Map Delete False' % self.desc)
def delete(self, *args, **kwargs): from commands.apigateway import Nginx kwargs = self.to_dict() kwargs['deploy_type'] = 'vhosts.d' kwargs['instance'] = self.apigateway kwargs['category_id'] = self.id nginx = Nginx(**kwargs) status = nginx.destory() if status: super(Vhosts, self).delete() else: if nginx.redestory(): print('%s Vhost Delete undo False' % self.domain) else: assert False, ('%s Vhost Delete False' % self.domain)
def delete(self, *args, **kwargs): from commands.apigateway import Nginx kwargs = self.to_dict() kwargs['deploy_type'] = 'upstreams' kwargs['instance'] = self.apigateway kwargs['category_id'] = self.id nginx = Nginx(**kwargs) status = nginx.destory() if status: super(Upstreams, self).delete() else: if nginx.redestory(): print('%s Upstream Delete undo True' % self.name) else: assert False, ('%s Upstream Delete undo False' % self.name)
def destroy(self, request, *args, **kwargs): instance = self.get_object() kwarg = instance.to_dict() kwarg['deploy_type'] = 'upstreams' kwarg['instance'] = instance.apigateway kwarg['category_id'] = instance.id ngx = Nginx(**kwarg) if ngx.check_upstream_depend(): return super().destroy(request, *args, **kwargs) else: return Response( status=status.HTTP_400_BAD_REQUEST, data={ 'message': '%s Upstream not delete, vhosts include upstream' % instance.name })
def update(self, request, *args, **kwargs): instance = self.queryset.filter(id=kwargs['pk'])[0] old_name = instance.name new_name = request.data['name'] if old_name != new_name: kwargs = instance.to_dict() kwargs['deploy_type'] = 'upstreams' kwargs['instance'] = instance.apigateway kwargs['category_id'] = instance.id ngx = Nginx(**kwargs) old_filename = '%s.conf' % old_name new_filename = '%s.conf' % new_name assert not ngx.build_file(filename=new_filename) == False, ( 'Upstream create %s file error' % new_name) assert not ngx.rename(old_filename, new_filename) == False, ( 'Upstream %s rename to %s file error' % (old_filename, new_filename)) return super().update(request, *args, **kwargs) else: return super().update(request, *args, **kwargs)
def update(self, request, *args, **kwargs): instance = self.queryset.filter(id=kwargs['pk'])[0] old_name = re.split("[ |,]", instance.domain)[0] new_name = re.split("[ |,]", request.data['domain'])[0] if old_name != new_name: kwargs = instance.to_dict() kwargs['deploy_type'] = 'vhosts.d' kwargs['instance'] = instance.apigateway kwargs['category_id'] = instance.id ngx = Nginx(**kwargs) old_filename = '%s.conf' % old_name new_filename = '%s.conf' % new_name assert not ngx.build_file(filename=new_filename) == False, ( 'Vhost create %s file error' % new_name) if ngx.rename(old_filename, new_filename): return super().update(request, *args, **kwargs) else: assert not ngx.undo_rename( old_filename, new_filename) == False, ('Vhost rename undo error') else: return super().update(request, *args, **kwargs)