<s> """<STR_LIT>""" <EOL> import web <EOL> from nailgun . api . v1 . handlers . base import CollectionHandler <EOL> from nailgun . api . v1 . handlers . base import SingleHandler <EOL> from nailgun . api . v1 . handlers . base import content <EOL> from nailgun . api . v1 . validators . node_group import NodeGroupValidator <EOL> from nailgun import consts <EOL> from nailgun . db import db <EOL> from nailgun import errors <EOL> from nailgun import objects <EOL> from nailgun . task . manager import UpdateDnsmasqTaskManager <EOL> class NodeGroupHandler ( SingleHandler ) : <EOL> """<STR_LIT>""" <EOL> single = objects . NodeGroup <EOL> validator = NodeGroupValidator <EOL> @ content <EOL> def DELETE ( self , group_id ) : <EOL> """<STR_LIT>""" <EOL> node_group = self . get_object_or_404 ( objects . NodeGroup , group_id ) <EOL> self . checked_data ( <EOL> self . validator . validate_delete , <EOL> instance = node_group <EOL> ) <EOL> db ( ) . delete ( node_group ) <EOL> db ( ) . flush ( ) <EOL> try : <EOL> task = UpdateDnsmasqTaskManager ( ) . execute ( ) <EOL> except errors . TaskAlreadyRunning : <EOL> raise self . http ( <NUM_LIT> , errors . UpdateDnsmasqTaskIsRunning . message ) <EOL> if task . status == consts . TASK_STATUSES . error : <EOL> raise self . http ( <NUM_LIT> , task . message ) <EOL> raise self . http ( <NUM_LIT> ) <EOL> class NodeGroupCollectionHandler ( CollectionHandler ) : <EOL> """<STR_LIT>""" <EOL> collection = objects . NodeGroupCollection <EOL> validator = NodeGroupValidator <EOL> @ content <EOL> def GET ( self ) : <EOL> """<STR_LIT>""" <EOL> user_data = web . input ( cluster_id = None ) <EOL> if user_data . cluster_id is not None : <EOL> return self . collection . to_json ( <EOL> self . collection . get_by_cluster_id ( <EOL> user_data . cluster_id <EOL> ) <EOL> ) <EOL> else : <EOL> return self . collection . to_json ( ) </s>
