#!/usr/bin/env python # -*- coding: utf-8 -*- # kpov_random_helpers 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): from pexpect import pxssh #import pexpect results = dict() peer_user = 'student' peer_passwd = 'vaje' sA = pxssh.pxssh() sB = pxssh.pxssh() #prijavimo se na streznik (IP_NM je IP nalov streznika) sA.login(IP_server, peer_user, peer_passwd) #prijavimo se na klienta (IP_static je IP naslov klienta) sB.login(IP_client, peer_user, peer_passwd) sA.sendline('sudo ps -A') sA.sendline(peer_passwd) sA.prompt() results['dhcp_proces'] = sA.before # tukaj dobimo podatke, ce je na IP_NM naslovu res postavljen DHCP streznik sB.sendline('sudo dhcping -s {} -h {} -c {}'.format(IP_server, MAC_client, IP_client)) sB.sendline(peer_passwd) sB.prompt() results['dhcp'] = sB.before # tukaj pa dobimo podatek, ce je IP, ki ga vraca DNS streznik za HOSTNAME_X pravilen sB.sendline('nslookup {}'.format(HOSTNAME_X)) sB.prompt() results['dns_hostname'] = sB.before sB.sendline('/sbin/ifconfig') sB.prompt() results['client_IP'] = sB.before sA.logout() sB.logout() return results def gen_params(user_id, params_meta): params = dict() r = random.Random(user_id+"bla") net = kpov_random_helpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24) params['IP_server'], params['IP_client'], params['IP_X'] = kpov_random_helpers.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)