<s> import argparse <EOL> from gcloud import dns <EOL> def create_zone ( project_id , name , dns_name , description ) : <EOL> client = dns . Client ( project = project_id ) <EOL> zone = client . zone ( <EOL> name , <EOL> dns_name = dns_name ) <EOL> zone . description = description <EOL> zone . create ( ) <EOL> return zone <EOL> def get_zone ( project_id , name ) : <EOL> client = dns . Client ( project = project_id ) <EOL> zones , _ = client . list_zones ( ) <EOL> zone = list ( filter ( lambda zone : zone . name == name , zones ) ) <EOL> return zone . pop ( ) if zone else None <EOL> def list_zones ( project_id ) : <EOL> client = dns . Client ( project = project_id ) <EOL> zones , _ = client . list_zones ( ) <EOL> return [ zone . name for zone in zones ] <EOL> def delete_zone ( project_id , name ) : <EOL> client = dns . Client ( project = project_id ) <EOL> zone = client . zone ( name , None ) <EOL> zone . delete ( ) <EOL> def list_resource_records ( project_id , zone_name ) : <EOL> client = dns . Client ( project = project_id ) <EOL> zone = client . zone ( zone_name , None ) <EOL> records , page_token = zone . list_resource_record_sets ( ) <EOL> while page_token is not None : <EOL> next_batch , page_token = zone . list_resource_record_sets ( <EOL> page_token = page_token ) <EOL> records . extend ( next_batch ) <EOL> return [ ( record . name , record . record_type , record . ttl , record . rrdatas ) <EOL> for record in records ] <EOL> def list_changes ( project_id , zone_name ) : <EOL> client = dns . Client ( project = project_id ) <EOL> zone = client . zone ( zone_name , None ) <EOL> changes , _ = zone . list_changes ( ) <EOL> return [ ( change . started , change . status ) for change in changes ] <EOL> def create_command ( args ) : <EOL> """<STR_LIT>""" <EOL> zone = create_zone ( <EOL> args . project_id , args . name , args . dns_name , args . description ) <EOL> print ( '<STR_LIT>' . format ( zone . name ) ) <EOL> def get_command ( args ) : <EOL> """<STR_LIT>""" <EOL> zone = get_zone ( args . project_id , args . name ) <EOL> if not zone : <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> print ( '<STR_LIT>' . format ( <EOL> zone . name , zone . dns_name , zone . description ) ) <EOL> def list_command ( args ) : <EOL> """<STR_LIT>""" <EOL> print ( list_zones ( args . project_id ) ) <EOL> def delete_command ( args ) : <EOL> """<STR_LIT>""" <EOL> delete_zone ( args . project_id , args . name ) <EOL> print ( '<STR_LIT>' . format ( args . name ) ) <EOL> def list_resource_records_command ( args ) : <EOL> """<STR_LIT>""" <EOL> records = list_resource_records ( args . project_id , args . name ) <EOL> for record in records : <EOL> print ( record ) <EOL> def changes_command ( args ) : <EOL> """<STR_LIT>""" <EOL> changes = list_changes ( args . project_id , args . name ) <EOL> for change in changes : <EOL> print ( change ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( ) <EOL> subparsers = parser . add_subparsers ( ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> create_parser = subparsers . add_parser ( <EOL> '<STR_LIT>' , help = create_command . __doc__ ) <EOL> create_parser . set_defaults ( func = create_command ) <EOL> create_parser . add_argument ( '<STR_LIT:name>' , help = '<STR_LIT>' ) <EOL> create_parser . add_argument ( <EOL> '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> create_parser . add_argument ( '<STR_LIT:description>' , help = '<STR_LIT>' ) <EOL> get_parser = subparsers . add_parser ( '<STR_LIT>' , help = get_command . __doc__ ) <EOL> get_parser . add_argument ( '<STR_LIT:name>' , help = '<STR_LIT>' ) <EOL> get_parser . set_defaults ( func = get_command ) <EOL> list_parser = subparsers . add_parser ( '<STR_LIT:list>' , help = list_command . __doc__ ) <EOL> list_parser . set_defaults ( func = list_command ) <EOL> delete_parser = subparsers . add_parser ( <EOL> '<STR_LIT>' , help = delete_command . __doc__ ) <EOL> delete_parser . add_argument ( '<STR_LIT:name>' , help = '<STR_LIT>' ) <EOL> delete_parser . set_defaults ( func = delete_command ) <EOL> list_rr_parser = subparsers . add_parser ( <EOL> '<STR_LIT>' , help = list_resource_records_command . __doc__ ) <EOL> list_rr_parser . add_argument ( '<STR_LIT:name>' , help = '<STR_LIT>' ) <EOL> list_rr_parser . set_defaults ( func = list_resource_records_command ) <EOL> changes_parser = subparsers . add_parser ( <EOL> '<STR_LIT>' , help = changes_command . __doc__ ) <EOL> changes_parser . add_argument ( '<STR_LIT:name>' , help = '<STR_LIT>' ) <EOL> changes_parser . set_defaults ( func = changes_command ) <EOL> args = parser . parse_args ( ) <EOL> args . func ( args ) </s>
