Пример #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 DispatchHW(ObjectDispatch):
    object_url = "/en-US/core/api/v1_core/{1}/{2}/"
    object_list_url = "/en-US/core/api/v1_core/{1}/"
    resource_name = 'hwadapter'
    dtype = 'HW'
    dgroup = 'dhcp'

    update_args = [
        name_argument('name'),
        mac_argument('mac'),
        group_argument('group'),
        enable_dhcp_argument('enable_dhcp'),
        description_argument('description'),
        comment_argument('comment')
    ]

    create_args = update_args + [
        sreg_argument('sreg'),
    ]

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

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

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

    def format_response(self, nas, resp_msg, user_msg):
        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():
                resp_list.append("{0}: {1}".format(k, v))
        return resp_list
Пример #3
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)]
Пример #4
0
class DispatchSite(CoreDispatch):
    resource_name = 'site'
    dtype = 'SITE'
    dgroup = 'core'

    update_args = [
        name_argument('full_name'),
        comment_argument('comment'),
        description_argument('description'),
        update_pk_argument('pk', dtype)
    ]

    create_args = [
        name_argument('full_name', required=True),
        comment_argument('comment'),
        description_argument('description')
    ]

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

    detail_args = [detail_pk_argument('pk', dtype)]
Пример #5
0
class DispatchVlan(CoreDispatch):
    resource_name = 'vlan'
    dtype = 'VLAN'
    dgroup = 'core'

    update_args = [
        name_argument('name'),
        number_argument('number'),
        comment_argument('comment'),
        description_argument('description'),
        update_pk_argument('pk', dtype)
    ]

    create_args = [
        name_argument('name', required=True),
        number_argument('number', required=True),
        comment_argument('comment'),
        description_argument('description')
    ]

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

    detail_args = [detail_pk_argument('pk', dtype)]
Пример #6
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)]
Пример #7
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)]
Пример #8
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)]
Пример #9
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
Пример #10
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
class DispatchSystem(CoreDispatch):
    object_url = "/en-US/core/api/v1_core/{1}/{2}/"
    object_list_url = "/en-US/core/api/v1_core/{1}/"
    resource_name = 'system'
    dtype = 'SYS'
    dgroup = 'core'

    create_args = [
        foreign_key_argument('operating-system',
                             'The primary key of an OperatingSystem'),
        foreign_key_argument('server-model',
                             'The primary key of a ServerModel'),
        foreign_key_argument('allocation', 'The primary key of an Allocation'),
        foreign_key_argument('system-rack', 'The primary key of a SystemRack'),
        foreign_key_argument('system-type', 'The primary key of a SystemType'),
        foreign_key_argument('system-status',
                             'The primary key of a SystemStatus'),
        general_argument('serial', 'Serial number'),
        general_argument('oob-ip', 'Out of bands ip address'),
        general_argument('asset-tag', 'Asset Tag'),
        general_argument('notes', 'Notes about a system'),
        general_argument('rack-order',
                         'Rack order (e.x.: 1.2, 33, 4.0)',
                         type=float,
                         test_data=lambda: ('rack-order', '1.1')),
        general_argument('switch-ports', 'Switch Port'),
        general_argument('patch-panel-port', 'Patch Panel Port'),
        general_argument('oob-switch-port', 'OOB switch port'),
        date_argument('purchase-date', 'Date purchased'),
        general_argument('purchase-price', 'Purchase Price'),
        datetime_argument(
            'change-password', 'When the last password change was. Format is '
            'yyyy-mm-ddThh-mm (iso-8601)'),
        date_argument('warranty-start', 'Warrenty start date. Format is '
                      'yyyy-mm-dd'),
        date_argument('warranty-end', 'Warrenty end date yyyy-mm-dd'),
        notes_argument('description', 'Notes about this system'),
        comment_argument('comment'),
    ]

    # When a system is updated, there may be a new hostname. A user can use
    # 'new-hostname' to specify a new hostname and use --pk <hostname> to
    # specify which host is getting the new hostname.
    update_args = [system_pk_argument(), new_hostname_argument()] + create_args

    # When a system is created, there must be a hostname
    create_args = create_args + [
        hostname_argument('hostname', 'A valid hostname'),
    ]

    delete_args = [
        system_pk_argument(action='deleting'),
        comment_argument('comment')
    ]

    detail_args = [system_pk_argument(action='detailing')]

    def update_url(self, nas):
        pk = nas.pk or nas.hostname
        return self.object_url.format(API_MAJOR_VERSION, self.resource_name,
                                      pk)
Пример #12
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
Пример #13
0
class DispatchNetwork(CoreDispatch):
    resource_name = 'network'
    dtype = 'NET'
    dgroup = 'core'
    ip_type = None

    def test_setup(self):
        def setUp(self):
            def create_site():
                command = [EXEC, DispatchSite.dtype, 'create']
                for add_arg, extract_arg, test_f in DispatchSite.create_args:
                    command.append(test_method_to_params(test_f()))

                site_ret, site_errors, site_rc = call_to_json(
                    ' '.join(command))

                if site_errors:
                    self.fail(site_errors)

                self.assertEqual(0, site_rc)

                # Make sure the SREG was created correctly
                self.assertTrue('http_status' in site_ret)
                self.assertEqual(site_ret['http_status'], 201)
                self.assertTrue('pk' in site_ret)
                return site_ret['pk']

            def create_vlan():
                command = [EXEC, DispatchVlan.dtype, 'create']
                for add_arg, extract_arg, test_f in DispatchVlan.create_args:
                    command.append(test_method_to_params(test_f()))

                vlan_ret, vlan_errors, vlan_rc = call_to_json(
                    ' '.join(command))

                if vlan_errors:
                    self.fail(vlan_errors)

                self.assertEqual(0, vlan_rc)

                # Make sure the SREG was created correctly
                self.assertTrue('http_status' in vlan_ret)
                self.assertEqual(vlan_ret['http_status'], 201)
                self.assertTrue('pk' in vlan_ret)
                return vlan_ret['pk']

            self.site_pk = create_site()
            self.vlan_pk = create_site()

            def modify_command(command_str):
                command_str = command_str.replace('{{ site }}',
                                                  str(self.site_pk))
                command_str = command_str.replace('{{ vlan }}',
                                                  str(self.vlan_pk))
                return command_str

            self.modify_command = modify_command

        return setUp

    def test_teardown(self):
        def tearDown(self):
            # Delete the object
            def delete_vlan():
                delete_command = "{0} {1} delete --pk {2}".format(
                    EXEC, 'VLAN', self.vlan_pk)
                ret, errors, rc = call_to_json(delete_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)
                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 204)

            def delete_site():
                delete_command = "{0} {1} delete --pk {2}".format(
                    EXEC, 'SITE', self.vlan_pk)
                ret, errors, rc = call_to_json(delete_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)
                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 204)

            delete_vlan()
            delete_site()

        return tearDown

    update_args = [
        site_argument('site'),
        vlan_argument('vlan'),
        network_str_argument('network-str'),
        comment_argument('comment'),
        description_argument('description'),
        update_pk_argument('pk', dtype)
    ]

    create_args = [
        site_argument('site'),
        vlan_argument('vlan'),
        network_str_argument('network-str'),
        comment_argument('comment'),
        description_argument('description'),
    ]

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

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

    def get_create_data(self, nas):
        data = super(DispatchNetwork, self).get_create_data(nas)
        return set_ip_type('network_str', data)

    def get_update_data(self, nas):
        data = super(DispatchNetwork, self).get_update_data(nas)
        return set_ip_type('network_str', data)