summaryrefslogtreecommitdiff
path: root/tasks/dhcp_dns_predefined_ip
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-02-24 21:05:27 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-02-24 21:05:27 +0100
commit8081a5520a441b43a8a7a73f3a90c7aacfaa8e10 (patch)
treec7f49bd33ed19d53afc0ee9df8b2c82c200c5910 /tasks/dhcp_dns_predefined_ip
parent9963b74f777edf985540eac71b1ca095f88b8bca (diff)
Move everything one level up
Diffstat (limited to 'tasks/dhcp_dns_predefined_ip')
-rw-r--r--tasks/dhcp_dns_predefined_ip/task.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/tasks/dhcp_dns_predefined_ip/task.py b/tasks/dhcp_dns_predefined_ip/task.py
new file mode 100644
index 0000000..4822c2a
--- /dev/null
+++ b/tasks/dhcp_dns_predefined_ip/task.py
@@ -0,0 +1,116 @@
+# kpov_util should be imported by add_assignment.py
+
+instructions = {
+ 'si':"""
+<pre>Ustvari tri navidezne računalnike. Za enega (SimpleArbiter) uporabi sliko diska simpleArbiter. Na drugega (DHCP_server) postavi strežnika DHCP in DNS in poskrbi, da ta računalnik dobi IP naslov {IP_server}. Poskrbi, da bo preostali računalnik (DHCP_client) dobil naslov {IP_client}, ki mu ga določi DHCP strežnik. Poskrbi še,da DNS strežnik vrne za hostname {HOSTNAME_X} IP naslov {IP_X}.</pre>
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ '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': '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_server': {'descriptions': {'si': 'IP naslov DHCP streznika'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_client': {'descriptions': {'si': 'IP naslov DHCP klienta'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'MAC_client': {'descriptions': {'si': 'MAC naslov DHCP klienta'}, 'w': True, 'public': True, 'type': 'MAC', 'generated': False},
+ 'HOSTNAME_X': {'descriptions': {'si': 'Hostname za DNS'}, 'w': False, 'public': True, 'type': 'short_text', 'generated': True},
+ 'IP_X': {'descriptions': {'si': 'Naslov, ki ga vrne DNS'}, 'w': False, 'public': False, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_server, IP_client, MAC_client, HOSTNAME_X):
+ tests = {
+ IP_server: (
+ ('dhcp_proces', 'sudo ps -A')),
+ IP_client: (
+ ('dhcp', 'sudo dhcping -s {} -h {} -c {}'.format(IP_server, MAC_client, IP_client)),
+ ('dns_hostname', 'nslookup {}'.format(HOSTNAME_X)),
+ ('client_IP', '/sbin/ifconfig')),
+ }
+
+ results = collections.defaultdict(str)
+ for host, host_tests in tests.items():
+ results.update(kpov_util.ssh_test(host, 'student', 'vaje', host_tests))
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id+"bla")
+ net = kpov_util.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['IP_server'], params['IP_client'], params['IP_X'] = kpov_util.IPv4_addr_gen(r, net, 3)
+ params['HOSTNAME_X'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in range(5)])
+ return params
+
+def task_check(results, params):
+ import re
+ score = 0
+ hints = []
+ if results['dhcp'].find("Got answer from: {}".format(params['IP_server'])) > -1:
+ score += 2
+ else:
+ hints += ["dhcp server IP wrong"]
+ if results['dhcp_proces'].find("dhcpd") > -1:
+ score += 2
+ else:
+ hints += ["dhcp wrong"]
+ if results['dns_hostname'].find("Address: {}".format(params['IP_X'])) >= 0:
+ score += 2
+ else:
+ hints += ['dns hostname IP wrong']
+ if results['dns_hostname'].find("Server:\t\t{}".format(params['IP_server'])) > -1:
+ score += 2
+ else:
+ hints += ['dns server IP wrong']
+ if results['client_IP'].find('inet {}'.format(params['IP_client'])) > -1:
+ score += 2
+ else:
+ hints += ['client IP wrong']
+ return score, hints
+
+
+def prepare_disks(templates, task_params, global_params):
+ write_default_config(templates['simpleArbiterDhcp'], global_params)
+