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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# kpov_random_helpers should be imported by add_assignment.py
# TODO: finish this!
instructions = {
'si':u"""
Postavi dva navidezna racunalnika:
- SimpleArbiterDhcpRdate s slike diska simpleArbiterRdate ter
-rdateClient.
Na rdateClient ustvarite uporabnika test z geslom test. Nastavite cas na
rdateClient tako, da kot rdate strežnik uporabite SimpleArbiterDhcpRdate.
Nato v domacem imeniku uporabnika test spravite program z imenom guliver,
ki prebere 4 byte podatkov s standardnega vhoda in jih pretvori v
predznaceno celo število, pri cemer naj uporablja zapis z debelim koncem
(big endian).
Število naj program izpiše na standardni izhod.
V param_meta dodajte parameter, katerega vrednost bo nakljucen string
sestavljen iz crk in stevilk.Tega parametra student ne bo mogel
nastavljati sam. S tem parametrom se bo preverjalo ali je prišlo do
prepisovanja.
"""
'en':u"""
Setup two virtual machines:
-SimpleArbiterDhcpRdate from disk image simpleArbiterRdate and
-rdateClient.
On rdateClient create a user "test" with password "test". Set time on rdateClient
so that it will use SimpleArbiterDhcpRdate as it's rdate server. After that create
a program named guliver in the root directory of user "test". This program has to
read 4bytes from standard input and convert them to signed number using big endian rule.
Write this number to standard output.
Generate a random string from both letters and numbers and add it as a parameter
to param_meta. This parameter will not be accessible to students and will be used
to check if student copied his work from someone else.
"""
}
computers = {
'rdateClient': {
'disks': [
{ 'name': 'maliBrezNetworkManager',
},
#{ 'name': 'CDROM',
# 'options':{'readonly': True},
# 'parts': [],# no parts, no mounting.
#}
],
'network_interfaces': [{'network': 'net1'}],
'flavor': 'm1.tiny',
'config_drive': False
},
'SimpleArbiter': {
'disks': [
{ 'name': 'simpleArbiterDhcpRdate',
# 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} }
# Tu sem dolocil parametre
params_meta = {
'Ime':{}
'Datum':{}
'Sifra':{}
}
def task(IP_NM, DNS_NM, IP_static, DNS_static):
import pxssh
import pexpect
results = dict()
peer_user = 'student'
peer_passwd = 'vaje'
sA = pxssh.pxssh()
sB = pxssh.pxssh()
sA.login(IP_NM, peer_user, peer_passwd)
sB.login(IP_static, peer_user, peer_passwd)
# sA
# make sure NM is not handling eth0
results['NM_nmcli'] = sA.run('nmcli d')
results['NM_nslookup'] = sA.run('nslookup www.arnes.si')
# sB
# check whether NM is handling eth0
results['static_nmcli'] = sB.run('nmcli d')
results['static_nslookup'] = sB.run('nslookup www.arnes.si')
sA.logout()
sB.logout()
return results
#Dolocil sem tri parametre in sicer jih lahko vidite v prams_meta,
#zato prosim da jih upostevate v naslednih nalogah.
def gen_params(user_id, params_meta):
import socket
import struct
import datetime
params = dict()
r = random.Random(user_id)
params['Ime'] = "guliver"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("ntp1.arnes.si",37))
podatek = s.recv(4)
stevilka = struct.unpack("!I",podatek)
stevilka = stevilka[0]
t = datetime.date(year=1850,month=1,day=1)
t = t + datetime.timedelta(seconds=stevilka)
params['Datum'] = t
rez = ""
crke = "ABCDEFGHIJKLMNOPRSTUVZXYQ"
c = random.Random(crke)
for x in user_id:
rez += x + c.choice()
params['Sifra'] = rez
return params
def task_check(results, params):
import re
score = 0
if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1:
score += 3
if results['static_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_static'])) > -1:
score += 3
if re.search(r'eth0 +802-.*connected', results['NM_nmcli']):
score += 2
if not re.search(r'eth0 +802-.*connected', results['static_nmcli']):
score += 2
#score = 0
return score
def prepare_disks(templates, params):
# d = templates['simpleArbiterDhcp']
pass
|