Exemplo n.º 1
0
 def _mod_geo_Create(self, dyn_zone, change):
     new = change.new
     fqdn = new.fqdn
     _type = new._type
     label = '{}:{}'.format(fqdn, _type)
     node = DSFNode(new.zone.name, fqdn)
     td = TrafficDirector(label, ttl=new.ttl, nodes=[node], publish='Y')
     self.log.debug('_mod_geo_Create: td=%s', td.service_id)
     self._mod_rulesets(td, change)
     self.traffic_directors[fqdn] = {_type: td}
Exemplo n.º 2
0
def _new_dyn_traffic_director_service(name,
                                      ttl=DEFAULT_TD_TTL,
                                      records=None,
                                      attach_nodes=None) -> TrafficDirector:
    """Creates an opinionated Dyn Traffic Director service

    - Creates a CNAME recordset
    - Expects all records to be DSFCNAMERecord type
    - Creates a single failover chain pointing to the recordset
    - Creates a single pool pointing to the failover chain
    - Creates a single ruleset that always responds and points to the pool

    NOTE: The dyn module TrafficDirector constructor has side effects and calls
          the Dyn API multiple times. It is possible that Dyn resources are
          created even if the constructor failed
    """

    if records is None:
        records = []
    if attach_nodes is None:
        attach_nodes = []

    try:
        record_set = DSFRecordSet('CNAME',
                                  label=name,
                                  automation='manual',
                                  records=records)
        failover_chain = DSFFailoverChain(label=name, record_sets=[record_set])
        rpool = DSFResponsePool(label=name, rs_chains=[failover_chain])
        ruleset = DSFRuleset(label=name,
                             criteria_type='always',
                             response_pools=[rpool])

        # Constructor does the actual resource creation and checking for
        # creation completion.
        # It returns returns a resource ID which we don't need
        return TrafficDirector(name,
                               ttl=ttl,
                               rulesets=[ruleset],
                               nodes=attach_nodes)
    except Exception as e:
        raise CreateTrafficDirectorError(
            f'Exception caught during creation of Traffic Director: {name} '
            f'The exception was: {e}')