def action_blacklist_list(): designateclient = Designate(options.config, debug=options.debug, log=logger) blacklists = designateclient.list_blacklists() outputs = ['pattern','description','id'] if options.pretty: x = PrettyTable() x.field_names = outputs x.align['pattern'] = 'l' x.align['description'] = 'l' if isinstance(blacklists, list): for b in blacklists: if not isinstance(b, dict): b = b.to_dict() array = [] for o in outputs: array.append(b[o]) x.add_row(array) print(x) else: header = 'Blacklisted DNS domains (%s)' % (', '.join(outputs)) printer.output_dict({'header': header}) output = OrderedDict() if isinstance(blacklists, list): for b in blacklists: if not isinstance(b, dict): b = b.to_dict() for out in outputs: output[out] = b[out] printer.output_dict(objects=output, one_line=True, sort=False)
def action_blacklist_list(): designateclient = Designate(options.config, debug=options.debug, log=logger) blacklists = designateclient.list_blacklists() outputs = ['pattern', 'description', 'id'] if options.pretty: x = PrettyTable() x.field_names = outputs x.align['pattern'] = 'l' x.align['description'] = 'l' if isinstance(blacklists, list): for b in blacklists: if not isinstance(b, dict): b = b.to_dict() array = [] for o in outputs: array.append(b[o]) x.add_row(array) print(x) else: header = 'Blacklisted DNS domains (%s)' % (', '.join(outputs)) printer.output_dict({'header': header}) output = OrderedDict() if isinstance(blacklists, list): for b in blacklists: if not isinstance(b, dict): b = b.to_dict() for out in outputs: output[out] = b[out] printer.output_dict(objects=output, one_line=True, sort=False)
def action_tld_update(): designateclient = Designate(options.config, debug=options.debug, log=logger) data = dict() if options.name: data['name'] = options.name if options.comment: data['description'] = options.comment designateclient.update_tld(tld=options.this_id, values=data)
def action_blacklist_update(): designateclient = Designate(options.config, debug=options.debug, log=logger) data = dict() if options.pattern: data['pattern'] = options.pattern if options.comment: data['description'] = options.comment designateclient.update_blacklist(blacklist_id=options.this_id, values=data)
def action_tld_show(): designateclient = Designate(options.config, debug=options.debug, log=logger) tld = designateclient.get_tld(name=options.name) print print " Name: ......... %s" % tld['name'] print " Description: .. %s" % tld['description'] print " Created at: ... %s" % tld['created_at'] print " Updated at: ... %s" % tld['updated_at'] print " ID: ........... %s" % tld['id'] print
def action_blacklist_show(): designateclient = Designate(options.config, debug=options.debug, log=logger) res = designateclient.get_blacklist(blacklist_id=options.this_id) print print " Pattern: ...... %s" % res['pattern'] print " Description: .. %s" % res['description'] print " Created at: ... %s" % res['created_at'] print " Updated at: ... %s" % res['updated_at'] print " ID: ........... %s" % res['id'] print
def action_tld_import(): designateclient = Designate(options.config, debug=options.debug, log=logger) global BULK_DESC # get all registered tlds existing = designateclient.list_tlds() registered_tlds = [] if isinstance(existing, list): for this_tld in existing: if not isinstance(this_tld, dict): this_tld = this_tld.to_dict() if this_tld["description"] == BULK_DESC: registered_tlds.append(this_tld["name"]) # read the import file bulkfile = open(options.file, "r") iana_tlds = [] for name in bulkfile: name = name.rstrip() name = unicode(name, 'utf-8') name = name.lower() if re.match("^#.*", name): continue if re.match("^xn--", name): continue #name = name.decode('idna') iana_tlds.append(name) # remove any registered "bulk import" tlds that aren't in the file remove_tlds = __diff_arrays(registered_tlds, iana_tlds) for name in remove_tlds: if options.debug: print "debug: removing tld: %s" % name designateclient.delete_tld(tld=name) # add any new tlds from the file add_tlds = __diff_arrays(iana_tlds, registered_tlds) for name in add_tlds: if options.debug: print "debug: creating tld: %s" % name designateclient.create_tld(name=name, description=BULK_DESC)
def action_tld_import(): designateclient = Designate(options.config, debug=options.debug, log=logger) global BULK_DESC # get all registered tlds existing = designateclient.list_tlds() registered_tlds = [] if isinstance(existing, list): for this_tld in existing: if not isinstance(this_tld, dict): this_tld = this_tld.to_dict() if this_tld["description"] == BULK_DESC: registered_tlds.append(this_tld["name"]); # read the import file bulkfile = open(options.file, "r") iana_tlds = [] for name in bulkfile: name = name.rstrip() name = unicode(name, 'utf-8') name = name.lower() if re.match("^#.*", name): continue if re.match("^xn--", name): continue #name = name.decode('idna') iana_tlds.append(name) # remove any registered "bulk import" tlds that aren't in the file remove_tlds = __diff_arrays(registered_tlds, iana_tlds) for name in remove_tlds: if options.debug: print "debug: removing tld: %s" % name designateclient.delete_tld(tld=name) # add any new tlds from the file add_tlds = __diff_arrays(iana_tlds, registered_tlds) for name in add_tlds: if options.debug: print "debug: creating tld: %s" % name designateclient.create_tld(name=name, description=BULK_DESC)
def action_blacklist_delete(): designateclient = Designate(options.config, debug=options.debug, log=logger) designateclient.delete_blacklist(blacklist_id=options.this_id)
def action_blacklist_create(): designateclient = Designate(options.config, debug=options.debug, log=logger) designateclient.create_blacklist(pattern=options.pattern, description=options.comment)
def action_tld_delete(): designateclient = Designate(options.config, debug=options.debug, log=logger) designateclient.delete_tld(tld=options.this_id)
def action_tld_create(): designateclient = Designate(options.config, debug=options.debug, log=logger) designateclient.create_tld(name=options.name, description=options.comment)
#!/usr/bin/env python """ Setup designate DNS """ import utils from himlarcli.designate import Designate from himlarcli import utils as himutils himutils.is_virtual_env() # Input args desc = 'Manage designate' actions = ['show', 'create'] # Example opt_args (see utils.py) #opt_args = { '-n': { 'dest': 'name', 'help': 'flavor class (mandatory)', 'required': True }, # '-p': { 'dest': 'project', 'help': 'project to grant or revoke access'} } opt_args = {} options = utils.get_action_options(desc, actions, dry_run=True, opt_args=opt_args) dns = Designate(options.config, debug=options.debug) if options.action[0] == 'show': if options.dry_run: print 'DRY-RUN: show' else: print 'show' elif options.action[0] == 'create': if options.dry_run: print 'DRY-RUN: create' else: print 'create'