Beispiel #1
0
class DispatchSRV(DNSDispatch):
    resource_name = 'srv'
    dtype = 'SRV'
    dgroup = 'dns'

    create_args = [
        fqdn_argument('fqdn', dtype),  # ~> (labmda, lambda)
        ttl_argument('ttl'),
        port_argument('port'),
        weight_argument('weight'),
        priority_argument('priority'),
        target_argument('target'),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = create_args + [
        update_pk_argument('pk', dtype)
    ]

    delete_args = [
        delete_pk_argument('pk', dtype)
    ]

    detail_args = [detail_pk_argument('pk', dtype)]
Beispiel #2
0
class DispatchA(DNSDispatch):
    resource_name = 'addressrecord'
    dtype = 'A'
    dgroup = 'dns'
    ip_type = '4'

    create_args = [
        fqdn_argument('fqdn', dtype),  # ~> (labmda, lambda)
        ttl_argument('ttl'),
        ip_argument('ip_str', ip_type),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = create_args + [
        update_pk_argument('pk', dtype)
    ]

    delete_args = [
        delete_pk_argument('pk', dtype)
    ]

    detail_args = [detail_pk_argument('pk', dtype)]

    def get_create_data(self, nas):
        data = super(DispatchA, self).get_create_data(nas)
        data['ip_type'] = self.ip_type
        return data

    def get_update_data(self, nas):
        data = super(DispatchA, self).get_update_data(nas)
        data['ip_type'] = self.ip_type
        return data
Beispiel #3
0
class DispatchAAAA(DispatchA):
    dtype = 'AAAA'
    dgroup = 'dns'

    create_args = [
        fqdn_argument('fqdn', dtype),  # ~> (labmda, lambda)
        ttl_argument('ttl'),
        ip_argument('ip_str', '6'),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = create_args + [update_pk_argument('pk', dtype)]

    delete_args = [delete_pk_argument('pk', dtype)]

    detail_args = [detail_pk_argument('pk', dtype)]
Beispiel #4
0
class DispatchTXT(DNSDispatch):
    resource_name = 'txt'
    dtype = 'TXT'
    dgroup = 'dns'

    create_args = [
        fqdn_argument('fqdn', dtype),  # ~> (labmda, lambda)
        ttl_argument('ttl'),
        target_argument('txt_data'),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = create_args + [update_pk_argument('pk', dtype)]

    delete_args = [delete_pk_argument('pk', dtype)]

    detail_args = [detail_pk_argument('pk', dtype)]
Beispiel #5
0
class DispatchMX(DNSDispatch):
    resource_name = 'mx'
    dtype = 'MX'
    dgroup = 'dns'

    create_args = [
        fqdn_argument('fqdn', dtype),  # ~> (labmda, lambda)
        ttl_argument('ttl'),
        priority_argument('priority'),
        target_argument('server'),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = create_args + [update_pk_argument('pk', dtype)]

    delete_args = [delete_pk_argument('pk', dtype)]

    detail_args = [detail_pk_argument('pk', dtype)]
Beispiel #6
0
class DispatchA(DNSDispatch):
    resource_name = 'addressrecord'
    dtype = 'A'
    dgroup = 'dns'

    create_args = [
        fqdn_argument('fqdn', dtype),  # ~> (labmda, lambda)
        ttl_argument('ttl'),
        ip_argument('ip_str', '4'),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = create_args + [
        update_pk_argument('pk', dtype)
    ]

    delete_args = [
        delete_pk_argument('pk', dtype)
    ]

    detail_args = [detail_pk_argument('pk', dtype)]

    def determine_ip_type(self, ip_str):
        if ip_str.find(':') > -1:
            ip_type = '6'
        else:
            ip_type = '4'  # Default to 4
        return ip_type

    def get_create_data(self, nas):
        data = super(DispatchA, self).get_create_data(nas)
        data['ip_type'] = self.determine_ip_type(data.get('ip_str', ''))
        return data

    def get_update_data(self, nas):
        data = super(DispatchA, self).get_update_data(nas)
        data['ip_type'] = self.determine_ip_type(data.get('ip_str', ''))
        return data
Beispiel #7
0
class DispatchSREG(DNSDispatch):
    object_url = "/en-US/core/api/v1_core/{1}/{2}/"
    object_list_url = "/en-US/core/api/v1_core/{1}/"
    resource_name = 'staticreg'
    dtype = 'SREG'
    dgroup = 'dns'
    ip_type = '4'  # Used for testing

    common_args = [
        fqdn_argument('fqdn', dtype),
        ttl_argument('ttl'),
        ip_argument('ip_str', ip_type),
        view_arguments('views'),
        description_argument('description'),
        comment_argument('comment')
    ]

    update_args = common_args + [
        name_argument('name', prefix='nic'),
        update_pk_argument('pk', dtype)
    ]

    create_args = common_args + [
        system_argument('system_hostname'),
    ]

    delete_args = [delete_pk_argument('pk', dtype)]

    detail_args = [detail_pk_argument('pk', dtype)]

    def get_create_data(self, nas):
        data = super(DispatchSREG, self).get_create_data(nas)
        return set_ip_type('ip_str', data)

    def get_update_data(self, nas):
        data = super(DispatchSREG, self).get_update_data(nas)
        return set_ip_type('ip_str', data)

    def format_hwadapters(self, hws):
        # This is never called if p_json is true
        resp_list = []
        for i, hw in enumerate(hws):
            for k, v in hw.iteritems():
                resp_list.append("\t{0} | {1}: {2}".format(i, k, v))
        return resp_list

    def format_response(self, nas, resp_msg, user_msg):
        # Override this so we can display hwadapters better
        resp_list = []
        if nas.p_json:
            resp_list.append(json.dumps(resp_msg, indent=2))
        else:
            resp_list.append(user_msg)
            for k, v in resp_msg.iteritems():
                if k == 'hwadapter_set':
                    continue  # handle these last
                    # indent these
                else:
                    resp_list.append("{0}: {1}".format(k, v))
            if resp_msg.get('hwadapter_set', None):
                resp_list.append("Hardware Adapters: {0}".format('-' * 20))
                resp_list += self.format_hwadapters(resp_msg['hwadapter_set'])
        return resp_list