summaryrefslogtreecommitdiff
path: root/tasks/set_motd/task.py
blob: 89b78f60346231a0b89edf2d865a8d787df706dd (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
instructions = {
    'si': '''\
<p>
Ustvari dva navidezna računalnika - imenujmo ju <em>arbiter</em> in <em>student</em>.
Na računalniku <em>student</em> ustvarite uporabnika z uporabniškim imenom <code>{{peer_user}}</code>. IP navideznega računalnika <em>student</em> ter geslo za uporabnika <code>{{peer_user}}</code> nastavite sami.

<p>
Poskrbite, da se bo v sporočilu, ki se ob prijavi izpiše na računalniku <em>student</em>, pojavil niz

<pre><code>{{niz}}</code></pre>

<p>
Temu sporočilu v angleščini rečemo <em lang="en">message of the day</em> oziroma <em>MOTD</em>. Ocenjevalni program pričakuje, da se bo ob koncu prijave pojavila ukazna vrstica oblike

<pre><code>username@hostname:~$ </code></pre>

Pazite, da se bo takšna vrstica pojavila šele po nizu, ki ste ga dobili v teh navodilih.
    ''',
    'en': '''\
<p>
Create two virtual machines named <em>arbiter</em> and <em>student</em>. On <em>student</em>, create a user with the username <code>{{peer_user}}</code>. Set the IP of <em>student</em> and the password for <code>{{peer_user}}</code> yourself.

<p>
Set the <em>message of the day</em> (MOTD) on <em>student</em> to

<pre><code>{{niz}}</code></pre>

<p>
This is the message which is displayed when you log in. The grading system expects that after login a prompt similar to

<pre><code>username@hostname:~$ </code></pre>

<p>
appears. Make sure that this line shows up only after the string you got in these instructions.
'''
}

computers = {
    'arbiter': {
        'disks': [{'name': 'dhcp-gw'}],
        'flavor': 'm1.tiny',
        'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
        'config_drive': True,
        'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"}
    },
    'student': {
        'disks': [{ 'name': 'console'}],
        'flavor': 'm1.tiny',
        'network_interfaces': [{'network': 'net1'}],
        'config_drive': True,
        'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"}
    }
}

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

params_meta = {
    'peer_ip': {'descriptions': {'si': 'IP računalnika', 'en':'IP'}, 'w': True, 'public': True, 'type': 'IP', 'generated': False},
    'peer_user': {'descriptions': {'si': 'ime uporabnika', 'en':'Username'}, 'w': False, 'public': True, 'type': 'username', 'generated': True},
    'peer_passwd': {'descriptions': {'si': 'geslo uporabnika', 'en': 'Password'}, 'w': True, 'public': True, 'type': 'alnumstr', 'generated': False},
    'niz': {'descriptions':{'si': 'niz, ki naj se v motd pokaže', 'en': 'The string which should be displayed in the MOTD'}, 'w': False, 'public': True, 'type': 'short_text', 'generated': True},
}

def task(peer_ip, peer_user, peer_passwd, niz):
    "Check whether ssh works and return the MOTD."
    return kpov_util.ssh_test(peer_ip, peer_user, peer_passwd)

def gen_params(user_id, params_meta):
    return kpov_util.default_gen(user_id, params_meta)

def task_check(results, params):
    niz = params['niz']
    score = 0
    hints = []
    if results['ssh'] is True:
        score += 4
        if niz in results['motd']:
            score += 6
        else:
            hints += ['wrong motd:\n' + results['motd'] + '\n']
    else:
        hints += ['ssh failed: ' + results['ssh']]
    return score, hints

def prepare_disks(templates, task_params, global_params):
    write_default_config(templates['dhcp-gw'], global_params)