当前位置: 首页>>代码示例>>Python>>正文


Python DynectDNS.DynectRest类代码示例

本文整理汇总了Python中dynect.DynectDNS.DynectRest的典型用法代码示例。如果您正苦于以下问题:Python DynectRest类的具体用法?Python DynectRest怎么用?Python DynectRest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DynectRest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: point_dns_to_stack

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')
开发者ID:6a68,项目名称:identity-ops,代码行数:25,代码来源:stack_control.py

示例2: setUp

 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'})
开发者ID:whiskybar,项目名称:ddcheck,代码行数:26,代码来源:test_dyndns.py

示例3: queryDynect

    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
开发者ID:MailOnline,项目名称:alerta,代码行数:57,代码来源:daemon.py

示例4: update_dynect

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')
开发者ID:dyninc,项目名称:DNS-Syslog_Responder-Python,代码行数:23,代码来源:failover_listener.py

示例5: queryDynect

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
开发者ID:DiegoVazquezNanini,项目名称:alerta,代码行数:47,代码来源:alert-dynect.py

示例6: DynectRest

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': 'UserAPIKey',
}
# 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"
开发者ID:mady4ever,项目名称:GSLB,代码行数:31,代码来源:get_zone.py

示例7: DynectRest

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': 'UserAPIKey',
}

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',
开发者ID:mady4ever,项目名称:GSLB,代码行数:31,代码来源:create_qps_report.py

示例8: DynectRest

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': 'UserAPIKey',
}

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,
开发者ID:mady4ever,项目名称:GSLB,代码行数:31,代码来源:create_response_pool.py

示例9: DynectRest

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": "UserAPIKey"}

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)
开发者ID:mady4ever,项目名称:GSLB,代码行数:31,代码来源:delete_user.py

示例10: DynectRest

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': 'UserAPIKey',
}

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',
开发者ID:mady4ever,项目名称:GSLB,代码行数:31,代码来源:create_active_failover_service.py

示例11: point_dns_to_stack

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')
开发者ID:jrgm,项目名称:identity-ops,代码行数:81,代码来源:stack_control.py

示例12: DynectRest

###
import sys, getpass, string
from dynect.DynectDNS import DynectRest   # API module available from dynect site

print "Username: ",
user = sys.stdin.readline(80).rstrip()
passwd = getpass.getpass("Password: ")
login_args = { 'customer_name': 'mycompany',
               'user_name': user,
               'password': passwd, }

zones = [ u'/AllRecord/mycompany.net/', u'/AllRecord/mycompany.co.jp/', 
          u'/AllRecord/mycompany.com/', ]

try:
    rest_iface = DynectRest()
    response = rest_iface.execute('/Session/', 'POST', login_args)
    if response['status'] != 'success':
        sys.exit("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':
开发者ID:dcherry-calamp,项目名称:linux-scripts,代码行数:31,代码来源:dynect-dump.py

示例13: DynectRest

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': 'UserAPIKey',
}

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',
开发者ID:mady4ever,项目名称:GSLB,代码行数:31,代码来源:create_traffic_director_service.py

示例14: DynectRest

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': 'UserAPIKey',
}

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);
开发者ID:mady4ever,项目名称:GSLB,代码行数:30,代码来源:delete_A_record.py

示例15: get_dsf_byfqdn

def get_dsf_byfqdn( dyn_iface, fqdn ):
    response = dyn_iface.execute('/DSF/','GET')
    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']
开发者ID:StoneTools,项目名称:DNS-TD_Example,代码行数:30,代码来源:TD_update.py


注:本文中的dynect.DynectDNS.DynectRest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。