Example #1
0
 def _post(self):
     """Create a new :class:`RTTMRegion` on the DynECT System"""
     uri = '/RTTMRegion/{}/{}/'.format(self._zone, self._fqdn)
     api_args = {'region_code': self._region_code,
                 'pool': [poole.to_json() for poole in self._pool]}
     if self._autopopulate:
         if self._autopopulate not in ('Y', 'N'):
             raise DynectInvalidArgumentError('autopopulate',
                                              self._autopopulate,
                                              ('Y', 'N'))
         api_args['autopopulate'] = self._autopopulate
     if self._ep:
         api_args['ep'] = self._ep
     if self._apmc:
         api_args['apmc'] = self._apmc
     if self._epmc:
         api_args['epmc'] = self._epmc
     if self._serve_count:
         api_args['serve_count'] = self._serve_count
     if self._failover_mode:
         if self._failover_mode not in self.valid_modes:
             raise DynectInvalidArgumentError('failover_mode',
                                              self._failover_mode,
                                              self.valid_modes)
         api_args['failover_mode'] = self._failover_mode
     if self._failover_data:
         if self._failover_data not in self.valid_modes:
             raise DynectInvalidArgumentError('failover_data',
                                              self._failover_data,
                                              self.valid_modes)
         api_args['failover_data'] = self._failover_data
     response = DynectSession.get_session().execute(uri, 'POST', api_args)
     self._build(response['data'])
Example #2
0
 def _post(self,
           contact=None,
           ttl=60,
           serial_style='increment',
           file_name=None,
           master_ip=None,
           timeout=None):
     """Create a new :class:`Zone` object on the DynECT System"""
     if contact is None and file_name is None and master_ip is None:
         raise DynectInvalidArgumentError('contact', None)
     if file_name is not None:
         self._post_with_file(file_name)
     elif master_ip is not None:
         self._xfer(master_ip, timeout)
     else:
         self._contact = contact
         self._ttl = ttl
         if serial_style not in self.valid_serials:
             raise DynectInvalidArgumentError(serial_style,
                                              self.valid_serials)
         self._serial_style = serial_style
         api_args = {
             'zone': self._name,
             'rname': self._contact,
             'ttl': self._ttl,
             'serial_style': self._serial_style
         }
         response = DynectSession.get_session().execute(
             self.uri, 'POST', api_args)
         self._build(response['data'])
Example #3
0
    def __init__(self, address, label, weight, serve_mode, **kwargs):
        """Create a :class:`RegionPoolEntry` object

        :param address: The IPv4 address or FQDN of this Node IP
        :param label: A descriptive string identifying this IP
        :param weight:  A number from 1-15 describing how often this record
            should be served. The higher the number, the more often the address
            is served
        :param serve_mode: Sets the behavior of this particular record. Must be
            one of 'always', 'obey', 'remove', or 'no'
        """
        super(RegionPoolEntry, self).__init__()
        self.valid_modes = ('always', 'obey', 'remove', 'no')
        self._address = address
        self._label = label
        self._task_id = None
        self._zone = kwargs.get('zone')
        self._fqdn = kwargs.get('fqdn')
        self._region_code = kwargs.get('region_code')
        if weight not in range(1, 16):
            raise DynectInvalidArgumentError('weight', weight, '1-15')
        self._weight = weight
        if serve_mode not in self.valid_modes:
            raise DynectInvalidArgumentError('serve_mode', serve_mode,
                                             self.valid_modes)
        self._serve_mode = serve_mode
        self._log = []
        self._build(kwargs)
Example #4
0
 def serve_mode(self, serve_mode):
     if serve_mode not in self.valid_modes:
         raise DynectInvalidArgumentError('serve_mode', serve_mode,
                                          self.valid_modes)
     self._serve_mode = serve_mode
     api_args = {'serve_mode': self._serve_mode}
     self._update(api_args)
Example #5
0
 def notify_events(self, value):
     for val in value:
         if val not in self.valid_notify_events:
             raise DynectInvalidArgumentError('notify_events', val,
                                              self.valid_notify_events)
     value = ','.join(value)
     api_args = {'notify_events': value}
     self._update(api_args)
Example #6
0
 def notify_events(self, value):
     for val in value:
         if val not in self.valid_notify_events:
             raise DynectInvalidArgumentError('notify_events', val,
                                              self.valid_notify_events)
     value = ','.join(value)
     api_args = {'notify_events': value}
     response = DynectSession.get_session().execute(self.uri, 'PUT',
                                                    api_args)
     self._build(response['data'])
Example #7
0
    def _post_with_file(self, file_name):
        """Create a :class:`Zone` from a RFC1035 style Master file. A ZoneFile
        for BIND or tinydns will also be accepted

        :param file_name: The path to a valid ZoneFile
        """
        full_path = os.path.abspath(file_name)
        file_size = os.path.getsize(full_path)
        if file_size > 1048576:
            raise DynectInvalidArgumentError('Zone File Size', file_size,
                                             'Under 1MB')
        else:
            uri = '/ZoneFile/{}/'.format(self.name)
            f = open(full_path, 'r')
            content = f.read()
            f.close()
            api_args = {'file': content}
            response = DynectSession.get_session().execute(
                uri, 'POST', api_args)
            self.__poll_for_get()
            self._build(response['data'])
Example #8
0
 def serial_style(self, value):
     if value not in self.valid_serials:
         raise DynectInvalidArgumentError('serial_style', value,
                                          self.valid_serials)
     self.__root_soa.serial_style = value
Example #9
0
    def _post(self, contact_nickname, performance_monitor, region, ttl=None,
              auto_recover=None, notify_events=None, syslog_server=None,
              syslog_port=514, syslog_ident='dynect', syslog_facility='daemon',
              syslog_delivery='change', syslog_probe_fmt=None,
              syslog_status_fmt=None, syslog_rttm_fmt=None,
              recovery_delay=None, monitor=None):
        """Create a new RTTM Service on the DynECT System"""
        self._auto_recover = auto_recover
        self._ttl = ttl
        self._notify_events = notify_events
        self._syslog_server = syslog_server
        self._syslog_port = syslog_port
        self._syslog_ident = syslog_ident
        self._syslog_facility = syslog_facility
        self._syslog_delivery = syslog_delivery
        self._region += region
        self._monitor = monitor
        self._performance_monitor = performance_monitor
        self._contact_nickname = contact_nickname
        self._syslog_probe_fmt = syslog_probe_fmt
        self._syslog_status_fmt = syslog_status_fmt
        self._syslog_rttm_fmt = syslog_rttm_fmt
        self._recovery_delay = recovery_delay
        api_args = {}
        if auto_recover:
            if auto_recover not in ('Y', 'N'):
                raise DynectInvalidArgumentError('auto_recover', auto_recover,
                                                 ('Y', 'N'))
            api_args['auto_recover'] = self._auto_recover
        if ttl:
            if ttl not in self.valid_ttls:
                raise DynectInvalidArgumentError('ttl', ttl, self.valid_ttls)
            api_args['ttl'] = self._ttl
        if notify_events:
            for event in notify_events:
                if event not in self.valid_notify_events:
                    raise DynectInvalidArgumentError('notify_events', event,
                                                     self.valid_notify_events)
            api_args['notify_events'] = self._notify_events
        if syslog_server:
            api_args['syslog_server'] = self._syslog_server
        if syslog_port:
            api_args['syslog_port'] = self._syslog_port
        if syslog_ident:
            api_args['syslog_ident'] = self._syslog_ident
        if syslog_facility:
            if syslog_facility not in self.valid_syslog_facilities:
                raise DynectInvalidArgumentError('syslog_facility',
                                                 syslog_facility,
                                                 self.valid_syslog_facilities)
            api_args['syslog_facility'] = self._syslog_facility
        if syslog_delivery:
            api_args['syslog_delivery'] = self._syslog_delivery
        if syslog_probe_fmt:
            api_args['syslog_probe_fmt'] = self._syslog_probe_fmt
        if syslog_status_fmt:
            api_args['syslog_status_fmt'] = self._syslog_status_fmt
        if syslog_rttm_fmt:
            api_args['syslog_rttm_fmt'] = self._syslog_rttm_fmt
        if recovery_delay:
            api_args['recovery_delay'] = self._recovery_delay
        if region:
            api_args['region'] = [reg._json for reg in self._region]
        if monitor:
            api_args['monitor'] = self._monitor.to_json()
        if performance_monitor:
            mon_args = self._performance_monitor.to_json()
            api_args['performance_monitor'] = mon_args
        if contact_nickname:
            api_args['contact_nickname'] = self._contact_nickname

        # API expects a CSV string, not a list
        if isinstance(self.notify_events, list):
            api_args['notify_events'] = ','.join(self.notify_events)

        response = DynectSession.get_session().execute(self.uri, 'POST',
                                                       api_args)
        self._build(response['data'])
Example #10
0
 def failover_data(self, value):
     if value not in self.valid_modes:
         raise DynectInvalidArgumentError('failover_data', value,
                                          self.valid_modes)
     api_args = {'failover_data': value}
     self._update(api_args)
Example #11
0
    def __init__(self, zone, fqdn, region_code, *args, **kwargs):
        """Create a :class:`RTTMRegion` object

        :param region_code: Name of the region
        :param pool: (*arg) The IP Pool list for this region
        :param autopopulate: If set to Y, this region will automatically be
            filled in from the global pool, and any other options passed in for
            this region will be ignored
        :param ep: Eligibility Pool - How many records will make it into the
            eligibility pool. The addresses that get chosen will be those that
            respond the fastest
        :param apmc: The minimum amount of IPs that must be in the up state,
            otherwise the region will be in failover
        :param epmc: The minimum amount of IPs that must be populated in the
            EP, otherwise the region will be in failover
        :param serve_count: How many records will be returned in each DNS
            response
        :param failover_mode: How the region should failover. Must be one of
            'ip', 'cname', 'region', or 'global'
        :param failover_data: Dependent upon failover_mode. Must be one of ip',
            'cname', 'region', or 'global'
        """
        super(RTTMRegion, self).__init__()
        self.valid_region_codes = ('US West', 'US Central', 'US East', 'Asia',
                                   'EU West', 'EU Central', 'EU East',
                                   'global')
        self.valid_modes = ('ip', 'cname', 'region', 'global')
        self._task_id = None
        self._zone = zone
        self._fqdn = fqdn
        self._autopopulate = self._ep = self._apmc = None
        self._epmc = self._serve_count = self._failover_mode = None
        self._failover_data = None
        if len(args) != 0:
            pool = args[0]
        else:
            pool = None
        if region_code not in self.valid_region_codes:
            raise DynectInvalidArgumentError('region_code', region_code,
                                             self.valid_region_codes)
        self._region_code = region_code
        self._pool = []
        self.uri = '/RTTMRegion/{}/{}/{}/'.format(self._zone, self._fqdn,
                                                  self._region_code)
        # Backwards Compatability, since we changed the structure of this
        # Class:
        if kwargs.get('pool'):
            warnings.warn("passing pool as keyword argument is\
                          depreciated! please pass in as 4th argument",
                          DeprecationWarning)
            pool = kwargs.pop('pool')

        if not pool and len(kwargs) == 0:
            self._get()
        if len(kwargs) > 0:
            self._build(kwargs)
        if pool:
            for poole in pool:
                if isinstance(poole, dict):
                    rpe = RegionPoolEntry(zone=self._zone,
                                          fqdn=self._fqdn,
                                          region_code=self._region_code,
                                          **poole)
                    self._pool.append(rpe)
                else:
                    if not poole.zone:
                        poole.zone = self._zone
                    if not poole.fqdn:
                        poole.fqdn = self._fqdn
                    if not poole.region_code:
                        poole.region_code = self._region_code
                    self._pool.append(poole)
        self._status = None
Example #12
0
 def weight(self, new_weight):
     if new_weight < 1 or new_weight > 15:
         raise DynectInvalidArgumentError('weight', new_weight, '1-15')
     self._weight = new_weight
     api_args = {'weight': self._weight}
     self._update(api_args)
Example #13
0
 def syslog_facility(self, value):
     if value not in self.valid_syslog_facilities:
         raise DynectInvalidArgumentError('syslog_facility', value,
                                          self.valid_syslog_facilities)
     api_args = {'syslog_facility': value}
     self._update(api_args)
Example #14
0
 def ttl(self, value):
     if value not in self.valid_ttls:
         raise DynectInvalidArgumentError('ttl', value, self.valid_ttls)
     api_args = {'ttl': value}
     self._update(api_args)
Example #15
0
 def auto_recover(self, value):
     if value not in ('Y', 'N'):
         raise DynectInvalidArgumentError('auto_recover', value,
                                          ('Y', 'N'))
     api_args = {'auto_recover': value}
     self._update(api_args)