# SPDX-License-Identifier: AGPL-3.0-or-later # kpov_util should be imported by add_assignment.py instructions = { 'si':"""
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}.
""" } 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)