#!/usr/bin/env python # -*- coding: utf-8 -*- # kpov_random_helpers should be imported by add_assignment.py # Postavi nek film na Internet tako, da ga bodo lahko ostali videli. # TODO: finish this instructions = { 'si':u""" Postavi navidezni računalnik SimpleArbiter z diska simpleArbiter. Posodobi datoteko /etc/apt/sources.list, preveri posodobitve in naloži VLC. Posnemi ali kako drugače ustvari film ter poskrbi, da bo film dostopen na lokalnem omrežju prek RTP z imenom toka {TOK} na naslovu {NASLOV}. Računaj, da bodo film lahko videli tvoji sošolci. Kršenje avtorskih pravic je pri reševanju te naloge strogo prepovedano. """, 'en':u""" Set up a virtual computer SimpleArbiter from the simpleArbiter disk. Update /etc/apt/sources.list, check the for updates and install VLC. Record or otherwise create a movie and make sure the movie is avaliable on your local network via RTP with the name of the stream {TOK} at the address {NASLOV}. Take into account that the movie may be seen by your classmates. Copyright infrigement while solving this task is strictly prohibited. """ } computers = { 'SimpleArbiter': { 'disks': [ { 'name': 'simpleArbiter', # 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 = { 'test-net': {'public': True} } params_meta = { 'NASLOV': {'descriptions': {'si': 'RTP multicast IP naslov'}, 'w': False, 'public':True, 'type': 'stream_name', 'generated': True}, 'PORT': {'descriptions': {'si': 'RTP VRATA'}, 'w': False, 'public':True, 'type': 'port', 'generated': True}, 'TOK': {'descriptions': {'si': 'Naslov (ime) toka'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True}, } def task(NASLOV, TOK): import pexpect results = dict() results['ps'] = pexpect.run('ps xa') results['tcpdump_hex'] = pexpect.run('sudo /usr/sbin/tcpdump -x -c 2 dst host 239.255.255.255 and port 9875'.format(NASLOV)) results['tcpdump'] = pexpect.run('sudo /usr/sbin/tcpdump -c 8 dst host {}'.format(NASLOV)) return results def gen_params(user_id, params_meta): params = dict() r = random.Random(user_id) net = kpov_random_helpers.IPv4_net_gen(r, min_hosts = 16, local=True, multicast=True) params['NASLOV'] = kpov_random_helpers.IPv4_addr_gen(r, net, 1)[0] params['PORT'] = str(r.randint(5000, 6000)) params['TOK'] = kpov_random_helpers.hostname_gen(r) return params def task_check(results, params): import re packs = results['tcpdump_hex'].split('> 239.255.255.255.9875: UDP, length') p1 = packs[1] p1_l = p1.split('\n') p1_d = p1_l[1:-1] p1_s = "" for i in p1_d: p1_s += "".join([j for j in i.split(' ')[1:]]) sname = "".join([ hex(ord(i))[2:] for i in params['TOK']]) if p1_s.find(sname) > 2: score += 5 s = "IP [^ ]* > {}.{}: UDP, length [0-9]+\n\r".format( re.escape(params['NASLOV']), params['PORT']) if re.search(s, results['tcpdump']): score += 5 return score def prepare_disks(templates, params): # d = templates['simpleArbiterDhcp'] pass