def point_dns_to_stack(environment, stack_type, name): import sys from dynect.DynectDNS import DynectRest # sudo pip install https://github.com/dyninc/Dynect-API-Python-Library/zipball/master rest_iface = DynectRest() if 'AWS_CONFIG_DIR' in os.environ: user_data_filename = os.path.join(os.environ['AWS_CONFIG_DIR'], 'dynect.json') else: user_data_filename = 'config/dynect.json' with open(user_data_filename, 'r') as f: dynect_credentials = json.load(f) # Log in response = rest_iface.execute('/Session/', 'POST', dynect_credentials) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action response = rest_iface.execute('/CNAMERecord/anosrep.org/www.anosrep.org/', 'GET') # Log out, to be polite rest_iface.execute('/Session/', 'DELETE')
def update_dynect(rules, ip, customername, username, password, recover = False): """ Check id there needs to be updates made and if so call update record for each one """ if ip in rules: dynect = DynectRest() login(customername, username, password, dynect) try: for match in rules[ip]: if recover: if update_record(match["zone"], match["fqdn"], match["secondary"], ip, dynect): print match["fqdn"] + " has recoverd to IP address " + ip else: if update_record(match["zone"], match["fqdn"], ip, match["secondary"], dynect): print match["fqdn"] + " has failed over to IP address " + match["secondary"] except Exception: print Exception traceback.print_exc() rules = {} finally: # Log out, to be polite dynect.execute('/Session/', 'DELETE')
def queryDynect(self): LOG.info('Query DynECT to get the state of GSLBs') try: rest_iface = DynectRest() if CONF.debug and CONF.use_stderr: rest_iface.verbose = True # login credentials = { 'customer_name': CONF.dynect_customer, 'user_name': CONF.dynect_username, 'password': CONF.dynect_password, } LOG.debug('credentials = %s', credentials) response = rest_iface.execute('/Session/', 'POST', credentials) if response['status'] != 'success': LOG.error('Failed to create API session: %s', response['msgs'][0]['INFO']) self.updating = False return # Discover all the Zones in DynECT response = rest_iface.execute('/Zone/', 'GET') LOG.debug('/Zone/ => %s', json.dumps(response, indent=4)) zone_resources = response['data'] # Discover all the LoadBalancers for resource in zone_resources: zone = resource.split('/')[3] # eg. /REST/Zone/guardiannews.com/ response = rest_iface.execute('/LoadBalance/' + zone + '/', 'GET') LOG.debug('/LoadBalance/%s/ => %s', zone, json.dumps(response, indent=4)) gslb = response['data'] # Discover LoadBalancer pool information. for lb in gslb: fqdn = lb.split('/')[4] # eg. /REST/LoadBalance/guardiannews.com/id.guardiannews.com/ response = rest_iface.execute('/LoadBalance/' + zone + '/' + fqdn + '/', 'GET') LOG.debug('/LoadBalance/%s/%s/ => %s', zone, fqdn, json.dumps(response, indent=4)) status = response['data']['status'] monitor = response['data']['monitor'] self.info['gslb-' + fqdn] = {'status': status, 'gslb': fqdn, 'rawData': monitor} for pool in response['data']['pool']: name = '%s-%s' % (fqdn, pool['label'].replace(' ', '-')) status = '%s:%s:%s' % (pool['status'], pool['serve_mode'], pool['weight']) self.info['pool-' + name] = {'status': status, 'gslb': fqdn, 'rawData': pool} LOG.info('Finished object discovery query.') LOG.debug('GSLBs and Pools: %s', json.dumps(self.info, indent=4)) # logout rest_iface.execute('/Session/', 'DELETE') except Exception, e: LOG.error('Failed to discover GSLBs: %s', e) self.updating = False
def queryDynect(): global info logging.info('Quering DynECT to get the state of GSLBs') # Creating DynECT API session try: rest_iface = DynectRest() response = rest_iface.execute('/Session/', 'POST', config) if response['status'] != 'success': logging.error('Incorrect credentials') sys.exit(1) # Discover all the Zones in DynECT response = rest_iface.execute('/Zone/', 'GET') zone_resources = response['data'] # Discover all the LoadBalancers for item in zone_resources: zone = item.split('/')[3] response = rest_iface.execute('/LoadBalance/'+zone+'/', 'GET') gslb = response['data'] # Discover LoadBalancer pool information. for lb in gslb: fqdn = lb.split('/')[4] response = rest_iface.execute('/LoadBalance/'+zone+'/'+fqdn+'/', 'GET') info['gslb-'+fqdn] = response['data']['status'], 'gslb-'+fqdn for i in response['data']['pool']: name = '%s-%s' % (fqdn, i['label'].replace(' ','-')) state = '%s:%s:%s' % (i['status'], i['serve_mode'], i['weight']) parent = 'gslb-'+fqdn info['pool-'+name] = state, parent logging.info('Finish quering and object discovery.') logging.info('GSLBs and Pools: %s', json.dumps(info)) rest_iface.execute('/Session/', 'DELETE') except Exception, e: logging.error('Failed to discover GSLBs: %s', e) pass
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) user_name = 'testuser' user_info = { 'user_name' : user_name, 'password' : 'thepass', 'group_name' : [ 'ADMIN', 'OWNER' ], 'permission' : [ 'RecordGet', 'RecordUpdate' ], 'zone' : [ { 'zone_name' : 'test.com'
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) """ zones = { 'rname' : 'www.gslb.com', 'ttl' : '3600', 'zone' : 'gslb.com', } """ report_data = { 'breakdown' : 'zones', 'end_ts' : '1446535242',
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get AF services as authentication succeded" response = rest_iface.execute('/REST/Failover/gslb.com/www.gslb.com', 'GET') if response['status'] != 'success': pretty = PrettyPrinter() msg = "Getting AF service failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response['data'] print "Getting AF succeded"
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) traffic_srv_id = '54eHrIuDkcKpg9DdnmrThgpGCsI' response_pool= { 'label':'AsiaDC', 'publish' : 'Y' # Mahendra - always publish otherwise it will not be seen on the UI, as changes will get discarded. } """ response_pool= { 'serviceid' : traffic_srv_id,
def queryDynect(self): LOG.info('Query DynECT to get the state of GSLBs') try: rest_iface = DynectRest() if CONF.debug and CONF.use_stderr: rest_iface.verbose = True # login credentials = { 'customer_name': CONF.dynect_customer, 'user_name': CONF.dynect_username, 'password': CONF.dynect_password, } LOG.debug('credentials = %s', credentials) response = rest_iface.execute('/Session/', 'POST', credentials) if response['status'] != 'success': LOG.error('Failed to create API session: %s', response['msgs'][0]['INFO']) self.updating = False return # Discover all the Zones in DynECT response = rest_iface.execute('/Zone/', 'GET') LOG.debug('/Zone/ => %s', json.dumps(response, indent=4)) zone_resources = response['data'] # Discover all the LoadBalancers for resource in zone_resources: zone = resource.split('/')[ 3] # eg. /REST/Zone/guardiannews.com/ response = rest_iface.execute('/LoadBalance/' + zone + '/', 'GET') LOG.debug('/LoadBalance/%s/ => %s', zone, json.dumps(response, indent=4)) gslb = response['data'] # Discover LoadBalancer pool information. for lb in gslb: fqdn = lb.split( '/' )[4] # eg. /REST/LoadBalance/guardiannews.com/id.guardiannews.com/ response = rest_iface.execute( '/LoadBalance/' + zone + '/' + fqdn + '/', 'GET') LOG.debug('/LoadBalance/%s/%s/ => %s', zone, fqdn, json.dumps(response, indent=4)) status = response['data']['status'] monitor = response['data']['monitor'] self.info['gslb-' + fqdn] = { 'status': status, 'gslb': fqdn, 'rawData': monitor } for pool in response['data']['pool']: name = '%s-%s' % (fqdn, pool['label'].replace( ' ', '-')) status = '%s:%s:%s' % ( pool['status'], pool['serve_mode'], pool['weight']) self.info['pool-' + name] = { 'status': status, 'gslb': fqdn, 'rawData': pool } LOG.info('Finished object discovery query.') LOG.debug('GSLBs and Pools: %s', json.dumps(self.info, indent=4)) # logout rest_iface.execute('/Session/', 'DELETE') except Exception, e: LOG.error('Failed to discover GSLBs: %s', e) self.updating = False
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get Zone as authentication succeded" response = rest_iface.execute('/Zone/', 'GET') if response['status'] != 'sucess': pretty = PrettyPrinter() msg = "Getting zone failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response['data'] print "Getting zone succeded"
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) """ zones = { 'rname' : 'www.gslb.com', 'ttl' : '3600', 'zone' : 'gslb.com', } """ active_failover_srv = { 'fqdn' : 'www.gslb.com', 'address' : '1.2.3.4',
def point_dns_to_stack(region, stack_type, application, name): import sys import os import json import boto.ec2.elb from dynect.DynectDNS import DynectRest # sudo pip install https://github.com/dyninc/Dynect-API-Python-Library/zipball/master if stack_type == 'stage': zone = 'anosrep.org' if application == 'persona': elbs = {'firefoxos.anosrep.org': 'w-anosrep-org', 'login.anosrep.org': 'w-anosrep-org', 'www.anosrep.org': 'w-anosrep-org', 'static.login.anosrep.org': 'w-login-anosrep-org', 'verifier.login.anosrep.org': 'w-login-anosrep-org'} elif application == 'bridge-yahoo': elbs = {'yahoo.login.anosrep.org': 'yahoo-login-anosrep-org'} elif application == 'bridge-gmail': elbs = {'gmail.login.anosrep.org': 'gmail-login-anosrep-org'} else: raise ValueError("application value is bad : %s" % application) elif stack_type == 'prod': zone = 'persona.org' if application == 'persona': elbs = {'login.persona.org': 'persona-org', 'www.persona.org': 'persona-org'} elif application == 'bridge-yahoo': elbs = {'yahoo.login.persona.org': 'yahoo-login-persona-org'} elif application == 'bridge-gmail': elbs = {'gmail.login.persona.org': 'gmail-login-persona-org'} else: raise ValueError("application value is bad : %s" % application) new_names = {} # TODO : This doesn't work for prod because we need to inject multiple regions into traffic mangement conn_elb = boto.ec2.elb.connect_to_region(region) load_balancers = conn_elb.get_all_load_balancers(load_balancer_names=['%s-%s' % (x, name) for x in set(elbs.values())]) for load_balancer in load_balancers: new_names['-'.join(load_balancer.name.split('-')[:-1])] = load_balancer.dns_name rest_iface = DynectRest() if 'AWS_CONFIG_DIR' in os.environ: user_data_filename = os.path.join(os.environ['AWS_CONFIG_DIR'], 'dynect.json') else: user_data_filename = 'config/dynect.json' with open(user_data_filename, 'r') as f: dynect_credentials = json.load(f) # Log in response = rest_iface.execute('/Session/', 'POST', dynect_credentials) if response['status'] != 'success': sys.exit("Incorrect credentials") for record in elbs.keys(): # Get record_id uri = '/CNAMERecord/%s/%s/' % (zone, record) response = rest_iface.execute(uri, 'GET') record_id = response['data'][0].split('/')[-1] uri = uri + record_id + '/' # Get current record response = rest_iface.execute(uri, 'GET') old_name = response['data']['rdata']['cname'] # Set new record new_name = new_names[elbs[record]] + '.' arguments = {'rdata': {'cname': new_name}} logging.info('calling "%s" to change the record from "%s" to "%s"' % (uri, old_name, new_name)) response = rest_iface.execute(uri, 'PUT', arguments) logging.info(json.dumps(response['msgs'])) # Publish the new zone response = rest_iface.execute('/Zone/%s' % zone, 'PUT', {'publish': 1}) logging.info('new zone published with updates at serial number %s' % response['data']['serial']) # Log out, to be polite rest_iface.execute('/Session/', 'DELETE')
import sys, getpass, string from dynect.DynectDNS import DynectRest # API module available from dynect site print "Username: "******"Password: "******"Incorrect credentials") for zone in zones: response = rest_iface.execute(zone, 'GET') zone_resources = response['data'] print "\nrecord_type\trecord\t\ttarget" for resource in zone_resources: res = rest_iface.execute(resource, 'GET') rtype = string.lower(res['data']['record_type']) if rtype == 'cname': print "%s\t%s\t\t%s" % \ ( res['data']['record_type'], res['data']['fqdn'], res['data']['rdata'][rtype] ) elif rtype == 'a': print "%s\t%s\t\t%s" % \
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) nodes = [ { 'zone' : 'gslb.com' , 'node' : 'www.gslb.com',}] criteria = { 'geoip' : { 'country' : [ 'US' ] } } records = [ { 'label' : 'USEast007', 'weight' : '5', 'automation' : 'auto',
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) A_srv_name = 'www3.gslb.com' arecord = { 'fqdn' : 'www3.gslb.com', 'zone' : 'gslb.com', } print "Deleting A Record" url = "/REST/ARecord/gslb.com/%s" % A_srv_name response = api.execute(url,'DELETE',arecord);
for uri in response['data']: dsf = dyn_iface.execute( uri, 'GET') for node_dict in dsf['data']['nodes']: if node_dict['fqdn'] == fqdn: return uri return 0 #read API credentials from file try: creds = get_creds() except: sys.exit('Unable to open configuation file: config.cfg') dyn_iface = DynectRest() # Log in response = dyn_iface.execute('/Session/', 'POST', creds) if response['status'] != 'success': sys.exit("Unable to Login to DynECT DNS API. Please check credentials in config.cfg") #obtain parent uri for DSF service by FQDN #also possible to get DSF directly by label dsf_uri = get_dsf_byfqdn( dyn_iface, 'example.dsfexample.com' ) #get full description of service using URI dsf_desc = dyn_iface.execute(dsf_uri, 'GET') #grab IDs from service description #can be used later to direclty access service or other URIs dsf_id = dsf_desc['data']['service_id'] #at this point we could look at rulesets->response pools->records by parsing the DSF object #instead we will use paramaters to enumerate specific records for demonstration purposes
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get QPS report as authentication succeded" response = rest_iface.execute('/REST/QPSReport/', 'GET') if response['status'] != 'success': pretty = PrettyPrinter() msg = "Getting zone failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response['data'] print "Getting QPS report succeded"
rest_iface = DynectRest() # Inputs from user for login to the DynECT API. customer = raw_input("Enter your Customer Name: ") username = raw_input("Enter your Username: "******"Enter your password: "******"Incorrect credentials") elif response['status'] == 'success': print 'Login Successful to DynECT API.' # Inputs from user to path to Zone Files. path = raw_input("Enter your path to your Zone Files: ") # Going through the Zone Files Directory. for zoneFileName in os.listdir(path): zone_path = os.path.join(path, zoneFileName)
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get traffic director service as authentication succeded" services = { 'label' : 'Test*', 'detail' : 'true', } response = rest_iface.execute('/REST/DSF/', 'GET', services) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Getting traffic director service : %s " % pretty.pformat(response)
class TestDynDns(): def setUp(self): self.customer_name = os.environ.get('TEST_DYNDNS_CUSTOMER_NAME') self.user_name = os.environ.get('TEST_DYNDNS_USER_NAME') self.password = os.environ.get('TEST_DYNDNS_PASSWORD') self.zone = os.environ.get('TEST_DYNDNS_ZONE') if not all((self.customer_name, self.user_name, self.password, self.zone)): raise SkipTest('Please set env variables TEST_DYNDNS_CUSTOMER_NAME, TEST_DYNDNS_USER_NAME, TEST_DYNDNS_PASSWORD and TEST_DYNDNS_ZONE.') arguments = { 'customer_name': self.customer_name, 'user_name': self.user_name, 'password': self.password, } self.rest_iface = DynectRest() self.rest_iface.execute('/Session/', 'POST', arguments) self.rest_iface.execute('/Node/%s/root.%s/' % (self.zone, self.zone), 'DELETE') self.rest_iface.execute('/Node/%s/cname1.%s/' % (self.zone, self.zone), 'DELETE') self.rest_iface.execute('/Node/%s/cname2.%s/' % (self.zone, self.zone), 'DELETE') self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'address': '127.0.0.1'}, 'ttl': 10}) self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'address': '127.0.0.2'}, 'ttl': 10}) self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'address': '127.0.0.3'}, 'ttl': 10}) self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'address': '127.0.0.4'}, 'ttl': 10}) self.rest_iface.execute('/AAAARecord/%s/root.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'address': '::1'}, 'ttl': 10}) self.rest_iface.execute('/AAAARecord/%s/root.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'address': '::2'}, 'ttl': 10}) self.rest_iface.execute('/CNAMERecord/%s/cname1.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'cname': 'root.%s.' % self.zone}, 'ttl': 10}) self.rest_iface.execute('/CNAMERecord/%s/cname2.%s/' % (self.zone, self.zone), 'POST', {'rdata': {'cname': 'cname1.%s.' % self.zone}, 'ttl': 10}) self.rest_iface.execute('/Zone/%s/' % self.zone, 'PUT', {'publish': 'true'}) def test_remove_records_with_disabled_readd_feature(self): dyndns = DynDns( dry_run=False, customer_name=self.customer_name, user_name=self.user_name, password=self.password, ) dyndns.sync_records( failed=[ Checkpoint(url='http://127.0.0.1/health/', host='cname2.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.1', type='A'), # remove this Checkpoint(url='http://127.0.0.4/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.4', type='A'), # remove this Checkpoint(url='http://127.0.0.104/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.4', type='A'), # non existent Checkpoint(url='http://[::2]/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='::2', type='AAAA'), # ipv6 ], passed=[], enable_readd=False, ) # IPv4 removed tools.assert_equal( set([ '127.0.0.2', '127.0.0.3', ]), set([ self.rest_iface.execute(url, 'GET')['data']['rdata']['address'] for url in self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'GET')['data'] ]) ) # IPv6 removed tools.assert_equal( set([ '::1', ]), set([ self.rest_iface.execute(url, 'GET')['data']['rdata']['address'] for url in self.rest_iface.execute('/AAAARecord/%s/root.%s/' % (self.zone, self.zone), 'GET')['data'] ]) ) # CNAMEs kept tools.assert_equal( [{u'cname': u'root.pantheondnstestdomain.com.'}], [ self.rest_iface.execute(url, 'GET')['data']['rdata'] for url in self.rest_iface.execute('/CNAMERecord/%s/cname1.%s/' % (self.zone, self.zone), 'GET')['data'] ] ) tools.assert_equal( [{u'cname': u'cname1.pantheondnstestdomain.com.'}], [ self.rest_iface.execute(url, 'GET')['data']['rdata'] for url in self.rest_iface.execute('/CNAMERecord/%s/cname2.%s/' % (self.zone, self.zone), 'GET')['data'] ] ) dyndns.sync_records( failed=[ Checkpoint(url='http://127.0.0.2/health/', host='cname2.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.1', type='A'), Checkpoint(url='http://127.0.0.3/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.4', type='A'), ], passed=[], enable_readd=False, ) # IPv4 not removed - we are not deleting when all records fails tools.assert_equal( set([ '127.0.0.2', '127.0.0.3', ]), set([ self.rest_iface.execute(url, 'GET')['data']['rdata']['address'] for url in self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'GET')['data'] ]) ) def test_remove_records_with_enabled_readd_feature(self): dyndns = DynDns( dry_run=False, customer_name=self.customer_name, user_name=self.user_name, password=self.password, ) dyndns.sync_records( failed=[ Checkpoint(url='http://127.0.0.1/health/', host='cname2.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.1', type='A'), # remove this Checkpoint(url='http://127.0.0.4/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.4', type='A'), # remove this Checkpoint(url='http://127.0.0.104/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.4', type='A'), # non existent Checkpoint(url='http://[::2]/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='::2', type='AAAA'), # ipv6 ], passed=[ Checkpoint(url='http://127.0.0.2/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.2', type='A'), # remove this Checkpoint(url='http://127.0.0.3/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='127.0.0.3', type='A'), # remove this Checkpoint(url='http://[::1]/health/', host='root.%s' % self.zone, record='root.%s.' % self.zone, ip='::1', type='AAAA'), # ipv6 ], enable_readd=True, ) # IPv4 removed tools.assert_equal( set([ '127.0.0.2', '127.0.0.3', ]), set([ self.rest_iface.execute(url, 'GET')['data']['rdata']['address'] for url in self.rest_iface.execute('/ARecord/%s/root.%s/' % (self.zone, self.zone), 'GET')['data'] ]) ) # IPv6 removed tools.assert_equal( set([ '::1', ]), set([ self.rest_iface.execute(url, 'GET')['data']['rdata']['address'] for url in self.rest_iface.execute('/AAAARecord/%s/root.%s/' % (self.zone, self.zone), 'GET')['data'] ]) )
def point_dns_to_stack(region, stack_type, name): import sys import os import json import boto.ec2.elb from dynect.DynectDNS import DynectRest # sudo pip install https://github.com/dyninc/Dynect-API-Python-Library/zipball/master if stack_type == 'stage': elbs = { 'firefoxos.anosrep.org': 'w-anosrep-org', 'login.anosrep.org': 'w-anosrep-org', 'www.anosrep.org': 'w-anosrep-org', 'static.login.anosrep.org': 'w-login-anosrep-org', 'verifier.login.anosrep.org': 'w-login-anosrep-org', 'gmail.login.anosrep.org': 'gmail-login-anosrep-org', 'yahoo.login.anosrep.org': 'yahoo-login-anosrep-org' } zone = 'anosrep.org' elif stack_type == 'prod': elbs = { 'login.persona.org': 'persona-org', 'www.persona.org': 'persona-org', 'gmail.login.persona.org': 'gmail-login-persona-org', 'yahoo.login.persona.org': 'yahoo-login-persona-org' } zone = 'persona.org' new_names = {} # TODO : This doesn't work for prod because we need to inject multiple regions into traffic mangement conn_elb = boto.ec2.elb.connect_to_region(region) load_balancers = conn_elb.get_all_load_balancers( load_balancer_names=['%s-%s' % (x, name) for x in set(elbs.values())]) for load_balancer in load_balancers: new_names['-'.join( load_balancer.name.split('-')[:-1])] = load_balancer.dns_name rest_iface = DynectRest() if 'AWS_CONFIG_DIR' in os.environ: user_data_filename = os.path.join(os.environ['AWS_CONFIG_DIR'], 'dynect.json') else: user_data_filename = 'config/dynect.json' with open(user_data_filename, 'r') as f: dynect_credentials = json.load(f) # Log in response = rest_iface.execute('/Session/', 'POST', dynect_credentials) if response['status'] != 'success': sys.exit("Incorrect credentials") for record in elbs.keys(): # Get record_id uri = '/CNAMERecord/%s/%s/' % (zone, record) response = rest_iface.execute(uri, 'GET') record_id = response['data'][0].split('/')[-1] uri = uri + record_id + '/' # Get current record response = rest_iface.execute(uri, 'GET') old_name = response['data']['rdata']['cname'] # Set new record new_name = new_names[elbs[record]] + '.' arguments = {'rdata': {'cname': new_name}} logging.info('calling "%s" to change the record from "%s" to "%s"' % (uri, old_name, new_name)) response = rest_iface.execute(uri, 'PUT', arguments) logging.info(json.dumps(response['msgs'])) # Publish the new zone response = rest_iface.execute('/Zone/%s' % zone, 'PUT', {'publish': 1}) logging.info('new zone published with updates at serial number %s' % response['data']['serial']) # Log out, to be polite rest_iface.execute('/Session/', 'DELETE')
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get response pool as authentication succeded" r_pool_data = { 'service_id' : 'oKodxPBLfY7EDl_KOnSB2pOfYq8', 'label' : 'Japan DC', } response = rest_iface.execute('/REST/DSFResponsePool/54eHrIuDkcKpg9DdnmrThgpGCsI/', 'GET') if response['status'] != 'success': pretty = PrettyPrinter() msg = "Getting response failed: %s " % pretty.pformat(response) sys.exit(msg)
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = {"customer_name": "ciscocloud", "user_name": "UserName", "password": "******"} response = api.execute("/REST/Session/", "POST", args) if response["status"] != "success": pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) user_name = "testuser" print "Deleting User" url = "/REST/User/%s" % user_name response = api.execute(url, "DELETE") if response["status"] != "success": pretty = PrettyPrinter() msg = "Deleting the User failed: %s" % pretty.pformat(response) sys.exit(msg)
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get Groups as authentication succeded" response = rest_iface.execute('/REST/PermissionGroup/', 'GET') if response['status'] != 'success': pretty = PrettyPrinter() msg = "Getting Group failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response['data'] print "Getting Groups succeded"
except: #raise exception is config read fails raise #read API credentials from file try: creds = get_creds() except: sys.exit('Unable to open configuation file: config.cfg') #create Dyn Traffic Managment interface dyn_iface = DynectRest() # Log in response = dyn_iface.execute('/Session/', 'POST', creds) if response['status'] != 'success': sys.exit("Unable to Login to DynECT DNS API. Please check credentials in config.cfg") #some variable about location of TD (example2.dsfexample.com) zone = 'dsfexample.com' node = 'example2' #create new DSF argum = { #name of the service 'label' : 'exampleTD', #location of the FQDN 'nodes' : [ { 'zone' : zone, 'fqdn' : node + '.' + zone
args = sys.argv help_list = ["/?", "?", "help", "-h", "-he4lp"] print(args) # Login to API api = DynectRest() print("Log in DYN API") pargs = { 'customer_name': 'Infinata', 'user_name': input('Enter your Dynect username: '******'password': getpass.getpass(prompt='Password:'******'/REST/Session/', 'POST', pargs) if response['status'] != 'success': pretty = PrettyPrinter() msg = "** Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) print("** Login successful.") print(args) if args in help_list: print( "*** NAME: dyndns tool \n" "DESCRIPTION: " + "utilizes flat file to make bulk changes to dyndns domain records" "BASIC USEAGE: python dyndns.py {optional file path to backup or custom change file"
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) job_id = '1953472563' jobs = { 'job_id' : '1953472563',} url = "/REST/Job/%s" % job_id response = api.execute(url,'GET',jobs); if response['status'] != 'sucess': pretty = PrettyPrinter()
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get response pool as authentication succeded" r_pool_data = { 'service_id' : 'oKodxPBLfY7EDl_KOnSB2pOfYq8', 'label' : 'Japan DC', } response = rest_iface.execute('/REST/DSFResponsePool/54eHrIuDkcKpg9DdnmrThgpGCsI/CUEKLBd35CLXI_KtqXYB8FMyBUk/', 'GET') if response['status'] != 'success': pretty = PrettyPrinter() msg = "Getting response failed: %s " % pretty.pformat(response) sys.exit(msg)
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = {"customer_name": "ciscocloud", "user_name": "UserName", "password": "******"} # ciscocloud UserName Cisco!gs1b response = rest_iface.execute("/Session/", "POST", arguments) if response["status"] != "success": sys.exit("Incorrect credentials") # Perform action print "Get User as authentication succeded" response = rest_iface.execute("/REST/User/", "GET") if response["status"] != "success": pretty = PrettyPrinter() msg = "Getting User failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response["data"] print "Getting User succeded" print zone_resources # Log out, to be polite print "Deleting session"
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get password as authentication succeded" username = { 'user_name' : 'mahepate',} response = rest_iface.execute('/REST/UpdateUserPassword/mahepate', 'GET', username) if response['status'] != 'sucess': pretty = PrettyPrinter() msg = "Getting Password failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response['data']
from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter import sys api = DynectRest() # We need to login print "Logging in to API" args = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } response = api.execute('/REST/Session/', 'POST', args) if response['status'] != 'success': pretty = PrettyPrinter() msg = "Login to API failed: %s" % pretty.pformat(response) sys.exit(msg) zone_srv_name = 'gslb.com' zones = { 'zone' : 'gslb.com', } print "Creating the zone gslb.com with rr www.gslb.com" url = "/REST/Zone/%s" % zone_srv_name
import sys from dynect.DynectDNS import DynectRest from pprint import PrettyPrinter rest_iface = DynectRest() # Log in print "Logging in to API" arguments = { 'customer_name': 'ciscocloud', 'user_name': 'UserName', 'password': '******', } # ciscocloud UserName Cisco!gs1b response = rest_iface.execute('/Session/', 'POST', arguments) if response['status'] != 'success': sys.exit("Incorrect credentials") # Perform action print "Get GSLB services as authentication succeded" response = rest_iface.execute('/REST/GSLB/gslb.com', 'GET') if response['status'] != 'sucess': pretty = PrettyPrinter() msg = "Getting gslb service failed: %s " % pretty.pformat(response) sys.exit(msg) zone_resources = response['data'] print "Getting gslb succeded"