示例#1
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
示例#2
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)]
示例#3
0
class DispatchPTR(DNSDispatch):
    resource_name = 'ptr'
    dtype = 'PTR'
    dgroup = 'dns'

    create_args = [
        ttl_argument('ttl'),
        ip_argument('ip_str', '4'),
        view_arguments('views'),
        target_argument('name'),
        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(DispatchPTR, 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(DispatchPTR, self).get_update_data(nas)
        data['ip_type'] = self.determine_ip_type(data.get('ip_str', ''))
        return data
示例#4
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
示例#5
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