Example #1
0
 def _post(self, record_type, address, user=None):
     """Create a new DynamicDNS Service on the DynECT System"""
     self._record_type = record_type
     self._address = address
     if user:
         self._user = user
     self.uri = '/DDNS/{}/{}/{}/'.format(self._zone, self._fqdn,
                                         self._record_type)
     api_args = {'address': self._address}
     if user:
         api_args['user'] = self._user
         api_args['full_setup'] = True
     response = DynectSession.get_session().execute(self.uri, 'POST',
                                                    api_args)
     for key, val in response['data'].items():
         if user:
             if key == 'ddns':
                 for ddns_key, ddns_val in val.items():
                     setattr(self, '_' + ddns_key, ddns_val)
             if key == 'new_user':
                 user_name = val['user_name']
                 del val['user_name']
                 self._user = User(user_name, api=False, **val)
         elif key == 'active':
             self._active = Active(val)
         else:
             setattr(self, '_' + key, val)
Example #2
0
 def _build(self, data):
     """Build this object based on the data contained in an API response"""
     for key, val in data.items():
         if key == 'active':
             self._active = Active(val)
         else:
             setattr(self, '_' + key, val)
Example #3
0
    def __init__(self, zone, fqdn, *args, **kwargs):
        """Create a new :class:`DynamicDNS` service object

        :param zone: The zone to attach this DDNS Service to
        :param fqdn: The FQDN of the node where this service will be attached
        :param record_type: Either A, for IPv4, or AAAA, for IPv6
        :param address: IPv4 or IPv6 address for the service
        :param full_setup: Flag to indicate a user is specified
        :param user: Name of the user to create, or the name of an existing
            update user to allow access to this service
        """
        super(DynamicDNS, self).__init__()
        self._zone = zone
        self._fqdn = fqdn
        self._record_type = self._address = self.uri = self._user = None
        self._active = None
        if 'api' in kwargs:
            del kwargs['api']
            for key, val in kwargs.items():
                if key == 'active':
                    self._active = Active(val)
                else:
                    setattr(self, '_' + key, val)
        elif len(args) + len(kwargs) == 1:
            self._get(*args, **kwargs)
        elif 'record_type' in kwargs and len(kwargs) == 1:
            self._get(*args, **kwargs)
        else:
            self._post(*args, **kwargs)
Example #4
0
 def _get(self, record_type=None):
     """Build an object around an existing DynECT DynamicDNS Service"""
     self._record_type = record_type
     self.uri = '/DDNS/{}/{}/{}/'.format(self._zone, self._fqdn,
                                         self._record_type)
     api_args = {}
     response = DynectSession.get_session().execute(self.uri, 'GET',
                                                    api_args)
     for key, val in response['data'].items():
         if key == 'active':
             self._active = Active(val)
         else:
             setattr(self, '_' + key, val)
Example #5
0
 def _build(self, data):
     """Build this object from the data returned in an API response"""
     self._task_id = None
     for key, val in data.items():
         if key == 'monitor':
             self._monitor = HealthMonitor(**val)
         elif key == 'active':
             self._active = Active(val)
         elif key == "task_id" and not val:
             self._task_id = None
         elif key == "task_id":
             self._task_id = Task(val)
         else:
             setattr(self, '_' + key, val)
Example #6
0
 def _build(self, data):
     """Iterate over API data responses and update this object according to
     the data returned
     """
     for key, val in data.items():
         if key == 'keys':
             self._keys = APIList(DynectSession.get_session, 'keys')
             for key_data in val:
                 key_data['key_type'] = key_data['type']
                 del key_data['type']
                 self._keys.append(DNSSECKey(**key_data))
         elif key == 'active':
             self._active = Active(val)
         else:
             setattr(self, '_' + key, val)
     self.uri = '/DNSSEC/{}/'.format(self._zone)
     self._keys.uri = self.uri
Example #7
0
    def _build(self, data):
        """Build the neccesary substructures under this :class:`RTTM`"""
        for key, val in data.items():
            if key == 'region':
                self._region = APIList(DynectSession.get_session, 'region')
                for region in val:
                    code = region.pop('region_code', None)
                    pool = region.pop('pool', None)
                    status = region.pop('status', None)

                    r = RTTMRegion(self._zone, self._fqdn, code, pool,
                                   **region)
                    r._status = status
                    self._region.append(r)
            elif key == 'monitor':
                if self._monitor is not None:
                    self._monitor.zone = self._zone
                    self._monitor.fqdn = self._fqdn
                else:
                    proto = val.pop('protocol', None)
                    inter = val.pop('interval', None)
                    self._monitor = Monitor(proto, inter, **val)
            elif key == 'performance_monitor':
                if self._performance_monitor is not None:
                    self._performance_monitor.zone = self._zone
                    self._performance_monitor.fqdn = self._fqdn
                else:
                    proto = val.pop('protocol', None)
                    inter = val.pop('interval', None)
                    self._performance_monitor = PerformanceMonitor(proto,
                                                                   inter,
                                                                   **val)
            elif key == 'notify_events':
                self._notify_events = [item.strip() for item in val.split(',')]
            elif key == 'active':
                self._active = Active(val)
            elif key == "task_id" and not val:
                self._task_id = None
            elif key == "task_id":
                self._task_id = Task(val)
            else:
                setattr(self, '_' + key, val)
        self._region.uri = self.uri