Ejemplo n.º 1
0
def text_argument(field_name):
    def add_text_argument(parser, required=True):
        parser.add_argument(
            '--text', default=None, type=str, dest='text',
            help="The text data.", required=required
        )

    def test_data():
        return 'text', TEST_TEXT

    return add_text_argument, build_extractor(field_name, 'text'), test_data
Ejemplo n.º 2
0
def value_argument(field_name):
    def add_value_argument(parser, required=True):
        parser.add_argument(
            '--value/-v', default=None, type=str, dest='value',
            help="The value.", required=required
        )

    def test_data():
        return 'value', 'testvalue'

    return add_value_argument, build_extractor(field_name, 'value'), test_data
Ejemplo n.º 3
0
def priority_argument(field_name):
    def add_priority_arg(parser, required=True):
        write_num_argument(
            parser, 'priority', 'priority', "The priority number of a record",
            required=required
        )

    def test_data():
        return 'priority', TEST_PRIORITY

    return add_priority_arg, build_extractor(field_name, 'priority'), test_data
Ejemplo n.º 4
0
def group_argument(field_name):
    def add_group_argument(parser, required=False):
        parser.add_argument(
            '--dhcp-group', type=str, dest='group',
            default='', required=required, help="The name of an existing dhcp "
            "group"
        )
    test_data = lambda: ''

    extractor = build_extractor(field_name, field_name)
    return add_group_argument, extractor, test_data
Ejemplo n.º 5
0
def key_argument(field_name):
    def add_key_argument(parser, required=True):
        parser.add_argument(
            '--key/-k', default=None, type=str, dest='key',
            help="The key.", required=required
        )

    def test_data():
        return 'key', 'testkey'

    return add_key_argument, build_extractor(field_name, 'key'), test_data
Ejemplo n.º 6
0
def port_argument(field_name):
    def add_port_argument(parser, required=True):
        write_num_argument(
            parser, 'port', 'port', "The target port of an SRV " "record",
            required=required
        )

    def test_data():
        return 'port', TEST_PORT

    return add_port_argument, build_extractor(field_name, 'port'), test_data
Ejemplo n.º 7
0
def weight_argument(field_name):
    def add_weight_arg(parser, required=True):
        write_num_argument(
            parser, 'weight', 'weight', "The " "weight number of an SRV "
            "record", required=required
        )

    def test_data():
        return 'weight', TEST_WEIGHT

    return add_weight_arg, build_extractor(field_name, 'weight'), test_data
Ejemplo n.º 8
0
def target_argument(field_name):
    def add_target_arg(parser, required=True):
        parser.add_argument(
            '--target', default=None, type=str, dest='target',
            help="The target name of a record", required=required
        )

    def test_data():
        return 'target', TEST_FQDN

    return add_target_arg, build_extractor(field_name, 'target'), test_data
Ejemplo n.º 9
0
def name_argument(field_name, required=False):
    def add_name_arg(parser, required=required, **kwargs):
        parser.add_argument(
            '--{0}'.format(field_name), type=str,
            dest=field_name, help="A name.",
            required=required
        )

    def test_data():
        return field_name, TEST_NAME()  # Reuse this test data

    return add_name_arg, build_extractor(field_name, field_name), test_data
Ejemplo n.º 10
0
def name_argument(field_name, prefix='nic'):
    def add_com_arg(parser, required=False, **kwargs):
        parser.add_argument('--{0}'.format('name'),
                            type=str,
                            dest='name',
                            help="A short name",
                            required=required)

    def test_data():
        return 'name', TEST_INAME(prefix=prefix)  # Reuse this test data

    return add_com_arg, build_extractor(field_name, 'name'), test_data
Ejemplo n.º 11
0
def priority_argument(field_name):
    def add_priority_arg(parser, required=True):
        write_num_argument(parser,
                           'priority',
                           'priority',
                           "The priority number of a record",
                           required=required)

    def test_data():
        return 'priority', TEST_PRIORITY

    return add_priority_arg, build_extractor(field_name, 'priority'), test_data
Ejemplo n.º 12
0
def mac_argument(field_name):
    def add_com_arg(parser, required=True, **kwargs):
        parser.add_argument(
            '--{0}'.format(field_name), default="", type=str,
            dest='mac', help="Mac Address",
            required=required
        )

    def test_data():
        return field_name, TEST_MAC()

    return add_com_arg, build_extractor(field_name, field_name), test_data
def name_argument(field_name, required=False):
    def add_name_arg(parser, required=required, **kwargs):
        parser.add_argument('--{0}'.format(field_name),
                            type=str,
                            dest=field_name,
                            help="A name.",
                            required=required)

    def test_data():
        return field_name, TEST_NAME()  # Reuse this test data

    return add_name_arg, build_extractor(field_name, field_name), test_data
Ejemplo n.º 14
0
def port_argument(field_name):
    def add_port_argument(parser, required=True):
        write_num_argument(parser,
                           'port',
                           'port', "The target port of an SRV "
                           "record",
                           required=required)

    def test_data():
        return 'port', TEST_PORT

    return add_port_argument, build_extractor(field_name, 'port'), test_data
Ejemplo n.º 15
0
def name_argument(field_name):
    def add_com_arg(parser, required=True, **kwargs):
        parser.add_argument(
            '--{0}'.format('name'), type=str,
            dest='name', help="A short name",
            required=required
        )

    def test_data():
        return 'name', TEST_INAME()  # Reuse this test data

    return add_com_arg, build_extractor(field_name, 'name'), test_data
def mac_argument(field_name):
    def add_com_arg(parser, required=True, **kwargs):
        parser.add_argument('--{0}'.format(field_name),
                            default="",
                            type=str,
                            dest='mac',
                            help="Mac Address",
                            required=required)

    def test_data():
        return field_name, TEST_MAC()

    return add_com_arg, build_extractor(field_name, field_name), test_data
Ejemplo n.º 17
0
def new_hostname_argument():
    def add_srt_arg(parser, **kwargs):
        parser.add_argument(
            '--new-hostname', default="", type=str,
            dest='hostname', required=False, help='If you are changing the '
            'hostname of an existing system specify it with --hostname and '
            'use this option to assign a new hostname'
        )

    def test_data():
        return 'new-hostname', TEST_STR()

    return add_srt_arg, build_extractor('hostname', 'hostname'), test_data
Ejemplo n.º 18
0
def value_argument(field_name):
    def add_value_argument(parser, required=True):
        parser.add_argument('--value/-v',
                            default=None,
                            type=str,
                            dest='value',
                            help="The value.",
                            required=required)

    def test_data():
        return 'value', 'testvalue'

    return add_value_argument, build_extractor(field_name, 'value'), test_data
Ejemplo n.º 19
0
def target_argument(field_name):
    def add_target_arg(parser, required=True):
        parser.add_argument('--target',
                            default=None,
                            type=str,
                            dest='target',
                            help="The target name of a record",
                            required=required)

    def test_data():
        return 'target', TEST_FQDN

    return add_target_arg, build_extractor(field_name, 'target'), test_data
Ejemplo n.º 20
0
def weight_argument(field_name):
    def add_weight_arg(parser, required=True):
        write_num_argument(parser,
                           'weight',
                           'weight', "The "
                           "weight number of an SRV "
                           "record",
                           required=required)

    def test_data():
        return 'weight', TEST_WEIGHT

    return add_weight_arg, build_extractor(field_name, 'weight'), test_data
Ejemplo n.º 21
0
def key_argument(field_name):
    def add_key_argument(parser, required=True):
        parser.add_argument('--key/-k',
                            default=None,
                            type=str,
                            dest='key',
                            help="The key.",
                            required=required)

    def test_data():
        return 'key', 'testkey'

    return add_key_argument, build_extractor(field_name, 'key'), test_data
def number_argument(field_name, required=False):
    def add_number_argument(parser, required=required):
        write_num_argument(parser,
                           field_name,
                           field_name,
                           "A number number.",
                           required=required)

    def test_data():
        return field_name, TEST_PORT

    return (add_number_argument, build_extractor(field_name,
                                                 field_name), test_data)
Ejemplo n.º 23
0
def foreign_key_argument(field_name, help):
    real_fname = field_name.replace('-', '_')

    def add_srt_arg(parser, **kwargs):
        parser.add_argument(
            '--{0}-pk'.format(field_name), default="", type=str,
            dest=real_fname, required=False, help=help
        )

    def test_data():
        return '', ''

    return add_srt_arg, build_extractor(real_fname, real_fname), test_data
Ejemplo n.º 24
0
def str_argument(field_name, help):
    display_name = field_name.replace('_', '-')

    def add_srt_arg(parser, **kwargs):
        parser.add_argument(
            '--{0}'.format(display_name), default="", type=str,
            dest=field_name, required=False, help=help
        )

    def test_data():
        return field_name, TEST_STR()  # Reuse this test data

    return add_srt_arg, build_extractor(field_name, field_name), test_data
Ejemplo n.º 25
0
def text_argument(field_name):
    def add_text_argument(parser, required=True):
        parser.add_argument('--text',
                            default=None,
                            type=str,
                            dest='text',
                            help="The text data.",
                            required=required)

    def test_data():
        return 'text', TEST_TEXT

    return add_text_argument, build_extractor(field_name, 'text'), test_data
def group_argument(field_name):
    def add_group_argument(parser, required=False):
        parser.add_argument('--dhcp-group',
                            type=str,
                            dest='group',
                            default='',
                            required=required,
                            help="The name of an existing dhcp "
                            "group")

    test_data = lambda: ''

    extractor = build_extractor(field_name, field_name)
    return add_group_argument, extractor, test_data
Ejemplo n.º 27
0
def system_argument(field_name):
    # We need rdtype because SRV requires a '_' to prefix it's test data
    def add_system_argument(parser, required=True):
        parser.add_argument(
            '--{0}'.format(field_name), default="", type=str, dest=field_name,
            help="The hostname of the system this registration is associated "
            "with", required=True
        )

    def test_data():
        return 'system_hostname', 'toolsdev1.dmz.scl3.mozilla.com'

    extractor = build_extractor(field_name, field_name)
    return add_system_argument, extractor, test_data
Ejemplo n.º 28
0
def system_argument(field_name):
    display_name = field_name.replace('_', '-')

    def add_system_argument(parser, required=True):
        parser.add_argument(
            '--{0}'.format(display_name), default="", type=str,
            dest=field_name, help="The hostname of the system this "
            "registration is associated with", required=True
        )

    def test_data():
        return 'system-hostname', 'toolsdev1.dmz.scl3.mozilla.com'

    extractor = build_extractor(field_name, field_name)
    return add_system_argument, extractor, test_data
Ejemplo n.º 29
0
def number_argument(field_name, required=False):
    def add_number_argument(parser, required=required):
        write_num_argument(
            parser, field_name, field_name, "A number number.",
            required=required
        )

    def test_data():
        return field_name, TEST_PORT

    return (
        add_number_argument,
        build_extractor(field_name, field_name),
        test_data
    )
Ejemplo n.º 30
0
def notes_argument(field_name, help):
    """
    Work around for systems calling it 'Notes' and everything else calling it
    'Description'.
    """
    def add_srt_arg(parser, **kwargs):
        parser.add_argument(
            '--description', default="", type=str, dest='notes',
            required=False, help=help
        )

    def test_data():
        return 'description', 'asdfasdf'

    return add_srt_arg, build_extractor('notes', 'notes'), test_data
Ejemplo n.º 31
0
def ip_argument(field_name, ip_type):
    def add_ip_argument(parser, required=True):
        parser.add_argument(
            '--ip', default=None, type=str, dest='ip',
            help="A string representation of an IP address.",
            required=required
        )

    def test_data():
        if ip_type == '4':
            return 'ip', TEST_IPv4()
        elif ip_type == '6':
            return 'ip', TEST_IPv6()

    return add_ip_argument, build_extractor(field_name, 'ip'), test_data
Ejemplo n.º 32
0
def ttl_argument(field_name):
    def add_ttl_argument(parser, **kwargs):
        write_num_argument(
            parser, 'ttl', 'ttl', "The ttl of a record.", required=False
        )

    def extract_ttl(nas):
        data = {}
        if nas.ttl:
            data['ttl'] = nas.ttl
        return data

    def test_data():
        return 'ttl', TEST_TTL

    return add_ttl_argument, build_extractor(field_name, 'ttl'), test_data
Ejemplo n.º 33
0
def ip_argument(field_name, ip_type):
    def add_ip_argument(parser, required=True):
        parser.add_argument('--ip',
                            default=None,
                            type=str,
                            dest='ip',
                            help="A string representation of an IP address.",
                            required=required)

    def test_data():
        if ip_type == '4':
            return 'ip', TEST_IPv4()
        elif ip_type == '6':
            return 'ip', TEST_IPv6()

    return add_ip_argument, build_extractor(field_name, 'ip'), test_data
Ejemplo n.º 34
0
def system_argument(field_name):
    # We need rdtype because SRV requires a '_' to prefix it's test data
    def add_system_argument(parser, required=True):
        parser.add_argument(
            '--{0}'.format(field_name),
            default="",
            type=str,
            dest=field_name,
            help="The hostname of the system this registration is associated "
            "with",
            required=True)

    def test_data():
        return 'system_hostname', 'toolsdev1.dmz.scl3.mozilla.com'

    extractor = build_extractor(field_name, field_name)
    return add_system_argument, extractor, test_data
Ejemplo n.º 35
0
def system_argument(field_name):
    display_name = field_name.replace('_', '-')

    def add_system_argument(parser, required=True):
        parser.add_argument('--{0}'.format(display_name),
                            default="",
                            type=str,
                            dest=field_name,
                            help="The hostname of the system this "
                            "registration is associated with",
                            required=True)

    def test_data():
        return 'system-hostname', 'toolsdev1.dmz.scl3.mozilla.com'

    extractor = build_extractor(field_name, field_name)
    return add_system_argument, extractor, test_data
Ejemplo n.º 36
0
def ttl_argument(field_name):
    def add_ttl_argument(parser, **kwargs):
        write_num_argument(parser,
                           'ttl',
                           'ttl',
                           "The ttl of a record.",
                           required=False)

    def extract_ttl(nas):
        data = {}
        if nas.ttl:
            data['ttl'] = nas.ttl
        return data

    def test_data():
        return 'ttl', TEST_TTL

    return add_ttl_argument, build_extractor(field_name, 'ttl'), test_data
Ejemplo n.º 37
0
def fqdn_argument(field_name, rdtype):
    # We need rdtype because SRV requires a '_' to prefix it's test data
    def add_fqdn_argument(parser, required=True):
        parser.add_argument(
            '--fqdn', default="", type=str, dest='fqdn',
            help="The FQDN of the record being created. If you use this "
            "option you cannot use label or domain", required=False
        )

    def test_data():
        if rdtype == "CNAME":
            # Make the target different so avoid cname loop errors
            return 'fqdn', "A" + TEST_FQDN
        if rdtype == "SRV":
            return 'fqdn', "_" + TEST_FQDN
        else:
            return 'fqdn', TEST_FQDN

    return add_fqdn_argument, build_extractor(field_name, 'fqdn'), test_data
Ejemplo n.º 38
0
def system_detail_pk_argument():
    def add_pk_arg(parser, **kwargs):
        arg_g = parser.add_mutually_exclusive_group(required=True)
        arg_g.add_argument(
            '--hostname', type=str, dest='pk',
            help='The hostname of a system you are detailing'
        )
        arg_g.add_argument(
            '--pk', type=str, dest='pk',
            help='The integer primary key of a system you are detailing'
        )

    def extract_pk(nas):
        if nas.hostname:
            return {'pk': nas.hostname}
        else:
            return {'pk': nas.pk}

    return add_pk_arg, build_extractor('hostname', 'hostname'), lambda: None
Ejemplo n.º 39
0
def enable_dhcp_argument(field_name):
    def add_enable_dhcp_argument(parser, required=False):
        dhcp_group = parser.add_mutually_exclusive_group()

        dhcp_group.add_argument(
            '--no-dhcp', default=False, action='store_false',
            dest='enable_dhcp', help="Disable dhcp.", required=required
        )

        dhcp_group.add_argument(
            '--dhcp', default=True, action='store_true', dest='enable_dhcp',
            help="Enabled dhcp (True by default).", required=required
        )

    def test_data():
        return '', '--no-dhcp'

    extractor = build_extractor(field_name, 'enable_dhcp')

    return add_enable_dhcp_argument, extractor, test_data
Ejemplo n.º 40
0
def system_pk_argument(action='updating'):
    def add_pk_arg(parser, **kwargs):
        arg_g = parser.add_mutually_exclusive_group(required=True)
        arg_g.add_argument(
            '--hostname', type=str, dest='pk',
            help='The hostname of a system you are {0}'.format(action)
        )
        arg_g.add_argument(
            '--pk', type=str, dest='pk',
            help='The integer primary key of a system you are '
            '{0}'.format(action)
        )

    def extract_pk(nas):
        if nas.hostname:
            return {'pk': nas.hostname}
        else:
            return {'pk': nas.pk}

    return add_pk_arg, build_extractor('hostname', 'hostname'), lambda: None
Ejemplo n.º 41
0
def fqdn_argument(field_name, rdtype):
    # We need rdtype because SRV requires a '_' to prefix it's test data
    def add_fqdn_argument(parser, required=True):
        parser.add_argument(
            '--fqdn',
            default="",
            type=str,
            dest='fqdn',
            help="The FQDN of the record being created. If you use this "
            "option you cannot use label or domain",
            required=required)

    def test_data():
        if rdtype == "CNAME":
            # Make the target different so avoid cname loop errors
            return 'fqdn', "A" + TEST_FQDN
        if rdtype == "SRV":
            return 'fqdn', "_" + TEST_FQDN
        else:
            return 'fqdn', TEST_FQDN

    return add_fqdn_argument, build_extractor(field_name, 'fqdn'), test_data
def network_str_argument(field_name, required=False):
    def add_network_argument(parser, required=required):
        parser.add_argument('--{0}'.format(field_name),
                            type=str,
                            dest='network_str',
                            required=required,
                            help="Complete CIDR Notation")

    def test_data():
        return 'network-str', TEST_NETWORK

    def build_extractor(field_name, nas_name):
        def extractor(nas):
            if not getattr(nas, nas_name):
                return {}
            data = {field_name: getattr(nas, nas_name)}
            return data

        return extractor

    return (add_network_argument, build_extractor('network_str',
                                                  'network_str'), test_data)
Ejemplo n.º 43
0
def network_str_argument(field_name, required=False):
    def add_network_argument(parser, required=required):
        parser.add_argument(
            '--{0}'.format(field_name), type=str, dest='network_str',
            required=required, help="Complete CIDR Notation"
        )

    def test_data():
        return 'network-str', TEST_NETWORK

    def build_extractor(field_name, nas_name):
        def extractor(nas):
            if not getattr(nas, nas_name):
                return {}
            data = {field_name: getattr(nas, nas_name)}
            return data
        return extractor

    return (
        add_network_argument,
        build_extractor('network_str', 'network_str'),
        test_data
    )
def enable_dhcp_argument(field_name):
    def add_enable_dhcp_argument(parser, required=False):
        dhcp_group = parser.add_mutually_exclusive_group()

        dhcp_group.add_argument('--no-dhcp',
                                default=False,
                                action='store_false',
                                dest='enable_dhcp',
                                help="Disable dhcp.",
                                required=required)

        dhcp_group.add_argument('--dhcp',
                                default=True,
                                action='store_true',
                                dest='enable_dhcp',
                                help="Enabled dhcp (True by default).",
                                required=required)

    def test_data():
        return '', '--no-dhcp'

    extractor = build_extractor(field_name, 'enable_dhcp')

    return add_enable_dhcp_argument, extractor, test_data