summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/set_ip_dhcp_hostname/task.py
blob: 77648e6bfb7cdc751612dca0be6e40bc619b2f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# kpov_util should be imported by add_assignment.py

instructions = {
    'si':"""
Ustvari tri navidezne računalnike. Za disk prvega uporabi sliko diska simpleArbiterDhcp.
Za enega od ostalih dveh (Z_DHCP) poskrbi, da bo dobil IP prek DHCP, pri čemer
naj kot hostname strežniku pošlje ime, ki ga dobiš na simpleArbiterDhcp. 
Za drugega (BREZ_DHCP) poskrbi, da bo imel statično nastavljen IP.

Prvi omrežni vmesnik računalnika SimpleArbiter naj bo povezan na Internet. Drugi naj bo povezan na neko lokalno omrežje, na katerega bosta priklopljena računalnika Z_DHCP ter BREZ_DHCP. Na računalniku Z_DHCP poskrbite, da bo ob pridobivanju naslova DHCP strežniku poslal tudi posebej nastavljeno ime računalnika (hostname), ki ne bo enako dejanskemu imenu računalnika (tistemu, ki ga izpiše ukaz hostname).

Naslov BREZ_DHCP ter ime računalnika za Z_DHCP dobite ob zagonu run_test.py na računalniku SimpleArbiter.
"""
}

computers = {
    'Z_DHCP': {
        'disks': [
            {   'name': 'Z_DHCP',
            },
            #{   'name': 'CDROM',
            #    'options':{'readonly': True},
            #    'parts': [],# no parts, no mounting.
            #}
        ],
        'network_interfaces': [{'network': 'net1'}],
        'flavor': 'm1.tiny',
        'config_drive': False

    },
    'BREZ_DHCP': {
        'disks': [
            {   'name': 'BREZ_DHCP',
            },
            #{   'name': 'CDROM',
            #    'options':{'readonly': True},
            #    'parts': [],# no parts, no mounting.
            #}
        ],
        'network_interfaces': [{'network': 'net1'}],
        'flavor': 'm1.tiny',
        'config_drive': False

    },
    'SimpleArbiter': {
        'disks': [
            {   'name': 'simpleArbiterDhcp',
                # attempt automount
            },
            #{   'name': 'CDROM',
            #    'options': {'readonly': True},
            #    'parts': [{'dev': 'b1', 'path': '/cdrom'}],
            #},
        ],
        'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
        'flavor': 'm1.tiny',
        'config_drive': False
    }
}

networks = { 'net1': {'public': False}, 'test-net': {'public': True} }

params_meta = {
    'IP_DHCP': {'descriptions': {'si': 'Naslov za DHCP'}, 'w': False, 'public': False, 'type': 'IP', 'generated': True},
    'Hostname_DHCP': {'descriptions': {'si': 'Ime DHCP'}, 'w': False, 'public': True, 'type': 'hostname', 'generated': True},
    'IP_static': {'descriptions': {'si': 'Naslov BREZ_DHCP'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
    'IP_dhcp_static': {'descriptions': {'si': 'Dodeljen IP brez DHCP'}, 'w': False, 'public': False, 'type': 'IP', 'generated': True},
}

def task(IP_DHCP, Hostname_DHCP, IP_static, MAC_static, IP_dhcp_static):
    from pexpect import pxssh
    import pexpect
    results = dict()
    # check hostname of DHCP
    # check the hostname in the response of IP_DHCP
    # check availability of IP_static
    # check non-availability of IP_dhcp_static
    return results
                       
def gen_params(user_id, params_meta):
    r = random.Random(user_id)
    # IP_NM, DNS_NM, IP_static, DNS_static)
    net = kpov_util.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
    params['IP_DHCP'], params['IP_static'], params['IP_dhcp_static'] = kpov_util.IPv4_addr_gen(r, net, 3)
    params['Hostname_DHCP'] = kpov_util.hostname_gen(r)
    return params

def task_check(results, params):
    import re
    score = -9
    hints = []
    if results['bla']:
        score += 3
    return score, hints

def prepare_disks(templates, task_params, global_params):
#    d = templates['simpleArbiterDhcp']
#   create config for static_DHCP
#   set static_DHCP hostname
    write_default_config(templates['simpleArbiterDhcp'], global_params)